mirror of
https://github.com/claunia/romrepomgr.git
synced 2025-12-16 11:14:45 +00:00
Implement multi-threading import of ROM files.
This commit is contained in:
108
RomRepoMgr/Models/RomImporter.cs
Normal file
108
RomRepoMgr/Models/RomImporter.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Media;
|
||||
using ReactiveUI;
|
||||
using RomRepoMgr.Core.EventArgs;
|
||||
|
||||
namespace RomRepoMgr.Models;
|
||||
|
||||
public class RomImporter : ReactiveObject
|
||||
{
|
||||
bool _indeterminate;
|
||||
double _maximum;
|
||||
double _minimum;
|
||||
double _progress;
|
||||
Color _statusColor;
|
||||
string _statusMessage;
|
||||
public string Filename { get; internal init; }
|
||||
public bool Running { get; private set; } = true;
|
||||
|
||||
public bool Indeterminate
|
||||
{
|
||||
get => _indeterminate;
|
||||
set => this.RaiseAndSetIfChanged(ref _indeterminate, value);
|
||||
}
|
||||
|
||||
public double Progress
|
||||
{
|
||||
get => _progress;
|
||||
set => this.RaiseAndSetIfChanged(ref _progress, value);
|
||||
}
|
||||
|
||||
public double Maximum
|
||||
{
|
||||
get => _maximum;
|
||||
set => this.RaiseAndSetIfChanged(ref _maximum, value);
|
||||
}
|
||||
|
||||
public double Minimum
|
||||
{
|
||||
get => _minimum;
|
||||
set => this.RaiseAndSetIfChanged(ref _minimum, value);
|
||||
}
|
||||
|
||||
public string StatusMessage
|
||||
{
|
||||
get => _statusMessage;
|
||||
set => this.RaiseAndSetIfChanged(ref _statusMessage, value);
|
||||
}
|
||||
|
||||
public Color StatusColor
|
||||
{
|
||||
get => _statusColor;
|
||||
set => this.RaiseAndSetIfChanged(ref _statusColor, value);
|
||||
}
|
||||
|
||||
internal void OnErrorOccurred(object sender, ErrorEventArgs e)
|
||||
{
|
||||
StatusMessage = e.Message;
|
||||
StatusColor = Colors.Red;
|
||||
|
||||
if(!Indeterminate) return;
|
||||
|
||||
Indeterminate = false;
|
||||
Progress = 0;
|
||||
}
|
||||
|
||||
internal void OnSetIndeterminateProgress(object sender, EventArgs e)
|
||||
{
|
||||
Indeterminate = true;
|
||||
}
|
||||
|
||||
internal void OnSetMessage(object sender, MessageEventArgs e)
|
||||
{
|
||||
StatusMessage = e.Message;
|
||||
}
|
||||
|
||||
internal void OnSetProgress(object sender, ProgressEventArgs e)
|
||||
{
|
||||
Progress = e.Value;
|
||||
}
|
||||
|
||||
internal void OnSetProgressBounds(object sender, ProgressBoundsEventArgs e)
|
||||
{
|
||||
Indeterminate = false;
|
||||
Maximum = e.Maximum;
|
||||
Minimum = e.Minimum;
|
||||
}
|
||||
|
||||
internal void OnWorkFinished(object sender, MessageEventArgs e)
|
||||
{
|
||||
Indeterminate = false;
|
||||
Maximum = 1;
|
||||
Minimum = 0;
|
||||
Progress = 1;
|
||||
StatusMessage = e.Message;
|
||||
Running = false;
|
||||
}
|
||||
|
||||
public void OnImportedRom(object sender, ImportedRomItemEventArgs e)
|
||||
{
|
||||
Indeterminate = false;
|
||||
Maximum = 1;
|
||||
Minimum = 0;
|
||||
Progress = 1;
|
||||
StatusMessage = e.Item.Status;
|
||||
Running = false;
|
||||
}
|
||||
}
|
||||
@@ -1,92 +1,68 @@
|
||||
/******************************************************************************
|
||||
// RomRepoMgr - ROM repository manager
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2020-2024 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reactive;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
using RomRepoMgr.Core.EventArgs;
|
||||
using RomRepoMgr.Core.Models;
|
||||
using RomRepoMgr.Core.Workers;
|
||||
using RomRepoMgr.Models;
|
||||
using RomRepoMgr.Resources;
|
||||
using RomRepoMgr.Views;
|
||||
|
||||
namespace RomRepoMgr.ViewModels;
|
||||
|
||||
public sealed class ImportRomFolderViewModel : ViewModelBase
|
||||
public class ImportRomFolderViewModel : ViewModelBase
|
||||
{
|
||||
readonly ImportRomFolder _view;
|
||||
bool _canClose;
|
||||
bool _canStart;
|
||||
bool _isImporting;
|
||||
bool _isReady;
|
||||
bool _knownOnlyChecked;
|
||||
bool _progress2IsIndeterminate;
|
||||
double _progress2Maximum;
|
||||
double _progress2Minimum;
|
||||
double _progress2Value;
|
||||
bool _progress2Visible;
|
||||
bool _progressIsIndeterminate;
|
||||
double _progressMaximum;
|
||||
double _progressMinimum;
|
||||
double _progressValue;
|
||||
bool _progressVisible;
|
||||
bool _recurseArchivesChecked;
|
||||
bool _removeFilesChecked;
|
||||
bool _removeFilesEnabled;
|
||||
string _status2Message;
|
||||
string _statusMessage;
|
||||
bool _canClose;
|
||||
bool _canStart;
|
||||
string _folderPath;
|
||||
bool _isImporting;
|
||||
bool _isReady;
|
||||
bool _knownOnlyChecked;
|
||||
int _listPosition;
|
||||
bool _progress2IsIndeterminate;
|
||||
double _progress2Maximum;
|
||||
double _progress2Minimum;
|
||||
double _progress2Value;
|
||||
bool _progress2Visible;
|
||||
bool _progressIsIndeterminate;
|
||||
double _progressMaximum;
|
||||
double _progressMinimum;
|
||||
double _progressValue;
|
||||
bool _progressVisible;
|
||||
bool _recurseArchivesChecked;
|
||||
bool _removeFilesChecked;
|
||||
bool _removeFilesEnabled;
|
||||
FileImporter _rootImporter;
|
||||
string _statusMessage;
|
||||
string _statusMessage2;
|
||||
bool _statusMessage2Visible;
|
||||
readonly Stopwatch _stopwatch = new();
|
||||
|
||||
// Mock
|
||||
public ImportRomFolderViewModel()
|
||||
{
|
||||
#pragma warning disable PH2080
|
||||
FolderPath = "C:\\ROMs";
|
||||
#pragma warning restore PH2080
|
||||
SelectFolderCommand = ReactiveCommand.CreateFromTask(SelectFolderAsync);
|
||||
CloseCommand = ReactiveCommand.Create(Close);
|
||||
StartCommand = ReactiveCommand.Create(Start);
|
||||
CanClose = true;
|
||||
RemoveFilesChecked = false;
|
||||
KnownOnlyChecked = true;
|
||||
RecurseArchivesChecked = Settings.Settings.UnArUsable;
|
||||
RemoveFilesEnabled = false;
|
||||
}
|
||||
|
||||
public ImportRomFolderViewModel(ImportRomFolder view, string folderPath)
|
||||
{
|
||||
_view = view;
|
||||
FolderPath = folderPath;
|
||||
_removeFilesChecked = false;
|
||||
_knownOnlyChecked = true;
|
||||
_recurseArchivesChecked = Settings.Settings.UnArUsable;
|
||||
ImportResults = [];
|
||||
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
|
||||
StartCommand = ReactiveCommand.Create(ExecuteStartCommand);
|
||||
IsReady = true;
|
||||
CanStart = true;
|
||||
CanClose = true;
|
||||
_removeFilesEnabled = false;
|
||||
}
|
||||
public ReactiveCommand<Unit, Unit> SelectFolderCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> StartCommand { get; }
|
||||
public Window View { get; init; }
|
||||
|
||||
public string FolderPath { get; }
|
||||
public bool RecurseArchivesEnabled => Settings.Settings.UnArUsable;
|
||||
public bool RecurseArchivesEnabled => Settings.Settings.UnArUsable;
|
||||
|
||||
public bool RemoveFilesChecked
|
||||
{
|
||||
@@ -166,10 +142,16 @@ public sealed class ImportRomFolderViewModel : ViewModelBase
|
||||
set => this.RaiseAndSetIfChanged(ref _progress2Visible, value);
|
||||
}
|
||||
|
||||
public string Status2Message
|
||||
public bool StatusMessage2Visible
|
||||
{
|
||||
get => _status2Message;
|
||||
set => this.RaiseAndSetIfChanged(ref _status2Message, value);
|
||||
get => _statusMessage2Visible;
|
||||
set => this.RaiseAndSetIfChanged(ref _statusMessage2Visible, value);
|
||||
}
|
||||
|
||||
public string StatusMessage2
|
||||
{
|
||||
get => _statusMessage2;
|
||||
set => this.RaiseAndSetIfChanged(ref _statusMessage2, value);
|
||||
}
|
||||
|
||||
public double Progress2Minimum
|
||||
@@ -196,14 +178,12 @@ public sealed class ImportRomFolderViewModel : ViewModelBase
|
||||
set => this.RaiseAndSetIfChanged(ref _progress2IsIndeterminate, value);
|
||||
}
|
||||
|
||||
public bool IsImporting
|
||||
public string FolderPath
|
||||
{
|
||||
get => _isImporting;
|
||||
set => this.RaiseAndSetIfChanged(ref _isImporting, value);
|
||||
get => _folderPath;
|
||||
set => this.RaiseAndSetIfChanged(ref _folderPath, value);
|
||||
}
|
||||
|
||||
public ObservableCollection<ImportRomItem> ImportResults { get; }
|
||||
|
||||
public bool CanClose
|
||||
{
|
||||
get => _canClose;
|
||||
@@ -216,75 +196,266 @@ public sealed class ImportRomFolderViewModel : ViewModelBase
|
||||
set => this.RaiseAndSetIfChanged(ref _canStart, value);
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> StartCommand { get; }
|
||||
|
||||
void ExecuteCloseCommand() => _view.Close();
|
||||
|
||||
void ExecuteStartCommand()
|
||||
public bool IsImporting
|
||||
{
|
||||
IsReady = false;
|
||||
ProgressVisible = true;
|
||||
IsImporting = true;
|
||||
CanStart = false;
|
||||
CanClose = false;
|
||||
Progress2Visible = true;
|
||||
|
||||
var worker = new FileImporter(KnownOnlyChecked, RemoveFilesChecked);
|
||||
worker.SetIndeterminateProgress += OnWorkerOnSetIndeterminateProgress;
|
||||
worker.SetMessage += OnWorkerOnSetMessage;
|
||||
worker.SetProgress += OnWorkerOnSetProgress;
|
||||
worker.SetProgressBounds += OnWorkerOnSetProgressBounds;
|
||||
worker.SetIndeterminateProgress2 += OnWorkerOnSetIndeterminateProgress2;
|
||||
worker.SetMessage2 += OnWorkerOnSetMessage2;
|
||||
worker.SetProgress2 += OnWorkerOnSetProgress2;
|
||||
worker.SetProgressBounds2 += OnWorkerOnSetProgressBounds2;
|
||||
worker.Finished += OnWorkerOnFinished;
|
||||
worker.ImportedRom += OnWorkerOnImportedRom;
|
||||
|
||||
_ = Task.Run(() => worker.ProcessPath(FolderPath, true, RecurseArchivesChecked));
|
||||
get => _isImporting;
|
||||
set => this.RaiseAndSetIfChanged(ref _isImporting, value);
|
||||
}
|
||||
|
||||
void OnWorkerOnImportedRom(object sender, ImportedRomItemEventArgs args) =>
|
||||
Dispatcher.UIThread.Post(() => ImportResults.Add(args.Item));
|
||||
|
||||
void OnWorkerOnFinished(object sender, EventArgs args) => Dispatcher.UIThread.Post(() =>
|
||||
public ObservableCollection<RomImporter> Importers { get; } = [];
|
||||
|
||||
void Start()
|
||||
{
|
||||
ProgressVisible = false;
|
||||
StatusMessage = Localization.Finished;
|
||||
CanClose = true;
|
||||
Progress2Visible = false;
|
||||
});
|
||||
_rootImporter = new FileImporter(KnownOnlyChecked, RemoveFilesChecked);
|
||||
_rootImporter.SetMessage += SetMessage;
|
||||
_rootImporter.SetIndeterminateProgress += SetIndeterminateProgress;
|
||||
_rootImporter.SetProgress += SetProgress;
|
||||
_rootImporter.SetProgressBounds += SetProgressBounds;
|
||||
_rootImporter.Finished += EnumeratingFilesFinished;
|
||||
ProgressIsIndeterminate = true;
|
||||
ProgressVisible = true;
|
||||
CanClose = false;
|
||||
CanStart = false;
|
||||
IsImporting = true;
|
||||
|
||||
void OnWorkerOnSetProgressBounds(object sender, ProgressBoundsEventArgs args) => Dispatcher.UIThread.Post(() =>
|
||||
_ = Task.Run(() => _rootImporter.FindFiles(FolderPath));
|
||||
}
|
||||
|
||||
void SetProgressBounds(object sender, ProgressBoundsEventArgs e) => Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
ProgressIsIndeterminate = false;
|
||||
ProgressMaximum = args.Maximum;
|
||||
ProgressMinimum = args.Minimum;
|
||||
ProgressMaximum = e.Maximum;
|
||||
ProgressMinimum = e.Minimum;
|
||||
});
|
||||
|
||||
void OnWorkerOnSetProgress(object sender, ProgressEventArgs args) =>
|
||||
Dispatcher.UIThread.Post(() => ProgressValue = args.Value);
|
||||
void SetProgress(object sender, ProgressEventArgs e)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => ProgressValue = e.Value);
|
||||
}
|
||||
|
||||
void OnWorkerOnSetMessage(object sender, MessageEventArgs args) =>
|
||||
Dispatcher.UIThread.Post(() => StatusMessage = args.Message);
|
||||
|
||||
void OnWorkerOnSetIndeterminateProgress(object sender, EventArgs args) =>
|
||||
void SetIndeterminateProgress(object sender, EventArgs e)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => ProgressIsIndeterminate = true);
|
||||
}
|
||||
|
||||
void OnWorkerOnSetProgressBounds2(object sender, ProgressBoundsEventArgs args) => Dispatcher.UIThread.Post(() =>
|
||||
void SetProgress2Bounds(object sender, ProgressBoundsEventArgs e) => Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
Progress2IsIndeterminate = false;
|
||||
Progress2Maximum = args.Maximum;
|
||||
Progress2Minimum = args.Minimum;
|
||||
Progress2Maximum = e.Maximum;
|
||||
Progress2Minimum = e.Minimum;
|
||||
});
|
||||
|
||||
void OnWorkerOnSetProgress2(object sender, ProgressEventArgs args) =>
|
||||
Dispatcher.UIThread.Post(() => Progress2Value = args.Value);
|
||||
void SetProgress2(object sender, ProgressEventArgs e)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => Progress2Value = e.Value);
|
||||
}
|
||||
|
||||
void OnWorkerOnSetMessage2(object sender, MessageEventArgs args) =>
|
||||
Dispatcher.UIThread.Post(() => Status2Message = args.Message);
|
||||
|
||||
void OnWorkerOnSetIndeterminateProgress2(object sender, EventArgs args) =>
|
||||
void SetIndeterminateProgress2(object sender, EventArgs e)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => Progress2IsIndeterminate = true);
|
||||
}
|
||||
|
||||
void EnumeratingFilesFinished(object sender, EventArgs e)
|
||||
{
|
||||
_rootImporter.Finished -= EnumeratingFilesFinished;
|
||||
|
||||
if(RecurseArchivesChecked)
|
||||
{
|
||||
Progress2Visible = true;
|
||||
StatusMessage2Visible = true;
|
||||
_rootImporter.SetMessage2 += SetMessage2;
|
||||
_rootImporter.SetIndeterminateProgress2 += SetIndeterminateProgress2;
|
||||
_rootImporter.SetProgress2 += SetProgress2;
|
||||
_rootImporter.SetProgressBounds2 += SetProgress2Bounds;
|
||||
|
||||
_rootImporter.Finished += CheckArchivesFinished;
|
||||
|
||||
_ = Task.Run(() =>
|
||||
{
|
||||
_stopwatch.Restart();
|
||||
_rootImporter.SeparateFilesAndArchives();
|
||||
});
|
||||
}
|
||||
else
|
||||
ProcessFiles();
|
||||
}
|
||||
|
||||
void ProcessFiles()
|
||||
{
|
||||
_listPosition = 0;
|
||||
ProgressMinimum = 0;
|
||||
ProgressMaximum = _rootImporter.Files.Count;
|
||||
ProgressValue = 0;
|
||||
ProgressIsIndeterminate = false;
|
||||
ProgressVisible = true;
|
||||
CanClose = false;
|
||||
CanStart = false;
|
||||
IsReady = false;
|
||||
IsImporting = true;
|
||||
_stopwatch.Restart();
|
||||
|
||||
Parallel.ForEach(_rootImporter.Files,
|
||||
file =>
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
StatusMessage = string.Format(Localization.ImportingItem, Path.GetFileName(file));
|
||||
ProgressValue = _listPosition;
|
||||
});
|
||||
|
||||
var model = new RomImporter
|
||||
{
|
||||
Filename = Path.GetFileName(file),
|
||||
Indeterminate = true
|
||||
};
|
||||
|
||||
var worker = new FileImporter(KnownOnlyChecked, RemoveFilesChecked);
|
||||
worker.SetIndeterminateProgress2 += model.OnSetIndeterminateProgress;
|
||||
worker.SetMessage2 += model.OnSetMessage;
|
||||
worker.SetProgress2 += model.OnSetProgress;
|
||||
worker.SetProgressBounds2 += model.OnSetProgressBounds;
|
||||
worker.ImportedRom += model.OnImportedRom;
|
||||
worker.WorkFinished += model.OnWorkFinished;
|
||||
|
||||
Dispatcher.UIThread.Post(() => Importers.Add(model));
|
||||
|
||||
worker.ImportFile(file);
|
||||
|
||||
worker.SaveChanges();
|
||||
Interlocked.Increment(ref _listPosition);
|
||||
});
|
||||
|
||||
_stopwatch.Stop();
|
||||
Console.WriteLine("Took " + _stopwatch.Elapsed.TotalSeconds + " seconds to process files.");
|
||||
|
||||
_rootImporter.UpdateRomStats();
|
||||
|
||||
_listPosition = 0;
|
||||
ProgressMinimum = 0;
|
||||
ProgressMaximum = 1;
|
||||
ProgressValue = 0;
|
||||
ProgressIsIndeterminate = false;
|
||||
ProgressVisible = false;
|
||||
CanClose = true;
|
||||
CanStart = false;
|
||||
IsReady = false;
|
||||
IsImporting = false;
|
||||
StatusMessage = Localization.Finished;
|
||||
}
|
||||
|
||||
void ProcessArchives()
|
||||
{
|
||||
// For each archive
|
||||
ProgressMaximum = _rootImporter.Archives.Count;
|
||||
ProgressMinimum = 0;
|
||||
ProgressValue = 0;
|
||||
ProgressIsIndeterminate = false;
|
||||
Progress2Visible = true;
|
||||
StatusMessage2Visible = true;
|
||||
_listPosition = 0;
|
||||
_stopwatch.Restart();
|
||||
|
||||
foreach(string archive in _rootImporter.Archives)
|
||||
{
|
||||
StatusMessage = "Processing archive: " + Path.GetFileName(archive);
|
||||
ProgressValue = _listPosition++;
|
||||
|
||||
// Create FileImporter
|
||||
var archiveImporter = new FileImporter(KnownOnlyChecked, RemoveFilesChecked);
|
||||
|
||||
archiveImporter.SetIndeterminateProgress2 += SetIndeterminateProgress2;
|
||||
archiveImporter.SetMessage2 += SetMessage2;
|
||||
archiveImporter.SetProgress2 += SetProgress2;
|
||||
archiveImporter.SetProgressBounds2 += SetProgress2Bounds;
|
||||
|
||||
// Extract archive
|
||||
bool ret = archiveImporter.ExtractArchive(archive);
|
||||
|
||||
if(!ret) continue;
|
||||
|
||||
// Process files in archive
|
||||
Parallel.ForEach(archiveImporter.Files,
|
||||
file =>
|
||||
{
|
||||
var model = new RomImporter
|
||||
{
|
||||
Filename = Path.GetFileName(file),
|
||||
Indeterminate = true
|
||||
};
|
||||
|
||||
var worker = new FileImporter(KnownOnlyChecked, RemoveFilesChecked);
|
||||
worker.SetIndeterminateProgress2 += model.OnSetIndeterminateProgress;
|
||||
worker.SetMessage2 += model.OnSetMessage;
|
||||
worker.SetProgress2 += model.OnSetProgress;
|
||||
worker.SetProgressBounds2 += model.OnSetProgressBounds;
|
||||
worker.ImportedRom += model.OnImportedRom;
|
||||
worker.WorkFinished += model.OnWorkFinished;
|
||||
|
||||
Dispatcher.UIThread.Post(() => Importers.Add(model));
|
||||
|
||||
worker.ImportFile(file);
|
||||
|
||||
worker.SaveChanges();
|
||||
|
||||
worker.Files.Clear();
|
||||
});
|
||||
|
||||
// Remove temporary files
|
||||
archiveImporter.CleanupExtractedArchive();
|
||||
|
||||
// Save database changes
|
||||
archiveImporter.SaveChanges();
|
||||
}
|
||||
|
||||
_stopwatch.Stop();
|
||||
Console.WriteLine("Took " + _stopwatch.Elapsed.TotalSeconds + " seconds to process archives.");
|
||||
|
||||
Progress2Visible = false;
|
||||
StatusMessage2Visible = false;
|
||||
|
||||
ProcessFiles();
|
||||
}
|
||||
|
||||
void CheckArchivesFinished(object sender, EventArgs e)
|
||||
{
|
||||
_stopwatch.Stop();
|
||||
Console.WriteLine("Took {0} seconds to check archives.", _stopwatch.Elapsed.TotalSeconds);
|
||||
|
||||
Progress2Visible = false;
|
||||
StatusMessage2Visible = false;
|
||||
|
||||
_rootImporter.Finished -= CheckArchivesFinished;
|
||||
|
||||
ProcessArchives();
|
||||
}
|
||||
|
||||
void SetMessage(object sender, MessageEventArgs e)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => StatusMessage = e.Message);
|
||||
}
|
||||
|
||||
void SetMessage2(object sender, MessageEventArgs e)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => StatusMessage2 = e.Message);
|
||||
}
|
||||
|
||||
void Close() => View.Close();
|
||||
|
||||
async Task SelectFolderAsync()
|
||||
{
|
||||
IReadOnlyList<IStorageFolder> result =
|
||||
await View.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
|
||||
{
|
||||
Title = Localization.ImportRomsFolderDialogTitle
|
||||
});
|
||||
|
||||
if(result.Count < 1) return;
|
||||
|
||||
FolderPath = result[0].TryGetLocalPath() ?? string.Empty;
|
||||
|
||||
IsReady = true;
|
||||
CanStart = true;
|
||||
CanClose = true;
|
||||
}
|
||||
}
|
||||
@@ -171,17 +171,14 @@ public class MainWindowViewModel : ViewModelBase
|
||||
|
||||
async Task ExecuteImportRomFolderCommandAsync()
|
||||
{
|
||||
IReadOnlyList<IStorageFolder> result =
|
||||
await _view.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
|
||||
{
|
||||
Title = Localization.ImportRomsFolderDialogTitle
|
||||
});
|
||||
var dialog = new ImportRomFolder();
|
||||
|
||||
if(result.Count < 1) return;
|
||||
var viewModel = new ImportRomFolderViewModel
|
||||
{
|
||||
View = dialog
|
||||
};
|
||||
|
||||
var dialog = new ImportRomFolder();
|
||||
var importRomFolderViewModel = new ImportRomFolderViewModel(dialog, result[0].Path.LocalPath);
|
||||
dialog.DataContext = importRomFolderViewModel;
|
||||
dialog.DataContext = viewModel;
|
||||
_ = dialog.ShowDialog(_view);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,38 +1,13 @@
|
||||
<!--
|
||||
// /***************************************************************************
|
||||
// RomRepoMgr - ROM repository manager
|
||||
// ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
|
||||
//
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// ‐‐[ License ] ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
|
||||
// Copyright © 2020-2024 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
-->
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="clr-namespace:RomRepoMgr.ViewModels;assembly=RomRepoMgr"
|
||||
xmlns:resources="clr-namespace:RomRepoMgr.Resources"
|
||||
xmlns:vm="clr-namespace:RomRepoMgr.ViewModels"
|
||||
xmlns:models="clr-namespace:RomRepoMgr.Models"
|
||||
mc:Ignorable="d"
|
||||
Width="480"
|
||||
Height="360"
|
||||
Width="1024"
|
||||
Height="768"
|
||||
x:Class="RomRepoMgr.Views.ImportRomFolder"
|
||||
Icon="/Assets/avalonia-logo.ico"
|
||||
CanResize="False"
|
||||
@@ -41,93 +16,118 @@
|
||||
<Design.DataContext>
|
||||
<vm:ImportRomFolderViewModel />
|
||||
</Design.DataContext>
|
||||
<Border Padding="15">
|
||||
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,*,Auto">
|
||||
<StackPanel Grid.Row="0"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Stretch">
|
||||
<TextBlock Text="{x:Static resources:Localization.PathLabel}"
|
||||
FontWeight="Bold" />
|
||||
<TextBlock Text="{Binding FolderPath, Mode=OneWay}" />
|
||||
</StackPanel>
|
||||
<CheckBox Grid.Row="1"
|
||||
IsChecked="{Binding RemoveFilesChecked, Mode=TwoWay}"
|
||||
IsEnabled="{Binding RemoveFilesEnabled, Mode=OneWay}"
|
||||
IsVisible="{Binding IsReady, Mode=OneWay}">
|
||||
<CheckBox.Content>
|
||||
<TextBlock Text="{x:Static resources:Localization.RemoveFilesLabel}" />
|
||||
</CheckBox.Content>
|
||||
</CheckBox>
|
||||
<CheckBox Grid.Row="2"
|
||||
IsChecked="{Binding KnownOnlyChecked, Mode=TwoWay}"
|
||||
IsVisible="{Binding IsReady, Mode=OneWay}">
|
||||
<CheckBox.Content>
|
||||
<TextBlock Text="{x:Static resources:Localization.KnownOnlyLabel}" />
|
||||
</CheckBox.Content>
|
||||
</CheckBox>
|
||||
<CheckBox Grid.Row="3"
|
||||
IsChecked="{Binding RecurseArchivesChecked, Mode=TwoWay}"
|
||||
IsEnabled="{Binding RecurseArchivesEnabled, Mode=OneWay}"
|
||||
IsVisible="{Binding IsReady, Mode=OneWay}">
|
||||
<CheckBox.Content>
|
||||
<TextBlock Text="{x:Static resources:Localization.RecurseArchivesLabel}" />
|
||||
</CheckBox.Content>
|
||||
</CheckBox>
|
||||
<TextBlock Grid.Row="4"
|
||||
Text="{Binding StatusMessage, Mode=OneWay}"
|
||||
<Grid RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, *, Auto"
|
||||
Margin="16"
|
||||
RowSpacing="8">
|
||||
<StackPanel Grid.Row="0"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Stretch"
|
||||
Spacing="8">
|
||||
<Button Content="{x:Static resources:Localization.ChooseLabel}"
|
||||
Command="{Binding SelectFolderCommand, Mode=OneWay}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBlock Text="{x:Static resources:Localization.PathLabel}"
|
||||
FontWeight="Bold"
|
||||
HorizontalAlignment="Center" />
|
||||
<ProgressBar Grid.Row="5"
|
||||
Minimum="{Binding ProgressMinimum, Mode=OneWay}"
|
||||
Maximum="{Binding ProgressMaximum, Mode=OneWay}"
|
||||
Value="{Binding ProgressValue, Mode=OneWay}"
|
||||
IsIndeterminate="{Binding ProgressIsIndeterminate, Mode=OneWay}"
|
||||
IsVisible="{Binding ProgressVisible, Mode=OneWay}" />
|
||||
<StackPanel Grid.Row="6"
|
||||
IsVisible="{Binding Progress2Visible, Mode=OneWay}">
|
||||
<TextBlock Text="{Binding Status2Message, Mode=OneWay}" />
|
||||
<ProgressBar Minimum="{Binding Progress2Minimum, Mode=OneWay}"
|
||||
Maximum="{Binding Progress2Maximum, Mode=OneWay}"
|
||||
Value="{Binding Progress2Value, Mode=OneWay}"
|
||||
IsIndeterminate="{Binding Progress2IsIndeterminate, Mode=OneWay}" />
|
||||
</StackPanel>
|
||||
<DataGrid Grid.Row="7"
|
||||
ItemsSource="{Binding ImportResults, Mode=OneWay}"
|
||||
HorizontalScrollBarVisibility="Visible"
|
||||
IsVisible="{Binding IsImporting, Mode=OneWay}">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Binding="{Binding Filename, Mode=OneWay}"
|
||||
Width="Auto"
|
||||
IsReadOnly="True">
|
||||
<DataGridTextColumn.Header>
|
||||
<TextBlock Text="{x:Static resources:Localization.ResultFilenameLabel}" />
|
||||
</DataGridTextColumn.Header>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Binding="{Binding Status, Mode=OneWay}"
|
||||
Width="Auto"
|
||||
IsReadOnly="True">
|
||||
<DataGridTextColumn.Header>
|
||||
<TextBlock Text="{x:Static resources:Localization.ResultStatusLabel}" />
|
||||
</DataGridTextColumn.Header>
|
||||
</DataGridTextColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<StackPanel Grid.Row="8"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Right">
|
||||
<Button HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center"
|
||||
IsEnabled="{Binding CanClose, Mode=OneWay}"
|
||||
Command="{Binding CloseCommand, Mode=OneWay}">
|
||||
<TextBlock Text="{x:Static resources:Localization.CloseLabel}" />
|
||||
</Button>
|
||||
<Button HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center"
|
||||
IsEnabled="{Binding CanStart, Mode=OneWay}"
|
||||
Command="{Binding StartCommand, Mode=OneWay}">
|
||||
<TextBlock Text="{x:Static resources:Localization.StartLabel}" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
VerticalAlignment="Center" />
|
||||
<TextBlock Text="{Binding FolderPath, Mode=OneWay}"
|
||||
VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
<CheckBox Grid.Row="1"
|
||||
IsChecked="{Binding RemoveFilesChecked, Mode=TwoWay}"
|
||||
IsEnabled="{Binding RemoveFilesEnabled, Mode=OneWay}"
|
||||
IsVisible="{Binding IsReady, Mode=OneWay}">
|
||||
<CheckBox.Content>
|
||||
<TextBlock Text="{x:Static resources:Localization.RemoveFilesLabel}" />
|
||||
</CheckBox.Content>
|
||||
</CheckBox>
|
||||
<CheckBox Grid.Row="2"
|
||||
IsChecked="{Binding KnownOnlyChecked, Mode=TwoWay}"
|
||||
IsVisible="{Binding IsReady, Mode=OneWay}">
|
||||
<CheckBox.Content>
|
||||
<TextBlock Text="{x:Static resources:Localization.KnownOnlyLabel}" />
|
||||
</CheckBox.Content>
|
||||
</CheckBox>
|
||||
<CheckBox Grid.Row="3"
|
||||
IsChecked="{Binding RecurseArchivesChecked, Mode=TwoWay}"
|
||||
IsEnabled="{Binding RecurseArchivesEnabled, Mode=OneWay}"
|
||||
IsVisible="{Binding IsReady, Mode=OneWay}">
|
||||
<CheckBox.Content>
|
||||
<TextBlock Text="{x:Static resources:Localization.RecurseArchivesLabel}" />
|
||||
</CheckBox.Content>
|
||||
</CheckBox>
|
||||
<TextBlock Grid.Row="4"
|
||||
Text="{Binding StatusMessage, Mode=OneWay}"
|
||||
FontWeight="Bold"
|
||||
HorizontalAlignment="Center" />
|
||||
<ProgressBar Grid.Row="5"
|
||||
Minimum="{Binding ProgressMinimum, Mode=OneWay}"
|
||||
Maximum="{Binding ProgressMaximum, Mode=OneWay}"
|
||||
Value="{Binding ProgressValue, Mode=OneWay}"
|
||||
IsIndeterminate="{Binding ProgressIsIndeterminate, Mode=OneWay}"
|
||||
IsVisible="{Binding ProgressVisible, Mode=OneWay}" />
|
||||
<TextBlock Grid.Row="6"
|
||||
Text="{Binding StatusMessage2, Mode=OneWay}"
|
||||
IsVisible="{Binding StatusMessage2Visible, Mode=OneWay}"
|
||||
FontWeight="Bold"
|
||||
HorizontalAlignment="Center" />
|
||||
<ProgressBar Grid.Row="7"
|
||||
Minimum="{Binding Progress2Minimum, Mode=OneWay}"
|
||||
Maximum="{Binding Progress2Maximum, Mode=OneWay}"
|
||||
Value="{Binding Progress2Value, Mode=OneWay}"
|
||||
IsIndeterminate="{Binding Progress2IsIndeterminate, Mode=OneWay}"
|
||||
IsVisible="{Binding Progress2Visible, Mode=OneWay}" />
|
||||
<DataGrid Grid.Row="8"
|
||||
ItemsSource="{Binding Importers, Mode=OneWay}"
|
||||
HorizontalScrollBarVisibility="Visible"
|
||||
IsVisible="{Binding IsImporting, Mode=OneWay}">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Binding="{Binding Filename, Mode=OneWay}"
|
||||
Width="Auto"
|
||||
IsReadOnly="True">
|
||||
<DataGridTextColumn.Header>
|
||||
<TextBlock Text="{x:Static resources:Localization.ResultFilenameLabel}" />
|
||||
</DataGridTextColumn.Header>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Binding="{Binding StatusMessage, Mode=OneWay}"
|
||||
Width="Auto"
|
||||
IsReadOnly="True"
|
||||
Foreground="{Binding StatusColor, Mode=OneWay}">
|
||||
<DataGridTextColumn.Header>
|
||||
<TextBlock Text="{x:Static resources:Localization.ResultStatusLabel}" />
|
||||
</DataGridTextColumn.Header>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTemplateColumn Width="Auto"
|
||||
MinWidth="180"
|
||||
Header="{x:Static resources:Localization.ProgressLabel}">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate DataType="models:RomImporter">
|
||||
<ProgressBar Minimum="{Binding Minimum, Mode=OneWay}"
|
||||
Maximum="{Binding Maximum, Mode=OneWay}"
|
||||
Value="{Binding Progress, Mode=OneWay}"
|
||||
IsIndeterminate="{Binding Indeterminate, Mode=OneWay}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<StackPanel Grid.Row="9"
|
||||
Orientation="Horizontal"
|
||||
IsVisible="{Binding IsReady, Mode=OneWay}"
|
||||
HorizontalAlignment="Right"
|
||||
Spacing="8">
|
||||
<Button HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center"
|
||||
IsEnabled="{Binding CanClose, Mode=OneWay}"
|
||||
Command="{Binding CloseCommand, Mode=OneWay}">
|
||||
<TextBlock Text="{x:Static resources:Localization.CloseLabel}" />
|
||||
</Button>
|
||||
<Button HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center"
|
||||
IsEnabled="{Binding CanStart, Mode=OneWay}"
|
||||
Command="{Binding StartCommand, Mode=OneWay}">
|
||||
<TextBlock Text="{x:Static resources:Localization.StartLabel}" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -1,36 +1,11 @@
|
||||
/******************************************************************************
|
||||
// RomRepoMgr - ROM repository manager
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2020-2024 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace RomRepoMgr.Views;
|
||||
|
||||
public sealed partial class ImportRomFolder : Window
|
||||
public class ImportRomFolder : Window
|
||||
{
|
||||
public ImportRomFolder() => InitializeComponent();
|
||||
|
||||
void InitializeComponent() => AvaloniaXamlLoader.Load(this);
|
||||
public ImportRomFolder()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user