Process start refactor to be compatible with .NET Core

This commit is contained in:
Justin Swanson 2020-01-25 21:21:41 -06:00
parent 638542c617
commit 805fc47b78
15 changed files with 47 additions and 33 deletions

View File

@ -1123,6 +1123,21 @@ namespace Wabbajack.Common
File.Delete(path);
}
public static void StartProcessFromFile(string file)
{
Process.Start(new ProcessStartInfo("cmd.exe", $"/c {file}")
{
CreateNoWindow = true,
});
}
public static void OpenWebsite(string url)
{
Process.Start(new ProcessStartInfo("cmd.exe", $"/c start {url}")
{
CreateNoWindow = true,
});
}
public static bool IsInPath(this string path, string parent)
{

View File

@ -40,8 +40,6 @@ namespace Wabbajack.Lib
public abstract string ModListOutputFolder { get; }
public abstract string ModListOutputFile { get; }
public bool ShowReportWhenFinished { get; set; } = true;
public bool IgnoreMissingFiles { get; set; }
public ICollection<Archive> SelectedArchives = new List<Archive>();
@ -161,15 +159,6 @@ namespace Wabbajack.Lib
Utils.DeleteDirectory(ModListOutputFolder);
}
public void ShowReport()
{
if (!ShowReportWhenFinished) return;
var file = Path.GetTempFileName() + ".html";
File.WriteAllText(file, ModList.ReportHTML);
Process.Start(file);
}
public void GenerateReport()
{
string css;

View File

@ -291,8 +291,6 @@ namespace Wabbajack.Lib
ResetMembers();
ShowReport();
UpdateTracker.NextStep("Done Building Modlist");
return true;

View File

@ -255,8 +255,6 @@ namespace Wabbajack.Lib
ResetMembers();
ShowReport();
UpdateTracker.NextStep("Done Building ModList");
return true;

View File

@ -38,7 +38,6 @@ namespace Wabbajack.Test
mo2Folder: utils.MO2Folder,
mo2Profile: profile,
outputFile: profile + Consts.ModListExtension);
compiler.ShowReportWhenFinished = false;
Assert.IsTrue(await compiler.Begin());
return compiler;
}

View File

@ -78,7 +78,6 @@ namespace Wabbajack.Test
mo2Profile: profile,
outputFile: profile + Consts.ModListExtension);
compiler.MO2DownloadsFolder = Path.Combine(utils.DownloadsFolder);
compiler.ShowReportWhenFinished = false;
Assert.IsTrue(await compiler.Begin());
}
@ -166,7 +165,6 @@ namespace Wabbajack.Test
mo2Folder: utils.MO2Folder,
mo2Profile: profile,
outputFile: profile + Consts.ModListExtension);
compiler.ShowReportWhenFinished = false;
Assert.IsTrue(await compiler.Begin());
return compiler;
}

View File

@ -184,8 +184,16 @@ namespace Wabbajack
{
try
{
var successful = await this.Compiler.Compile();
Completed = ErrorResponse.Create(successful);
var modList = await this.Compiler.Compile();
Completed = ErrorResponse.Create(modList.Succeeded);
try
{
ShowReport(modList.Value);
}
catch (Exception ex)
{
Utils.Error(ex, $"Error opening manifest report");
}
}
catch (Exception ex)
{
@ -267,5 +275,12 @@ namespace Wabbajack
.Switch()
.ToGuiProperty(this, nameof(CurrentCpuCount));
}
public void ShowReport(ModList modList)
{
var file = Path.GetTempFileName() + ".html";
File.WriteAllText(file, modList.ReportHTML);
Utils.StartProcessFromFile(file);
}
}
}

View File

@ -12,6 +12,6 @@ namespace Wabbajack
ModlistSettingsEditorVM ModlistSettings { get; }
void Unload();
IObservable<bool> CanCompile { get; }
Task<bool> Compile();
Task<GetResponse<ModList>> Compile();
}
}

View File

