private void DeleteFiles(SFVFile sfvFile) { WriteLogEntry("Deleting archive files..."); RaiseSubProgressEvent("Deleting archive files...", 100); try { foreach (string filePath in sfvFile.ContainedFilePaths) { try { if (FileHandler.FileExists(filePath)) { WriteLogEntry(LogType.Debug, "Deleting archive file, path=" + filePath); FileHandler.DeleteFile(filePath); } } catch (Exception ex) { WriteLogEntry("An exception occurred while deleting archive file, path=" + filePath, ex); } } if (FileHandler.FileExists(sfvFile.SFVFilePath)) { WriteLogEntry(LogType.Debug, "Deleting SFV file, path=" + sfvFile.SFVFilePath); FileHandler.DeleteFile(sfvFile.SFVFilePath); } } catch (Exception ex) { WriteLogEntry("An exception occurred while deleting archive files, sfvfile=" + sfvFile.SFVFilePath, ex); } }
private void ProcessSFVFile(string sfvFilePath, RootPath rootPath) { SFVFile sfvFile = null; try { WriteLogEntry("Validating SFV file references, sfvfile=" + sfvFilePath); RaiseSubProgressEvent("Validating SFV file references...", 0); sfvFile = new SFVFile(sfvFilePath); sfvFile.Progress += sfvFile_Progress; string rarFilePath = sfvFile.ContainedFilePaths.OrderBy(filePath => filePath) .FirstOrDefault(filePath => filePath.EndsWith(".rar", StringComparison.CurrentCultureIgnoreCase)); Record record = new Record(Path.GetDirectoryName(sfvFile.SFVFilePath), Path.GetFileName(sfvFile.SFVFilePath), Path.GetFileName(rarFilePath), sfvFile.ContainedFilePaths.Count, FileHandler.GetTotalFileSize(sfvFile.ContainedFilePaths)); AddRecord(record); if (!string.IsNullOrEmpty(rarFilePath)) { if (sfvFile.Validate()) { WriteLogEntry("Validation OK, proceeding with extraction..."); AddRecord(record.Succeed()); if (ExtractRARContent(rarFilePath, rootPath, record)) { DeleteFiles(sfvFile); } } else { WriteLogEntry(LogType.Warning, "Validation FAILED, skipping archive"); AddRecord(record.Fail()); } } else { WriteLogEntry(LogType.Warning, "SFV file does not refer to any .rar file, skipping further processing"); AddRecord(record.Fail()); } } catch (Exception ex) { WriteLogEntry("An exception occurred while processing SFV file, path=" + sfvFilePath, ex); AddRecord(new Record(RecordStatus.Failure, Path.GetDirectoryName(sfvFilePath), Path.GetFileName(sfvFilePath), string.Empty, 0, 0)); } finally { if (sfvFile != null) { sfvFile.Progress -= sfvFile_Progress; } } }