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>
|
||||
private void Dispose(bool disposing) {
|
||||
if (null != this._COMObject) {
|
||||
LOG.DebugFormat("Disposing {0}", this._InterceptType.ToString());
|
||||
if (Marshal.IsComObject(this._COMObject)) {
|
||||
try {
|
||||
while (Marshal.ReleaseComObject(this._COMObject) > 0) ;
|
||||
|
|
|
@ -59,18 +59,22 @@ namespace Greenshot.Interop.Office {
|
|||
return null;
|
||||
}
|
||||
|
||||
Inspectors inspectors = outlookApplication.Inspectors;
|
||||
using (Inspectors inspectors = outlookApplication.Inspectors) {
|
||||
if (inspectors != null && inspectors.Count > 0) {
|
||||
for (int i = 1; i <= inspectors.Count; i++) {
|
||||
Inspector inspector = outlookApplication.Inspectors[i];
|
||||
if (canExportToInspector(inspector, allowMeetingAsTarget)) {
|
||||
Item currentItem = inspector.CurrentItem;
|
||||
using (Inspector inspector = outlookApplication.Inspectors[i]) {
|
||||
string inspectorCaption = inspector.Caption;
|
||||
using (Item currentItem = inspector.CurrentItem) {
|
||||
if (canExportToInspector(currentItem, allowMeetingAsTarget)) {
|
||||
OlObjectClass currentItemClass = currentItem.Class;
|
||||
inspectorCaptions.Add(inspector.Caption, currentItemClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.Warn("Problem retrieving word destinations, ignoring: ", ex);
|
||||
}
|
||||
|
@ -80,12 +84,11 @@ namespace Greenshot.Interop.Office {
|
|||
/// <summary>
|
||||
/// Return true if we can export to the supplied inspector
|
||||
/// </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>
|
||||
/// <returns></returns>
|
||||
private static bool canExportToInspector(Inspector inspector, bool allowMeetingAsTarget) {
|
||||
private static bool canExportToInspector(Item currentItem, bool allowMeetingAsTarget) {
|
||||
try {
|
||||
Item currentItem = inspector.CurrentItem;
|
||||
if (currentItem != null) {
|
||||
OlObjectClass currentItemClass = currentItem.Class;
|
||||
if (OlObjectClass.olMail.Equals(currentItemClass)) {
|
||||
|
@ -101,7 +104,7 @@ namespace Greenshot.Interop.Office {
|
|||
if (string.IsNullOrEmpty(appointmentItem.Organizer) || (currentUser == null && currentUser.Equals(appointmentItem.Organizer))) {
|
||||
return true;
|
||||
} 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) {
|
||||
LOG.DebugFormat("Got {0} inspectors to check", inspectors.Count);
|
||||
for (int i = 1; i <= inspectors.Count; i++) {
|
||||
Inspector inspector = outlookApplication.Inspectors[i];
|
||||
using (Inspector inspector = outlookApplication.Inspectors[i]) {
|
||||
string currentCaption = inspector.Caption;
|
||||
if (currentCaption.StartsWith(inspectorCaption)) {
|
||||
if (canExportToInspector(inspector, allowMeetingAsTarget)) {
|
||||
using (Item currentItem = inspector.CurrentItem) {
|
||||
if (canExportToInspector(currentItem, allowMeetingAsTarget)) {
|
||||
try {
|
||||
return ExportToInspector(inspector, tmpFile, attachmentName);
|
||||
return ExportToInspector(inspector, currentItem, tmpFile, attachmentName);
|
||||
} catch (Exception exExport) {
|
||||
LOG.Error("Export to " + currentCaption + " failed.", exExport);
|
||||
}
|
||||
|
@ -143,18 +147,20 @@ namespace Greenshot.Interop.Office {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Export the file to the supplied inspector
|
||||
/// </summary>
|
||||
/// <param name="inspector"></param>
|
||||
/// <param name="inspector">Inspector</param>
|
||||
/// <param name="currentItem">Item</param>
|
||||
/// <param name="tmpFile"></param>
|
||||
/// <param name="attachmentName"></param>
|
||||
/// <returns></returns>
|
||||
private static bool ExportToInspector(Inspector inspector, string tmpFile, string attachmentName) {
|
||||
Item currentItem = inspector.CurrentItem;
|
||||
private static bool ExportToInspector(Inspector inspector, Item currentItem, string tmpFile, string attachmentName) {
|
||||
if (currentItem == null) {
|
||||
LOG.Warn("No current item.");
|
||||
return false;
|
||||
|
@ -250,7 +256,7 @@ namespace Greenshot.Interop.Office {
|
|||
}
|
||||
|
||||
// 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) {
|
||||
// Add the content id to the attachment, this only works for Outlook >= 2007
|
||||
try {
|
||||
|
@ -259,6 +265,7 @@ namespace Greenshot.Interop.Office {
|
|||
} catch {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.WarnFormat("Problem while trying to add attachment to Item '{0}' : {1}", inspector.Caption, ex);
|
||||
return false;
|
||||
|
@ -299,12 +306,11 @@ namespace Greenshot.Interop.Office {
|
|||
break;
|
||||
case EmailFormat.HTML:
|
||||
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);
|
||||
// Create the attachment
|
||||
using (Attachment attachment = newMail.Attachments.Add(tmpFile, OlAttachmentType.olByValue, 0, attachmentName)) {
|
||||
// add content ID to the attachment
|
||||
if (outlookVersion.Major >= 12) {
|
||||
// Add the content id to the attachment
|
||||
try {
|
||||
contentID = Guid.NewGuid().ToString();
|
||||
PropertyAccessor propertyAccessor = attachment.PropertyAccessor;
|
||||
|
@ -314,6 +320,7 @@ namespace Greenshot.Interop.Office {
|
|||
contentID = Path.GetFileName(tmpFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newMail.BodyFormat = OlBodyFormat.olFormatHTML;
|
||||
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.Start();
|
||||
}
|
||||
if (newItem != null) {
|
||||
newItem.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -45,13 +45,14 @@ namespace Greenshot.Interop.Office {
|
|||
using (IWordApplication wordApplication = COMWrapper.GetInstance<IWordApplication>()) {
|
||||
if (wordApplication != null) {
|
||||
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)) {
|
||||
return InsertIntoExistingDocument(wordDocument, tmpFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -67,9 +68,15 @@ namespace Greenshot.Interop.Office {
|
|||
LOG.WarnFormat("Couldn't set zoom to 100, error: {0}", e.Message);
|
||||
}
|
||||
}
|
||||
try {
|
||||
wordDocument.Application.Activate();
|
||||
} catch {}
|
||||
try {
|
||||
wordDocument.Activate();
|
||||
} catch {}
|
||||
try {
|
||||
wordDocument.ActiveWindow.Activate();
|
||||
} catch {}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue