Ionite
2 years ago
committed by
GitHub
9 changed files with 158 additions and 27 deletions
Binary file not shown.
@ -0,0 +1,39 @@ |
|||||||
|
using System; |
||||||
|
using System.Diagnostics; |
||||||
|
using System.IO; |
||||||
|
using System.Threading.Tasks; |
||||||
|
|
||||||
|
namespace StabilityMatrix.Helper; |
||||||
|
|
||||||
|
public static class ProcessRunner |
||||||
|
{ |
||||||
|
public static async Task<string> RunProcessAsync(string fileName, string arguments) |
||||||
|
{ |
||||||
|
using var process = new Process(); |
||||||
|
process.StartInfo.FileName = fileName; |
||||||
|
process.StartInfo.Arguments = arguments; |
||||||
|
process.StartInfo.UseShellExecute = false; |
||||||
|
process.StartInfo.RedirectStandardOutput = true; |
||||||
|
process.StartInfo.CreateNoWindow = true; |
||||||
|
process.Start(); |
||||||
|
|
||||||
|
var output = await process.StandardOutput.ReadToEndAsync(); |
||||||
|
await process.WaitForExitAsync(); |
||||||
|
|
||||||
|
return output; |
||||||
|
} |
||||||
|
|
||||||
|
public static Process RunProcess(string fileName, string arguments) |
||||||
|
|
||||||
|
{ |
||||||
|
using var process = new Process(); |
||||||
|
process.StartInfo.FileName = fileName; |
||||||
|
process.StartInfo.Arguments = arguments; |
||||||
|
process.StartInfo.UseShellExecute = false; |
||||||
|
process.StartInfo.RedirectStandardOutput = true; |
||||||
|
process.StartInfo.CreateNoWindow = true; |
||||||
|
process.Start(); |
||||||
|
|
||||||
|
return process; |
||||||
|
} |
||||||
|
} |
@ -1,16 +0,0 @@ |
|||||||
using System.Collections.ObjectModel; |
|
||||||
|
|
||||||
namespace StabilityMatrix; |
|
||||||
|
|
||||||
internal class InstallerViewModel |
|
||||||
{ |
|
||||||
public InstallerViewModel() |
|
||||||
{ |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public static ObservableCollection<BasePackage> Packages => new() |
|
||||||
{ |
|
||||||
new A3WebUI(), |
|
||||||
}; |
|
||||||
} |
|
@ -1,4 +1,4 @@ |
|||||||
namespace StabilityMatrix; |
namespace StabilityMatrix.Models; |
||||||
|
|
||||||
public abstract class BasePackage |
public abstract class BasePackage |
||||||
{ |
{ |
@ -0,0 +1,89 @@ |
|||||||
|
using System.Collections.ObjectModel; |
||||||
|
using System.Threading.Tasks; |
||||||
|
using Windows.UI.Popups; |
||||||
|
using CommunityToolkit.Mvvm.Input; |
||||||
|
using StabilityMatrix.Helper; |
||||||
|
using StabilityMatrix.Models; |
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.Diagnostics; |
||||||
|
using System.Runtime.CompilerServices; |
||||||
|
using CommunityToolkit.Mvvm.ComponentModel; |
||||||
|
using Microsoft.UI.Xaml; |
||||||
|
|
||||||
|
namespace StabilityMatrix.ViewModels; |
||||||
|
|
||||||
|
internal class InstallerViewModel : INotifyPropertyChanged |
||||||
|
{ |
||||||
|
private string installedText; |
||||||
|
private int progressValue; |
||||||
|
|
||||||
|
public InstallerViewModel() |
||||||
|
{ |
||||||
|
InstalledText = "shrug"; |
||||||
|
ProgressValue = 0; |
||||||
|
} |
||||||
|
|
||||||
|
public static ObservableCollection<BasePackage> Packages => new() |
||||||
|
{ |
||||||
|
new A3WebUI(), |
||||||
|
}; |
||||||
|
|
||||||
|
public string InstalledText |
||||||
|
{ |
||||||
|
get => installedText; |
||||||
|
private set |
||||||
|
{ |
||||||
|
if (value == installedText) return; |
||||||
|
installedText = value; |
||||||
|
OnPropertyChanged(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public int ProgressValue |
||||||
|
{ |
||||||
|
get => progressValue; |
||||||
|
set |
||||||
|
{ |
||||||
|
if (value == progressValue) return; |
||||||
|
progressValue = value; |
||||||
|
OnPropertyChanged(); |
||||||
|
OnPropertyChanged(nameof(ProgressBarVisibility)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public Visibility ProgressBarVisibility => ProgressValue > 0 ? Visibility.Visible : Visibility.Collapsed; |
||||||
|
|
||||||
|
public AsyncRelayCommand InstallCommand => new(InstallGitIfNecessary); |
||||||
|
private async Task InstallGitIfNecessary() |
||||||
|
{ |
||||||
|
var gitOutput = await ProcessRunner.RunProcessAsync("git", "--version"); |
||||||
|
if (gitOutput.Contains("git version 2")) |
||||||
|
{ |
||||||
|
InstalledText = "Installed"; |
||||||
|
ProgressValue = 100; |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
InstalledText = "Not Installed"; |
||||||
|
var installProcess = ProcessRunner.RunProcess("Assets\\Git-2.40.1-64-bit.exe", "/SILENT /NORESTART"); |
||||||
|
while (!installProcess.StandardOutput.EndOfStream && !installProcess.HasExited) |
||||||
|
{ |
||||||
|
Debug.WriteLine(await installProcess.StandardOutput.ReadLineAsync()); |
||||||
|
} |
||||||
|
|
||||||
|
if (installProcess.ExitCode == 0) |
||||||
|
{ |
||||||
|
InstalledText = "Git successfully installed"; |
||||||
|
ProgressValue = 100; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public event PropertyChangedEventHandler PropertyChanged; |
||||||
|
|
||||||
|
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) |
||||||
|
{ |
||||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue