Browse Source

Merge pull request #1 from ionite34/install-git-if-necessary

pull/5/head
Ionite 2 years ago committed by GitHub
parent
commit
ba7148d0ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      StabilityMatrix/A3WebUI.cs
  2. BIN
      StabilityMatrix/Assets/Git-2.40.1-64-bit.exe
  3. 39
      StabilityMatrix/Helper/ProcessRunner.cs
  4. 16
      StabilityMatrix/InstallPage.xaml
  5. 1
      StabilityMatrix/InstallPage.xaml.cs
  6. 16
      StabilityMatrix/InstallerViewModel.cs
  7. 2
      StabilityMatrix/Models/BasePackage.cs
  8. 12
      StabilityMatrix/StabilityMatrix.csproj
  9. 89
      StabilityMatrix/ViewModels/InstallerViewModel.cs

4
StabilityMatrix/A3WebUI.cs

@ -1,4 +1,6 @@
namespace StabilityMatrix; using StabilityMatrix.Models;
namespace StabilityMatrix;
public class A3WebUI: BasePackage public class A3WebUI: BasePackage
{ {

BIN
StabilityMatrix/Assets/Git-2.40.1-64-bit.exe

Binary file not shown.

39
StabilityMatrix/Helper/ProcessRunner.cs

@ -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;
}
}

16
StabilityMatrix/InstallPage.xaml

@ -6,12 +6,13 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:system="using:System" xmlns:system="using:System"
xmlns:viewModels="using:StabilityMatrix.ViewModels"
xmlns:models="using:StabilityMatrix.Models"
mc:Ignorable="d" mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
d:DataContext="{d:DesignInstance Type=local:InstallerViewModel}">
<Page.DataContext> <Page.DataContext>
<local:InstallerViewModel/> <viewModels:InstallerViewModel/>
</Page.DataContext> </Page.DataContext>
<Grid> <Grid>
@ -28,7 +29,7 @@
</ListView.ItemsSource> </ListView.ItemsSource>
<ListView.ItemTemplate> <ListView.ItemTemplate>
<DataTemplate x:DataType="local:BasePackage"> <DataTemplate x:DataType="models:BasePackage">
<Grid Height="110" Margin="6"> <Grid Height="110" Margin="6">
<StackPanel Grid.Column="0" VerticalAlignment="Top" Margin="10,0,0,0"> <StackPanel Grid.Column="0" VerticalAlignment="Top" Margin="10,0,0,0">
<TextBlock Text="{x:Bind DisplayName}" x:Phase="1" Margin="0,5,0,5" Style="{ThemeResource BaseTextBlockStyle}" /> <TextBlock Text="{x:Bind DisplayName}" x:Phase="1" Margin="0,5,0,5" Style="{ThemeResource BaseTextBlockStyle}" />
@ -38,6 +39,11 @@
</DataTemplate> </DataTemplate>
</ListView.ItemTemplate> </ListView.ItemTemplate>
</ListView> </ListView>
<StackPanel Orientation="Vertical">
<Button Content="Install" Command="{Binding InstallCommand}" Width="100" Height="50" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding InstalledText}" HorizontalAlignment="Center" Padding="8"/>
<ProgressBar Visibility="{Binding ProgressBarVisibility}" Value="{Binding ProgressValue, FallbackValue=10}"
Maximum="100" Width="500" Style="{ThemeResource DefaultProgressBarStyle}"/>
</StackPanel>
</Grid> </Grid>
</Page> </Page>

1
StabilityMatrix/InstallPage.xaml.cs

@ -16,6 +16,7 @@ using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime; using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation; using Windows.Foundation;
using Windows.Foundation.Collections; using Windows.Foundation.Collections;
using StabilityMatrix.ViewModels;
// To learn more about WinUI, the WinUI project structure, // To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info. // and more about our project templates, see: http://aka.ms/winui-project-info.

16
StabilityMatrix/InstallerViewModel.cs

@ -1,16 +0,0 @@
using System.Collections.ObjectModel;
namespace StabilityMatrix;
internal class InstallerViewModel
{
public InstallerViewModel()
{
}
public static ObservableCollection<BasePackage> Packages => new()
{
new A3WebUI(),
};
}

2
StabilityMatrix/BasePackage.cs → StabilityMatrix/Models/BasePackage.cs

@ -1,4 +1,4 @@
namespace StabilityMatrix; namespace StabilityMatrix.Models;
public abstract class BasePackage public abstract class BasePackage
{ {

12
StabilityMatrix/StabilityMatrix.csproj

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework> <TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
@ -10,6 +10,10 @@
<PublishProfile>win10-$(Platform).pubxml</PublishProfile> <PublishProfile>win10-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI> <UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling> <EnableMsixTooling>true</EnableMsixTooling>
<LangVersion>11</LangVersion>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<None Remove="InstallPage.xaml" /> <None Remove="InstallPage.xaml" />
@ -27,6 +31,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.221109.1" /> <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.221109.1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.755" /> <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.755" />
<Manifest Include="$(ApplicationManifest)" /> <Manifest Include="$(ApplicationManifest)" />
@ -40,6 +45,11 @@
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'"> <ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" /> <ProjectCapability Include="Msix" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Update="Assets\Git-2.40.1-64-bit.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup> <ItemGroup>
<Page Update="LaunchPage.xaml"> <Page Update="LaunchPage.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>

89
StabilityMatrix/ViewModels/InstallerViewModel.cs

@ -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…
Cancel
Save