mirror of
https://github.com/claunia/romrepomgr.git
synced 2025-12-16 19:24:51 +00:00
Update list of ROM sets when adding a new DAT.
This commit is contained in:
34
RomRepoMgr.Core/EventArgs/RomSetEventArgs.cs
Normal file
34
RomRepoMgr.Core/EventArgs/RomSetEventArgs.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
/******************************************************************************
|
||||
// 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 RomRepoMgr.Core.Models;
|
||||
|
||||
namespace RomRepoMgr.Core.EventArgs
|
||||
{
|
||||
public sealed class RomSetEventArgs : System.EventArgs
|
||||
{
|
||||
public RomSetModel RomSet { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ using RomRepoMgr.Core.Models;
|
||||
|
||||
namespace RomRepoMgr.Core.EventArgs
|
||||
{
|
||||
public sealed class RomSetEventArgs : System.EventArgs
|
||||
public sealed class RomSetsEventArgs : System.EventArgs
|
||||
{
|
||||
public List<RomSetModel> RomSets { get; set; }
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Aaru.Checksums;
|
||||
using RomRepoMgr.Core.EventArgs;
|
||||
using RomRepoMgr.Core.Models;
|
||||
using RomRepoMgr.Database;
|
||||
using RomRepoMgr.Database.Models;
|
||||
using SabreTools.Library.DatFiles;
|
||||
@@ -112,6 +113,22 @@ namespace RomRepoMgr.Core.Workers
|
||||
Context.Singleton.RomSets.Add(romSet);
|
||||
Context.Singleton.SaveChanges();
|
||||
|
||||
RomSetAdded?.Invoke(this, new RomSetEventArgs
|
||||
{
|
||||
RomSet = new RomSetModel
|
||||
{
|
||||
Author = romSet.Author,
|
||||
Comment = romSet.Comment,
|
||||
Date = romSet.Date,
|
||||
Description = romSet.Description,
|
||||
Filename = romSet.Filename,
|
||||
Homepage = romSet.Homepage,
|
||||
Name = romSet.Name,
|
||||
Sha384 = romSet.Sha384,
|
||||
Version = romSet.Version
|
||||
}
|
||||
});
|
||||
|
||||
SetMessage?.Invoke(this, new MessageEventArgs
|
||||
{
|
||||
Message = "Compressing DAT file..."
|
||||
@@ -144,5 +161,6 @@ namespace RomRepoMgr.Core.Workers
|
||||
public event EventHandler<ProgressBoundsEventArgs> SetProgressBounds;
|
||||
public event EventHandler<ProgressEventArgs> SetProgress;
|
||||
public event EventHandler<MessageEventArgs> SetMessage;
|
||||
public event EventHandler<RomSetEventArgs> RomSetAdded;
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ namespace RomRepoMgr
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
|
||||
void OnGotRomSets(object sender, RomSetEventArgs e) => _romSets = e.RomSets;
|
||||
void OnGotRomSets(object sender, RomSetsEventArgs e) => _romSets = e.RomSets;
|
||||
|
||||
void OnSplashFinished(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
@@ -154,8 +154,11 @@ namespace RomRepoMgr.ViewModels
|
||||
|
||||
internal void OnOpened()
|
||||
{
|
||||
ProgressVisible = true;
|
||||
ProgressVisible = true;
|
||||
_worker.RomSetAdded += RomSetAdded;
|
||||
Task.Run(_worker.Import);
|
||||
}
|
||||
|
||||
public event EventHandler<RomSetEventArgs> RomSetAdded;
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,9 @@ using System.Reactive;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
using RomRepoMgr.Core.EventArgs;
|
||||
using RomRepoMgr.Core.Models;
|
||||
using RomRepoMgr.Views;
|
||||
|
||||
@@ -88,9 +90,11 @@ namespace RomRepoMgr.ViewModels
|
||||
|
||||
internal async void ExecuteImportDatCommand()
|
||||
{
|
||||
var dlgOpen = new OpenFileDialog();
|
||||
dlgOpen.AllowMultiple = false;
|
||||
dlgOpen.Title = "Import DAT file...";
|
||||
var dlgOpen = new OpenFileDialog
|
||||
{
|
||||
AllowMultiple = false,
|
||||
Title = "Import DAT file..."
|
||||
};
|
||||
|
||||
dlgOpen.Filters.Add(new FileDialogFilter
|
||||
{
|
||||
@@ -118,8 +122,14 @@ namespace RomRepoMgr.ViewModels
|
||||
|
||||
var dialog = new ImportDat();
|
||||
var importDatViewModel = new ImportDatViewModel(dialog, result[0]);
|
||||
dialog.DataContext = importDatViewModel;
|
||||
importDatViewModel.RomSetAdded += ImportDatViewModelOnRomSetAdded;
|
||||
dialog.DataContext = importDatViewModel;
|
||||
await dialog.ShowDialog(_view);
|
||||
}
|
||||
|
||||
void ImportDatViewModelOnRomSetAdded(object sender, RomSetEventArgs e) => Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
RomSets.Add(e.RomSet);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -306,7 +306,7 @@ namespace RomRepoMgr.ViewModels
|
||||
{
|
||||
try
|
||||
{
|
||||
GotRomSets?.Invoke(this, new RomSetEventArgs
|
||||
GotRomSets?.Invoke(this, new RomSetsEventArgs
|
||||
{
|
||||
RomSets = Context.Singleton.RomSets.OrderBy(r => r.Name).ThenBy(r => r.Version).
|
||||
ThenBy(r => r.Date).ThenBy(r => r.Description).ThenBy(r => r.Comment).
|
||||
@@ -351,6 +351,6 @@ namespace RomRepoMgr.ViewModels
|
||||
|
||||
internal event EventHandler WorkFinished;
|
||||
|
||||
internal event EventHandler<RomSetEventArgs> GotRomSets;
|
||||
internal event EventHandler<RomSetsEventArgs> GotRomSets;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user