Browse Source

Migration dialog fixes

pull/14/head
Ionite 1 year ago
parent
commit
abb6f92c57
No known key found for this signature in database
  1. 18
      StabilityMatrix/DataDirectoryMigrationDialog.xaml
  2. 18
      StabilityMatrix/Models/InstalledPackage.cs
  3. 2
      StabilityMatrix/SelectInstallLocationsDialog.xaml
  4. 2
      StabilityMatrix/ViewModels/DataDirectoryMigrationViewModel.cs
  5. 50
      StabilityMatrix/ViewModels/MainWindowViewModel.cs

18
StabilityMatrix/DataDirectoryMigrationDialog.xaml

@ -1,7 +1,5 @@
<ui:ContentDialog
CloseButtonText="Close"
DialogHeight="720"
DialogWidth="840"
Loaded="DataDirectoryMigrationDialog_OnLoaded"
Title="Select Data Directory"
d:DataContext="{d:DesignInstance Type=viewModels:DataDirectoryMigrationViewModel,
@ -24,14 +22,18 @@
<ui:ContentDialog.Resources>
<!-- ReSharper disable once Xaml.StaticResourceNotResolved -->
<Style BasedOn="{StaticResource {x:Type ui:ContentDialog}}" TargetType="{x:Type local:SelectInstallLocationsDialog}" />
<converters:StringNullOrEmptyToVisibilityConverter x:Key="StringNullOrEmptyToVisibilityConverter" />
<Style BasedOn="{StaticResource {x:Type ui:ContentDialog}}" TargetType="{x:Type local:DataDirectoryMigrationDialog}" />
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<converters:ValueConverterGroup x:Key="InvertIsStringNullOrWhitespaceConverter">
<converters:IsStringNullOrWhitespaceConverter />
<converters:BoolNegationConverter />
</converters:ValueConverterGroup>
</ui:ContentDialog.Resources>
<Grid
Margin="16"
MaxHeight="900"
MaxWidth="700"
MinHeight="300"
VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
@ -39,7 +41,7 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel MaxWidth="700">
<StackPanel>
<TextBlock
FontSize="16"
Margin="8,8,8,8"
@ -47,13 +49,13 @@
TextWrapping="Wrap" />
<ui:InfoBar
IsClosable="False"
IsOpen="{Binding AutoMigrateText, Converter={StaticResource StringNullOrEmptyToVisibilityConverter}}"
IsOpen="{Binding AutoMigrateText, Converter={StaticResource InvertIsStringNullOrWhitespaceConverter}}"
Margin="8"
Severity="Success"
Title="{Binding AutoMigrateText, FallbackValue=5 Packages will be automatically migrated to the new format}" />
<ui:InfoBar
IsClosable="False"
IsOpen="{Binding NeedsMoveMigrateText, Converter={StaticResource StringNullOrEmptyToVisibilityConverter}}"
IsOpen="{Binding NeedsMoveMigrateText, Converter={StaticResource InvertIsStringNullOrWhitespaceConverter}}"
Margin="8"
Severity="Informational"
Title="{Binding NeedsMoveMigrateText, FallbackValue=2 Packages are not relative to the Data Directory and will be moved this may take a few minutes}" />

18
StabilityMatrix/Models/InstalledPackage.cs

@ -89,6 +89,24 @@ public class InstalledPackage
return false;
}
/// <summary>
/// Check if the old Path can be migrated to the new LibraryPath.
/// </summary>
/// <param name="libraryDirectory"></param>
/// <returns></returns>
public bool CanPureMigratePath(string? libraryDirectory = null)
{
#pragma warning disable CS0618
var oldPath = Path;
#pragma warning restore CS0618
if (oldPath == null) return false;
// Check if the path is a sub-path of the library
var library = libraryDirectory ?? GlobalConfig.LibraryDir;
var relativePath = GetSubPath(library, oldPath);
return relativePath != null;
}
/// <summary>
/// Migrate the old Path to the new LibraryPath.
/// If libraryDirectory is null, GlobalConfig.LibraryDir is used.

2
StabilityMatrix/SelectInstallLocationsDialog.xaml

@ -29,7 +29,7 @@
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</ui:ContentDialog.Resources>
<Grid Height="600" Margin="16,0,16,16">
<Grid Height="500" Margin="16,0,16,16">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />

2
StabilityMatrix/ViewModels/DataDirectoryMigrationViewModel.cs

@ -47,7 +47,7 @@ public partial class DataDirectoryMigrationViewModel : ObservableObject
// Get all old packages
var oldPackages = settingsManager.GetOldInstalledPackages().ToArray();
// Attempt to migrate with pure, and count successful migrations
AutoMigrateCount = oldPackages.Count(p => p.TryPureMigratePath());
AutoMigrateCount = oldPackages.Count(p => p.CanPureMigratePath());
// Any remaining packages need to be moved
NeedsMoveMigrateCount = oldPackages.Length - AutoMigrateCount;
}

50
StabilityMatrix/ViewModels/MainWindowViewModel.cs

@ -118,35 +118,35 @@ public partial class MainWindowViewModel : ObservableObject
private async Task DoSettingsCheck()
{
var found = settingsManager.TryFindLibrary();
if (found)
return;
// 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
// Check if library path is set
if (!settingsManager.TryFindLibrary())
{
var dialog = dialogFactory.CreateInstallLocationsDialog();
var result = await dialog.ShowAsync();
if (result != ContentDialogResult.Primary)
{
Application.Current.Shutdown();
}
// 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);
// 1. For portable mode, call settings.SetPortableMode()
var viewModel = (dialog.DataContext as SelectInstallLocationsViewModel)!;
if (viewModel.IsPortableMode)
// need to show dialog to choose library location
if (!settingsManager.TryFindLibrary())
{
settingsManager.SetPortableMode();
}
// 2. For custom path, call settings.SetLibraryPath(path)
else
{
settingsManager.SetLibraryPath(viewModel.DataDirectory);
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);
}
}
}

Loading…
Cancel
Save