From d32f1baec3447c5f460ad1085bf559928b21be2c Mon Sep 17 00:00:00 2001 From: Ionite Date: Mon, 17 Jul 2023 17:38:53 -0400 Subject: [PATCH] Convert remaining path combines to os independent --- StabilityMatrix.Avalonia/DesignData/DesignData.cs | 2 +- .../ViewModels/Dialogs/InstallerViewModel.cs | 2 +- .../ViewModels/Dialogs/OneClickInstallViewModel.cs | 7 +++++-- StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs | 3 ++- StabilityMatrix.Core/Helper/HardwareHelper.cs | 5 +---- StabilityMatrix.Core/Models/InstalledPackage.cs | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/StabilityMatrix.Avalonia/DesignData/DesignData.cs b/StabilityMatrix.Avalonia/DesignData/DesignData.cs index ba086a9e..32bac023 100644 --- a/StabilityMatrix.Avalonia/DesignData/DesignData.cs +++ b/StabilityMatrix.Avalonia/DesignData/DesignData.cs @@ -49,7 +49,7 @@ public static class DesignData DisplayName = "My Installed Package", PackageName = "stable-diffusion-webui", PackageVersion = "v1.0.0", - LibraryPath = "Packages\\example-webui", + LibraryPath = $"Packages{Environment.NewLine}example-webui", LastUpdateCheck = DateTimeOffset.Now } }, diff --git a/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs index eb07be0d..a33e19a5 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs @@ -189,7 +189,7 @@ public partial class InstallerViewModel : ContentDialogViewModelBase var package = new InstalledPackage { DisplayName = SelectedPackage.DisplayName, - LibraryPath = $"Packages\\{InstallName}", + LibraryPath = Path.Combine("Packages", InstallName), Id = Guid.NewGuid(), PackageName = SelectedPackage.Name, PackageVersion = version, diff --git a/StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs index 01f209e8..12c88017 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.ObjectModel; +using System.IO; using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; @@ -114,11 +115,13 @@ public partial class OneClickInstallViewModel : ViewModelBase } IsIndeterminate = false; + var libraryDir = settingsManager.LibraryDir; + // get latest version & download & install SubHeaderText = "Getting latest version..."; var latestVersion = await SelectedPackage.GetLatestVersion(); SelectedPackage.InstallLocation = - $"{settingsManager.LibraryDir}\\Packages\\{SelectedPackage.Name}"; + Path.Combine(libraryDir, "Packages", SelectedPackage.Name); SelectedPackage.ConsoleOutput += (_, output) => SubSubHeaderText = output.Text; await DownloadPackage(latestVersion); @@ -130,7 +133,7 @@ public partial class OneClickInstallViewModel : ViewModelBase var installedPackage = new InstalledPackage { DisplayName = SelectedPackage.DisplayName, - LibraryPath = $"Packages\\{SelectedPackage.Name}", + LibraryPath = Path.Combine("Packages", SelectedPackage.Name), Id = Guid.NewGuid(), PackageName = SelectedPackage.Name, PackageVersion = latestVersion, diff --git a/StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs index 6dfc9400..db4cabae 100644 --- a/StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs @@ -2,6 +2,7 @@ using System.Collections.Immutable; using System.Collections.ObjectModel; using System.Diagnostics; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -158,7 +159,7 @@ public partial class LaunchPageViewModel : PageViewModelBase, IDisposable await pyRunner.Initialize(); // Get path from package - var packagePath = $"{settingsManager.LibraryDir}\\{activeInstall.LibraryPath!}"; + var packagePath = Path.Combine(settingsManager.LibraryDir, activeInstall.LibraryPath!); basePackage.ConsoleOutput += OnProcessOutputReceived; basePackage.Exited += OnProcessExited; diff --git a/StabilityMatrix.Core/Helper/HardwareHelper.cs b/StabilityMatrix.Core/Helper/HardwareHelper.cs index 1b715332..66d678ca 100644 --- a/StabilityMatrix.Core/Helper/HardwareHelper.cs +++ b/StabilityMatrix.Core/Helper/HardwareHelper.cs @@ -73,7 +73,7 @@ public static partial class HardwareHelper name = match.Groups[1].Value.Trim(); } - match = MyRegex().Match(gpuOutput); + match = Regex.Match(gpuOutput, @"prefetchable\) \[size=(\\d+)M\]"); if (match.Success) { memoryBytes = ulong.Parse(match.Groups[1].Value) * 1024 * 1024; @@ -123,9 +123,6 @@ public static partial class HardwareHelper { return IterGpuInfo().Any(gpu => gpu.IsAmd); } - - [GeneratedRegex("prefetchable\\) \\[size=(\\d+)M\\]")] - private static partial Regex MyRegex(); } public enum Level diff --git a/StabilityMatrix.Core/Models/InstalledPackage.cs b/StabilityMatrix.Core/Models/InstalledPackage.cs index b8aa0fd4..22f4da87 100644 --- a/StabilityMatrix.Core/Models/InstalledPackage.cs +++ b/StabilityMatrix.Core/Models/InstalledPackage.cs @@ -52,7 +52,7 @@ public class InstalledPackage // Further check if the path is a sub-path of the library var isSubPath = relativePath != "." && relativePath != ".." - && !relativePath.StartsWith("..\\") + && !relativePath.StartsWith(".." + Environment.NewLine) && !System.IO.Path.IsPathRooted(relativePath); return isSubPath ? relativePath : null; }