Browse Source

Merge pull request #139 from ionite34/move-space-warning

Move free space warning to migration dialog
pull/14/head
JT 1 year ago committed by GitHub
parent
commit
ea5339f399
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      StabilityMatrix/DataDirectoryMigrationDialog.xaml
  2. 5
      StabilityMatrix/DataDirectoryMigrationDialog.xaml.cs
  3. 2
      StabilityMatrix/SelectInstallLocationsDialog.xaml
  4. 28
      StabilityMatrix/ViewModels/DataDirectoryMigrationViewModel.cs
  5. 51
      StabilityMatrix/ViewModels/MainWindowViewModel.cs
  6. 18
      StabilityMatrix/ViewModels/SelectInstallLocationsViewModel.cs

34
StabilityMatrix/DataDirectoryMigrationDialog.xaml

@ -7,6 +7,7 @@
d:DesignHeight="512" d:DesignHeight="512"
d:DesignWidth="640" d:DesignWidth="640"
mc:Ignorable="d" mc:Ignorable="d"
UseLayoutRounding="True"
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}" ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}" ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
x:Class="StabilityMatrix.DataDirectoryMigrationDialog" x:Class="StabilityMatrix.DataDirectoryMigrationDialog"
@ -28,6 +29,10 @@
<converters:IsStringNullOrWhitespaceConverter /> <converters:IsStringNullOrWhitespaceConverter />
<converters:BoolNegationConverter /> <converters:BoolNegationConverter />
</converters:ValueConverterGroup> </converters:ValueConverterGroup>
<converters:ValueConverterGroup x:Key="InvertAndVisibilitate">
<converters:BoolNegationConverter />
<BooleanToVisibilityConverter />
</converters:ValueConverterGroup>
</ui:ContentDialog.Resources> </ui:ContentDialog.Resources>
<Grid <Grid
@ -39,6 +44,7 @@
<RowDefinition Height="*" /> <RowDefinition Height="*" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel> <StackPanel>
@ -48,6 +54,12 @@
TextAlignment="Center" TextAlignment="Center"
Text="It looks like you have data from an older version of Stability Matrix before v1.1.0, would you like to migrate it?" Text="It looks like you have data from an older version of Stability Matrix before v1.1.0, would you like to migrate it?"
TextWrapping="Wrap" /> TextWrapping="Wrap" />
<ui:InfoBar
IsClosable="False"
IsOpen="{Binding HasFreeSpaceError}"
Margin="8"
Severity="Warning"
Title="The drive you selected doesn't have enough space for migration. If you don't want to migrate, simply click 'No Thanks'. Otherwise, please choose a different directory before proceeding with the migration." />
<ui:InfoBar <ui:InfoBar
IsClosable="False" IsClosable="False"
IsOpen="{Binding AutoMigrateText, Converter={StaticResource InvertIsStringNullOrWhitespaceConverter}}" IsOpen="{Binding AutoMigrateText, Converter={StaticResource InvertIsStringNullOrWhitespaceConverter}}"
@ -81,17 +93,27 @@
VerticalAlignment="Center" /> VerticalAlignment="Center" />
</StackPanel> </StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center"> <StackPanel Grid.Row="2"
Orientation="Horizontal"
HorizontalAlignment="Center">
<ui:Button <ui:Button
Appearance="Info" Appearance="Secondary"
Click="NoThanks_OnClick" Click="NoThanks_OnClick"
Content="No Thanks" Content="No Thanks"
FontSize="16" FontSize="16"
HorizontalAlignment="Center" HorizontalAlignment="Center"
Margin="8" Margin="8"
Visibility="{Binding CanShowNoThanksButton, Converter={StaticResource BooleanToVisibilityConverter}}" Visibility="{Binding CanShowNoThanksButton, Converter={StaticResource BooleanToVisibilityConverter}}"
IsEnabled="{Binding IsMigrating, Converter={StaticResource BoolNegationConverter}}" IsEnabled="{Binding IsMigrating, Converter={StaticResource BoolNegationConverter}}"/>
Padding="16,8" /> <ui:Button Appearance="Info"
Click="Back_OnClick"
Content="Select Directory"
FontSize="16"
HorizontalAlignment="Center"
Margin="8"
Visibility="{Binding HasFreeSpaceError, Converter={StaticResource BooleanToVisibilityConverter}}"
IsEnabled="{Binding IsMigrating, Converter={StaticResource BoolNegationConverter}}"/>
<ui:Button <ui:Button
Appearance="Success" Appearance="Success"
Click="ContinueButton_OnClick" Click="ContinueButton_OnClick"
@ -99,8 +121,8 @@
FontSize="16" FontSize="16"
HorizontalAlignment="Center" HorizontalAlignment="Center"
Margin="8" Margin="8"
IsEnabled="{Binding IsMigrating, Converter={StaticResource BoolNegationConverter}}" Visibility="{Binding HasFreeSpaceError, Converter={StaticResource InvertAndVisibilitate}}"
Padding="16,8" /> IsEnabled="{Binding IsMigrating, Converter={StaticResource BoolNegationConverter}}"/>
</StackPanel> </StackPanel>
</Grid> </Grid>

