2020-08-21 23:34:07 +01:00
|
|
|
|
/******************************************************************************
|
|
|
|
|
|
// 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
|
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
2020-08-22 04:40:39 +01:00
|
|
|
|
using System.Collections.Generic;
|
2020-08-22 03:26:43 +01:00
|
|
|
|
using System.Collections.ObjectModel;
|
2020-08-24 03:20:06 +01:00
|
|
|
|
using System.Linq;
|
2020-08-22 03:13:49 +01:00
|
|
|
|
using System.Reactive;
|
|
|
|
|
|
using Avalonia;
|
|
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
2020-08-22 13:44:40 +01:00
|
|
|
|
using Avalonia.Threading;
|
2020-08-24 02:29:07 +01:00
|
|
|
|
using MessageBox.Avalonia;
|
|
|
|
|
|
using MessageBox.Avalonia.Enums;
|
2020-08-22 03:13:49 +01:00
|
|
|
|
using ReactiveUI;
|
2020-08-22 13:44:40 +01:00
|
|
|
|
using RomRepoMgr.Core.EventArgs;
|
2020-08-26 01:46:02 +01:00
|
|
|
|
using RomRepoMgr.Core.Filesystem;
|
2020-08-22 13:36:39 +01:00
|
|
|
|
using RomRepoMgr.Core.Models;
|
2020-08-30 03:00:14 +01:00
|
|
|
|
using RomRepoMgr.Resources;
|
2020-08-22 03:13:49 +01:00
|
|
|
|
using RomRepoMgr.Views;
|
|
|
|
|
|
|
2020-08-21 23:34:07 +01:00
|
|
|
|
namespace RomRepoMgr.ViewModels
|
2020-08-21 22:22:24 +01:00
|
|
|
|
{
|
|
|
|
|
|
public class MainWindowViewModel : ViewModelBase
|
|
|
|
|
|
{
|
2020-08-22 03:13:49 +01:00
|
|
|
|
readonly MainWindow _view;
|
|
|
|
|
|
|
2020-08-24 02:29:07 +01:00
|
|
|
|
RomSetModel _selectedRomSet;
|
|
|
|
|
|
|
2020-08-22 13:32:43 +01:00
|
|
|
|
public MainWindowViewModel(MainWindow view, List<RomSetModel> romSets)
|
2020-08-22 03:13:49 +01:00
|
|
|
|
{
|
2020-08-22 19:28:58 +01:00
|
|
|
|
_view = view;
|
|
|
|
|
|
ExitCommand = ReactiveCommand.Create(ExecuteExitCommand);
|
|
|
|
|
|
SettingsCommand = ReactiveCommand.Create(ExecuteSettingsCommand);
|
|
|
|
|
|
AboutCommand = ReactiveCommand.Create(ExecuteAboutCommand);
|
|
|
|
|
|
ImportDatCommand = ReactiveCommand.Create(ExecuteImportDatCommand);
|
|
|
|
|
|
ImportDatFolderCommand = ReactiveCommand.Create(ExecuteImportDatFolderCommand);
|
2020-08-22 21:57:05 +01:00
|
|
|
|
ImportRomFolderCommand = ReactiveCommand.Create(ExecuteImportRomFolderCommand);
|
2020-08-24 02:29:07 +01:00
|
|
|
|
DeleteRomSetCommand = ReactiveCommand.Create(ExecuteDeleteRomSetCommand);
|
2020-08-24 03:20:06 +01:00
|
|
|
|
EditRomSetCommand = ReactiveCommand.Create(ExecuteEditRomSetCommand);
|
2020-08-24 04:01:55 +01:00
|
|
|
|
ExportDatCommand = ReactiveCommand.Create(ExecuteExportDatCommand);
|
2020-08-24 23:27:03 +01:00
|
|
|
|
ExportRomsCommand = ReactiveCommand.Create(ExecuteExportRomsCommand);
|
2020-08-26 01:46:02 +01:00
|
|
|
|
MountCommand = ReactiveCommand.Create(ExecuteMountCommand);
|
2020-08-22 19:28:58 +01:00
|
|
|
|
RomSets = new ObservableCollection<RomSetModel>(romSets);
|
2020-08-22 03:13:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-30 03:00:14 +01:00
|
|
|
|
public ObservableCollection<RomSetModel> RomSets { get; }
|
|
|
|
|
|
public string RomSetLabel => Localization.RomSets;
|
|
|
|
|
|
public string RomSetNameLabel => Localization.RomSetNameLabel;
|
|
|
|
|
|
public string RomSetVersionLabel => Localization.RomSetVersionLabel;
|
|
|
|
|
|
public string RomSetAuthorLabel => Localization.RomSetAuthorLabel;
|
|
|
|
|
|
public string RomSetDateLabel => Localization.RomSetDateLabel;
|
|
|
|
|
|
public string RomSetDescriptionLabel => Localization.RomSetDescriptionLabel;
|
|
|
|
|
|
public string RomSetCommentLabel => Localization.RomSetCommentLabel;
|
|
|
|
|
|
public string RomSetTotalMachinesLabel => Localization.RomSetTotalMachinesLabel;
|
|
|
|
|
|
public string RomSetCompleteMachinesLabel => Localization.RomSetCompleteMachinesLabel;
|
|
|
|
|
|
public string RomSetIncompleteMachinesLabel => Localization.RomSetIncompleteMachinesLabel;
|
|
|
|
|
|
public string RomSetTotalRomsLabel => Localization.RomSetTotalRomsLabel;
|
|
|
|
|
|
public string RomSetHaveRomsLabel => Localization.RomSetHaveRomsLabel;
|
|
|
|
|
|
public string RomSetMissRomsLabel => Localization.RomSetMissRomsLabel;
|
|
|
|
|
|
public bool IsVfsAvailable => Fuse.IsAvailable;
|
|
|
|
|
|
public string FileMenuText => Localization.FileMenuText;
|
|
|
|
|
|
public string FileMenuImportDatFileText => Localization.FileMenuImportDatFileText;
|
|
|
|
|
|
public string FileMenuImportDatFolderText => Localization.FileMenuImportDatFolderText;
|
|
|
|
|
|
public string FileMenuSettingsText => Localization.FileMenuSettingsText;
|
|
|
|
|
|
public string FileMenuExitText => Localization.FileMenuExitText;
|
|
|
|
|
|
public string FilesystemMenuText => Localization.FilesystemMenuText;
|
|
|
|
|
|
public string FilesystemMenuMountText => Localization.FilesystemMenuMountText;
|
|
|
|
|
|
public string RomsMenuText => Localization.RomsMenuText;
|
|
|
|
|
|
public string RomsMenuImportText => Localization.RomsMenuImportText;
|
|
|
|
|
|
public string RomSetsMenuText => Localization.RomSetsMenuText;
|
|
|
|
|
|
public string RomSetsMenuSaveRomsText => Localization.RomSetsMenuSaveRomsText;
|
|
|
|
|
|
public string RomSetsMenuSaveDatText => Localization.RomSetsMenuSaveDatText;
|
|
|
|
|
|
public string RomSetsMenuEditText => Localization.RomSetsMenuEditText;
|
|
|
|
|
|
public string RomSetsMenuDeleteText => Localization.RomSetsMenuDeleteText;
|
|
|
|
|
|
public string HelpMenuText => Localization.HelpMenuText;
|
|
|
|
|
|
public string HelpMenuAboutText => Localization.HelpMenuAboutText;
|
2020-08-22 03:26:43 +01:00
|
|
|
|
|
2020-08-22 03:13:49 +01:00
|
|
|
|
public bool NativeMenuSupported =>
|
|
|
|
|
|
NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as
|
|
|
|
|
|
IClassicDesktopStyleApplicationLifetime)?.MainWindow);
|
|
|
|
|
|
|
2020-08-22 19:28:58 +01:00
|
|
|
|
public ReactiveCommand<Unit, Unit> AboutCommand { get; }
|
|
|
|
|
|
public ReactiveCommand<Unit, Unit> ExitCommand { get; }
|
|
|
|
|
|
public ReactiveCommand<Unit, Unit> SettingsCommand { get; }
|
|
|
|
|
|
public ReactiveCommand<Unit, Unit> ImportDatCommand { get; }
|
|
|
|
|
|
public ReactiveCommand<Unit, Unit> ImportDatFolderCommand { get; }
|
2020-08-22 21:57:05 +01:00
|
|
|
|
public ReactiveCommand<Unit, Unit> ImportRomFolderCommand { get; }
|
2020-08-24 02:29:07 +01:00
|
|
|
|
public ReactiveCommand<Unit, Unit> DeleteRomSetCommand { get; }
|
2020-08-24 03:20:06 +01:00
|
|
|
|
public ReactiveCommand<Unit, Unit> EditRomSetCommand { get; }
|
2020-08-24 04:01:55 +01:00
|
|
|
|
public ReactiveCommand<Unit, Unit> ExportDatCommand { get; }
|
2020-08-24 23:27:03 +01:00
|
|
|
|
public ReactiveCommand<Unit, Unit> ExportRomsCommand { get; }
|
2020-08-26 01:46:02 +01:00
|
|
|
|
public ReactiveCommand<Unit, Unit> MountCommand { get; }
|
2020-08-24 02:29:07 +01:00
|
|
|
|
|
|
|
|
|
|
public RomSetModel SelectedRomSet
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _selectedRomSet;
|
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _selectedRomSet, value);
|
|
|
|
|
|
}
|
2020-08-22 03:13:49 +01:00
|
|
|
|
|
|
|
|
|
|
internal async void ExecuteSettingsCommand()
|
|
|
|
|
|
{
|
2020-08-22 21:19:34 +01:00
|
|
|
|
var dialog = new SettingsDialog();
|
|
|
|
|
|
dialog.DataContext = new SettingsViewModel(dialog);
|
|
|
|
|
|
await dialog.ShowDialog(_view);
|
2020-08-22 03:13:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal void ExecuteExitCommand() =>
|
|
|
|
|
|
(Application.Current.ApplicationLifetime as ClassicDesktopStyleApplicationLifetime)?.Shutdown();
|
|
|
|
|
|
|
|
|
|
|
|
internal void ExecuteAboutCommand()
|
|
|
|
|
|
{
|
|
|
|
|
|
var dialog = new About();
|
|
|
|
|
|
dialog.DataContext = new AboutViewModel(dialog);
|
|
|
|
|
|
dialog.ShowDialog(_view);
|
|
|
|
|
|
}
|
2020-08-22 04:40:39 +01:00
|
|
|
|
|
2020-08-30 03:00:14 +01:00
|
|
|
|
async void ExecuteImportDatCommand()
|
2020-08-22 04:40:39 +01:00
|
|
|
|
{
|
2020-08-22 13:44:40 +01:00
|
|
|
|
var dlgOpen = new OpenFileDialog
|
|
|
|
|
|
{
|
|
|
|
|
|
AllowMultiple = false,
|
2020-08-30 03:00:14 +01:00
|
|
|
|
Title = Localization.ImportDatFileDialogTitle
|
2020-08-22 13:44:40 +01:00
|
|
|
|
};
|
2020-08-22 04:40:39 +01:00
|
|
|
|
|
|
|
|
|
|
dlgOpen.Filters.Add(new FileDialogFilter
|
|
|
|
|
|
{
|
|
|
|
|
|
Extensions = new List<string>
|
|
|
|
|
|
{
|
|
|
|
|
|
"*.dat",
|
|
|
|
|
|
"*.xml"
|
|
|
|
|
|
},
|
2020-08-30 03:00:14 +01:00
|
|
|
|
Name = Localization.DatFilesDialogLabel
|
2020-08-22 04:40:39 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
dlgOpen.Filters.Add(new FileDialogFilter
|
|
|
|
|
|
{
|
|
|
|
|
|
Extensions = new List<string>
|
|
|
|
|
|
{
|
|
|
|
|
|
"*.*"
|
|
|
|
|
|
},
|
2020-08-30 03:00:14 +01:00
|
|
|
|
Name = Localization.AllFilesDialogLabel
|
2020-08-22 04:40:39 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
string[] result = await dlgOpen.ShowAsync(_view);
|
|
|
|
|
|
|
|
|
|
|
|
if(result?.Length != 1)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-08-22 13:36:39 +01:00
|
|
|
|
var dialog = new ImportDat();
|
|
|
|
|
|
var importDatViewModel = new ImportDatViewModel(dialog, result[0]);
|
2020-08-22 13:44:40 +01:00
|
|
|
|
importDatViewModel.RomSetAdded += ImportDatViewModelOnRomSetAdded;
|
|
|
|
|
|
dialog.DataContext = importDatViewModel;
|
2020-08-22 04:40:39 +01:00
|
|
|
|
await dialog.ShowDialog(_view);
|
|
|
|
|
|
}
|
2020-08-22 13:44:40 +01:00
|
|
|
|
|
2020-08-30 03:00:14 +01:00
|
|
|
|
void ImportDatViewModelOnRomSetAdded(object sender, RomSetEventArgs e) =>
|
|
|
|
|
|
Dispatcher.UIThread.Post(() => RomSets.Add(e.RomSet));
|
2020-08-22 19:28:58 +01:00
|
|
|
|
|
2020-08-30 03:00:14 +01:00
|
|
|
|
async void ExecuteImportDatFolderCommand()
|
2020-08-22 19:28:58 +01:00
|
|
|
|
{
|
|
|
|
|
|
var dlgOpen = new OpenFolderDialog
|
|
|
|
|
|
{
|
2020-08-30 03:00:14 +01:00
|
|
|
|
Title = Localization.ImportDatFolderDialogTitle
|
2020-08-22 19:28:58 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
string result = await dlgOpen.ShowAsync(_view);
|
|
|
|
|
|
|
|
|
|
|
|
if(result == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
var dialog = new ImportDatFolder();
|
|
|
|
|
|
var importDatFolderViewModel = new ImportDatFolderViewModel(dialog, result);
|
|
|
|
|
|
importDatFolderViewModel.RomSetAdded += ImportDatViewModelOnRomSetAdded;
|
|
|
|
|
|
dialog.DataContext = importDatFolderViewModel;
|
|
|
|
|
|
await dialog.ShowDialog(_view);
|
|
|
|
|
|
}
|
2020-08-22 21:57:05 +01:00
|
|
|
|
|
2020-08-30 03:00:14 +01:00
|
|
|
|
async void ExecuteImportRomFolderCommand()
|
2020-08-22 21:57:05 +01:00
|
|
|
|
{
|
|
|
|
|
|
var dlgOpen = new OpenFolderDialog
|
|
|
|
|
|
{
|
2020-08-30 03:00:14 +01:00
|
|
|
|
Title = Localization.ImportRomsFolderDialogTitle
|
2020-08-22 21:57:05 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
2020-08-24 02:29:07 +01:00
|
|
|
|
|
|
|
|
|
|
async void ExecuteDeleteRomSetCommand()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(SelectedRomSet == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-08-30 03:00:14 +01:00
|
|
|
|
ButtonResult result = await MessageBoxManager.
|
|
|
|
|
|
GetMessageBoxStandardWindow(Localization.DeleteRomSetMsgBoxTitle,
|
|
|
|
|
|
string.
|
|
|
|
|
|
Format(Localization.DeleteRomSetMsgBoxCaption,
|
|
|
|
|
|
SelectedRomSet.Name), ButtonEnum.YesNo,
|
|
|
|
|
|
Icon.Database).ShowDialog(_view);
|
2020-08-24 02:29:07 +01:00
|
|
|
|
|
|
|
|
|
|
if(result == ButtonResult.No)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
var dialog = new RemoveDat();
|
|
|
|
|
|
var removeDatViewModel = new RemoveDatViewModel(dialog, SelectedRomSet.Id);
|
|
|
|
|
|
dialog.DataContext = removeDatViewModel;
|
|
|
|
|
|
await dialog.ShowDialog(_view);
|
|
|
|
|
|
|
|
|
|
|
|
RomSets.Remove(SelectedRomSet);
|
|
|
|
|
|
SelectedRomSet = null;
|
|
|
|
|
|
}
|
2020-08-24 03:20:06 +01:00
|
|
|
|
|
|
|
|
|
|
void ExecuteEditRomSetCommand()
|
|
|
|
|
|
{
|
2020-08-24 04:01:55 +01:00
|
|
|
|
if(SelectedRomSet == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-08-24 03:20:06 +01:00
|
|
|
|
var window = new EditDat();
|
|
|
|
|
|
var viewModel = new EditDatViewModel(window, SelectedRomSet);
|
|
|
|
|
|
|
|
|
|
|
|
viewModel.RomSetModified += (sender, args) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
RomSetModel old = RomSets.FirstOrDefault(r => r.Id == args.RomSet.Id);
|
|
|
|
|
|
|
|
|
|
|
|
if(old == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
RomSets.Remove(old);
|
|
|
|
|
|
RomSets.Add(args.RomSet);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
window.DataContext = viewModel;
|
|
|
|
|
|
|
|
|
|
|
|
window.Show();
|
|
|
|
|
|
}
|
2020-08-24 04:01:55 +01:00
|
|
|
|
|
|
|
|
|
|
async void ExecuteExportDatCommand()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(SelectedRomSet == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
var dlgSave = new SaveFileDialog
|
|
|
|
|
|
{
|
|
|
|
|
|
InitialFileName = SelectedRomSet.Filename
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
string result = await dlgSave.ShowAsync(_view);
|
|
|
|
|
|
|
|
|
|
|
|
if(result == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
var dialog = new ExportDat();
|
|
|
|
|
|
var viewModel = new ExportDatViewModel(dialog, SelectedRomSet.Sha384, result);
|
|
|
|
|
|
dialog.DataContext = viewModel;
|
|
|
|
|
|
await dialog.ShowDialog(_view);
|
|
|
|
|
|
}
|
2020-08-24 23:27:03 +01:00
|
|
|
|
|
|
|
|
|
|
async void ExecuteExportRomsCommand()
|
|
|
|
|
|
{
|
|
|
|
|
|
var dlgOpen = new OpenFolderDialog
|
|
|
|
|
|
{
|
2020-08-30 03:00:14 +01:00
|
|
|
|
Title = Localization.ExportRomsDialogTitle
|
2020-08-24 23:27:03 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
string result = await dlgOpen.ShowAsync(_view);
|
|
|
|
|
|
|
|
|
|
|
|
if(result == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
var dialog = new ExportRoms();
|
|
|
|
|
|
var viewModel = new ExportRomsViewModel(dialog, result, SelectedRomSet.Id);
|
|
|
|
|
|
dialog.DataContext = viewModel;
|
|
|
|
|
|
await dialog.ShowDialog(_view);
|
|
|
|
|
|
}
|
2020-08-26 01:46:02 +01:00
|
|
|
|
|
|
|
|
|
|
async void ExecuteMountCommand()
|
|
|
|
|
|
{
|
|
|
|
|
|
var dlgOpen = new OpenFolderDialog
|
|
|
|
|
|
{
|
2020-08-30 03:00:14 +01:00
|
|
|
|
Title = Localization.SelectMountPointDialogTitle
|
2020-08-26 01:46:02 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
string result = await dlgOpen.ShowAsync(_view);
|
|
|
|
|
|
|
|
|
|
|
|
if(result == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
var fs = new Fuse
|
|
|
|
|
|
{
|
|
|
|
|
|
MountPoint = result
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
fs.Start();
|
|
|
|
|
|
}
|
2020-08-21 22:22:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|