diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin.sln b/src/AcaciaZPushPlugin/AcaciaZPushPlugin.sln index 905ae8e..eb30fbe 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin.sln +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin.sln @@ -1,12 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AcaciaZPushPlugin", "AcaciaZPushPlugin\AcaciaZPushPlugin.csproj", "{1A7427A5-F814-4B07-98B2-C67D758B65D6}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginDebugger", "PluginDebugger\PluginDebugger.csproj", "{9258AD17-0A25-4669-A95C-93EC70882551}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OutlookRestarter", "OutlookRestarter\OutlookRestarter.csproj", "{222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -41,6 +43,18 @@ Global {9258AD17-0A25-4669-A95C-93EC70882551}.Release|x64.Build.0 = Release|Any CPU {9258AD17-0A25-4669-A95C-93EC70882551}.Release|x86.ActiveCfg = Release|Any CPU {9258AD17-0A25-4669-A95C-93EC70882551}.Release|x86.Build.0 = Release|Any CPU + {222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Debug|x64.ActiveCfg = Debug|Any CPU + {222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Debug|x64.Build.0 = Debug|Any CPU + {222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Debug|x86.ActiveCfg = Debug|Any CPU + {222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Debug|x86.Build.0 = Debug|Any CPU + {222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Release|Any CPU.Build.0 = Release|Any CPU + {222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Release|x64.ActiveCfg = Release|Any CPU + {222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Release|x64.Build.0 = Release|Any CPU + {222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Release|x86.ActiveCfg = Release|Any CPU + {222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/SecondaryContacts/FeatureSecondaryContacts.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/SecondaryContacts/FeatureSecondaryContacts.cs index baa5cc8..4952c4d 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/SecondaryContacts/FeatureSecondaryContacts.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/SecondaryContacts/FeatureSecondaryContacts.cs @@ -26,6 +26,7 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Windows.Forms; using static Acacia.DebugOptions; namespace Acacia.Features.SecondaryContacts @@ -57,6 +58,10 @@ namespace Acacia.Features.SecondaryContacts } } + // Contains the ids of folders for which we've shown a warning. This is both to prevent + // warning multiple times and to detect the case when the app has been restarted. + private readonly HashSet _warnedFolders = new HashSet(); + public FeatureSecondaryContacts() { @@ -68,27 +73,67 @@ namespace Acacia.Features.SecondaryContacts OnUnpatchedFolderDiscovered); } - private void OnUnpatchedFolderDiscovered(IFolder folder) { string strippedName = folder.Name.StripSuffix(SUFFIX_CONTACTS); Logger.Instance.Debug(this, "Patching secondary contacts folder: {0}", strippedName); - // Note that somehow it fails if these are updated in one go, so do the steps individually + // To patch we need to do the following + // 1) Update the sync type from 18 to 14 + // 2) Update the container class from Note to Contact + // 3) Patch the name + // Note that the above steps need to be done in this order and individually for this to work. + // + // At some point after 2 we also need to restart Outlook to make it appear in the list of contact folders. + // So, when the folder is detected, we make it invisible and perform steps 1 and 2. We issue a warning + // that Outlook must be restarted. When the folder is detected again and is invisible, that means we've restarted + // At this point the name is patched and the folder is made visible. - // Sync type - Logger.Instance.Trace(this, "Setting sync type"); - folder.SetProperty(OutlookConstants.PR_EAS_SYNCTYPE, (int)OutlookConstants.SyncType.UserContact); + if (!folder.AttrHidden) + { + // Stage 1 - // Container type - Logger.Instance.Trace(this, "Setting container class"); - folder.SetProperty(OutlookConstants.PR_CONTAINER_CLASS, "IPF.Contact"); + // Sync type + Logger.Instance.Trace(this, "Setting sync type"); + folder.SetProperty(OutlookConstants.PR_EAS_SYNCTYPE, (int)OutlookConstants.SyncType.UserContact); - // And the name - Logger.Instance.Trace(this, "Patching name"); - folder.Name = strippedName; + // Container type + Logger.Instance.Trace(this, "Setting container class"); + folder.SetProperty(OutlookConstants.PR_CONTAINER_CLASS, "IPF.Contact"); - Logger.Instance.Debug(this, "Patched secondary contacts folder: {0}", strippedName); + // Make it invisible. + folder.AttrHidden = true; + + Logger.Instance.Debug(this, "Patched secondary contacts folder: {0}", strippedName); + // Register and show a warning, if not already done. + // Note that patching may be done multiple times. + if (!_warnedFolders.Contains(folder.EntryId)) + { + _warnedFolders.Add(folder.EntryId); + + if (MessageBox.Show(StringUtil.GetResourceString("SecondaryContactsPatched_Body", strippedName), + StringUtil.GetResourceString("SecondaryContactsPatched_Title"), + MessageBoxButtons.YesNo, + MessageBoxIcon.Warning + ) == DialogResult.Yes) + { + ThisAddIn.Instance.Restart(); + } + } + } + // If _warnedFolders does not contain the folder (and it's hidden), this means Outlook was restarted. + else if (!_warnedFolders.Contains(folder.EntryId)) + { + // Stage 2 + + // Patch the name + Logger.Instance.Trace(this, "Patching name"); + folder.Name = strippedName; + + // Show it + folder.AttrHidden = false; + Logger.Instance.Debug(this, "Shown secondary contacts folder: {0}", strippedName); + } } } } \ No newline at end of file diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Properties/Resources.Designer.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Properties/Resources.Designer.cs index 22a01c6..f2f609e 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Properties/Resources.Designer.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Properties/Resources.Designer.cs @@ -785,6 +785,24 @@ namespace Acacia.Properties { } } + /// + /// Looks up a localized string similar to To synchronise the contacts folder '{0}', Outlook must be restarted. Click 'Yes' to restart Outlook now, or 'No' if you plan to restart Outlook later.. + /// + internal static string SecondaryContactsPatched_Body { + get { + return ResourceManager.GetString("SecondaryContactsPatched_Body", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Contacts folder. + /// + internal static string SecondaryContactsPatched_Title { + get { + return ResourceManager.GetString("SecondaryContactsPatched_Title", resourceCulture); + } + } + /// /// Looks up a localized string similar to Unable to open the shared folder. Please ensure you have permission to open the shared folder.. /// diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Properties/Resources.resx b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Properties/Resources.resx index ccf7cde..93b5c6b 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Properties/Resources.resx +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Properties/Resources.resx @@ -431,4 +431,12 @@ Shows the about dialog, which contains licensing and version information. + + To synchronise the contacts folder '{0}', Outlook must be restarted. Click 'Yes' to restart Outlook now, or 'No' if you plan to restart Outlook later. + Shown when a secondary contact folder is detected, to inform the user that a restart is required + + + Contacts folder + Shown when a secondary contact folder is detected, to inform the user that a restart is required + \ No newline at end of file diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/OutlookWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/OutlookWrapper.cs index 2bb4efe..36e4bcf 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/OutlookWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/OutlookWrapper.cs @@ -112,7 +112,14 @@ namespace Acacia.Stubs.OutlookWrappers { get { - return Props.GetProperty(OutlookConstants.PR_ATTR_HIDDEN); + try + { + return Props.GetProperty(OutlookConstants.PR_ATTR_HIDDEN); + } + catch(System.Exception) + { + return false; + } } set { diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ThisAddIn.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ThisAddIn.cs index 9006c34..269c820 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ThisAddIn.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ThisAddIn.cs @@ -29,6 +29,9 @@ using Acacia.UI; using Acacia.ZPush; using System.Globalization; using Acacia.UI.Outlook; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Reflection; namespace Acacia { @@ -188,6 +191,35 @@ namespace Acacia #endregion + #region Misc helpers + + public void SendReceive() + { + Outlook.NameSpace session = Application.Session; + session.SendAndReceive(false); + ComRelease.Release(session); + } + + public void Restart() + { + // Can not use the assembly location, as that is in the GAC + string codeBase = Assembly.GetExecutingAssembly().CodeBase; + UriBuilder uri = new UriBuilder(codeBase); + string path = Uri.UnescapeDataString(uri.Path); + // Create the path to the restarter + path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), "OutlookRestarter.exe"); + + // Run that + Process process = new Process(); + process.StartInfo = new ProcessStartInfo(path, Environment.CommandLine); + process.Start(); + + // And close us + Application.Quit(); + } + + #endregion + #region Ribbons private OutlookUI _outlookUI; diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushAccount.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushAccount.cs index 3e70eac..09fc992 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushAccount.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushAccount.cs @@ -72,7 +72,7 @@ namespace Acacia.ZPush /// public void SendReceive() { - ThisAddIn.Instance.Application.Session.SendAndReceive(false); + ThisAddIn.Instance.SendReceive(); } #endregion diff --git a/src/AcaciaZPushPlugin/OutlookRestarter/App.config b/src/AcaciaZPushPlugin/OutlookRestarter/App.config new file mode 100644 index 0000000..d740e88 --- /dev/null +++ b/src/AcaciaZPushPlugin/OutlookRestarter/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/AcaciaZPushPlugin/OutlookRestarter/Kopano.ico b/src/AcaciaZPushPlugin/OutlookRestarter/Kopano.ico new file mode 100644 index 0000000..0b80522 Binary files /dev/null and b/src/AcaciaZPushPlugin/OutlookRestarter/Kopano.ico differ diff --git a/src/AcaciaZPushPlugin/OutlookRestarter/OutlookRestarter.csproj b/src/AcaciaZPushPlugin/OutlookRestarter/OutlookRestarter.csproj new file mode 100644 index 0000000..54cb405 --- /dev/null +++ b/src/AcaciaZPushPlugin/OutlookRestarter/OutlookRestarter.csproj @@ -0,0 +1,69 @@ + + + + + Debug + AnyCPU + {222C4DA5-FA31-471A-B127-5E0C6AD2CB3C} + WinExe + Properties + OutlookRestarter + OutlookRestarter + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + ..\Build\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + ..\Build\Release\ + TRACE + prompt + 4 + + + Kopano.ico + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/AcaciaZPushPlugin/OutlookRestarter/Program.cs b/src/AcaciaZPushPlugin/OutlookRestarter/Program.cs new file mode 100644 index 0000000..8e86e2e --- /dev/null +++ b/src/AcaciaZPushPlugin/OutlookRestarter/Program.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OutlookRestarter +{ + class Program + { + [STAThread] + static void Main(string[] args) + { + Process process = new Process(); + process.StartInfo = new ProcessStartInfo(args[0], string.Join(" ", args.Skip(1))); + process.Start(); + } + } +} diff --git a/src/AcaciaZPushPlugin/OutlookRestarter/Properties/AssemblyInfo.cs b/src/AcaciaZPushPlugin/OutlookRestarter/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0472212 --- /dev/null +++ b/src/AcaciaZPushPlugin/OutlookRestarter/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("OutlookRestarter")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("OutlookRestarter")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("222c4da5-fa31-471a-b127-5e0c6ad2cb3c")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]