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. 36
      StabilityMatrix/DataDirectoryMigrationDialog.xaml
  2. 5
      StabilityMatrix/DataDirectoryMigrationDialog.xaml.cs
  3. 2
      StabilityMatrix/SelectInstallLocationsDialog.xaml
  4. 30
      StabilityMatrix/ViewModels/DataDirectoryMigrationViewModel.cs
  5. 65
      StabilityMatrix/ViewModels/MainWindowViewModel.cs
  6. 18
      StabilityMatrix/ViewModels/SelectInstallLocationsViewModel.cs

36
StabilityMatrix/DataDirectoryMigrationDialog.xaml

@ -7,6 +7,7 @@
d:DesignHeight="512"
d:DesignWidth="640"
mc:Ignorable="d"
UseLayoutRounding="True"
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
x:Class="StabilityMatrix.DataDirectoryMigrationDialog"
@ -28,6 +29,10 @@
<converters:IsStringNullOrWhitespaceConverter />
<converters:BoolNegationConverter />
</converters:ValueConverterGroup>
<converters:ValueConverterGroup x:Key="InvertAndVisibilitate">
<converters:BoolNegationConverter />
<BooleanToVisibilityConverter />
</converters:ValueConverterGroup>
</ui:ContentDialog.Resources>
<Grid
@ -39,6 +44,7 @@
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel>
@ -48,6 +54,12 @@
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?"
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
IsClosable="False"
IsOpen="{Binding AutoMigrateText, Converter={StaticResource InvertIsStringNullOrWhitespaceConverter}}"
@ -80,18 +92,28 @@
Text="{Binding MigrateProgressText, FallbackValue=Migrating 1 of 2 Packages}"
VerticalAlignment="Center" />
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center">
<StackPanel Grid.Row="2"
Orientation="Horizontal"
HorizontalAlignment="Center">
<ui:Button
Appearance="Info"
Appearance="Secondary"
Click="NoThanks_OnClick"
Content="No Thanks"
FontSize="16"
HorizontalAlignment="Center"
Margin="8"
Visibility="{Binding CanShowNoThanksButton, Converter={StaticResource BooleanToVisibilityConverter}}"
IsEnabled="{Binding IsMigrating, Converter={StaticResource BoolNegationConverter}}"
Padding="16,8" />
IsEnabled="{Binding IsMigrating, Converter={StaticResource BoolNegationConverter}}"/>
<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
Appearance="Success"
Click="ContinueButton_OnClick"
@ -99,8 +121,8 @@
FontSize="16"
HorizontalAlignment="Center"
Margin="8"
IsEnabled="{Binding IsMigrating, Converter={StaticResource BoolNegationConverter}}"
Padding="16,8" />
Visibility="{Binding HasFreeSpaceError, Converter={StaticResource InvertAndVisibilitate}}"
IsEnabled="{Binding IsMigrating, Converter={StaticResource BoolNegationConverter}}"/>
</StackPanel>
</Grid>

5
StabilityMatrix/DataDirectoryMigrationDialog.xaml.cs

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

2
StabilityMatrix/SelectInstallLocationsDialog.xaml

@ -97,7 +97,7 @@
IsOpen="True"
FontSize="13"
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." />
</StackPanel>

30
StabilityMatrix/ViewModels/DataDirectoryMigrationViewModel.cs

@ -7,6 +7,7 @@ using CommunityToolkit.Mvvm.Input;
using NLog;
using StabilityMatrix.Helper;
using StabilityMatrix.Models;
using StabilityMatrix.Models.FileInterfaces;
using StabilityMatrix.Python;
namespace StabilityMatrix.ViewModels;
@ -36,12 +37,19 @@ public partial class DataDirectoryMigrationViewModel : ObservableObject
[ObservableProperty] private bool isMigrating;
[ObservableProperty] private bool canShowNoThanksButton;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(NeedsMoveMigrateText))]
[NotifyPropertyChangedFor(nameof(MigrateProgressText))]
private bool hasFreeSpaceError;
public string AutoMigrateText => AutoMigrateCount == 0 ? string.Empty :
$"{AutoMigrateCount} Packages will be automatically migrated to the new format";
public string NeedsMoveMigrateText => NeedsMoveMigrateCount == 0 ? string.Empty :
$"{NeedsMoveMigrateCount} Packages are not relative to the Data Directory and will be moved, this may take a few minutes";
public string NeedsMoveMigrateText => NeedsMoveMigrateCount == 0 || HasFreeSpaceError
? 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]
private string migrateProgressText = "";
@ -62,10 +70,11 @@ public partial class DataDirectoryMigrationViewModel : ObservableObject
this.packageFactory = packageFactory;
}
public void OnLoaded()
public async Task OnLoaded()
{
AutoMigrateCount = 0;
NeedsMoveMigrateCount = 0;
HasFreeSpaceError = false;
// Get all old packages
var oldPackages = settingsManager.GetOldInstalledPackages().ToArray();
@ -78,6 +87,19 @@ public partial class DataDirectoryMigrationViewModel : ObservableObject
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"StabilityMatrix");
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()

65
StabilityMatrix/ViewModels/MainWindowViewModel.cs

@ -137,30 +137,7 @@ public partial class MainWindowViewModel : ObservableObject
// Check if library path is set
if (!settingsManager.TryFindLibrary())
{
// See if this is an existing user for message variation
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var settingsPath = Path.Combine(appDataPath, "StabilityMatrix", "settings.json");
var isExistingUser = File.Exists(settingsPath);
// need to show dialog to choose library location
var dialog = dialogFactory.CreateInstallLocationsDialog();
var result = await dialog.ShowAsync();
if (result != ContentDialogResult.Primary)
{
Application.Current.Shutdown();
}
// 1. For portable mode, call settings.SetPortableMode()
var viewModel = (dialog.DataContext as SelectInstallLocationsViewModel)!;
if (viewModel.IsPortableMode)
{
settingsManager.SetPortableMode();
}
// 2. For custom path, call settings.SetLibraryPath(path)
else
{
settingsManager.SetLibraryPath(viewModel.DataDirectory);
}
await ShowPathSelectionDialog();
}
// Try to find library again, should be found now
@ -174,10 +151,48 @@ public partial class MainWindowViewModel : ObservableObject
{
var dialog = dialogFactory.CreateDataDirectoryMigrationDialog();
var result = await dialog.ShowAsync();
if (result != ContentDialogResult.Primary)
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
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var settingsPath = Path.Combine(appDataPath, "StabilityMatrix", "settings.json");
var isExistingUser = File.Exists(settingsPath);
// need to show dialog to choose library location
var dialog = dialogFactory.CreateInstallLocationsDialog();
var result = await dialog.ShowAsync();
if (result != ContentDialogResult.Primary)
{
Application.Current.Shutdown();
}
// 1. For portable mode, call settings.SetPortableMode()
var viewModel = (dialog.DataContext as SelectInstallLocationsViewModel)!;
if (viewModel.IsPortableMode)
{
settingsManager.SetPortableMode();
}
// 2. For custom path, call settings.SetLibraryPath(path)
else
{
settingsManager.SetLibraryPath(viewModel.DataDirectory);
}
}

18
StabilityMatrix/ViewModels/SelectInstallLocationsViewModel.cs

@ -67,24 +67,6 @@ public partial class SelectInstallLocationsViewModel : ObservableObject
{
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
if (!Directory.Exists(DataDirectory))
{

Loading…
Cancel
Save