public void Restart() { // 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") && !_addIn.ProfileName.Contains("\"")) { commandLine += " /profile " + Util.QuoteCommandLine(_addIn.ProfileName); } // Custom command line foreach (ZPushAccount account in _resyncAccounts) { string path = account.Account.BackingFilePath; if (!string.IsNullOrEmpty(path) && System.IO.Path.GetExtension(path) == ".ost") { commandLine += " /cleankoe " + Util.QuoteCommandLine(path); } } foreach (KeyValuePair <ZPushAccount, GABUser> share in _shares) { using (RegistryKey key = OutlookRegistryUtils.OpenProfileOutlookKey(_addIn.ProfileName, RegistryKeyPermissionCheck.ReadWriteSubTree)) { int accountId = (int)key.GetValue(OutlookConstants.REG_VAL_NEXT_ACCOUNT_ID); using (RegistryKey accountKey = key.CreateSubKey(string.Format("{0:X8}", accountId))) { accountKey.SetValue(OutlookConstants.REG_VAL_ACCOUNTNAME, share.Value.UserName + " through " + share.Key.DisplayName); accountKey.SetValue(OutlookConstants.REG_VAL_DISPLAYNAME, "Share for " + share.Value.DisplayName); accountKey.SetValue(OutlookConstants.REG_VAL_EMAIL, "test" + share.Key.Account.SmtpAddress); accountKey.SetValue(OutlookConstants.REG_VAL_EAS_SERVER, share.Key.Account.ServerURL); accountKey.SetValue(OutlookConstants.REG_VAL_EAS_USERNAME, share.Key.Account.UserName + ".share." + share.Value.UserName); accountKey.SetValue(OutlookConstants.REG_VAL_EAS_PASSWORD, share.Key.Account.EncryptedPassword); //accountKey.SetValue(OutlookConstants.REG_VAL_EAS_DEVICEID, share.Key.Account.DeviceId); accountKey.SetValue("clsid", "{ED475415-B0D6-11D2-8C3B-00104B2A6676}"); } key.SetValue(OutlookConstants.REG_VAL_NEXT_ACCOUNT_ID, accountId + 1); } } // Run that Process process = new Process(); process.StartInfo = new ProcessStartInfo(RestarterPath, Process.GetCurrentProcess().Id + " " + commandLine); process.Start(); // And close us and any other windows _addIn.Quit(CloseWindows); }
public void Restart() { // 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") && !_addIn.ProfileName.Contains("\"")) { commandLine += " /profile " + Util.QuoteCommandLine(_addIn.ProfileName); } // Custom command line foreach (ZPushAccount account in _resyncAccounts) { string path = account.Account.BackingFilePath; if (!string.IsNullOrEmpty(path) && System.IO.Path.GetExtension(path) == ".ost") { commandLine += " /cleankoe " + Util.QuoteCommandLine(path); } } if (_shares.Count > 0) { foreach (Share share in _shares) { Logger.Instance.Debug(this, "Adding KOE share: profile={0}, version={1}, accountid={2}, user={3}, email={4}, reminders={5}", _addIn.ProfileName, _addIn.VersionMajor, share.account.Account.AccountId, share.store.UserName, share.store.EmailAddress, share.showReminders); // TODO: escaping commandLine += " /sharekoe " + Util.QuoteCommandLine(_addIn.ProfileName + ":" + _addIn.VersionMajor + ":" + share.account.Account.AccountId + ":" + share.store.UserName + ":" + share.store.EmailAddress + ":" + share.store.EmailAddress + ":1:" + (share.showReminders ? "1" : "0")); } } string arch = Environment.Is64BitProcess ? "x64" : "x86"; string fullCommandLine = Process.GetCurrentProcess().Id + " " + arch + " " + commandLine; Logger.Instance.Debug(this, "Restarting KOE: {0}", fullCommandLine); // Run that Process process = new Process(); process.StartInfo = new ProcessStartInfo(RestarterPath, fullCommandLine); process.Start(); // And close us and any other windows _addIn.Quit(CloseWindows); }