mirror of
https://github.com/claunia/romrepomgr.git
synced 2025-12-16 19:24:51 +00:00
Parse DAT files.
This commit is contained in:
79
RomRepoMgr.Core/Workers/DatImporter.cs
Normal file
79
RomRepoMgr.Core/Workers/DatImporter.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
/******************************************************************************
|
||||
// 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.Diagnostics;
|
||||
using RomRepoMgr.Core.EventArgs;
|
||||
using SabreTools.Library.DatFiles;
|
||||
|
||||
namespace RomRepoMgr.Core.Workers
|
||||
{
|
||||
public sealed class DatImporter
|
||||
{
|
||||
readonly string _datPath;
|
||||
bool _aborted;
|
||||
|
||||
public DatImporter(string datPath) => _datPath = datPath;
|
||||
|
||||
public void Import()
|
||||
{
|
||||
try
|
||||
{
|
||||
SetIndeterminateProgress?.Invoke(this, System.EventArgs.Empty);
|
||||
|
||||
SetMessage?.Invoke(this, new MessageEventArgs
|
||||
{
|
||||
Message = "Parsing DAT file..."
|
||||
});
|
||||
|
||||
DateTime start = DateTime.UtcNow;
|
||||
var datFile = DatFile.CreateAndParse(_datPath);
|
||||
DateTime end = DateTime.UtcNow;
|
||||
double elapsed = (end - start).TotalSeconds;
|
||||
|
||||
WorkFinished?.Invoke(this, System.EventArgs.Empty);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
if(Debugger.IsAttached)
|
||||
throw;
|
||||
|
||||
ErrorOccurred?.Invoke(this, new ErrorEventArgs
|
||||
{
|
||||
Message = "Unhandled exception occurred."
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void Abort() => _aborted = true;
|
||||
|
||||
public event EventHandler SetIndeterminateProgress;
|
||||
public event EventHandler WorkFinished;
|
||||
public event EventHandler<ErrorEventArgs> ErrorOccurred;
|
||||
public event EventHandler<ProgressBoundsEventArgs> SetProgressBounds;
|
||||
public event EventHandler<ProgressEventArgs> SetProgress;
|
||||
public event EventHandler<MessageEventArgs> SetMessage;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user