Browse Source

- setup ViewModel with some databinding stuff

- added InstallGitIfNecessary command & button
- added MVVMToolkit nuget for all those goodies
- slight restructuring
pull/5/head
JT 2 years ago
parent
commit
882f9cf6bb
  1. 4
      StabilityMatrix/A3WebUI.cs
  2. BIN
      StabilityMatrix/Assets/Git-2.40.1-64-bit.exe
  3. 39
      StabilityMatrix/Helper/ProcessRunner.cs
  4. 18
      StabilityMatrix/InstallPage.xaml
  5. 3
      StabilityMatrix/InstallPage.xaml.cs
  6. 16
      StabilityMatrix/InstallerViewModel.cs
  7. 4
      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
{

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

18
StabilityMatrix/InstallPage.xaml

@ -6,12 +6,13 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:system="using:System"
xmlns:viewModels="using:StabilityMatrix.ViewModels"
xmlns:models="using:StabilityMatrix.Models"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
d:DataContext="{d:DesignInstance Type=local:InstallerViewModel}">
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.DataContext>
<local:InstallerViewModel/>
<viewModels:InstallerViewModel/>
</Page.DataContext>
<Grid>
@ -28,7 +29,7 @@
</ListView.ItemsSource>
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:BasePackage">
<DataTemplate x:DataType="models:BasePackage">
<Grid Height="110" Margin="6">
<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}" />
@ -38,6 +39,11 @@
</DataTemplate>
</ListView.ItemTemplate>
</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>
</Page>
</Page>

3
StabilityMatrix/InstallPage.xaml.cs

@ -16,6 +16,7 @@ using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using StabilityMatrix.ViewModels;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
@ -33,4 +34,4 @@ namespace StabilityMatrix
DataContext = new InstallerViewModel();
}
}
}
}

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(),
};
}

4
StabilityMatrix/BasePackage.cs → StabilityMatrix/Models/BasePackage.cs

@ -1,4 +1,4 @@
namespace StabilityMatrix;
namespace StabilityMatrix.Models;
public abstract class BasePackage
{
@ -7,4 +7,4 @@ public abstract class BasePackage
public abstract string Author { get; }
public string ByAuthor => $"By {Author}";
}
}

12
StabilityMatrix/StabilityMatrix.csproj

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