private void RunTask(SetupOperation task) { cancelSource = new CancellationTokenSource(); foreach (var b in taskButtons.Keys) { b.Enabled = false; } buttonCancel.Enabled = true; new Thread(() => RunTaskThread(task)).Start(); }
private static void UpdateSteamDirTargetsFile() { SetupOperation.CreateParentDirectory(targetsFilePath); File.WriteAllText(targetsFilePath, $@"<?xml version=""1.0"" encoding=""utf-8""?> <Project ToolsVersion=""14.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <PropertyGroup> <TerrariaSteamPath>{SteamDir}</TerrariaSteamPath> </PropertyGroup> </Project>"); }
public override void Run() { foreach (var task in tasks) { task.Run(); if (task.Failed()) { failed = task; return; } } }
internal static void UpdateTargetsFile() { SetupOperation.CreateParentDirectory(targetsFilePath); string gitsha = ""; RunCmd("", "git", "rev-parse HEAD", s => gitsha = s.Trim()); string branch = ""; RunCmd("", "git", "rev-parse --abbrev-ref HEAD", s => branch = s.Trim()); string GITHUB_HEAD_REF = Environment.GetEnvironmentVariable("GITHUB_HEAD_REF"); if (!string.IsNullOrWhiteSpace(GITHUB_HEAD_REF)) { Console.WriteLine($"GITHUB_HEAD_REF found: {GITHUB_HEAD_REF}"); branch = GITHUB_HEAD_REF; } string HEAD_SHA = Environment.GetEnvironmentVariable("HEAD_SHA"); if (!string.IsNullOrWhiteSpace(HEAD_SHA)) { Console.WriteLine($"HEAD_SHA found: {HEAD_SHA}"); gitsha = HEAD_SHA; } string targetsText = $@"<?xml version=""1.0"" encoding=""utf-8""?> <Project ToolsVersion=""14.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <!-- This file will always be overwritten, do not edit it manually. --> <PropertyGroup> <BranchName>{branch}</BranchName> <CommitSHA>{gitsha}</CommitSHA> <TerrariaSteamPath>{SteamDir}</TerrariaSteamPath> <tModLoaderSteamPath>{TMLSteamDir}</tModLoaderSteamPath> </PropertyGroup> </Project>"; if (File.Exists(targetsFilePath) && targetsText == File.ReadAllText(targetsFilePath)) { return; } File.WriteAllText(targetsFilePath, targetsText); }
public void DoAuto2(SetupOperation task) { var errorLogFile = Path.Combine(Program.logsDir, "error.log"); try { SetupOperation.DeleteFile(errorLogFile); if (!task.ConfigurationDialog()) { return; } if (!task.StartupWarning()) { return; } try { task.Run(); if (cancelSource.IsCancellationRequested) { throw new OperationCanceledException(); } } catch (OperationCanceledException e) { return; } if (task.Failed() || task.Warnings()) { task.FinishedDialog(); } } catch (Exception e) { SetStatus(e.Message); Environment.Exit(1); var status = ""; SetupOperation.CreateDirectory(Program.logsDir); File.WriteAllText(errorLogFile, status + "\r\n" + e); } }
private static void UpdateSteamDirTargetsFile() { SetupOperation.CreateParentDirectory(targetsFilePath); string targetsText = $@"<?xml version=""1.0"" encoding=""utf-8""?> <Project ToolsVersion=""14.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <PropertyGroup> <TerrariaSteamPath>{SteamDir}</TerrariaSteamPath> <tModLoaderSteamPath>{tMLSteamDir}</tModLoaderSteamPath> </PropertyGroup> </Project>"; if (File.Exists(targetsFilePath) && targetsText == File.ReadAllText(targetsFilePath)) { return; } File.WriteAllText(targetsFilePath, targetsText); }
private void RunTaskThread(SetupOperation task) { var errorLogFile = Path.Combine(Program.logsDir, "error.log"); try { SetupOperation.DeleteFile(errorLogFile); if (!task.ConfigurationDialog()) { return; } if (!task.StartupWarning()) { return; } try { task.Run(); if (cancelSource.IsCancellationRequested) { throw new OperationCanceledException(); } } catch (OperationCanceledException e) { Invoke(new Action(() => { labelStatus.Text = "Cancelled"; if (e.Message != new OperationCanceledException().Message) { labelStatus.Text += ": " + e.Message; } })); return; } if (task.Failed() || task.Warnings()) { task.FinishedDialog(); } Invoke(new Action(() => { labelStatus.Text = task.Failed() ? "Failed" : "Done"; })); } catch (Exception e) { var status = ""; Invoke(new Action(() => { status = labelStatus.Text; labelStatus.Text = "Error: " + e.Message.Trim(); })); SetupOperation.CreateDirectory(Program.logsDir); File.WriteAllText(errorLogFile, status + "\r\n" + e); } finally { Invoke(new Action(() => { foreach (var b in taskButtons.Keys) { b.Enabled = true; } buttonCancel.Enabled = false; progressBar.Value = 0; if (closeOnCancel) { Close(); } })); } }