@ -163,7 +163,7 @@ namespace Wabbajack
ModlistSettings?.Save();
}
public async Task<bool> Compile()
public async Task<GetResponse<ModList>> Compile()
{
string outputFile;
if (string.IsNullOrWhiteSpace(Parent.OutputLocation.TargetPath))
@ -194,7 +194,8 @@ namespace Wabbajack
{
Parent.MWVM.Settings.Performance.AttachToBatchProcessor(ActiveCompilation);
return await ActiveCompilation.Begin();
var success = await ActiveCompilation.Begin();
return GetResponse<ModList>.Create(success, ActiveCompilation.ModList);
}
}
finally

View File

@ -177,7 +177,7 @@ namespace Wabbajack
GameLocation.TargetPath = StoreHandler.Instance.GetGamePath(SelectedGame.Game, StoreType.GOG);
}
public async Task<bool> Compile()
public async Task<GetResponse<ModList>> Compile()
{
string outputFile = $"{ModlistSettings.ModListName}{Consts.ModListExtension}";
if (!string.IsNullOrWhiteSpace(Parent.OutputLocation.TargetPath))
@ -204,7 +204,8 @@ namespace Wabbajack
})
{
Parent.MWVM.Settings.Performance.AttachToBatchProcessor(ActiveCompilation);
return await ActiveCompilation.Begin();
var success = await ActiveCompilation.Begin();
return GetResponse<ModList>.Create(success, ActiveCompilation.ModList);
}
}
finally

View File

@ -323,7 +323,7 @@ namespace Wabbajack
VisitModListWebsiteCommand = ReactiveCommand.Create(
execute: () =>
{
Process.Start(ModList.Website);
Utils.OpenWebsite(ModList.Website);
return Unit.Default;
},
canExecute: this.WhenAny(x => x.ModList.Website)
@ -443,7 +443,7 @@ namespace Wabbajack
{
var file = Path.GetTempFileName() + ".html";
File.WriteAllText(file, HTMLReport);
Process.Start(file);
Utils.StartProcessFromFile(file);
}
}
}

View File

@ -54,7 +54,7 @@ namespace Wabbajack
Metadata = metadata;
Location = Path.Combine(Consts.ModListDownloadFolder, Metadata.Links.MachineURL + Consts.ModListExtension);
IsBroken = metadata.ValidationSummary.HasFailures;
OpenWebsiteCommand = ReactiveCommand.Create(() => Process.Start($"https://www.wabbajack.org/modlist/{Metadata.Links.MachineURL}"));
OpenWebsiteCommand = ReactiveCommand.Create(() => Utils.OpenWebsite($"https://www.wabbajack.org/modlist/{Metadata.Links.MachineURL}"));
ExecuteCommand = ReactiveCommand.CreateFromObservable<Unit, Unit>(
canExecute: this.WhenAny(x => x.IsBroken).Select(x => !x),
execute: (unit) =>

View File

@ -96,7 +96,7 @@ namespace Wabbajack
if (string.IsNullOrEmpty(Readme)) return;
if (SourceModList.ReadmeIsWebsite)
{
Process.Start(Readme);
Utils.OpenWebsite(Readme);
}
else
{

View File

@ -121,7 +121,7 @@ namespace Wabbajack
VisitNexusSiteCommand = ReactiveCommand.Create(
execute: () =>
{
Process.Start(TargetMod.ModURL);
Utils.OpenWebsite(TargetMod.ModURL);
return Unit.Default;
},
canExecute: this.WhenAny(x => x.TargetMod.ModURL)

View File

@ -17,17 +17,17 @@ namespace Wabbajack
private void GitHub_Click(object sender, RoutedEventArgs e)
{
Process.Start("https://github.com/wabbajack-tools/wabbajack");
Utils.OpenWebsite("https://github.com/wabbajack-tools/wabbajack");
}
private void Discord_Click(object sender, RoutedEventArgs e)
{
Process.Start("https://discord.gg/wabbajack");
Utils.OpenWebsite("https://discord.gg/wabbajack");
}
private void Patreon_Click(object sender, RoutedEventArgs e)
{
Process.Start("https://www.patreon.com/user?u=11907933");
Utils.OpenWebsite("https://www.patreon.com/user?u=11907933");
}
}
}