Check if The Unarchiver is usable.

This commit is contained in:
2020-08-23 21:21:55 +01:00
parent b698e75739
commit 8f289e3939
7 changed files with 109 additions and 25 deletions

View File

@@ -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;
}
}
}

View File

@@ -48,6 +48,7 @@ namespace RomRepoMgr.Settings
const string XDG_CONFIG_HOME_RESOLVED = ".config";
/// <summary>Current statistcs</summary>
public static SetSettings Current;
public static bool UnArUsable { get; set; }
/// <summary>Loads settings</summary>
public static void LoadSettings()

View File

@@ -68,21 +68,22 @@ namespace RomRepoMgr.ViewModels
FolderPath = folderPath;
_removeFilesChecked = false;
_knownOnlyChecked = true;
_recurseArchivesChecked = false;
_recurseArchivesChecked = Settings.Settings.UnArUsable;
ImportResults = new ObservableCollection<ImportRomFolderItem>();
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");
});

View File

@@ -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 ||

View File

@@ -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

View File

@@ -43,17 +43,19 @@
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Stretch">
<TextBlock Text="{Binding PathLabel}" FontWeight="Bold" /> <TextBlock Text="{Binding FolderPath}" />
</StackPanel>
<CheckBox Grid.Row="1" IsChecked="{Binding RemoveFilesChecked}" IsEnabled="{Binding IsReady}">
<CheckBox Grid.Row="1" IsChecked="{Binding RemoveFilesChecked}" IsEnabled="{Binding RemoveFilesEnabled}"
IsVisible="{Binding IsReady}">
<CheckBox.Content>
<TextBlock Text="{Binding RemoveFilesLabel}" IsEnabled="{Binding RemoveFilesEnabled}" />
<TextBlock Text="{Binding RemoveFilesLabel}" />
</CheckBox.Content>
</CheckBox>
<CheckBox Grid.Row="2" IsChecked="{Binding KnownOnlyChecked}">
<CheckBox Grid.Row="2" IsChecked="{Binding KnownOnlyChecked}" IsVisible="{Binding IsReady}">
<CheckBox.Content>
<TextBlock Text="{Binding KnownOnlyLabel}" />
</CheckBox.Content>
</CheckBox>
<CheckBox Grid.Row="3" IsChecked="{Binding RecurseArchivesChecked}" IsEnabled="False">
<CheckBox Grid.Row="3" IsChecked="{Binding RecurseArchivesChecked}"
IsEnabled="{Binding RecurseArchivesEnabled}" IsVisible="{Binding IsReady}">
<CheckBox.Content>
<TextBlock Text="{Binding RecurseArchivesLabel}" />
</CheckBox.Content>
@@ -82,7 +84,7 @@
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
<StackPanel Grid.Row="8" Orientation="Horizontal" IsVisible="{Binding IsReady}" HorizontalAlignment="Right">
<StackPanel Grid.Row="8" Orientation="Horizontal" HorizontalAlignment="Right">
<Button HorizontalAlignment="Right" VerticalAlignment="Center" IsEnabled="{Binding CanClose}"
Command="{Binding CloseCommand}">
<TextBlock Text="{Binding CloseLabel}" />

View File

@@ -5,7 +5,7 @@
xmlns:svg="clr-namespace:Svg.Skia.Avalonia;assembly=Svg.Skia.Avalonia" mc:Ignorable="d" d:DesignWidth="450"
d:DesignHeight="250" x:Class="RomRepoMgr.Views.SplashWindow" Icon="/Assets/avalonia-logo.ico"
Title="ROM Repository Manager" SystemDecorations="BorderOnly" WindowStartupLocation="CenterScreen" Width="250"
Height="140">
Height="175">
<Design.DataContext>
<vm:SplashWindowViewModel />
</Design.DataContext>
@@ -30,6 +30,24 @@
</Image>
<TextBlock Text="{Binding LoadingSettingsText}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<Image MaxWidth="24" MaxHeight="24" IsVisible="{Binding CheckingUnArOk}">
<Image.Source>
<svg:SvgImage Source="/Assets/emblem-checked.svg" />
</Image.Source>
</Image>
<Image MaxWidth="24" MaxHeight="24" IsVisible="{Binding CheckingUnArError}">
<Image.Source>
<svg:SvgImage Source="/Assets/emblem-error.svg" />
</Image.Source>
</Image>
<Image MaxWidth="24" MaxHeight="24" IsVisible="{Binding CheckingUnArUnknown}">
<Image.Source>
<svg:SvgImage Source="/Assets/emblem-question.svg" />
</Image.Source>
</Image>
<TextBlock Text="{Binding CheckingUnArText}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<Image MaxWidth="24" MaxHeight="24" IsVisible="{Binding LoadingDatabaseOk}">
<Image.Source>