5
StabilityMatrix/DataDirectoryMigrationDialog.xaml.cs

@ -35,4 +35,9 @@ public partial class DataDirectoryMigrationDialog : ContentDialog
viewModel.CleanupOldInstall(); viewModel.CleanupOldInstall();
Hide(ContentDialogResult.Primary); Hide(ContentDialogResult.Primary);
} }
private void Back_OnClick(object sender, RoutedEventArgs e)
{
Hide(ContentDialogResult.Secondary);
}
} }

2
StabilityMatrix/SelectInstallLocationsDialog.xaml

@ -97,7 +97,7 @@
IsOpen="True" IsOpen="True"
FontSize="13" FontSize="13"
Margin="0,8,0,0" Margin="0,8,0,0"
Padding="8" Padding="16"
Title="In Portable Mode, all data and settings will be stored in the same directory as the application. You will be able to move the application with its 'Data' folder to a different location or computer." /> Title="In Portable Mode, all data and settings will be stored in the same directory as the application. You will be able to move the application with its 'Data' folder to a different location or computer." />
</StackPanel> </StackPanel>

28
StabilityMatrix/ViewModels/DataDirectoryMigrationViewModel.cs

@ -7,6 +7,7 @@ using CommunityToolkit.Mvvm.Input;
using NLog; using NLog;
using StabilityMatrix.Helper; using StabilityMatrix.Helper;
using StabilityMatrix.Models; using StabilityMatrix.Models;
using StabilityMatrix.Models.FileInterfaces;
using StabilityMatrix.Python; using StabilityMatrix.Python;
namespace StabilityMatrix.ViewModels; namespace StabilityMatrix.ViewModels;
@ -37,11 +38,18 @@ public partial class DataDirectoryMigrationViewModel : ObservableObject
[ObservableProperty] private bool isMigrating; [ObservableProperty] private bool isMigrating;
[ObservableProperty] private bool canShowNoThanksButton; [ObservableProperty] private bool canShowNoThanksButton;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(NeedsMoveMigrateText))]
[NotifyPropertyChangedFor(nameof(MigrateProgressText))]
private bool hasFreeSpaceError;
public string AutoMigrateText => AutoMigrateCount == 0 ? string.Empty : public string AutoMigrateText => AutoMigrateCount == 0 ? string.Empty :
$"{AutoMigrateCount} Packages will be automatically migrated to the new format"; $"{AutoMigrateCount} Packages will be automatically migrated to the new format";
public string NeedsMoveMigrateText => NeedsMoveMigrateCount == 0 ? string.Empty : public string NeedsMoveMigrateText => NeedsMoveMigrateCount == 0 || HasFreeSpaceError
$"{NeedsMoveMigrateCount} Packages are not relative to the Data Directory and will be moved, this may take a few minutes"; ? string.Empty
: $"{NeedsMoveMigrateCount} Package{(NeedsMoveMigrateCount > 1 ? "s" : "")} {(NeedsMoveMigrateCount > 1 ? "are" : "is")} " +
"not relative to the Data Directory and will be moved, this may take a few minutes";
[ObservableProperty] [ObservableProperty]
private string migrateProgressText = ""; private string migrateProgressText = "";
@ -62,10 +70,11 @@ public partial class DataDirectoryMigrationViewModel : ObservableObject
this.packageFactory = packageFactory; this.packageFactory = packageFactory;
} }
public void OnLoaded() public async Task OnLoaded()
{ {
AutoMigrateCount = 0; AutoMigrateCount = 0;
NeedsMoveMigrateCount = 0; NeedsMoveMigrateCount = 0;
HasFreeSpaceError = false;
// Get all old packages // Get all old packages
var oldPackages = settingsManager.GetOldInstalledPackages().ToArray(); var oldPackages = settingsManager.GetOldInstalledPackages().ToArray();
@ -78,6 +87,19 @@ public partial class DataDirectoryMigrationViewModel : ObservableObject
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"StabilityMatrix"); "StabilityMatrix");
CanShowNoThanksButton = settingsManager.LibraryDir != oldLibraryDir; CanShowNoThanksButton = settingsManager.LibraryDir != oldLibraryDir;
if (settingsManager.LibraryDir != oldLibraryDir)
{
var oldDir = new DirectoryPath(oldLibraryDir);
var size = await oldDir.GetSizeAsync(includeSymbolicLinks: false);
// If there's not enough space in the new DataDirectory, show warning
if (size > new DriveInfo(settingsManager.LibraryDir).AvailableFreeSpace)
{
HasFreeSpaceError = true;
}
}
} }
public void CleanupOldInstall() public void CleanupOldInstall()

