Skip to content

Commit

Permalink
fix race condition on Linux with the disc already mounted
Browse files Browse the repository at this point in the history
it could result in a message that no disc keys were found until you restart the dumper
  • Loading branch information
13xforever committed Feb 2, 2024
1 parent 7a1a0d6 commit d1a8175
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Ps3DiscDumper/SettingsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,22 @@ static SettingsProvider()
settingsFolder = Path.Combine(Environment.GetFolderPath(SpecialFolder.LocalApplicationData), "ps3-disc-dumper");
settingsPath = Path.Combine(settingsFolder, "settings.json");
if (File.Exists(settingsPath))
{
Log.Debug("Found existing settings file, reading…");
savedSettings = Read() ?? savedSettings;
}
else
savedSettings = Import() ?? savedSettings;
{
if (OperatingSystem.IsWindows())
{
Log.Debug("No existing settings file was found, trying to import legacy settings…");
savedSettings = Import() ?? savedSettings;
}
else
{
Log.Debug("Using default settings");
}
}
Settings = savedSettings;
}
catch (Exception e)
Expand Down
8 changes: 8 additions & 0 deletions UI.Avalonia/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public MainViewModel(): this(new()){}
[ObservableProperty] private bool? validated;

internal Dumper? dumper;
private readonly SemaphoreSlim scanLock = new(1, 1);

partial void OnDiscInfoExpandedChanged(bool value)
{
Expand Down Expand Up @@ -99,6 +100,13 @@ private void CancelDump()

private async Task ScanDiscsAsync()
{
// ReSharper disable once MethodHasAsyncOverload
if (!scanLock.Wait(0))
{
Log.Debug("Another disc scan is already in progress, ignoring call");
return;
}

ResetViewModel();

FoundDisc = true;
Expand Down
2 changes: 2 additions & 0 deletions UI.Avalonia/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using IrdLibraryClient;
using Ps3DiscDumper;
using Ps3DiscDumper.POCOs;

Expand Down Expand Up @@ -53,6 +54,7 @@ private void ToggleSettingsPage()
{
Dispatcher.UIThread.Post(() =>
{
Log.Debug("Settings were changed, trying to re-scan the disc if present…");
mainPage.ResetViewModelCommand.Execute(null);
mainPage.ScanDiscsCommand.Execute(null);
}, DispatcherPriority.Background);
Expand Down
2 changes: 2 additions & 0 deletions UI.Avalonia/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Avalonia.Platform;
using Avalonia.Threading;
using Avalonia.VisualTree;
using IrdLibraryClient;
using UI.Avalonia.Utils;
using UI.Avalonia.Utils.ColorPalette;
using UI.Avalonia.ViewModels;
Expand Down Expand Up @@ -61,6 +62,7 @@ private void OnLoaded(object? sender, RoutedEventArgs e)

Dispatcher.UIThread.Post(() =>
{
Log.Debug("Main window is loaded, trying to scan the disc…");
mvm.ResetViewModelCommand.Execute(null);
mvm.ScanDiscsCommand.Execute(null);
}, DispatcherPriority.Background);
Expand Down
3 changes: 3 additions & 0 deletions UI.Avalonia/Views/MainWindow.axaml.linux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ private void MonitorDmesg()
DumperIsReady: false
}
})
{
Log.Debug($"Found udf mount message, trying to scan disc drives… ({nameof(vm.DumpingInProgress)}: {vm.DumpingInProgress}, {nameof(vm.FoundDisc)}: {vm.FoundDisc}, {nameof(vm.DumperIsReady)}: {vm.DumperIsReady})");
vm.ScanDiscsCommand.Execute(null);
}
}, DispatcherPriority.Background);
}
else if (line.Contains("busy inodes on changed media sr"))
Expand Down

0 comments on commit d1a8175

Please sign in to comment.