diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 35b66b2..34a4b75 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -178,8 +178,6 @@ namespace Bloxstrap await CheckLatestVersion(); - CheckInstallMigration(); - // install/update roblox if we're running for the first time, needs updating, or the player location doesn't exist if (App.IsFirstRun || _latestVersionGuid != App.State.Prop.VersionGuid || !File.Exists(_playerLocation)) await InstallLatestVersion(); @@ -477,71 +475,6 @@ namespace Bloxstrap App.Logger.WriteLine(LOG_IDENT, $"Registered as {totalSize} KB"); } - private void CheckInstallMigration() - { - const string LOG_IDENT = "Bootstrapper::CheckInstallMigration"; - - // check if we've changed our install location since the last time we started - // in which case, we'll have to copy over all our folders so we don't lose any mods and stuff - - using RegistryKey? applicationKey = Registry.CurrentUser.OpenSubKey($@"Software\{App.ProjectName}", true); - - string? oldInstallLocation = (string?)applicationKey?.GetValue("OldInstallLocation"); - - if (applicationKey is null || oldInstallLocation is null || oldInstallLocation == Paths.Base) - return; - - SetStatus("Migrating install location..."); - - if (Directory.Exists(oldInstallLocation)) - { - App.Logger.WriteLine(LOG_IDENT, $"Moving all files in {oldInstallLocation} to {Paths.Base}..."); - - foreach (string oldFileLocation in Directory.GetFiles(oldInstallLocation, "*.*", SearchOption.AllDirectories)) - { - string relativeFile = oldFileLocation.Substring(oldInstallLocation.Length + 1); - string newFileLocation = Path.Combine(Paths.Base, relativeFile); - string? newDirectory = Path.GetDirectoryName(newFileLocation); - - try - { - if (!String.IsNullOrEmpty(newDirectory)) - Directory.CreateDirectory(newDirectory); - - File.Move(oldFileLocation, newFileLocation, true); - } - catch (Exception ex) - { - App.Logger.WriteLine(LOG_IDENT, $"Failed to move {oldFileLocation} to {newFileLocation}! {ex}"); - } - } - - try - { - Directory.Delete(oldInstallLocation, true); - App.Logger.WriteLine(LOG_IDENT, "Deleted old install location"); - } - catch (Exception ex) - { - App.Logger.WriteLine(LOG_IDENT, $"Failed to delete old install location! {ex}"); - } - } - - applicationKey.DeleteValue("OldInstallLocation"); - - // allow shortcuts to be re-registered - if (Directory.Exists(Paths.StartMenu)) - Directory.Delete(Paths.StartMenu, true); - - if (File.Exists(DesktopShortcutLocation)) - { - File.Delete(DesktopShortcutLocation); - App.Settings.Prop.CreateDesktopIcon = true; - } - - App.Logger.WriteLine(LOG_IDENT, "Finished migrating install location!"); - } - public static void CheckInstall() { const string LOG_IDENT = "Bootstrapper::CheckInstall"; @@ -746,7 +679,7 @@ namespace Bloxstrap // if the folder we're installed to does not end with "Bloxstrap", we're installed to a user-selected folder // in which case, chances are they chose to install to somewhere they didn't really mean to (prior to the added warning in 2.4.0) // if so, we're walking on eggshells and have to ensure we only clean up what we need to clean up - bool cautiousUninstall = !Paths.Base.EndsWith(App.ProjectName); + bool cautiousUninstall = !Paths.Base.ToLower().EndsWith(App.ProjectName.ToLower()); var cleanupSequence = new List { @@ -1418,7 +1351,8 @@ namespace Bloxstrap App.Logger.WriteLine(LOG_IDENT, $"An exception occurred after downloading {totalBytesRead} bytes. ({i}/{maxTries})"); App.Logger.WriteException(LOG_IDENT, ex); - File.Delete(packageLocation); + if (File.Exists(packageLocation)) + File.Delete(packageLocation); if (i >= maxTries) throw; diff --git a/Bloxstrap/UI/Elements/Menu/MainWindow.xaml b/Bloxstrap/UI/Elements/Menu/MainWindow.xaml index 73260ad..6fee20e 100644 --- a/Bloxstrap/UI/Elements/Menu/MainWindow.xaml +++ b/Bloxstrap/UI/Elements/Menu/MainWindow.xaml @@ -59,26 +59,24 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/Bloxstrap/UI/Elements/Menu/MainWindow.xaml.cs b/Bloxstrap/UI/Elements/Menu/MainWindow.xaml.cs index 989fa65..968dabf 100644 --- a/Bloxstrap/UI/Elements/Menu/MainWindow.xaml.cs +++ b/Bloxstrap/UI/Elements/Menu/MainWindow.xaml.cs @@ -15,16 +15,14 @@ namespace Bloxstrap.UI.Elements.Menu public partial class MainWindow : INavigationWindow { private readonly IThemeService _themeService = new ThemeService(); - private readonly IDialogService _dialogService = new DialogService(); public MainWindow() { App.Logger.WriteLine("MainWindow::MainWindow", "Initializing menu"); - DataContext = new MainWindowViewModel(this, _dialogService); + DataContext = new MainWindowViewModel(this); SetTheme(); InitializeComponent(); - _dialogService.SetDialogControl(RootDialog); } public void SetTheme() diff --git a/Bloxstrap/UI/Elements/Menu/Pages/BehaviourPage.xaml.cs b/Bloxstrap/UI/Elements/Menu/Pages/BehaviourPage.xaml.cs index 68de8d7..1a7631d 100644 --- a/Bloxstrap/UI/Elements/Menu/Pages/BehaviourPage.xaml.cs +++ b/Bloxstrap/UI/Elements/Menu/Pages/BehaviourPage.xaml.cs @@ -1,5 +1,4 @@ -using Bloxstrap.UI.ViewModels.Menu; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -14,6 +13,8 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Bloxstrap.UI.ViewModels.Menu; + namespace Bloxstrap.UI.Elements.Menu.Pages { /// diff --git a/Bloxstrap/UI/Elements/Menu/Pages/InstallationPage.xaml b/Bloxstrap/UI/Elements/Menu/Pages/InstallationPage.xaml index 7f28503..3c34ffc 100644 --- a/Bloxstrap/UI/Elements/Menu/Pages/InstallationPage.xaml +++ b/Bloxstrap/UI/Elements/Menu/Pages/InstallationPage.xaml @@ -1,66 +1,79 @@  - - + Title="InstallationPage"> - - - - - - - - - - - - - - - - - - + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/Bloxstrap/UI/Elements/Menu/Pages/InstallationPage.xaml.cs b/Bloxstrap/UI/Elements/Menu/Pages/InstallationPage.xaml.cs index b58ea4a..a46ae0e 100644 --- a/Bloxstrap/UI/Elements/Menu/Pages/InstallationPage.xaml.cs +++ b/Bloxstrap/UI/Elements/Menu/Pages/InstallationPage.xaml.cs @@ -1,4 +1,19 @@ -using Bloxstrap.UI.ViewModels.Menu; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +using Bloxstrap.UI.ViewModels.Menu; namespace Bloxstrap.UI.Elements.Menu.Pages { diff --git a/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs index f8108ab..0e520ec 100644 --- a/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs @@ -14,8 +14,6 @@ namespace Bloxstrap.UI.ViewModels.Menu public class MainWindowViewModel : NotifyPropertyChangedViewModel { private readonly Window _window; - private readonly IDialogService _dialogService; - private readonly string _originalBaseDirectory = App.BaseDirectory; // we need this to check if the basedirectory changes public ICommand CloseWindowCommand => new RelayCommand(CloseWindow); public ICommand ConfirmSettingsCommand => new RelayCommand(ConfirmSettings); @@ -24,25 +22,31 @@ namespace Bloxstrap.UI.ViewModels.Menu public string ConfirmButtonText => App.IsFirstRun ? "Install" : "Save"; public bool ConfirmButtonEnabled { get; set; } = true; - public MainWindowViewModel(Window window, IDialogService dialogService) + public MainWindowViewModel(Window window) { _window = window; - _dialogService = dialogService; } private void CloseWindow() => _window.Close(); private void ConfirmSettings() { + if (!App.IsFirstRun) + { + App.ShouldSaveConfigs = true; + App.FastFlags.Save(); + CloseWindow(); + + return; + } + if (string.IsNullOrEmpty(App.BaseDirectory)) { Controls.ShowMessageBox("You must set an install location", MessageBoxImage.Error); return; } - bool shouldCheckInstallLocation = App.IsFirstRun || App.BaseDirectory != _originalBaseDirectory; - - if (shouldCheckInstallLocation && NavigationVisibility == Visibility.Visible) + if (NavigationVisibility == Visibility.Visible) { try { @@ -104,53 +108,28 @@ namespace Bloxstrap.UI.ViewModels.Menu return; } } - - if (App.IsFirstRun) + + if (NavigationVisibility == Visibility.Visible) { - if (NavigationVisibility == Visibility.Visible) - { - ((INavigationWindow)_window).Navigate(typeof(PreInstallPage)); + ((INavigationWindow)_window).Navigate(typeof(PreInstallPage)); - NavigationVisibility = Visibility.Collapsed; - OnPropertyChanged(nameof(NavigationVisibility)); + NavigationVisibility = Visibility.Collapsed; + OnPropertyChanged(nameof(NavigationVisibility)); - ConfirmButtonEnabled = false; - OnPropertyChanged(nameof(ConfirmButtonEnabled)); + ConfirmButtonEnabled = false; + OnPropertyChanged(nameof(ConfirmButtonEnabled)); - Task.Run(async delegate - { - await Task.Delay(3000); - - ConfirmButtonEnabled = true; - OnPropertyChanged(nameof(ConfirmButtonEnabled)); - }); - } - else + Task.Run(async delegate { - App.IsSetupComplete = true; - CloseWindow(); - } + await Task.Delay(3000); + + ConfirmButtonEnabled = true; + OnPropertyChanged(nameof(ConfirmButtonEnabled)); + }); } else { - App.ShouldSaveConfigs = true; - App.FastFlags.Save(); - - if (shouldCheckInstallLocation) - { - App.Logger.WriteLine("MainWindowViewModel::ConfirmSettings", $"Changing install location from {_originalBaseDirectory} to {App.BaseDirectory}"); - - Controls.ShowMessageBox( - $"{App.ProjectName} will install to the new location you've set the next time it runs.", - MessageBoxImage.Information - ); - - using RegistryKey registryKey = Registry.CurrentUser.CreateSubKey($@"Software\{App.ProjectName}"); - registryKey.SetValue("InstallLocation", App.BaseDirectory); - registryKey.SetValue("OldInstallLocation", _originalBaseDirectory); - Paths.Initialize(App.BaseDirectory); - } - + App.IsSetupComplete = true; CloseWindow(); } }