51
StabilityMatrix/ViewModels/MainWindowViewModel.cs

@ -136,6 +136,39 @@ public partial class MainWindowViewModel : ObservableObject
{ {
// Check if library path is set // Check if library path is set
if (!settingsManager.TryFindLibrary()) if (!settingsManager.TryFindLibrary())
{
await ShowPathSelectionDialog();
}
// Try to find library again, should be found now
if (!settingsManager.TryFindLibrary())
{
throw new Exception("Could not find library after setting path");
}
// Check if there are old packages, if so show migration dialog
if (settingsManager.GetOldInstalledPackages().Any())
{
var dialog = dialogFactory.CreateDataDirectoryMigrationDialog();
var result = await dialog.ShowAsync();
if (result == ContentDialogResult.None)
{
Application.Current.Shutdown();
}
else if (result == ContentDialogResult.Secondary)
{
var portableMarkerFile = Path.Combine("Data", ".sm-portable");
if (File.Exists(portableMarkerFile))
{
File.Delete(portableMarkerFile);
}
await ShowPathSelectionDialog();
await DoSettingsCheck();
}
}
}
private async Task ShowPathSelectionDialog()
{ {
// See if this is an existing user for message variation // See if this is an existing user for message variation
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
@ -163,24 +196,6 @@ public partial class MainWindowViewModel : ObservableObject
} }
} }
// Try to find library again, should be found now
if (!settingsManager.TryFindLibrary())
{
throw new Exception("Could not find library after setting path");
}
// Check if there are old packages, if so show migration dialog
if (settingsManager.GetOldInstalledPackages().Any())
{
var dialog = dialogFactory.CreateDataDirectoryMigrationDialog();
var result = await dialog.ShowAsync();
if (result != ContentDialogResult.Primary)
{
Application.Current.Shutdown();
}
}
}
/// <summary> /// <summary>
/// Updates the taskbar progress bar value and state. /// Updates the taskbar progress bar value and state.
/// </summary> /// </summary>

18
StabilityMatrix/ViewModels/SelectInstallLocationsViewModel.cs

@ -67,24 +67,6 @@ public partial class SelectInstallLocationsViewModel : ObservableObject
{ {
await using var delay = new MinimumDelay(100, 200); await using var delay = new MinimumDelay(100, 200);
if (settingsManager.GetOldInstalledPackages().Any())
{
var oldSettingsDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"StabilityMatrix");
var oldDir = new DirectoryPath(oldSettingsDir);
var size = await oldDir.GetSizeAsync(includeSymbolicLinks: false);
// If there's not enough space in the new DataDirectory, show warning
if (size > new DriveInfo(DataDirectory).AvailableFreeSpace)
{
IsStatusBadgeVisible = true;
IsDirectoryValid = false;
DirectoryStatusText = NotEnoughFreeSpaceText;
return false;
}
}
// Doesn't exist, this is fine as a new install, hide badge // Doesn't exist, this is fine as a new install, hide badge
if (!Directory.Exists(DataDirectory)) if (!Directory.Exists(DataDirectory))
{ {

Loading…
Cancel
Save