/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } for (int Idx = 0; Idx < TabControl.GetTabCount(); Idx++) { ((IMainWindowTabPanel)TabControl.GetTabData(Idx)).Dispose(); } StopScheduleTimer(); if (AutomationServer != null) { AutomationServer.Dispose(); AutomationServer = null; } if (AutomationLog != null) { AutomationLog.Close(); AutomationLog = null; } base.Dispose(disposing); }
private ApplicationSettingsWindow(string DefaultServerAndPort, string DefaultUserName, bool bUnstable, string OriginalExecutableFileName, UserSettings Settings, TextWriter Log) { InitializeComponent(); this.OriginalExecutableFileName = OriginalExecutableFileName; this.Settings = Settings; this.Log = Log; Utility.ReadGlobalPerforceSettings(ref InitialServerAndPort, ref InitialUserName, ref InitialDepotPath); bInitialUnstable = bUnstable; InitialAutomationPortNumber = AutomationServer.GetPortNumber(); InitialProtocolHandlerState = ProtocolHandlerUtils.GetState(); this.AutomaticallyRunAtStartupCheckBox.Checked = IsAutomaticallyRunAtStartup(); this.KeepInTrayCheckBox.Checked = Settings.bKeepInTray; this.ServerTextBox.Text = InitialServerAndPort; this.ServerTextBox.Select(ServerTextBox.TextLength, 0); this.ServerTextBox.CueBanner = (DefaultServerAndPort == null)? "Default" : String.Format("Default ({0})", DefaultServerAndPort); this.UserNameTextBox.Text = InitialUserName; this.UserNameTextBox.Select(UserNameTextBox.TextLength, 0); this.UserNameTextBox.CueBanner = (DefaultUserName == null)? "Default" : String.Format("Default ({0})", DefaultUserName); this.ParallelSyncThreadsSpinner.Value = Math.Max(Math.Min(Settings.SyncOptions.NumThreads, ParallelSyncThreadsSpinner.Maximum), ParallelSyncThreadsSpinner.Minimum); this.DepotPathTextBox.Text = InitialDepotPath; this.DepotPathTextBox.Select(DepotPathTextBox.TextLength, 0); this.DepotPathTextBox.CueBanner = DeploymentSettings.DefaultDepotPath; this.UseUnstableBuildCheckBox.Checked = bUnstable; if (InitialAutomationPortNumber > 0) { this.EnableAutomationCheckBox.Checked = true; this.AutomationPortTextBox.Enabled = true; this.AutomationPortTextBox.Text = InitialAutomationPortNumber.ToString(); } else { this.EnableAutomationCheckBox.Checked = false; this.AutomationPortTextBox.Enabled = false; this.AutomationPortTextBox.Text = AutomationServer.DefaultPortNumber.ToString(); } if (InitialProtocolHandlerState == ProtocolHandlerState.Installed) { this.EnableProtocolHandlerCheckBox.CheckState = CheckState.Checked; } else if (InitialProtocolHandlerState == ProtocolHandlerState.NotInstalled) { this.EnableProtocolHandlerCheckBox.CheckState = CheckState.Unchecked; } else { this.EnableProtocolHandlerCheckBox.CheckState = CheckState.Indeterminate; } }
private ApplicationSettingsWindow(string DefaultServerAndPort, string DefaultUserName, bool bUnstable, string OriginalExecutableFileName, UserSettings Settings, TextWriter Log) { InitializeComponent(); this.OriginalExecutableFileName = OriginalExecutableFileName; this.Settings = Settings; this.Log = Log; Utility.ReadGlobalPerforceSettings(ref InitialServerAndPort, ref InitialUserName, ref InitialDepotPath); bInitialUnstable = bUnstable; InitialAutomationPortNumber = AutomationServer.GetPortNumber(); this.AutomaticallyRunAtStartupCheckBox.Checked = IsAutomaticallyRunAtStartup(); this.KeepInTrayCheckBox.Checked = Settings.bKeepInTray; this.ServerTextBox.Text = InitialServerAndPort; this.ServerTextBox.Select(ServerTextBox.TextLength, 0); this.ServerTextBox.CueBanner = (DefaultServerAndPort == null)? "Default" : String.Format("Default ({0})", DefaultServerAndPort); this.UserNameTextBox.Text = InitialUserName; this.UserNameTextBox.Select(UserNameTextBox.TextLength, 0); this.UserNameTextBox.CueBanner = (DefaultUserName == null)? "Default" : String.Format("Default ({0})", DefaultUserName); this.DepotPathTextBox.Text = InitialDepotPath; this.DepotPathTextBox.Select(DepotPathTextBox.TextLength, 0); this.DepotPathTextBox.CueBanner = DeploymentSettings.DefaultDepotPath; this.UseUnstableBuildCheckBox.Checked = bUnstable; if (InitialAutomationPortNumber > 0) { this.EnableAutomationCheckBox.Checked = true; this.AutomationPortTextBox.Enabled = true; this.AutomationPortTextBox.Text = InitialAutomationPortNumber.ToString(); } else { this.EnableAutomationCheckBox.Checked = false; this.AutomationPortTextBox.Enabled = false; this.AutomationPortTextBox.Text = AutomationServer.DefaultPortNumber.ToString(); } }
public MainWindow(UpdateMonitor InUpdateMonitor, string InApiUrl, string InDataFolder, string InCacheFolder, bool bInRestoreStateOnLoad, string InOriginalExecutableFileName, bool bInUnstable, DetectProjectSettingsResult[] StartupProjects, LineBasedTextWriter InLog, UserSettings InSettings) { InitializeComponent(); UpdateMonitor = InUpdateMonitor; MainThreadSynchronizationContext = SynchronizationContext.Current; ApiUrl = InApiUrl; DataFolder = InDataFolder; CacheFolder = InCacheFolder; bRestoreStateOnLoad = bInRestoreStateOnLoad; OriginalExecutableFileName = InOriginalExecutableFileName; bUnstable = bInUnstable; Log = InLog; Settings = InSettings; // While creating tab controls during startup, we need to prevent layout calls resulting in the window handle being created too early. Disable layout calls here. SuspendLayout(); TabPanel.SuspendLayout(); TabControl.OnTabChanged += TabControl_OnTabChanged; TabControl.OnNewTabClick += TabControl_OnNewTabClick; TabControl.OnTabClicked += TabControl_OnTabClicked; TabControl.OnTabClosing += TabControl_OnTabClosing; TabControl.OnTabClosed += TabControl_OnTabClosed; TabControl.OnTabReorder += TabControl_OnTabReorder; TabControl.OnButtonClick += TabControl_OnButtonClick; SetupDefaultControl(); int SelectTabIdx = -1; foreach (DetectProjectSettingsResult StartupProject in StartupProjects) { int TabIdx = -1; if (StartupProject.bSucceeded) { TabIdx = TryOpenProject(StartupProject.Task, -1, OpenProjectOptions.Quiet); } else if (StartupProject.ErrorMessage != null) { CreateErrorPanel(-1, StartupProject.Task.SelectedProject, StartupProject.ErrorMessage); } if (TabIdx != -1 && Settings.LastProject != null && StartupProject.Task.SelectedProject.Equals(Settings.LastProject)) { SelectTabIdx = TabIdx; } } if (SelectTabIdx != -1) { TabControl.SelectTab(SelectTabIdx); } else if (TabControl.GetTabCount() > 0) { TabControl.SelectTab(0); } StartScheduleTimer(); if (bUnstable) { Text += String.Format(" (UNSTABLE BUILD {0})", Assembly.GetExecutingAssembly().GetName().Version); } AutomationLog = new TimestampLogWriter(new BoundedLogWriter(Path.Combine(DataFolder, "Automation.log"))); AutomationServer = new AutomationServer(Request => { MainThreadSynchronizationContext.Post(Obj => PostAutomationRequest(Request), null); }, AutomationLog); // Allow creating controls from now on TabPanel.ResumeLayout(false); ResumeLayout(false); bAllowCreatingHandle = true; }
/// <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(); } DialogResult = DialogResult.OK; Close(); }