diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IAddIn.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IAddIn.cs index 81efa1b..29af102 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IAddIn.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IAddIn.cs @@ -92,5 +92,6 @@ namespace Acacia.Stubs void InUI(Action action, bool synchronous = true); bool IsOffline { get; } + string ProfileName { get; } } } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddInWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddInWrapper.cs index 5b8aa63..64c72c5 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddInWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddInWrapper.cs @@ -84,6 +84,22 @@ namespace Acacia.Stubs.OutlookWrappers } } + public string ProfileName + { + get + { + NSOutlook.NameSpace session = _app.Session; + try + { + return session.CurrentProfileName; + } + finally + { + ComRelease.Release(session); + } + } + } + public void InUI(Action action, bool synchronous = true) { if (synchronous) @@ -148,9 +164,19 @@ namespace Acacia.Stubs.OutlookWrappers // Create the path to the restarter path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), "OutlookRestarter.exe"); + // Use the current command line, with a profile command if not specified + string commandLine = Environment.CommandLine; + // This selects both /profile and /profiles. In that case we don't specify the profile, otherwise + // we specify the current profile + // It seems to be impossible to escape a profile name with a quote, so in that case ignore it + if (!commandLine.ToLower().Contains("/profile") && !ProfileName.Contains("\"")) + { + commandLine += " /profile " + Util.QuoteCommandLine(ProfileName); + } + // Run that Process process = new Process(); - process.StartInfo = new ProcessStartInfo(path, Process.GetCurrentProcess().Id + " " + Environment.CommandLine); + process.StartInfo = new ProcessStartInfo(path, Process.GetCurrentProcess().Id + " " + commandLine); process.Start(); // And close us and any other windows diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Utils/RegistryUtil.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Utils/RegistryUtil.cs index ae9b834..4eb4aa2 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Utils/RegistryUtil.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Utils/RegistryUtil.cs @@ -87,6 +87,16 @@ namespace Acacia.Utils } } + private static string CombineKeys(string prefix, string suffix) + { + // Cannot use Path.Combine, as that throws on characters that are not allowed in paths, but may be + // allowed in the registry. + string key = prefix.StripSuffix("\\"); + key += "\\"; + key += suffix.StripPrefix("\\"); + return key; + } + public static RegistryKey OpenKeyImpl(string baseKeyPath, string suffix, bool localMachine, RegistryKeyPermissionCheck permissions) { // Add the suffix @@ -94,7 +104,7 @@ namespace Acacia.Utils if (string.IsNullOrEmpty(suffix)) keyPath = baseKeyPath; else - keyPath = System.IO.Path.Combine(baseKeyPath, suffix); + keyPath = CombineKeys(baseKeyPath, suffix); // Open the key. using (RegistryKey hive = RegistryKey.OpenBaseKey(localMachine ? RegistryHive.LocalMachine : RegistryHive.CurrentUser, RegistryView.Registry64)) diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Utils/Util.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Utils/Util.cs index f24aea7..fdbcca5 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Utils/Util.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Utils/Util.cs @@ -162,5 +162,16 @@ namespace Acacia.Utils #endregion + #region Command line + + /// + /// Quotes a single command line argument + /// + public static string QuoteCommandLine(string arg) + { + return "\"" + Regex.Replace(arg, @"(\\*)" + "\"", @"$1$1\" + "\"") + "\""; + } + + #endregion } }