Restarter command line now adds profile key, if possible

This commit is contained in:
Patrick Simpson 2017-03-08 11:18:37 +01:00
parent dfd393d3f5
commit 6b7ec839b0
4 changed files with 50 additions and 2 deletions

View File

@ -92,5 +92,6 @@ namespace Acacia.Stubs
void InUI(Action action, bool synchronous = true);
bool IsOffline { get; }
string ProfileName { get; }
}
}

View File

@ -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

View File

@ -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))

View File

@ -162,5 +162,16 @@ namespace Acacia.Utils
#endregion
#region Command line
/// <summary>
/// Quotes a single command line argument
/// </summary>
public static string QuoteCommandLine(string arg)
{
return "\"" + Regex.Replace(arg, @"(\\*)" + "\"", @"$1$1\" + "\"") + "\"";
}
#endregion
}
}