/// <summary> /// Handle URI passed in via command lines /// </summary> public static bool ProcessCommandLine(string[] Args, bool FirstInstance, EventWaitHandle ActivateEvent = null) { if (Args.Any(x => x.Equals(InstallHandlerArg, StringComparison.OrdinalIgnoreCase))) { if (Args.Any(x => x.Equals(ElevatedArg, StringComparison.OrdinalIgnoreCase))) { ProtocolHandlerUtils.InstallElevated(); } else { ProtocolHandlerUtils.Install(); } return(true); } else if (Args.Any(x => x.Equals(UninstallHandlerArg, StringComparison.OrdinalIgnoreCase))) { if (Args.Any(x => x.Equals(ElevatedArg, StringComparison.OrdinalIgnoreCase))) { ProtocolHandlerUtils.UninstallElevated(); } else { ProtocolHandlerUtils.Uninstall(); } return(true); } else { string UriIn = string.Empty; for (int Idx = 0; Idx < Args.Length; Idx++) { const string Prefix = "-uri="; if (Args[Idx].StartsWith(Prefix, StringComparison.OrdinalIgnoreCase)) { UriIn = Args[Idx].Substring(Prefix.Length); } } if (UriIn == string.Empty) { return(false); } Uri Uri; try { Uri = new Uri(UriIn); } catch { MessageBox.Show(String.Format("Invalid URI: {0}", UriIn)); return(true); } MethodInfo Handler; if (!Handlers.TryGetValue(Uri.Host, out Handler)) { MessageBox.Show(String.Format("Unknown action from URI request ('{0}')", Uri.Host)); return(true); } UriHandlerAttribute Attribute = Handler.GetCustomAttribute <UriHandlerAttribute>(); // handle case where we terminate after invoking handler if (Attribute.Terminate) { UriResult Result = HandleUri(UriIn); if (!Result.Success) { MessageBox.Show(Result.Error); } return(true); } if (!FirstInstance) { if (ActivateEvent != null) { ActivateEvent.Set(); } // send to main UGS process using IPC AutomationServer.SendUri(UriIn); return(true); } // we're in the main UGS process, which was also launched, defer handling to after main window is created return(false); } }
private void OkBtn_Click(object sender, EventArgs e) { // Update the settings string ServerAndPort = ServerTextBox.Text.Trim(); if (ServerAndPort.Length == 0) { ServerAndPort = null; } string UserName = UserNameTextBox.Text.Trim(); if (UserName.Length == 0) { UserName = null; } string DepotPath = DepotPathTextBox.Text.Trim(); if (DepotPath.Length == 0 || DepotPath == DeploymentSettings.DefaultDepotPath) { DepotPath = null; } bool bUnstable = UseUnstableBuildCheckBox.Checked; int AutomationPortNumber; if (!EnableAutomationCheckBox.Checked || !int.TryParse(AutomationPortTextBox.Text, out AutomationPortNumber)) { AutomationPortNumber = -1; } if (ServerAndPort != InitialServerAndPort || UserName != InitialUserName || DepotPath != InitialDepotPath || bUnstable != bInitialUnstable || AutomationPortNumber != InitialAutomationPortNumber) { // Try to log in to the new server, and check the application is there if (ServerAndPort != InitialServerAndPort || UserName != InitialUserName || DepotPath != InitialDepotPath) { string ErrorMessage; ModalTaskResult Result = PerforceModalTask.Execute(this, new PerforceConnection(UserName, null, ServerAndPort), new PerforceTestConnectionTask(DepotPath), "Connecting", "Checking connection, please wait...", Log, out ErrorMessage); if (Result != ModalTaskResult.Succeeded) { if (Result == ModalTaskResult.Failed) { MessageBox.Show(ErrorMessage, "Unable to connect"); } return; } } if (MessageBox.Show("UnrealGameSync must be restarted to apply these settings.\n\nWould you like to restart now?", "Restart Required", MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } bRestartUnstable = UseUnstableBuildCheckBox.Checked; Utility.SaveGlobalPerforceSettings(ServerAndPort, UserName, DepotPath); AutomationServer.SetPortNumber(AutomationPortNumber); } RegistryKey Key = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"); if (IsAutomaticallyRunAtStartup()) { Key.DeleteValue("UnrealGameSync", false); } else { Key.SetValue("UnrealGameSync", String.Format("\"{0}\" -RestoreState", OriginalExecutableFileName)); } if (Settings.bKeepInTray != KeepInTrayCheckBox.Checked || Settings.SyncOptions.NumThreads != ParallelSyncThreadsSpinner.Value) { Settings.SyncOptions.NumThreads = (int)ParallelSyncThreadsSpinner.Value; Settings.bKeepInTray = KeepInTrayCheckBox.Checked; Settings.Save(); } if (EnableProtocolHandlerCheckBox.CheckState == CheckState.Checked) { if (InitialProtocolHandlerState != ProtocolHandlerState.Installed) { ProtocolHandlerUtils.Install(); } } else if (EnableProtocolHandlerCheckBox.CheckState == CheckState.Unchecked) { if (InitialProtocolHandlerState != ProtocolHandlerState.NotInstalled) { ProtocolHandlerUtils.Uninstall(); } } DialogResult = DialogResult.OK; Close(); }