/// <summary> /// This function is responsible for finding and loading in new replays /// </summary> public async Task InitialLoadAsync() { _log.Information("Starting initial load of replays"); List <ReplayFileInfo> newFiles = new List <ReplayFileInfo>(); // Get all files from all defined replay folders IReadOnlyCollection <ReplayFileInfo> allFiles = _fileSystem.GetAllReplayFileInfo(); // Check if file exists in the database foreach (var file in allFiles) { if (_db.GetFileResult(file.Path) == null) { newFiles.Add(file); } } _log.Information($"Discovered {newFiles.Count} new files"); // Files not in the database are parsed and added foreach (var file in newFiles) { var parseResult = await _reader.ReadFile(file.Path).ConfigureAwait(false); FileResult newResult = new FileResult(file, parseResult) { IsNewFile = false }; _db.AddFileResult(newResult); } _log.Information("Initial load of replays complete"); }
/// <summary> /// Given replay path, construct ReplayFile with all properties initialized /// </summary> /// <param name="replayPath"></param> /// <returns></returns> private static async Task <ReplayFile> SetupReplayFileAsync(string replayPath) { var fileInfo = new ReplayFile { Location = replayPath, Name = Path.GetFileName(replayPath), }; switch (Path.GetExtension(replayPath)) { case ".rofl": fileInfo.Type = REPLAYTYPES.ROFL; break; case ".lrf": MessageBox.Show($"{fileInfo.Name} is a old LoLReplay file.\nROFLPlayer will try to open this file in compatibility mode, some data or features may be missing.", "Compatibility Mode", MessageBoxButtons.OK, MessageBoxIcon.Warning); fileInfo.Type = REPLAYTYPES.LRF; break; case ".lpr": MessageBox.Show($"{fileInfo.Name} is a old BaronReplay file. ROFLPlayer does not support opening this file.", "Compatibility Mode", MessageBoxButtons.OK, MessageBoxIcon.Error); fileInfo.Type = REPLAYTYPES.LPR; Environment.Exit(1); break; default: MessageBox.Show($"{fileInfo.Name} is not a supported file type", "Unsupported File", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); break; } var replayReader = new ReplayReader(); try { fileInfo = await replayReader.ReadFile(fileInfo); } catch (Exception ex) { MessageBox.Show($"Exception occured when parsing file:\n{ex.Message}", "Parsing Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } return(fileInfo); }