Browse Source

Merge remote-tracking branch 'origin/avalonia' into avalonia

pull/55/head
Ionite 1 year ago
parent
commit
ded897c440
No known key found for this signature in database
  1. 2
      StabilityMatrix.Avalonia/Controls/RefreshBadge.axaml
  2. 2
      StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs
  3. 5
      StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs
  4. 3
      StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs
  5. 4
      StabilityMatrix.Avalonia/Views/PackageManagerPage.axaml
  6. 10
      StabilityMatrix.Core/Helper/ArchiveHelper.cs
  7. 45
      StabilityMatrix.Core/Processes/ProcessRunner.cs
  8. 1
      StabilityMatrix.Tests/StabilityMatrix.Tests.csproj

2
StabilityMatrix.Avalonia/Controls/RefreshBadge.axaml

@ -18,6 +18,7 @@
Foreground="{Binding ColorBrush}"
Margin="4"
Padding="2"
Background="Transparent"
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsEnabled="{Binding !IsWorking}">
@ -27,6 +28,7 @@
FontSize="14"
Grid.Row="0"
Height="20"
BorderThickness="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsEnabled="{Binding IsWorking}"

2
StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs

@ -106,7 +106,7 @@ public partial class OneClickInstallViewModel : ViewModelBase
SubHeaderText = "Getting latest version...";
var latestVersion = await SelectedPackage.GetLatestVersion();
SelectedPackage.InstallLocation =
Path.Combine(libraryDir, "Packages", SelectedPackage.Name);
Path.Combine(libraryDir, "Packages", SelectedPackage.DisplayName);
SelectedPackage.ConsoleOutput += (_, output) => SubSubHeaderText = output.Text;
await DownloadPackage(latestVersion);

5
StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs

@ -92,6 +92,7 @@ public partial class LaunchPageViewModel : PageViewModelBase, IDisposable
EventManager.Instance.PackageLaunchRequested += OnPackageLaunchRequested;
EventManager.Instance.OneClickInstallFinished += OnOneClickInstallFinished;
EventManager.Instance.InstalledPackagesChanged += OnInstalledPackagesChanged;
// Handler for console input
Console.ApcInput += (_, message) =>
{
@ -101,7 +102,9 @@ public partial class LaunchPageViewModel : PageViewModelBase, IDisposable
}
};
}
private void OnInstalledPackagesChanged(object? sender, EventArgs e) => OnLoaded();
private void OnPackageLaunchRequested(object? sender, Guid e)
{
OnLoaded();

3
StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs

@ -107,6 +107,9 @@ public partial class MainWindowViewModel : ViewModelBase
throw new Exception("Could not find library after setting path");
}
// Tell LaunchPage to load any packages if they selected an existing directory
EventManager.Instance.OnInstalledPackagesChanged();
// Check if there are old packages, if so show migration dialog
// TODO: Migration dialog

4
StabilityMatrix.Avalonia/Views/PackageManagerPage.axaml

@ -3,14 +3,14 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:StabilityMatrix.Avalonia.ViewModels"
xmlns:mocks="clr-namespace:StabilityMatrix.Avalonia.DesignData;assembly=StabilityMatrix.Avalonia"
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
xmlns:models="clr-namespace:StabilityMatrix.Core.Models;assembly=StabilityMatrix.Core"
xmlns:controls="clr-namespace:StabilityMatrix.Avalonia.Controls"
xmlns:designData="clr-namespace:StabilityMatrix.Avalonia.DesignData"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:DataType="viewModels:PackageManagerViewModel"
x:CompileBindings="True"
d:DataContext="{x:Static mocks:DesignData.PackageManagerViewModel}"
d:DataContext="{x:Static designData:DesignData.PackageManagerViewModel}"
x:Class="StabilityMatrix.Avalonia.Views.PackageManagerPage">
<Grid Margin="16" RowDefinitions="Auto,*">

10
StabilityMatrix.Core/Helper/ArchiveHelper.cs

@ -112,12 +112,14 @@ public static partial class ArchiveHelper
public static async Task<ArchiveInfo> Extract7Z(string archivePath, string extractDirectory, IProgress<ProgressReport> progress)
{
var outputStore = new StringBuilder();
var onOutput = new Action<ProcessOutput>(s =>
var onOutput = new Action<string?>(s =>
{
if (s == null) return;
// Parse progress
Logger.Trace($"7z: {s}");
outputStore.AppendLine(s.Text);
var match = Regex7ZProgressFull().Match(s.Text);
outputStore.AppendLine(s);
var match = Regex7ZProgressFull().Match(s);
if (match.Success)
{
var percent = int.Parse(match.Groups[1].Value);
@ -132,7 +134,7 @@ public static partial class ArchiveHelper
$"x {ProcessRunner.Quote(archivePath)} -o{ProcessRunner.Quote(extractDirectory)} -y -bsp1";
Logger.Debug($"Starting process '{SevenZipPath}' with arguments '{args}'");
var process = ProcessRunner.StartAnsiProcess(SevenZipPath, args, outputDataReceived: onOutput);
var process = ProcessRunner.StartProcess(SevenZipPath, args, outputDataReceived: onOutput);
await ProcessRunner.WaitForExitConditionAsync(process);
progress.Report(new ProgressReport(1, "Finished extracting", type: ProgressType.Extract));

45
StabilityMatrix.Core/Processes/ProcessRunner.cs

@ -91,6 +91,51 @@ public static class ProcessRunner
return output;
}
public static Process StartProcess(
string fileName,
string arguments,
string? workingDirectory = null,
Action<string?>? outputDataReceived = null,
Dictionary<string, string>? environmentVariables = null)
{
Logger.Debug($"Starting process '{fileName}' with arguments '{arguments}'");
var info = new ProcessStartInfo
{
FileName = fileName,
Arguments = arguments,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
};
if (environmentVariables != null)
{
foreach (var (key, value) in environmentVariables)
{
info.EnvironmentVariables[key] = value;
}
}
if (workingDirectory != null)
{
info.WorkingDirectory = workingDirectory;
}
var process = new Process {StartInfo = info};
StartTrackedProcess(process);
if (outputDataReceived == null)
return process;
process.OutputDataReceived += (sender, args) => outputDataReceived(args.Data);
process.ErrorDataReceived += (sender, args) => outputDataReceived(args.Data);
process.BeginOutputReadLine();
process.BeginErrorReadLine();
return process;
}
public static AnsiProcess StartAnsiProcess(
string fileName,

1
StabilityMatrix.Tests/StabilityMatrix.Tests.csproj

@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>net7.0-windows10.0.17763.0</TargetFramework>
<RuntimeIdentifiers>win-x64;linux-x64;osx-x64;osx-arm64</RuntimeIdentifiers>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Loading…
Cancel
Save