From 8f289e39396627d62243146c1dda6e26efa9e6ab Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 23 Aug 2020 21:21:55 +0100 Subject: [PATCH] Check if The Unarchiver is usable. --- RomRepoMgr.Core/Workers/Compression.cs | 18 +++--- RomRepoMgr.Settings/Settings.cs | 1 + .../ViewModels/ImportRomFolderViewModel.cs | 16 ++--- RomRepoMgr/ViewModels/SettingsViewModel.cs | 3 + .../ViewModels/SplashWindowViewModel.cs | 64 ++++++++++++++++++- RomRepoMgr/Views/ImportRomFolder.xaml | 12 ++-- RomRepoMgr/Views/SplashWindow.xaml | 20 +++++- 7 files changed, 109 insertions(+), 25 deletions(-) diff --git a/RomRepoMgr.Core/Workers/Compression.cs b/RomRepoMgr.Core/Workers/Compression.cs index 3df8c39..f42805b 100644 --- a/RomRepoMgr.Core/Workers/Compression.cs +++ b/RomRepoMgr.Core/Workers/Compression.cs @@ -83,7 +83,7 @@ namespace RomRepoMgr.Core.Workers outFs.Dispose(); } - public void CheckUnar(string unArPath) + public bool CheckUnar(string unArPath) { if(string.IsNullOrWhiteSpace(unArPath)) { @@ -92,7 +92,7 @@ namespace RomRepoMgr.Core.Workers Message = "unar path is not set." }); - return; + return false; } string unarFolder = Path.GetDirectoryName(unArPath); @@ -109,7 +109,7 @@ namespace RomRepoMgr.Core.Workers Message = $"Cannot find unar executable at {unarPath}." }); - return; + return false; } if(!File.Exists(lsarPath)) @@ -119,7 +119,7 @@ namespace RomRepoMgr.Core.Workers Message = "Cannot find lsar executable." }); - return; + return false; } string unarOut, lsarOut; @@ -148,7 +148,7 @@ namespace RomRepoMgr.Core.Workers Message = "Cannot run unar." }); - return; + return false; } try @@ -175,7 +175,7 @@ namespace RomRepoMgr.Core.Workers Message = "Cannot run lsar." }); - return; + return false; } if(!unarOut.StartsWith("unar ", StringComparison.CurrentCulture)) @@ -185,7 +185,7 @@ namespace RomRepoMgr.Core.Workers Message = "Not the correct unar executable" }); - return; + return false; } if(!lsarOut.StartsWith("lsar ", StringComparison.CurrentCulture)) @@ -195,7 +195,7 @@ namespace RomRepoMgr.Core.Workers Message = "Not the correct lsar executable" }); - return; + return false; } var versionProcess = new Process @@ -217,6 +217,8 @@ namespace RomRepoMgr.Core.Workers { Message = versionProcess.StandardOutput.ReadToEnd().TrimEnd('\n') }); + + return true; } } } \ No newline at end of file diff --git a/RomRepoMgr.Settings/Settings.cs b/RomRepoMgr.Settings/Settings.cs index fe8a1f5..b99984f 100644 --- a/RomRepoMgr.Settings/Settings.cs +++ b/RomRepoMgr.Settings/Settings.cs @@ -48,6 +48,7 @@ namespace RomRepoMgr.Settings const string XDG_CONFIG_HOME_RESOLVED = ".config"; /// Current statistcs public static SetSettings Current; + public static bool UnArUsable { get; set; } /// Loads settings public static void LoadSettings() diff --git a/RomRepoMgr/ViewModels/ImportRomFolderViewModel.cs b/RomRepoMgr/ViewModels/ImportRomFolderViewModel.cs index c9a5785..c5d05fc 100644 --- a/RomRepoMgr/ViewModels/ImportRomFolderViewModel.cs +++ b/RomRepoMgr/ViewModels/ImportRomFolderViewModel.cs @@ -68,21 +68,22 @@ namespace RomRepoMgr.ViewModels FolderPath = folderPath; _removeFilesChecked = false; _knownOnlyChecked = true; - _recurseArchivesChecked = false; + _recurseArchivesChecked = Settings.Settings.UnArUsable; ImportResults = new ObservableCollection(); CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand); StartCommand = ReactiveCommand.Create(ExecuteStartCommand); IsReady = true; CanStart = true; CanClose = true; - _removeFilesEnabled = true; + _removeFilesEnabled = false; } - public string PathLabel => "Path:"; - public string FolderPath { get; } - public string RemoveFilesLabel => "Remove files after import successful."; - public string KnownOnlyLabel => "Only import known files."; - public string RecurseArchivesLabel => "Try to detect archives and import their contents."; + public string PathLabel => "Path:"; + public string FolderPath { get; } + public string RemoveFilesLabel => "Remove files after import successful."; + public string KnownOnlyLabel => "Only import known files."; + public string RecurseArchivesLabel => "Try to detect archives and import their contents."; + public bool RecurseArchivesEnabled => Settings.Settings.UnArUsable; public bool RemoveFilesChecked { @@ -301,7 +302,6 @@ namespace RomRepoMgr.ViewModels StatusMessage = "Finished!"; CanClose = true; Progress2Visible = false; - IsReady = true; Console.WriteLine($"Took {watch.Elapsed.TotalSeconds} seconds"); }); diff --git a/RomRepoMgr/ViewModels/SettingsViewModel.cs b/RomRepoMgr/ViewModels/SettingsViewModel.cs index 45b1521..f1d266f 100644 --- a/RomRepoMgr/ViewModels/SettingsViewModel.cs +++ b/RomRepoMgr/ViewModels/SettingsViewModel.cs @@ -320,7 +320,10 @@ namespace RomRepoMgr.ViewModels Settings.Settings.Current.TemporaryFolder = TemporaryPath; if(_unArChanged) + { Settings.Settings.Current.UnArchiverPath = UnArPath; + Settings.Settings.UnArUsable = true; + } if(_databaseChanged || _repositoryChanged || diff --git a/RomRepoMgr/ViewModels/SplashWindowViewModel.cs b/RomRepoMgr/ViewModels/SplashWindowViewModel.cs index 136884c..e4d9184 100644 --- a/RomRepoMgr/ViewModels/SplashWindowViewModel.cs +++ b/RomRepoMgr/ViewModels/SplashWindowViewModel.cs @@ -35,12 +35,17 @@ using Microsoft.EntityFrameworkCore; using ReactiveUI; using RomRepoMgr.Core.EventArgs; using RomRepoMgr.Core.Models; +using RomRepoMgr.Core.Workers; using RomRepoMgr.Database; namespace RomRepoMgr.ViewModels { public sealed class SplashWindowViewModel : ViewModelBase { + bool _checkingUnArError; + bool _checkingUnArOk; + string _checkingUnArText; + bool _checkingUnArUnknown; string _exitButtonText; bool _exitVisible; bool _loadingDatabaseError; @@ -48,7 +53,6 @@ namespace RomRepoMgr.ViewModels string _loadingDatabaseText; bool _loadingDatabaseUnknown; bool _loadingRomSetsError; - bool _loadingRomSetsOk; string _loadingRomSetsText; bool _loadingRomSetsUnknown; @@ -71,6 +75,9 @@ namespace RomRepoMgr.ViewModels LoadingSettingsOk = false; LoadingSettingsError = false; LoadingSettingsUnknown = true; + CheckingUnArOk = false; + CheckingUnArError = false; + CheckingUnArUnknown = true; LoadingDatabaseOk = false; LoadingDatabaseError = false; LoadingDatabaseUnknown = true; @@ -115,6 +122,30 @@ namespace RomRepoMgr.ViewModels set => this.RaiseAndSetIfChanged(ref _loadingSettingsUnknown, value); } + public string CheckingUnArText + { + get => _checkingUnArText; + set => this.RaiseAndSetIfChanged(ref _checkingUnArText, value); + } + + public bool CheckingUnArOk + { + get => _checkingUnArOk; + set => this.RaiseAndSetIfChanged(ref _checkingUnArOk, value); + } + + public bool CheckingUnArError + { + get => _checkingUnArError; + set => this.RaiseAndSetIfChanged(ref _checkingUnArError, value); + } + + public bool CheckingUnArUnknown + { + get => _checkingUnArUnknown; + set => this.RaiseAndSetIfChanged(ref _checkingUnArUnknown, value); + } + public string LoadingDatabaseText { get => _loadingDatabaseText; @@ -206,6 +237,7 @@ namespace RomRepoMgr.ViewModels { LoadingText = "ROM Repository Manager"; LoadingSettingsText = "Loading settings..."; + CheckingUnArText = "Checking The Unarchiver..."; LoadingDatabaseText = "Loading database..."; MigratingDatabaseText = "Migrating database..."; LoadingRomSetsText = "Loading ROM sets..."; @@ -220,7 +252,7 @@ namespace RomRepoMgr.ViewModels { Settings.Settings.LoadSettings(); - Dispatcher.UIThread.Post(LoadDatabase); + Dispatcher.UIThread.Post(CheckUnar); } catch(Exception e) { @@ -236,11 +268,37 @@ namespace RomRepoMgr.ViewModels ExitVisible = true; } - void LoadDatabase() + void CheckUnar() => Task.Run(() => { LoadingSettingsUnknown = false; LoadingSettingsOk = true; + try + { + var worker = new Compression(); + Settings.Settings.UnArUsable = worker.CheckUnar(Settings.Settings.Current.UnArchiverPath); + + Dispatcher.UIThread.Post(LoadDatabase); + } + catch(Exception e) + { + // TODO: Log error + Dispatcher.UIThread.Post(FailedCheckUnar); + } + }); + + void FailedCheckUnar() + { + CheckingUnArUnknown = false; + CheckingUnArError = true; + ExitVisible = true; + } + + void LoadDatabase() + { + CheckingUnArUnknown = false; + CheckingUnArOk = true; + Task.Run(() => { try diff --git a/RomRepoMgr/Views/ImportRomFolder.xaml b/RomRepoMgr/Views/ImportRomFolder.xaml index 5b12b5d..9bbb44c 100644 --- a/RomRepoMgr/Views/ImportRomFolder.xaml +++ b/RomRepoMgr/Views/ImportRomFolder.xaml @@ -43,17 +43,19 @@ - + - + - + - + @@ -82,7 +84,7 @@ - +