mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 05:53:27 -07:00
Trying out some stability changes, seems to work without side effects.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1867 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
d0ff4fbed6
commit
5076163b92
3 changed files with 66 additions and 48 deletions
|
@ -249,6 +249,7 @@ namespace Greenshot.Interop {
|
||||||
/// </param>
|
/// </param>
|
||||||
private void Dispose(bool disposing) {
|
private void Dispose(bool disposing) {
|
||||||
if (null != this._COMObject) {
|
if (null != this._COMObject) {
|
||||||
|
LOG.DebugFormat("Disposing {0}", this._InterceptType.ToString());
|
||||||
if (Marshal.IsComObject(this._COMObject)) {
|
if (Marshal.IsComObject(this._COMObject)) {
|
||||||
try {
|
try {
|
||||||
while (Marshal.ReleaseComObject(this._COMObject) > 0) ;
|
while (Marshal.ReleaseComObject(this._COMObject) > 0) ;
|
||||||
|
|
|
@ -59,18 +59,22 @@ namespace Greenshot.Interop.Office {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Inspectors inspectors = outlookApplication.Inspectors;
|
using (Inspectors inspectors = outlookApplication.Inspectors) {
|
||||||
if (inspectors != null && inspectors.Count > 0) {
|
if (inspectors != null && inspectors.Count > 0) {
|
||||||
for (int i = 1; i <= inspectors.Count; i++) {
|
for (int i = 1; i <= inspectors.Count; i++) {
|
||||||
Inspector inspector = outlookApplication.Inspectors[i];
|
using (Inspector inspector = outlookApplication.Inspectors[i]) {
|
||||||
if (canExportToInspector(inspector, allowMeetingAsTarget)) {
|
string inspectorCaption = inspector.Caption;
|
||||||
Item currentItem = inspector.CurrentItem;
|
using (Item currentItem = inspector.CurrentItem) {
|
||||||
|
if (canExportToInspector(currentItem, allowMeetingAsTarget)) {
|
||||||
OlObjectClass currentItemClass = currentItem.Class;
|
OlObjectClass currentItemClass = currentItem.Class;
|
||||||
inspectorCaptions.Add(inspector.Caption, currentItemClass);
|
inspectorCaptions.Add(inspector.Caption, currentItemClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.Warn("Problem retrieving word destinations, ignoring: ", ex);
|
LOG.Warn("Problem retrieving word destinations, ignoring: ", ex);
|
||||||
}
|
}
|
||||||
|
@ -80,12 +84,11 @@ namespace Greenshot.Interop.Office {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return true if we can export to the supplied inspector
|
/// Return true if we can export to the supplied inspector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="inspector">the Inspector to check</param>
|
/// <param name="currentItem">the Item to check</param>
|
||||||
/// <param name="allowMeetingAsTarget">bool true if also exporting to meetings</param>
|
/// <param name="allowMeetingAsTarget">bool true if also exporting to meetings</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static bool canExportToInspector(Inspector inspector, bool allowMeetingAsTarget) {
|
private static bool canExportToInspector(Item currentItem, bool allowMeetingAsTarget) {
|
||||||
try {
|
try {
|
||||||
Item currentItem = inspector.CurrentItem;
|
|
||||||
if (currentItem != null) {
|
if (currentItem != null) {
|
||||||
OlObjectClass currentItemClass = currentItem.Class;
|
OlObjectClass currentItemClass = currentItem.Class;
|
||||||
if (OlObjectClass.olMail.Equals(currentItemClass)) {
|
if (OlObjectClass.olMail.Equals(currentItemClass)) {
|
||||||
|
@ -101,7 +104,7 @@ namespace Greenshot.Interop.Office {
|
||||||
if (string.IsNullOrEmpty(appointmentItem.Organizer) || (currentUser == null && currentUser.Equals(appointmentItem.Organizer))) {
|
if (string.IsNullOrEmpty(appointmentItem.Organizer) || (currentUser == null && currentUser.Equals(appointmentItem.Organizer))) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LOG.DebugFormat("Not exporting to {0}, as organizer is {1} and currentuser {2}", inspector.Caption, appointmentItem.Organizer, currentUser);
|
LOG.DebugFormat("Not exporting, as organizer is {1} and currentuser {2}", appointmentItem.Organizer, currentUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,12 +131,13 @@ namespace Greenshot.Interop.Office {
|
||||||
if (inspectors != null && inspectors.Count > 0) {
|
if (inspectors != null && inspectors.Count > 0) {
|
||||||
LOG.DebugFormat("Got {0} inspectors to check", inspectors.Count);
|
LOG.DebugFormat("Got {0} inspectors to check", inspectors.Count);
|
||||||
for (int i = 1; i <= inspectors.Count; i++) {
|
for (int i = 1; i <= inspectors.Count; i++) {
|
||||||
Inspector inspector = outlookApplication.Inspectors[i];
|
using (Inspector inspector = outlookApplication.Inspectors[i]) {
|
||||||
string currentCaption = inspector.Caption;
|
string currentCaption = inspector.Caption;
|
||||||
if (currentCaption.StartsWith(inspectorCaption)) {
|
if (currentCaption.StartsWith(inspectorCaption)) {
|
||||||
if (canExportToInspector(inspector, allowMeetingAsTarget)) {
|
using (Item currentItem = inspector.CurrentItem) {
|
||||||
|
if (canExportToInspector(currentItem, allowMeetingAsTarget)) {
|
||||||
try {
|
try {
|
||||||
return ExportToInspector(inspector, tmpFile, attachmentName);
|
return ExportToInspector(inspector, currentItem, tmpFile, attachmentName);
|
||||||
} catch (Exception exExport) {
|
} catch (Exception exExport) {
|
||||||
LOG.Error("Export to " + currentCaption + " failed.", exExport);
|
LOG.Error("Export to " + currentCaption + " failed.", exExport);
|
||||||
}
|
}
|
||||||
|
@ -143,18 +147,20 @@ namespace Greenshot.Interop.Office {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Export the file to the supplied inspector
|
/// Export the file to the supplied inspector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="inspector"></param>
|
/// <param name="inspector">Inspector</param>
|
||||||
|
/// <param name="currentItem">Item</param>
|
||||||
/// <param name="tmpFile"></param>
|
/// <param name="tmpFile"></param>
|
||||||
/// <param name="attachmentName"></param>
|
/// <param name="attachmentName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static bool ExportToInspector(Inspector inspector, string tmpFile, string attachmentName) {
|
private static bool ExportToInspector(Inspector inspector, Item currentItem, string tmpFile, string attachmentName) {
|
||||||
Item currentItem = inspector.CurrentItem;
|
|
||||||
if (currentItem == null) {
|
if (currentItem == null) {
|
||||||
LOG.Warn("No current item.");
|
LOG.Warn("No current item.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -250,7 +256,7 @@ namespace Greenshot.Interop.Office {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the attachment (if inlined the attachment isn't visible as attachment!)
|
// Create the attachment (if inlined the attachment isn't visible as attachment!)
|
||||||
Attachment attachment = mailItem.Attachments.Add(tmpFile, OlAttachmentType.olByValue, inlinePossible ? 0 : 1, attachmentName);
|
using (Attachment attachment = mailItem.Attachments.Add(tmpFile, OlAttachmentType.olByValue, inlinePossible ? 0 : 1, attachmentName)) {
|
||||||
if (outlookVersion.Major >= 12) {
|
if (outlookVersion.Major >= 12) {
|
||||||
// Add the content id to the attachment, this only works for Outlook >= 2007
|
// Add the content id to the attachment, this only works for Outlook >= 2007
|
||||||
try {
|
try {
|
||||||
|
@ -259,6 +265,7 @@ namespace Greenshot.Interop.Office {
|
||||||
} catch {
|
} catch {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.WarnFormat("Problem while trying to add attachment to Item '{0}' : {1}", inspector.Caption, ex);
|
LOG.WarnFormat("Problem while trying to add attachment to Item '{0}' : {1}", inspector.Caption, ex);
|
||||||
return false;
|
return false;
|
||||||
|
@ -299,12 +306,11 @@ namespace Greenshot.Interop.Office {
|
||||||
break;
|
break;
|
||||||
case EmailFormat.HTML:
|
case EmailFormat.HTML:
|
||||||
default:
|
default:
|
||||||
// Create the attachment
|
|
||||||
Attachment attachment = newMail.Attachments.Add(tmpFile, OlAttachmentType.olByValue, 0, attachmentName);
|
|
||||||
// add content ID to the attachment
|
|
||||||
string contentID = Path.GetFileName(tmpFile);
|
string contentID = Path.GetFileName(tmpFile);
|
||||||
|
// Create the attachment
|
||||||
|
using (Attachment attachment = newMail.Attachments.Add(tmpFile, OlAttachmentType.olByValue, 0, attachmentName)) {
|
||||||
|
// add content ID to the attachment
|
||||||
if (outlookVersion.Major >= 12) {
|
if (outlookVersion.Major >= 12) {
|
||||||
// Add the content id to the attachment
|
|
||||||
try {
|
try {
|
||||||
contentID = Guid.NewGuid().ToString();
|
contentID = Guid.NewGuid().ToString();
|
||||||
PropertyAccessor propertyAccessor = attachment.PropertyAccessor;
|
PropertyAccessor propertyAccessor = attachment.PropertyAccessor;
|
||||||
|
@ -314,6 +320,7 @@ namespace Greenshot.Interop.Office {
|
||||||
contentID = Path.GetFileName(tmpFile);
|
contentID = Path.GetFileName(tmpFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
newMail.BodyFormat = OlBodyFormat.olFormatHTML;
|
newMail.BodyFormat = OlBodyFormat.olFormatHTML;
|
||||||
string htmlImgEmbedded = "<BR/><IMG border=0 hspace=0 alt=\"" + attachmentName + "\" align=baseline src=\"cid:" + contentID + "\"><BR/>";
|
string htmlImgEmbedded = "<BR/><IMG border=0 hspace=0 alt=\"" + attachmentName + "\" align=baseline src=\"cid:" + contentID + "\"><BR/>";
|
||||||
|
@ -363,6 +370,9 @@ namespace Greenshot.Interop.Office {
|
||||||
retryDisplayEmail.IsBackground = true;
|
retryDisplayEmail.IsBackground = true;
|
||||||
retryDisplayEmail.Start();
|
retryDisplayEmail.Start();
|
||||||
}
|
}
|
||||||
|
if (newItem != null) {
|
||||||
|
newItem.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -45,13 +45,14 @@ namespace Greenshot.Interop.Office {
|
||||||
using (IWordApplication wordApplication = COMWrapper.GetInstance<IWordApplication>()) {
|
using (IWordApplication wordApplication = COMWrapper.GetInstance<IWordApplication>()) {
|
||||||
if (wordApplication != null) {
|
if (wordApplication != null) {
|
||||||
for (int i = 1; i <= wordApplication.Documents.Count; i++) {
|
for (int i = 1; i <= wordApplication.Documents.Count; i++) {
|
||||||
IWordDocument wordDocument = wordApplication.Documents.item(i);
|
using (IWordDocument wordDocument = wordApplication.Documents.item(i)) {
|
||||||
if (wordDocument.ActiveWindow.Caption.StartsWith(wordCaption)) {
|
if (wordDocument.ActiveWindow.Caption.StartsWith(wordCaption)) {
|
||||||
return InsertIntoExistingDocument(wordDocument, tmpFile);
|
return InsertIntoExistingDocument(wordDocument, tmpFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,9 +68,15 @@ namespace Greenshot.Interop.Office {
|
||||||
LOG.WarnFormat("Couldn't set zoom to 100, error: {0}", e.Message);
|
LOG.WarnFormat("Couldn't set zoom to 100, error: {0}", e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
wordDocument.Application.Activate();
|
wordDocument.Application.Activate();
|
||||||
|
} catch {}
|
||||||
|
try {
|
||||||
wordDocument.Activate();
|
wordDocument.Activate();
|
||||||
|
} catch {}
|
||||||
|
try {
|
||||||
wordDocument.ActiveWindow.Activate();
|
wordDocument.ActiveWindow.Activate();
|
||||||
|
} catch {}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue