mirror of
https://github.com/claunia/romrepomgr.git
synced 2025-12-16 19:24:51 +00:00
Add window to import ROMs from folder.
This commit is contained in:
@@ -48,21 +48,20 @@ namespace RomRepoMgr.ViewModels
|
||||
string[] _datFiles;
|
||||
bool _isImporting;
|
||||
bool _isReady;
|
||||
|
||||
int _listPosition;
|
||||
bool _progress2IsIndeterminate;
|
||||
double _progress2Maximum;
|
||||
double _progress2Minimum;
|
||||
double _progress2Value;
|
||||
bool _progress2Visible;
|
||||
bool _progressIsIndeterminate;
|
||||
double _progressMaximum;
|
||||
double _progressMinimum;
|
||||
double _progressValue;
|
||||
bool _progressVisible;
|
||||
bool _recursiveChecked;
|
||||
string _status2Message;
|
||||
string _statusMessage;
|
||||
int _listPosition;
|
||||
bool _progress2IsIndeterminate;
|
||||
double _progress2Maximum;
|
||||
double _progress2Minimum;
|
||||
double _progress2Value;
|
||||
bool _progress2Visible;
|
||||
bool _progressIsIndeterminate;
|
||||
double _progressMaximum;
|
||||
double _progressMinimum;
|
||||
double _progressValue;
|
||||
bool _progressVisible;
|
||||
bool _recursiveChecked;
|
||||
string _status2Message;
|
||||
string _statusMessage;
|
||||
|
||||
public ImportDatFolderViewModel(ImportDatFolder view, string folderPath)
|
||||
{
|
||||
|
||||
235
RomRepoMgr/ViewModels/ImportRomFolderViewModel.cs
Normal file
235
RomRepoMgr/ViewModels/ImportRomFolderViewModel.cs
Normal file
@@ -0,0 +1,235 @@
|
||||
/******************************************************************************
|
||||
// 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 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reactive;
|
||||
using Avalonia.Threading;
|
||||
using JetBrains.Annotations;
|
||||
using ReactiveUI;
|
||||
using RomRepoMgr.Core.EventArgs;
|
||||
using RomRepoMgr.Views;
|
||||
|
||||
namespace RomRepoMgr.ViewModels
|
||||
{
|
||||
public sealed 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;
|
||||
string _status2Message;
|
||||
string _statusMessage;
|
||||
|
||||
public ImportRomFolderViewModel(ImportRomFolder view, string folderPath)
|
||||
{
|
||||
_view = view;
|
||||
FolderPath = folderPath;
|
||||
_removeFilesChecked = false;
|
||||
_knownOnlyChecked = true;
|
||||
_recurseArchivesChecked = false;
|
||||
ImportResults = new ObservableCollection<ImportRomFolderItem>();
|
||||
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
|
||||
StartCommand = ReactiveCommand.Create(ExecuteStartCommand);
|
||||
_isReady = true;
|
||||
}
|
||||
|
||||
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 RemoveFilesChecked
|
||||
{
|
||||
get => _removeFilesChecked;
|
||||
set => this.RaiseAndSetIfChanged(ref _removeFilesChecked, value);
|
||||
}
|
||||
|
||||
public bool KnownOnlyChecked
|
||||
{
|
||||
get => _knownOnlyChecked;
|
||||
set => this.RaiseAndSetIfChanged(ref _knownOnlyChecked, value);
|
||||
}
|
||||
|
||||
public bool RecurseArchivesChecked
|
||||
{
|
||||
get => _recurseArchivesChecked;
|
||||
set => this.RaiseAndSetIfChanged(ref _recurseArchivesChecked, value);
|
||||
}
|
||||
|
||||
public bool IsReady
|
||||
{
|
||||
get => _isReady;
|
||||
set => this.RaiseAndSetIfChanged(ref _isReady, value);
|
||||
}
|
||||
|
||||
public bool ProgressVisible
|
||||
{
|
||||
get => _progressVisible;
|
||||
set => this.RaiseAndSetIfChanged(ref _progressVisible, value);
|
||||
}
|
||||
|
||||
public string StatusMessage
|
||||
{
|
||||
get => _statusMessage;
|
||||
set => this.RaiseAndSetIfChanged(ref _statusMessage, value);
|
||||
}
|
||||
|
||||
public double ProgressMinimum
|
||||
{
|
||||
get => _progressMinimum;
|
||||
set => this.RaiseAndSetIfChanged(ref _progressMinimum, value);
|
||||
}
|
||||
|
||||
public double ProgressMaximum
|
||||
{
|
||||
get => _progressMaximum;
|
||||
set => this.RaiseAndSetIfChanged(ref _progressMaximum, value);
|
||||
}
|
||||
|
||||
public double ProgressValue
|
||||
{
|
||||
get => _progressValue;
|
||||
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
|
||||
{
|
||||
get => _isImporting;
|
||||
set => this.RaiseAndSetIfChanged(ref _isImporting, value);
|
||||
}
|
||||
|
||||
[NotNull]
|
||||
public string Title => "Import ROM files from folder...";
|
||||
|
||||
public ObservableCollection<ImportRomFolderItem> ImportResults { get; }
|
||||
public string ResultFilenameLabel => "Filename";
|
||||
public string ResultStatusLabel => "Status";
|
||||
public string CloseLabel => "Close";
|
||||
public string StartLabel => "Start";
|
||||
|
||||
public bool CanClose
|
||||
{
|
||||
get => _canClose;
|
||||
set => this.RaiseAndSetIfChanged(ref _canClose, value);
|
||||
}
|
||||
|
||||
public bool CanStart
|
||||
{
|
||||
get => _canStart;
|
||||
set => this.RaiseAndSetIfChanged(ref _canStart, value);
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> StartCommand { get; }
|
||||
|
||||
void ExecuteCloseCommand() => _view.Close();
|
||||
|
||||
void ExecuteStartCommand() {}
|
||||
|
||||
void OnWorkerOnWorkFinished(object sender, EventArgs args) => Dispatcher.UIThread.Post(() => {});
|
||||
|
||||
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(() => {});
|
||||
}
|
||||
|
||||
public sealed class ImportRomFolderItem
|
||||
{
|
||||
public string Filename { get; set; }
|
||||
public string Status { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,7 @@ namespace RomRepoMgr.ViewModels
|
||||
AboutCommand = ReactiveCommand.Create(ExecuteAboutCommand);
|
||||
ImportDatCommand = ReactiveCommand.Create(ExecuteImportDatCommand);
|
||||
ImportDatFolderCommand = ReactiveCommand.Create(ExecuteImportDatFolderCommand);
|
||||
ImportRomFolderCommand = ReactiveCommand.Create(ExecuteImportRomFolderCommand);
|
||||
RomSets = new ObservableCollection<RomSetModel>(romSets);
|
||||
}
|
||||
|
||||
@@ -72,6 +73,7 @@ namespace RomRepoMgr.ViewModels
|
||||
public ReactiveCommand<Unit, Unit> SettingsCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> ImportDatCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> ImportDatFolderCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> ImportRomFolderCommand { get; }
|
||||
|
||||
internal async void ExecuteSettingsCommand()
|
||||
{
|
||||
@@ -152,5 +154,23 @@ namespace RomRepoMgr.ViewModels
|
||||
dialog.DataContext = importDatFolderViewModel;
|
||||
await dialog.ShowDialog(_view);
|
||||
}
|
||||
|
||||
internal async void ExecuteImportRomFolderCommand()
|
||||
{
|
||||
var dlgOpen = new OpenFolderDialog
|
||||
{
|
||||
Title = "Import ROMs from folder..."
|
||||
};
|
||||
|
||||
string result = await dlgOpen.ShowAsync(_view);
|
||||
|
||||
if(result == null)
|
||||
return;
|
||||
|
||||
var dialog = new ImportRomFolder();
|
||||
var importRomFolderViewModel = new ImportRomFolderViewModel(dialog, result);
|
||||
dialog.DataContext = importRomFolderViewModel;
|
||||
await dialog.ShowDialog(_view);
|
||||
}
|
||||
}
|
||||
}
|
||||
97
RomRepoMgr/Views/ImportRomFolder.xaml
Normal file
97
RomRepoMgr/Views/ImportRomFolder.xaml
Normal file
@@ -0,0 +1,97 @@
|
||||
<!--
|
||||
// /***************************************************************************
|
||||
// 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 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" mc:Ignorable="d" d:DesignWidth="800"
|
||||
d:DesignHeight="450" Width="480" Height="360" x:Class="RomRepoMgr.Views.ImportRomFolder"
|
||||
Icon="/Assets/avalonia-logo.ico" CanResize="False" Title="{Binding Title}" WindowStartupLocation="CenterOwner">
|
||||
<Design.DataContext>
|
||||
<vm:ImportRomFolderViewModel />
|
||||
</Design.DataContext>
|
||||
<Border Padding="15">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" /> <RowDefinition Height="*" /> <RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<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.Content>
|
||||
<TextBlock Text="{Binding RemoveFilesLabel}" />
|
||||
</CheckBox.Content>
|
||||
</CheckBox>
|
||||
<CheckBox Grid.Row="2" IsChecked="{Binding KnownOnlyChecked}" IsEnabled="False">
|
||||
<CheckBox.Content>
|
||||
<TextBlock Text="{Binding KnownOnlyLabel}" />
|
||||
</CheckBox.Content>
|
||||
</CheckBox>
|
||||
<CheckBox Grid.Row="3" IsChecked="{Binding RecurseArchivesChecked}" IsEnabled="False">
|
||||
<CheckBox.Content>
|
||||
<TextBlock Text="{Binding RecurseArchivesLabel}" />
|
||||
</CheckBox.Content>
|
||||
</CheckBox>
|
||||
<TextBlock Grid.Row="4" Text="{Binding StatusMessage}" FontWeight="Bold" HorizontalAlignment="Center" />
|
||||
<ProgressBar Grid.Row="5" Minimum="{Binding ProgressMinimum}" Maximum="{Binding ProgressMaximum}"
|
||||
Value="{Binding ProgressValue}" IsIndeterminate="{Binding ProgressIsIndeterminate}"
|
||||
IsVisible="{Binding ProgressVisible}" />
|
||||
<StackPanel Grid.Row="6" IsVisible="{Binding Progress2Visible}">
|
||||
<TextBlock Text="{Binding Status2Message}" />
|
||||
<ProgressBar Minimum="{Binding Progress2Minimum}" Maximum="{Binding Progress2Maximum}"
|
||||
Value="{Binding Progress2Value}" IsIndeterminate="{Binding Progress2IsIndeterminate}" />
|
||||
</StackPanel>
|
||||
<DataGrid Grid.Row="7" Items="{Binding ImportResults}" HorizontalScrollBarVisibility="Visible"
|
||||
IsVisible="{Binding IsImporting}">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Binding="{Binding Filename}" Width="Auto" IsReadOnly="True">
|
||||
<DataGridTextColumn.Header>
|
||||
<TextBlock Text="{Binding ResultFilenameLabel}" />
|
||||
</DataGridTextColumn.Header>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Binding="{Binding Status}" Width="Auto" IsReadOnly="True">
|
||||
<DataGridTextColumn.Header>
|
||||
<TextBlock Text="{Binding ResultStatusLabel}" />
|
||||
</DataGridTextColumn.Header>
|
||||
</DataGridTextColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<StackPanel Grid.Row="8" Orientation="Horizontal" IsVisible="{Binding IsReady}" HorizontalAlignment="Right">
|
||||
<Button HorizontalAlignment="Right" VerticalAlignment="Center" IsEnabled="{Binding CanClose}"
|
||||
Command="{Binding CloseCommand}">
|
||||
<TextBlock Text="{Binding CloseLabel}" />
|
||||
</Button>
|
||||
<Button HorizontalAlignment="Right" VerticalAlignment="Center" IsEnabled="{Binding CanStart}"
|
||||
Command="{Binding StartCommand}">
|
||||
<TextBlock Text="{Binding StartLabel}" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Window>
|
||||
37
RomRepoMgr/Views/ImportRomFolder.xaml.cs
Normal file
37
RomRepoMgr/Views/ImportRomFolder.xaml.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
/******************************************************************************
|
||||
// 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 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace RomRepoMgr.Views
|
||||
{
|
||||
public sealed class ImportRomFolder : Window
|
||||
{
|
||||
public ImportRomFolder() => InitializeComponent();
|
||||
|
||||
void InitializeComponent() => AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,9 @@
|
||||
<Separator />
|
||||
<MenuItem Header="E_xit" IsVisible="{Binding !NativeMenuSupported}" Command="{Binding ExitCommand}" />
|
||||
</MenuItem>
|
||||
<MenuItem Header="_ROMs">
|
||||
<MenuItem Header="_Import folder" Command="{Binding ImportRomFolderCommand}" /> <Separator />
|
||||
</MenuItem>
|
||||
<MenuItem Header="_Help">
|
||||
<MenuItem Header="_About" Name="AboutMenuItem" IsVisible="{Binding !NativeMenuSupported}"
|
||||
Command="{Binding AboutCommand}" />
|
||||
|
||||
Reference in New Issue
Block a user