mirror of
https://github.com/claunia/romrepomgr.git
synced 2025-12-16 11:14:45 +00:00
[App] Make importing DAT folder multithreaded.
This commit is contained in:
99
RomRepoMgr/Models/DatImporter.cs
Normal file
99
RomRepoMgr/Models/DatImporter.cs
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Avalonia.Media;
|
||||||
|
using ReactiveUI;
|
||||||
|
using RomRepoMgr.Core.EventArgs;
|
||||||
|
|
||||||
|
namespace RomRepoMgr.Models;
|
||||||
|
|
||||||
|
public class DatImporter : ReactiveObject
|
||||||
|
{
|
||||||
|
bool _indeterminate;
|
||||||
|
double _maximum;
|
||||||
|
double _minimum;
|
||||||
|
double _progress;
|
||||||
|
Color _statusColor;
|
||||||
|
string _statusMessage;
|
||||||
|
public string Filename { get; internal init; }
|
||||||
|
public Task Task { get; set; }
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
6
RomRepoMgr/Resources/Localization.Designer.cs
generated
6
RomRepoMgr/Resources/Localization.Designer.cs
generated
@@ -764,5 +764,11 @@ namespace RomRepoMgr.Resources {
|
|||||||
return ResourceManager.GetString("NativeMenuQuitText", resourceCulture);
|
return ResourceManager.GetString("NativeMenuQuitText", resourceCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ProgressLabel {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("ProgressLabel", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -378,4 +378,7 @@ Tardará mucho tiempo...</value>
|
|||||||
<data name="NativeMenuQuitText" xml:space="preserve">
|
<data name="NativeMenuQuitText" xml:space="preserve">
|
||||||
<value>_Salir</value>
|
<value>_Salir</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="ProgressLabel" xml:space="preserve">
|
||||||
|
<value>Progreso</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -386,4 +386,7 @@ This will take a long time...</value>
|
|||||||
<data name="NativeMenuQuitText" xml:space="preserve">
|
<data name="NativeMenuQuitText" xml:space="preserve">
|
||||||
<value>_Quit</value>
|
<value>_Quit</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="ProgressLabel" xml:space="preserve">
|
||||||
|
<value>Progress</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -1,89 +1,71 @@
|
|||||||
/******************************************************************************
|
|
||||||
// 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;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reactive;
|
using System.Reactive;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Platform.Storage;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using RomRepoMgr.Core.EventArgs;
|
using RomRepoMgr.Core.EventArgs;
|
||||||
using RomRepoMgr.Core.Workers;
|
using RomRepoMgr.Models;
|
||||||
using RomRepoMgr.Resources;
|
using RomRepoMgr.Resources;
|
||||||
using RomRepoMgr.Views;
|
|
||||||
using ErrorEventArgs = RomRepoMgr.Core.EventArgs.ErrorEventArgs;
|
|
||||||
|
|
||||||
namespace RomRepoMgr.ViewModels;
|
namespace RomRepoMgr.ViewModels;
|
||||||
|
|
||||||
public sealed class ImportDatFolderViewModel : ViewModelBase
|
public class ImportDatFolderViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
readonly ImportDatFolder _view;
|
readonly Stopwatch _stopwatch = new();
|
||||||
bool _allFilesChecked;
|
bool _allFilesChecked;
|
||||||
bool _canClose;
|
bool _canClose;
|
||||||
bool _canStart;
|
bool _canStart;
|
||||||
string _category;
|
string _category;
|
||||||
string[] _datFiles;
|
string[] _datFiles;
|
||||||
bool _isImporting;
|
string _folderPath;
|
||||||
bool _isReady;
|
bool _isImporting;
|
||||||
int _listPosition;
|
bool _isReady;
|
||||||
bool _progress2IsIndeterminate;
|
int _listPosition;
|
||||||
double _progress2Maximum;
|
bool _progressIsIndeterminate;
|
||||||
double _progress2Minimum;
|
double _progressMaximum;
|
||||||
double _progress2Value;
|
double _progressMinimum;
|
||||||
bool _progress2Visible;
|
double _progressValue;
|
||||||
bool _progressIsIndeterminate;
|
bool _progressVisible;
|
||||||
double _progressMaximum;
|
bool _recursiveChecked;
|
||||||
double _progressMinimum;
|
string _statusMessage;
|
||||||
double _progressValue;
|
int _workers;
|
||||||
bool _progressVisible;
|
|
||||||
bool _recursiveChecked;
|
|
||||||
string _status2Message;
|
|
||||||
string _statusMessage;
|
|
||||||
|
|
||||||
// Mock
|
|
||||||
public ImportDatFolderViewModel()
|
public ImportDatFolderViewModel()
|
||||||
{
|
{
|
||||||
#pragma warning disable PH2080
|
CanClose = true;
|
||||||
FolderPath = "C:\\ROMs";
|
IsReady = true;
|
||||||
#pragma warning restore PH2080
|
SelectFolderCommand = ReactiveCommand.CreateFromTask(SelectFolderAsync);
|
||||||
|
CloseCommand = ReactiveCommand.Create(Close);
|
||||||
|
StartCommand = ReactiveCommand.Create(Start);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImportDatFolderViewModel(ImportDatFolder view, string folderPath)
|
public ReactiveCommand<Unit, Unit> SelectFolderCommand { get; }
|
||||||
|
public Window View { get; init; }
|
||||||
|
|
||||||
|
public bool IsReady
|
||||||
{
|
{
|
||||||
_view = view;
|
get => _isReady;
|
||||||
FolderPath = folderPath;
|
set => this.RaiseAndSetIfChanged(ref _isReady, value);
|
||||||
_allFilesChecked = false;
|
|
||||||
_recursiveChecked = true;
|
|
||||||
ImportResults = [];
|
|
||||||
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
|
|
||||||
StartCommand = ReactiveCommand.Create(ExecuteStartCommand);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string FolderPath { get; }
|
public string FolderPath
|
||||||
|
{
|
||||||
|
get => _folderPath;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _folderPath, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Category
|
||||||
|
{
|
||||||
|
get => _category;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _category, value);
|
||||||
|
}
|
||||||
|
|
||||||
public bool AllFilesChecked
|
public bool AllFilesChecked
|
||||||
{
|
{
|
||||||
@@ -105,24 +87,36 @@ public sealed class ImportDatFolderViewModel : ViewModelBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsReady
|
|
||||||
{
|
|
||||||
get => _isReady;
|
|
||||||
set => this.RaiseAndSetIfChanged(ref _isReady, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ProgressVisible
|
public bool ProgressVisible
|
||||||
{
|
{
|
||||||
get => _progressVisible;
|
get => _progressVisible;
|
||||||
set => this.RaiseAndSetIfChanged(ref _progressVisible, value);
|
set => this.RaiseAndSetIfChanged(ref _progressVisible, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool ProgressIsIndeterminate
|
||||||
|
{
|
||||||
|
get => _progressIsIndeterminate;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _progressIsIndeterminate, value);
|
||||||
|
}
|
||||||
|
|
||||||
public string StatusMessage
|
public string StatusMessage
|
||||||
{
|
{
|
||||||
get => _statusMessage;
|
get => _statusMessage;
|
||||||
set => this.RaiseAndSetIfChanged(ref _statusMessage, value);
|
set => this.RaiseAndSetIfChanged(ref _statusMessage, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool CanClose
|
||||||
|
{
|
||||||
|
get => _canClose;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _canClose, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CanStart
|
||||||
|
{
|
||||||
|
get => _canStart;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _canStart, value);
|
||||||
|
}
|
||||||
|
|
||||||
public double ProgressMinimum
|
public double ProgressMinimum
|
||||||
{
|
{
|
||||||
get => _progressMinimum;
|
get => _progressMinimum;
|
||||||
@@ -141,78 +135,113 @@ public sealed class ImportDatFolderViewModel : ViewModelBase
|
|||||||
set => this.RaiseAndSetIfChanged(ref _progressValue, value);
|
set => this.RaiseAndSetIfChanged(ref _progressValue, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ProgressIsIndeterminate
|
|
||||||
{
|
|
||||||
get => _progressIsIndeterminate;
|
|
||||||
set => this.RaiseAndSetIfChanged(ref _progressIsIndeterminate, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Progress2Visible
|
|
||||||
{
|
|
||||||
get => _progress2Visible;
|
|
||||||
set => this.RaiseAndSetIfChanged(ref _progress2Visible, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Status2Message
|
|
||||||
{
|
|
||||||
get => _status2Message;
|
|
||||||
set => this.RaiseAndSetIfChanged(ref _status2Message, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double Progress2Minimum
|
|
||||||
{
|
|
||||||
get => _progress2Minimum;
|
|
||||||
set => this.RaiseAndSetIfChanged(ref _progress2Minimum, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double Progress2Maximum
|
|
||||||
{
|
|
||||||
get => _progress2Maximum;
|
|
||||||
set => this.RaiseAndSetIfChanged(ref _progress2Maximum, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double Progress2Value
|
|
||||||
{
|
|
||||||
get => _progress2Value;
|
|
||||||
set => this.RaiseAndSetIfChanged(ref _progress2Value, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Progress2IsIndeterminate
|
|
||||||
{
|
|
||||||
get => _progress2IsIndeterminate;
|
|
||||||
set => this.RaiseAndSetIfChanged(ref _progress2IsIndeterminate, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsImporting
|
public bool IsImporting
|
||||||
{
|
{
|
||||||
get => _isImporting;
|
get => _isImporting;
|
||||||
set => this.RaiseAndSetIfChanged(ref _isImporting, value);
|
set => this.RaiseAndSetIfChanged(ref _isImporting, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Category
|
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
|
||||||
|
public ReactiveCommand<Unit, Unit> StartCommand { get; }
|
||||||
|
public ObservableCollection<DatImporter> Importers { get; } = [];
|
||||||
|
|
||||||
|
void Start()
|
||||||
{
|
{
|
||||||
get => _category;
|
_listPosition = 0;
|
||||||
set => this.RaiseAndSetIfChanged(ref _category, value);
|
ProgressMinimum = 0;
|
||||||
|
ProgressMaximum = _datFiles.Length;
|
||||||
|
ProgressValue = 0;
|
||||||
|
ProgressIsIndeterminate = false;
|
||||||
|
ProgressVisible = true;
|
||||||
|
CanClose = false;
|
||||||
|
CanStart = false;
|
||||||
|
IsReady = false;
|
||||||
|
IsImporting = true;
|
||||||
|
_workers = 0;
|
||||||
|
_stopwatch.Restart();
|
||||||
|
|
||||||
|
Import();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableCollection<ImportDatFolderItem> ImportResults { get; }
|
void Import()
|
||||||
|
|
||||||
public bool CanClose
|
|
||||||
{
|
{
|
||||||
get => _canClose;
|
Dispatcher.UIThread.Post(() =>
|
||||||
set => this.RaiseAndSetIfChanged(ref _canClose, value);
|
{
|
||||||
|
if(_listPosition >= _datFiles.Length)
|
||||||
|
{
|
||||||
|
if(_workers != 0) return;
|
||||||
|
|
||||||
|
ProgressVisible = false;
|
||||||
|
StatusMessage = Localization.Finished;
|
||||||
|
CanClose = true;
|
||||||
|
CanStart = false;
|
||||||
|
IsReady = true;
|
||||||
|
_stopwatch.Stop();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
StatusMessage = string.Format(Localization.ImportingItem, Path.GetFileName(_datFiles[_listPosition]));
|
||||||
|
ProgressValue = _listPosition;
|
||||||
|
|
||||||
|
var model = new DatImporter
|
||||||
|
{
|
||||||
|
Filename = Path.GetFileName(_datFiles[_listPosition]),
|
||||||
|
Minimum = 0,
|
||||||
|
Maximum = _datFiles.Length,
|
||||||
|
Progress = 0,
|
||||||
|
Indeterminate = false
|
||||||
|
};
|
||||||
|
|
||||||
|
var worker = new Core.Workers.DatImporter(_datFiles[_listPosition], Category);
|
||||||
|
worker.ErrorOccurred += model.OnErrorOccurred;
|
||||||
|
worker.SetIndeterminateProgress += model.OnSetIndeterminateProgress;
|
||||||
|
worker.SetMessage += model.OnSetMessage;
|
||||||
|
worker.SetProgress += model.OnSetProgress;
|
||||||
|
worker.SetProgressBounds += model.OnSetProgressBounds;
|
||||||
|
worker.WorkFinished += model.OnWorkFinished;
|
||||||
|
worker.RomSetAdded += RomSetAdded;
|
||||||
|
|
||||||
|
worker.WorkFinished += (_, _) =>
|
||||||
|
{
|
||||||
|
_workers--;
|
||||||
|
|
||||||
|
if(_workers < Environment.ProcessorCount) Import();
|
||||||
|
};
|
||||||
|
|
||||||
|
Importers.Add(model);
|
||||||
|
|
||||||
|
model.Task = Task.Run(worker.Import);
|
||||||
|
|
||||||
|
_workers++;
|
||||||
|
_listPosition++;
|
||||||
|
|
||||||
|
if(_workers < Environment.ProcessorCount) Import();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanStart
|
public event EventHandler<RomSetEventArgs> RomSetAdded;
|
||||||
|
|
||||||
|
void Close()
|
||||||
{
|
{
|
||||||
get => _canStart;
|
View.Close();
|
||||||
set => this.RaiseAndSetIfChanged(ref _canStart, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
|
async Task SelectFolderAsync()
|
||||||
public ReactiveCommand<Unit, Unit> StartCommand { get; }
|
{
|
||||||
|
IReadOnlyList<IStorageFolder> result =
|
||||||
|
await View.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
|
||||||
|
{
|
||||||
|
Title = Localization.ImportDatFolderDialogTitle
|
||||||
|
});
|
||||||
|
|
||||||
internal void OnOpened() => RefreshFiles();
|
if(result.Count < 1) return;
|
||||||
|
|
||||||
|
FolderPath = result[0].TryGetLocalPath() ?? string.Empty;
|
||||||
|
RecursiveChecked = true;
|
||||||
|
AllFilesChecked = false;
|
||||||
|
RefreshFiles();
|
||||||
|
}
|
||||||
|
|
||||||
void RefreshFiles()
|
void RefreshFiles()
|
||||||
{
|
{
|
||||||
@@ -222,7 +251,6 @@ public sealed class ImportDatFolderViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
IsReady = false;
|
IsReady = false;
|
||||||
ProgressVisible = true;
|
ProgressVisible = true;
|
||||||
Progress2Visible = false;
|
|
||||||
ProgressIsIndeterminate = true;
|
ProgressIsIndeterminate = true;
|
||||||
StatusMessage = Localization.SearchingForFiles;
|
StatusMessage = Localization.SearchingForFiles;
|
||||||
});
|
});
|
||||||
@@ -264,99 +292,4 @@ public sealed class ImportDatFolderViewModel : ViewModelBase
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecuteCloseCommand() => _view.Close();
|
|
||||||
|
|
||||||
void ExecuteStartCommand()
|
|
||||||
{
|
|
||||||
_listPosition = 0;
|
|
||||||
ProgressMinimum = 0;
|
|
||||||
ProgressMaximum = _datFiles.Length;
|
|
||||||
ProgressValue = 0;
|
|
||||||
ProgressIsIndeterminate = false;
|
|
||||||
ProgressVisible = true;
|
|
||||||
Progress2Visible = true;
|
|
||||||
CanClose = false;
|
|
||||||
CanStart = false;
|
|
||||||
IsReady = false;
|
|
||||||
IsImporting = true;
|
|
||||||
|
|
||||||
Import();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Import()
|
|
||||||
{
|
|
||||||
if(_listPosition >= _datFiles.Length)
|
|
||||||
{
|
|
||||||
Progress2Visible = false;
|
|
||||||
ProgressVisible = false;
|
|
||||||
StatusMessage = Localization.Finished;
|
|
||||||
CanClose = true;
|
|
||||||
CanStart = false;
|
|
||||||
IsReady = true;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
StatusMessage = string.Format(Localization.ImportingItem, Path.GetFileName(_datFiles[_listPosition]));
|
|
||||||
ProgressValue = _listPosition;
|
|
||||||
|
|
||||||
var worker = new DatImporter(_datFiles[_listPosition], Category);
|
|
||||||
worker.ErrorOccurred += OnWorkerOnErrorOccurred;
|
|
||||||
worker.SetIndeterminateProgress += OnWorkerOnSetIndeterminateProgress;
|
|
||||||
worker.SetMessage += OnWorkerOnSetMessage;
|
|
||||||
worker.SetProgress += OnWorkerOnSetProgress;
|
|
||||||
worker.SetProgressBounds += OnWorkerOnSetProgressBounds;
|
|
||||||
worker.WorkFinished += OnWorkerOnWorkFinished;
|
|
||||||
worker.RomSetAdded += RomSetAdded;
|
|
||||||
_ = Task.Run(worker.Import);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnWorkerOnWorkFinished(object sender, MessageEventArgs args) => Dispatcher.UIThread.Post(() =>
|
|
||||||
{
|
|
||||||
ImportResults.Add(new ImportDatFolderItem
|
|
||||||
{
|
|
||||||
Filename = Path.GetFileName(_datFiles[_listPosition]),
|
|
||||||
Status = args.Message
|
|
||||||
});
|
|
||||||
|
|
||||||
_listPosition++;
|
|
||||||
Import();
|
|
||||||
});
|
|
||||||
|
|
||||||
void OnWorkerOnSetProgressBounds(object sender, ProgressBoundsEventArgs args) => Dispatcher.UIThread.Post(() =>
|
|
||||||
{
|
|
||||||
Progress2IsIndeterminate = false;
|
|
||||||
Progress2Maximum = args.Maximum;
|
|
||||||
Progress2Minimum = args.Minimum;
|
|
||||||
});
|
|
||||||
|
|
||||||
void OnWorkerOnSetProgress(object sender, ProgressEventArgs args) =>
|
|
||||||
Dispatcher.UIThread.Post(() => Progress2Value = args.Value);
|
|
||||||
|
|
||||||
void OnWorkerOnSetMessage(object sender, MessageEventArgs args) =>
|
|
||||||
Dispatcher.UIThread.Post(() => Status2Message = args.Message);
|
|
||||||
|
|
||||||
void OnWorkerOnSetIndeterminateProgress(object sender, EventArgs args) =>
|
|
||||||
Dispatcher.UIThread.Post(() => Progress2IsIndeterminate = true);
|
|
||||||
|
|
||||||
void OnWorkerOnErrorOccurred(object sender, ErrorEventArgs args) => Dispatcher.UIThread.Post(() =>
|
|
||||||
{
|
|
||||||
ImportResults.Add(new ImportDatFolderItem
|
|
||||||
{
|
|
||||||
Filename = Path.GetFileName(_datFiles[_listPosition]),
|
|
||||||
Status = args.Message
|
|
||||||
});
|
|
||||||
|
|
||||||
_listPosition++;
|
|
||||||
Import();
|
|
||||||
});
|
|
||||||
|
|
||||||
public event EventHandler<RomSetEventArgs> RomSetAdded;
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class ImportDatFolderItem
|
|
||||||
{
|
|
||||||
public string Filename { get; set; }
|
|
||||||
public string Status { get; set; }
|
|
||||||
}
|
}
|
||||||
@@ -156,19 +156,17 @@ public class MainWindowViewModel : ViewModelBase
|
|||||||
|
|
||||||
async Task ExecuteImportDatFolderCommandAsync()
|
async Task ExecuteImportDatFolderCommandAsync()
|
||||||
{
|
{
|
||||||
IReadOnlyList<IStorageFolder> result =
|
var dialog = new ImportDatFolder();
|
||||||
await _view.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
|
|
||||||
{
|
|
||||||
Title = Localization.ImportDatFolderDialogTitle
|
|
||||||
});
|
|
||||||
|
|
||||||
if(result.Count < 1) return;
|
var viewModel = new ImportDatFolderViewModel
|
||||||
|
{
|
||||||
|
View = dialog
|
||||||
|
};
|
||||||
|
|
||||||
var dialog = new ImportDatFolder();
|
viewModel.RomSetAdded += ImportDatViewModelOnRomSetAdded;
|
||||||
var importDatFolderViewModel = new ImportDatFolderViewModel(dialog, result[0].Path.LocalPath);
|
|
||||||
importDatFolderViewModel.RomSetAdded += ImportDatViewModelOnRomSetAdded;
|
dialog.DataContext = viewModel;
|
||||||
dialog.DataContext = importDatFolderViewModel;
|
_ = dialog.ShowDialog(_view);
|
||||||
_ = dialog.ShowDialog(_view);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task ExecuteImportRomFolderCommandAsync()
|
async Task ExecuteImportRomFolderCommandAsync()
|
||||||
|
|||||||
@@ -1,139 +1,125 @@
|
|||||||
<!--
|
|
||||||
// /***************************************************************************
|
|
||||||
// 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"
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:vm="clr-namespace:RomRepoMgr.ViewModels;assembly=RomRepoMgr"
|
xmlns:vm="clr-namespace:RomRepoMgr.ViewModels"
|
||||||
xmlns:resources="clr-namespace:RomRepoMgr.Resources"
|
xmlns:resources="clr-namespace:RomRepoMgr.Resources"
|
||||||
|
xmlns:models="clr-namespace:RomRepoMgr.Models"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Width="480"
|
Width="800"
|
||||||
Height="360"
|
Height="600"
|
||||||
x:Class="RomRepoMgr.Views.ImportDatFolder"
|
x:Class="RomRepoMgr.Views.ImportDatFolder"
|
||||||
Icon="/Assets/avalonia-logo.ico"
|
|
||||||
CanResize="False"
|
|
||||||
Title="{x:Static resources:Localization.ImportDatFolderTitle}"
|
Title="{x:Static resources:Localization.ImportDatFolderTitle}"
|
||||||
WindowStartupLocation="CenterOwner">
|
Icon="/Assets/avalonia-logo.ico"
|
||||||
|
CanResize="False">
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
<vm:ImportDatFolderViewModel />
|
<vm:ImportDatFolderViewModel />
|
||||||
</Design.DataContext>
|
</Design.DataContext>
|
||||||
<Border Padding="15">
|
<Grid RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, *, Auto"
|
||||||
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,*,Auto">
|
Margin="16"
|
||||||
<StackPanel Grid.Row="0"
|
RowSpacing="8">
|
||||||
Orientation="Horizontal"
|
<StackPanel Grid.Row="0"
|
||||||
HorizontalAlignment="Stretch">
|
Orientation="Horizontal"
|
||||||
<TextBlock Text="{x:Static resources:Localization.PathLabel}"
|
HorizontalAlignment="Stretch"
|
||||||
FontWeight="Bold" />
|
Spacing="8">
|
||||||
<TextBlock Text="{Binding FolderPath, Mode=OneWay}" />
|
<Button Content="{x:Static resources:Localization.ChooseLabel}"
|
||||||
</StackPanel>
|
Command="{Binding SelectFolderCommand, Mode=OneWay}"
|
||||||
<Grid Grid.Row="1"
|
HorizontalAlignment="Left"
|
||||||
ColumnDefinitions="Auto,*">
|
VerticalAlignment="Center" />
|
||||||
<TextBlock Grid.Column="0"
|
<TextBlock Text="{x:Static resources:Localization.PathLabel}"
|
||||||
HorizontalAlignment="Right"
|
|
||||||
VerticalAlignment="Center"
|
|
||||||
Text="{x:Static resources:Localization.RomSetCategoryLabel}"
|
|
||||||
FontWeight="Bold"
|
|
||||||
Padding="5" />
|
|
||||||
<TextBox Grid.Column="1"
|
|
||||||
HorizontalAlignment="Stretch"
|
|
||||||
VerticalAlignment="Center"
|
|
||||||
Text="{Binding Category, Mode=OneWay}"
|
|
||||||
Padding="5" />
|
|
||||||
</Grid>
|
|
||||||
<CheckBox Grid.Row="2"
|
|
||||||
IsChecked="{Binding AllFilesChecked, Mode=TwoWay}"
|
|
||||||
IsEnabled="{Binding IsReady, Mode=OneWay}">
|
|
||||||
<CheckBox.Content>
|
|
||||||
<TextBlock Text="{x:Static resources:Localization.AllFilesLabel}" />
|
|
||||||
</CheckBox.Content>
|
|
||||||
</CheckBox>
|
|
||||||
<CheckBox Grid.Row="3"
|
|
||||||
IsChecked="{Binding RecursiveChecked, Mode=TwoWay}"
|
|
||||||
IsEnabled="{Binding IsReady, Mode=OneWay}">
|
|
||||||
<CheckBox.Content>
|
|
||||||
<TextBlock Text="{x:Static resources:Localization.RecursiveLabel}" />
|
|
||||||
</CheckBox.Content>
|
|
||||||
</CheckBox>
|
|
||||||
<TextBlock Grid.Row="4"
|
|
||||||
Text="{Binding StatusMessage, Mode=OneWay}"
|
|
||||||
FontWeight="Bold"
|
FontWeight="Bold"
|
||||||
HorizontalAlignment="Center" />
|
VerticalAlignment="Center" />
|
||||||
<ProgressBar Grid.Row="5"
|
<TextBlock Text="{Binding FolderPath, Mode=OneWay}"
|
||||||
Minimum="{Binding ProgressMinimum, Mode=OneWay}"
|
VerticalAlignment="Center" />
|
||||||
Maximum="{Binding ProgressMaximum, Mode=OneWay}"
|
</StackPanel>
|
||||||
Value="{Binding ProgressValue, Mode=OneWay}"
|
<Grid Grid.Row="1"
|
||||||
IsIndeterminate="{Binding ProgressIsIndeterminate, Mode=OneWay}"
|
ColumnDefinitions="Auto,*"
|
||||||
IsVisible="{Binding ProgressVisible, Mode=OneWay}" />
|
ColumnSpacing="8">
|
||||||
<StackPanel Grid.Row="6"
|
<TextBlock Grid.Column="0"
|
||||||
IsVisible="{Binding Progress2Visible, Mode=OneWay}">
|
HorizontalAlignment="Right"
|
||||||
<TextBlock Text="{Binding Status2Message, Mode=OneWay}" />
|
VerticalAlignment="Center"
|
||||||
<ProgressBar Minimum="{Binding Progress2Minimum, Mode=OneWay}"
|
Text="{x:Static resources:Localization.RomSetCategoryLabel}"
|
||||||
Maximum="{Binding Progress2Maximum, Mode=OneWay}"
|
FontWeight="Bold" />
|
||||||
Value="{Binding Progress2Value, Mode=OneWay}"
|
<TextBox Grid.Column="1"
|
||||||
IsIndeterminate="{Binding Progress2IsIndeterminate, Mode=OneWay}" />
|
HorizontalAlignment="Stretch"
|
||||||
</StackPanel>
|
VerticalAlignment="Center"
|
||||||
<DataGrid Grid.Row="7"
|
Text="{Binding Category, Mode=OneWay}" />
|
||||||
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"
|
|
||||||
IsVisible="{Binding IsReady, Mode=OneWay}"
|
|
||||||
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>
|
</Grid>
|
||||||
</Border>
|
<CheckBox Grid.Row="2"
|
||||||
|
IsChecked="{Binding AllFilesChecked, Mode=TwoWay}"
|
||||||
|
IsEnabled="{Binding IsReady, Mode=OneWay}">
|
||||||
|
<CheckBox.Content>
|
||||||
|
<TextBlock Text="{x:Static resources:Localization.AllFilesLabel}" />
|
||||||
|
</CheckBox.Content>
|
||||||
|
</CheckBox>
|
||||||
|
<CheckBox Grid.Row="3"
|
||||||
|
IsChecked="{Binding RecursiveChecked, Mode=TwoWay}"
|
||||||
|
IsEnabled="{Binding IsReady, Mode=OneWay}">
|
||||||
|
<CheckBox.Content>
|
||||||
|
<TextBlock Text="{x:Static resources:Localization.RecursiveLabel}" />
|
||||||
|
</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}" />
|
||||||
|
<DataGrid Grid.Row="6"
|
||||||
|
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:DatImporter">
|
||||||
|
<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="7"
|
||||||
|
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>
|
</Window>
|
||||||
@@ -1,44 +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 System;
|
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
using RomRepoMgr.ViewModels;
|
|
||||||
|
|
||||||
namespace RomRepoMgr.Views;
|
namespace RomRepoMgr.Views;
|
||||||
|
|
||||||
public sealed partial class ImportDatFolder : Window
|
public partial class ImportDatFolder : Window
|
||||||
{
|
{
|
||||||
public ImportDatFolder() => InitializeComponent();
|
public ImportDatFolder()
|
||||||
|
|
||||||
void InitializeComponent() => AvaloniaXamlLoader.Load(this);
|
|
||||||
|
|
||||||
protected override void OnOpened(EventArgs e)
|
|
||||||
{
|
{
|
||||||
base.OnOpened(e);
|
InitializeComponent();
|
||||||
(DataContext as ImportDatFolderViewModel)?.OnOpened();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user