internal static void SetOutputState(int state) { switch (state) { default: case 0: Form.SetOutputCurrentOperation("Current Operation", Theme.GetOutputOperationColor()); Form.SetOutputProgressBarColor(Theme.GetOutputProgressBarColor()); Form.SetOutputCurrentPercentage(100); Form.SetOutputTotalPercentage(100); break; case 1: Form.SetOutputCurrentOperation("ERROR!", System.Drawing.Color.Red); Form.SetOutputProgressBarColor(MetroFramework.MetroColorStyle.Red); Form.SetOutputCurrentPercentage(50); Form.SetOutputTotalPercentage(50); break; case 2: Form.SetOutputCurrentOperation("SUCCESS!", System.Drawing.Color.Green); Form.SetOutputProgressBarColor(MetroFramework.MetroColorStyle.Green); Form.SetOutputCurrentPercentage(100); Form.SetOutputTotalPercentage(100); break; } }
private static void DownloadUpdate() { Form.Invoke(() => { Form.SetStage(Form.StageEnum.Output); Form.SetOutputCurrentOperation("Downloading Installer Update...", Theme.GetOutputOperationColor()); }); string exe_path = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); string temp_path = Path.Combine(exe_path, (Path.GetFileNameWithoutExtension(UpdateAssetData.Download) + ".tmp.exe")); Interfaces.DisposableFile disposableFile = new Interfaces.DisposableFile(temp_path); try { if (!disposableFile.Download(UpdateAssetData.Download, (percentage) => { Form.Invoke(() => { Form.SetOutputCurrentPercentage(percentage); Form.SetOutputTotalPercentage(percentage); }); })) { disposableFile.Dispose(); DownloadFailed("TODO"); return; } if (!disposableFile.SHA512HashCheckFromURL(UpdateAssetData.SHA512)) { disposableFile.Dispose(); DownloadFailed("TODO"); return; } } catch (Exception ex) { disposableFile.Dispose(); DownloadFailed(ex.ToString()); return; } if (Form.IsClosing) { return; } Form.Invoke(() => Form.SetStage(Form.StageEnum.Output_Success)); disposableFile.ShouldDisposeFileData = false; Program.Relaunch(temp_path); }
internal static void RunOutputTest(int sleepms, int max_operations, int operations_until_failure = 0, bool testsuccess = false) { Form.SetStage(Form.StageEnum.Output); Form.mainForm.PageManager.SelectedTab = Form.mainForm.Tab_Output; new Thread(() => { int currentoperation = 1; for (currentoperation = 1; currentoperation <= max_operations; currentoperation++) { if (Form.IsClosing) { break; } Form.SetOutputCurrentPercentage(0); int totalpercentage = (100 / max_operations) * (currentoperation - 1); Form.SetOutputTotalPercentage(totalpercentage); if ((operations_until_failure != 0) && (currentoperation == operations_until_failure)) { if (!Form.IsClosing) { Form.Invoke(() => Form.SetStage(Form.StageEnum.Output_Failure)); } Program.CreateMessageBox($"Test Operation {currentoperation} ERROR", MessageBoxIcon.Error, MessageBoxButtons.OK); break; } for (int currentpercentage = 0; currentpercentage <= 100; currentpercentage++) { if (Form.IsClosing) { break; } Form.Invoke(() => { Form.SetOutputCurrentOperation($"Test Operation {currentoperation}", Theme.GetOutputOperationColor()); Form.SetOutputCurrentPercentage(currentpercentage); Form.SetOutputTotalPercentage(totalpercentage + (int)(25 * (currentpercentage * 0.01))); }); Thread.Sleep(sleepms); } } if (!Form.IsClosing) { Form.Invoke(() => Form.SetStage(Form.StageEnum.Output_Success)); } if ((operations_until_failure == 0) && testsuccess) { Program.CreateMessageBox($"Test SUCCESS", MessageBoxIcon.Asterisk, MessageBoxButtons.OK); } if (!Form.IsClosing) { Form.Invoke(() => { Form.SetStage(Form.StageEnum.Output); Form.SetOutputCurrentPercentage(100); Form.SetOutputTotalPercentage(100); int i = Form.mainForm.Debug_AutomatedState.SelectedIndex; Form.SetStage(Form.StageEnum.Debug); Form.mainForm.Debug_AutomatedState.SelectedIndex = i; }); } }).Start(); }
internal static void SetStage(StageEnum stage #if DEBUG , bool set_debug_index = true #endif ) { switch (stage) { #if DEBUG case StageEnum.Debug: Debug.SetFormStage(); goto select; #endif case StageEnum.Main: mainForm.Settings_RefreshReleases.Enabled = false; mainForm.Automated_Text.Visible = true; mainForm.Automated_Text_Failure.Visible = false; mainForm.Automated_Retry.Visible = false; mainForm.Automated_Divider.Visible = false; mainForm.Automated_Install.Visible = false; mainForm.Automated_Uninstall.Visible = false; mainForm.Automated_UnityGame_Text.Visible = false; mainForm.Automated_UnityGame_Select.Visible = false; #if DEBUG if (set_debug_index) { mainForm.Debug_AutomatedState.SelectedIndex = 0; } goto default; #else goto main; #endif case StageEnum.Automated_Failure: mainForm.Settings_RefreshReleases.Enabled = true; mainForm.Automated_Text.Visible = false; mainForm.Automated_Text_Failure.Visible = true; mainForm.Automated_Retry.Visible = true; #if DEBUG if (set_debug_index) { mainForm.Debug_AutomatedState.SelectedIndex = 1; } #endif goto default; case StageEnum.Automated_Success: mainForm.Settings_RefreshReleases.Enabled = true; mainForm.Automated_Text.Visible = false; mainForm.Automated_Text_Failure.Visible = false; mainForm.Automated_Retry.Visible = false; mainForm.Automated_Divider.Visible = true; mainForm.Automated_Install.Visible = true; mainForm.Automated_Uninstall.Visible = true; mainForm.Automated_UnityGame_Text.Visible = true; mainForm.Automated_UnityGame_Select.Visible = true; #if DEBUG if (set_debug_index) { mainForm.Debug_AutomatedState.SelectedIndex = 2; } #endif goto default; case StageEnum.Output: SetOutputCurrentOperation("Current Operation", Theme.GetOutputOperationColor()); SetOutputProgressBarColor(Theme.GetOutputProgressBarColor()); SetOutputCurrentPercentage(0); SetOutputTotalPercentage(0); #if DEBUG if (set_debug_index) { mainForm.Debug_OutputState.SelectedIndex = 0; } #endif goto output; case StageEnum.Output_Failure: SetOutputCurrentOperation("ERROR!", Color.Red); SetOutputProgressBarColor(MetroFramework.MetroColorStyle.Red); #if DEBUG if (set_debug_index) { mainForm.Debug_OutputState.SelectedIndex = 1; } #endif goto default; case StageEnum.Output_Success: SetOutputCurrentOperation("SUCCESS!", Color.Green); SetOutputProgressBarColor(MetroFramework.MetroColorStyle.Green); SetOutputCurrentPercentage(100); SetOutputTotalPercentage(100); #if DEBUG if (set_debug_index) { mainForm.Debug_OutputState.SelectedIndex = 2; } #endif goto default; case StageEnum.SelfUpdate: #if DEBUG goto default; #else mainForm.PageManager.Controls.Clear(); mainForm.PageManager.Controls.Add(mainForm.Tab_SelfUpdate); goto select; main: mainForm.PageManager.Controls.Clear(); mainForm.PageManager.Controls.Add(mainForm.Tab_Automated); mainForm.PageManager.Controls.Add(mainForm.Tab_ManualZip); mainForm.PageManager.Controls.Add(mainForm.Tab_Settings); goto select; #endif output: mainForm.PageManager.Controls.Clear(); mainForm.PageManager.Controls.Add(mainForm.Tab_Output); goto select; select: mainForm.PageManager.SelectedIndex = 0; goto default; default: break; } }