/****************************************************************************** // RomRepoMgr - ROM repository manager // ---------------------------------------------------------------------------- // // Author(s) : Natalia Portillo // // --[ 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 . // // ---------------------------------------------------------------------------- // 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 ErrorOccurred; public event EventHandler SetProgressBounds; public event EventHandler SetProgress; public event EventHandler SetMessage; } }