mirror of
https://github.com/claunia/romrepomgr.git
synced 2025-12-16 19:24:51 +00:00
Add option to remove ROM set.
This commit is contained in:
@@ -42,5 +42,6 @@ namespace RomRepoMgr.Core.Models
|
|||||||
public long TotalRoms { get; set; }
|
public long TotalRoms { get; set; }
|
||||||
public long HaveRoms { get; set; }
|
public long HaveRoms { get; set; }
|
||||||
public long MissRoms { get; set; }
|
public long MissRoms { get; set; }
|
||||||
|
public long Id { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -464,6 +464,7 @@ namespace RomRepoMgr.Core.Workers
|
|||||||
{
|
{
|
||||||
RomSet = new RomSetModel
|
RomSet = new RomSetModel
|
||||||
{
|
{
|
||||||
|
Id = romSet.Id,
|
||||||
Author = romSet.Author,
|
Author = romSet.Author,
|
||||||
Comment = romSet.Comment,
|
Comment = romSet.Comment,
|
||||||
Date = romSet.Date,
|
Date = romSet.Date,
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ using Avalonia;
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
|
using MessageBox.Avalonia;
|
||||||
|
using MessageBox.Avalonia.Enums;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using RomRepoMgr.Core.EventArgs;
|
using RomRepoMgr.Core.EventArgs;
|
||||||
using RomRepoMgr.Core.Models;
|
using RomRepoMgr.Core.Models;
|
||||||
@@ -41,6 +43,8 @@ namespace RomRepoMgr.ViewModels
|
|||||||
{
|
{
|
||||||
readonly MainWindow _view;
|
readonly MainWindow _view;
|
||||||
|
|
||||||
|
RomSetModel _selectedRomSet;
|
||||||
|
|
||||||
public MainWindowViewModel(MainWindow view, List<RomSetModel> romSets)
|
public MainWindowViewModel(MainWindow view, List<RomSetModel> romSets)
|
||||||
{
|
{
|
||||||
_view = view;
|
_view = view;
|
||||||
@@ -50,6 +54,7 @@ namespace RomRepoMgr.ViewModels
|
|||||||
ImportDatCommand = ReactiveCommand.Create(ExecuteImportDatCommand);
|
ImportDatCommand = ReactiveCommand.Create(ExecuteImportDatCommand);
|
||||||
ImportDatFolderCommand = ReactiveCommand.Create(ExecuteImportDatFolderCommand);
|
ImportDatFolderCommand = ReactiveCommand.Create(ExecuteImportDatFolderCommand);
|
||||||
ImportRomFolderCommand = ReactiveCommand.Create(ExecuteImportRomFolderCommand);
|
ImportRomFolderCommand = ReactiveCommand.Create(ExecuteImportRomFolderCommand);
|
||||||
|
DeleteRomSetCommand = ReactiveCommand.Create(ExecuteDeleteRomSetCommand);
|
||||||
RomSets = new ObservableCollection<RomSetModel>(romSets);
|
RomSets = new ObservableCollection<RomSetModel>(romSets);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +84,13 @@ namespace RomRepoMgr.ViewModels
|
|||||||
public ReactiveCommand<Unit, Unit> ImportDatCommand { get; }
|
public ReactiveCommand<Unit, Unit> ImportDatCommand { get; }
|
||||||
public ReactiveCommand<Unit, Unit> ImportDatFolderCommand { get; }
|
public ReactiveCommand<Unit, Unit> ImportDatFolderCommand { get; }
|
||||||
public ReactiveCommand<Unit, Unit> ImportRomFolderCommand { get; }
|
public ReactiveCommand<Unit, Unit> ImportRomFolderCommand { get; }
|
||||||
|
public ReactiveCommand<Unit, Unit> DeleteRomSetCommand { get; }
|
||||||
|
|
||||||
|
public RomSetModel SelectedRomSet
|
||||||
|
{
|
||||||
|
get => _selectedRomSet;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _selectedRomSet, value);
|
||||||
|
}
|
||||||
|
|
||||||
internal async void ExecuteSettingsCommand()
|
internal async void ExecuteSettingsCommand()
|
||||||
{
|
{
|
||||||
@@ -177,5 +189,29 @@ namespace RomRepoMgr.ViewModels
|
|||||||
dialog.DataContext = importRomFolderViewModel;
|
dialog.DataContext = importRomFolderViewModel;
|
||||||
await dialog.ShowDialog(_view);
|
await dialog.ShowDialog(_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async void ExecuteDeleteRomSetCommand()
|
||||||
|
{
|
||||||
|
if(SelectedRomSet == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ButtonResult result = await MessageBoxManager.GetMessageBoxStandardWindow("Delete ROM set",
|
||||||
|
string.
|
||||||
|
Format("Are you sure you want to delete the ROM set {0}?",
|
||||||
|
SelectedRomSet.Name), ButtonEnum.YesNo,
|
||||||
|
Icon.Database).
|
||||||
|
ShowDialog(_view);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
114
RomRepoMgr/ViewModels/RemoveDatViewModel.cs
Normal file
114
RomRepoMgr/ViewModels/RemoveDatViewModel.cs
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
// 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.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using ReactiveUI;
|
||||||
|
using RomRepoMgr.Core;
|
||||||
|
using RomRepoMgr.Database;
|
||||||
|
using RomRepoMgr.Database.Models;
|
||||||
|
using RomRepoMgr.Views;
|
||||||
|
|
||||||
|
namespace RomRepoMgr.ViewModels
|
||||||
|
{
|
||||||
|
public sealed class RemoveDatViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
readonly long _romSetId;
|
||||||
|
readonly RemoveDat _view;
|
||||||
|
string _statusMessage;
|
||||||
|
|
||||||
|
public RemoveDatViewModel(RemoveDat view, long romSetId)
|
||||||
|
{
|
||||||
|
_view = view;
|
||||||
|
_romSetId = romSetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
[NotNull]
|
||||||
|
public string Title => "Removing ROM set...";
|
||||||
|
|
||||||
|
public string StatusMessage
|
||||||
|
{
|
||||||
|
get => _statusMessage;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _statusMessage, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void OnOpened() => Task.Run(() =>
|
||||||
|
{
|
||||||
|
Dispatcher.UIThread.Post(() => StatusMessage = "Retrieving ROM set from database...");
|
||||||
|
|
||||||
|
RomSet romSet = Context.Singleton.RomSets.Find(_romSetId);
|
||||||
|
|
||||||
|
if(romSet == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Dispatcher.UIThread.Post(() => StatusMessage = "Removing ROM set from database...");
|
||||||
|
|
||||||
|
Context.Singleton.RomSets.Remove(romSet);
|
||||||
|
|
||||||
|
Dispatcher.UIThread.Post(() => StatusMessage = "Saving changes to database...");
|
||||||
|
|
||||||
|
Context.Singleton.SaveChanges();
|
||||||
|
|
||||||
|
Dispatcher.UIThread.Post(() => StatusMessage = "Removing DAT file from repo...");
|
||||||
|
|
||||||
|
byte[] sha384Bytes = new byte[48];
|
||||||
|
string sha384 = romSet.Sha384;
|
||||||
|
|
||||||
|
for(int i = 0; i < 48; i++)
|
||||||
|
{
|
||||||
|
if(sha384[i * 2] >= 0x30 &&
|
||||||
|
sha384[i * 2] <= 0x39)
|
||||||
|
sha384Bytes[i] = (byte)((sha384[i * 2] - 0x30) * 0x10);
|
||||||
|
else if(sha384[i * 2] >= 0x41 &&
|
||||||
|
sha384[i * 2] <= 0x46)
|
||||||
|
sha384Bytes[i] = (byte)((sha384[i * 2] - 0x37) * 0x10);
|
||||||
|
else if(sha384[i * 2] >= 0x61 &&
|
||||||
|
sha384[i * 2] <= 0x66)
|
||||||
|
sha384Bytes[i] = (byte)((sha384[i * 2] - 0x57) * 0x10);
|
||||||
|
|
||||||
|
if(sha384[(i * 2) + 1] >= 0x30 &&
|
||||||
|
sha384[(i * 2) + 1] <= 0x39)
|
||||||
|
sha384Bytes[i] += (byte)(sha384[(i * 2) + 1] - 0x30);
|
||||||
|
else if(sha384[(i * 2) + 1] >= 0x41 &&
|
||||||
|
sha384[(i * 2) + 1] <= 0x46)
|
||||||
|
sha384Bytes[i] += (byte)(sha384[(i * 2) + 1] - 0x37);
|
||||||
|
else if(sha384[(i * 2) + 1] >= 0x61 &&
|
||||||
|
sha384[(i * 2) + 1] <= 0x66)
|
||||||
|
sha384Bytes[i] += (byte)(sha384[(i * 2) + 1] - 0x57);
|
||||||
|
}
|
||||||
|
|
||||||
|
string datHash32 = Base32.ToBase32String(sha384Bytes);
|
||||||
|
string datFilesPath = Path.Combine(Settings.Settings.Current.RepositoryPath, "datfiles");
|
||||||
|
string compressedDatPath = Path.Combine(datFilesPath, datHash32 + ".lz");
|
||||||
|
|
||||||
|
if(File.Exists(compressedDatPath))
|
||||||
|
File.Delete(compressedDatPath);
|
||||||
|
|
||||||
|
Dispatcher.UIThread.Post(_view.Close);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -370,6 +370,7 @@ namespace RomRepoMgr.ViewModels
|
|||||||
ThenBy(r => r.Date).ThenBy(r => r.Description).ThenBy(r => r.Comment).
|
ThenBy(r => r.Date).ThenBy(r => r.Description).ThenBy(r => r.Comment).
|
||||||
ThenBy(r => r.Filename).Select(r => new RomSetModel
|
ThenBy(r => r.Filename).Select(r => new RomSetModel
|
||||||
{
|
{
|
||||||
|
Id = r.Id,
|
||||||
Author = r.Author,
|
Author = r.Author,
|
||||||
Comment = r.Comment,
|
Comment = r.Comment,
|
||||||
Date = r.Date,
|
Date = r.Date,
|
||||||
|
|||||||
@@ -19,6 +19,10 @@
|
|||||||
<MenuItem Header="_ROMs">
|
<MenuItem Header="_ROMs">
|
||||||
<MenuItem Header="_Import folder" Command="{Binding ImportRomFolderCommand}" /> <Separator />
|
<MenuItem Header="_Import folder" Command="{Binding ImportRomFolderCommand}" /> <Separator />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
<MenuItem Header="ROM _sets"
|
||||||
|
IsEnabled="{Binding SelectedRomSet, Converter={x:Static ObjectConverters.IsNotNull}}">
|
||||||
|
<MenuItem Header="_Delete" Command="{Binding DeleteRomSetCommand}" /> <Separator />
|
||||||
|
</MenuItem>
|
||||||
<MenuItem Header="_Help">
|
<MenuItem Header="_Help">
|
||||||
<MenuItem Header="_About" Name="AboutMenuItem" IsVisible="{Binding !NativeMenuSupported}"
|
<MenuItem Header="_About" Name="AboutMenuItem" IsVisible="{Binding !NativeMenuSupported}"
|
||||||
Command="{Binding AboutCommand}" />
|
Command="{Binding AboutCommand}" />
|
||||||
@@ -29,7 +33,8 @@
|
|||||||
<TabItem.Header>
|
<TabItem.Header>
|
||||||
<TextBlock Text="{Binding RomSetLabel}" />
|
<TextBlock Text="{Binding RomSetLabel}" />
|
||||||
</TabItem.Header>
|
</TabItem.Header>
|
||||||
<DataGrid Items="{Binding RomSets}" HorizontalScrollBarVisibility="Visible">
|
<DataGrid Items="{Binding RomSets}" HorizontalScrollBarVisibility="Visible"
|
||||||
|
SelectedItem="{Binding SelectedRomSet, Mode=TwoWay}">
|
||||||
<DataGrid.Columns>
|
<DataGrid.Columns>
|
||||||
<DataGridTextColumn Binding="{Binding Name}" Width="Auto" IsReadOnly="True">
|
<DataGridTextColumn Binding="{Binding Name}" Width="Auto" IsReadOnly="True">
|
||||||
<DataGridTextColumn.Header>
|
<DataGridTextColumn.Header>
|
||||||
|
|||||||
45
RomRepoMgr/Views/RemoveDat.xaml
Normal file
45
RomRepoMgr/Views/RemoveDat.xaml
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<!--
|
||||||
|
// /***************************************************************************
|
||||||
|
// 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="90" x:Class="RomRepoMgr.Views.RemoveDat"
|
||||||
|
Icon="/Assets/avalonia-logo.ico" CanResize="False" Title="{Binding Title}" WindowStartupLocation="CenterOwner">
|
||||||
|
<Design.DataContext>
|
||||||
|
<vm:RemoveDatViewModel />
|
||||||
|
</Design.DataContext>
|
||||||
|
<Border Padding="15">
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto" /> <RowDefinition Height="auto" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<TextBlock Grid.Row="0" Text="{Binding StatusMessage}" HorizontalAlignment="Center" />
|
||||||
|
<ProgressBar Grid.Row="1" IsIndeterminate="True" HorizontalAlignment="Stretch" />
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
</Window>
|
||||||
45
RomRepoMgr/Views/RemoveDat.xaml.cs
Normal file
45
RomRepoMgr/Views/RemoveDat.xaml.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
// 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 Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
using RomRepoMgr.ViewModels;
|
||||||
|
|
||||||
|
namespace RomRepoMgr.Views
|
||||||
|
{
|
||||||
|
public sealed class RemoveDat : Window
|
||||||
|
{
|
||||||
|
public RemoveDat() => InitializeComponent();
|
||||||
|
|
||||||
|
void InitializeComponent() => AvaloniaXamlLoader.Load(this);
|
||||||
|
|
||||||
|
protected override void OnOpened(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnOpened(e);
|
||||||
|
(DataContext as RemoveDatViewModel)?.OnOpened();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user