private static bool ExtractRarArchive(string archive, string destination, FileInfo archiveFI, Rar rar) { Debugger.LogMessageToFile("[Archive extractor] Found RAR archive: " + archiveFI.FullName); #region Open if (!rar.Open(archive)) { Debugger.LogMessageToFile("[Archive extractor] Failed to open archive: " + rar.LastErrorText); //MessageBox.Show("Failed to open archive " + rar.LastErrorText); return false; } Debugger.LogMessageToFile("[Archive extractor] Archive opened succesfully."); #endregion #region Extract //TODO: Check if destination directory exists and if not, create it if (!rar.Unrar(destination)) { Debugger.LogMessageToFile("[Archive extractor] Failed to extract archive: " + rar.LastErrorText); //MessageBox.Show("Failed to extract archive " + rar.LastErrorText); return false; } Debugger.LogMessageToFile("[Archive extractor] Archive was extracted succesfully."); #endregion rar.Close(); DeleteLeftOfMultiparts(rar); return true; }
internal static bool ExtractArchive(string archive, string destination) { //REFACTOR: Only create RAR and ZIP classes after discovering that the file actually has a .zip or .rar extension FileInfo archiveFI = new FileInfo(archive); Rar rar = new Rar(); FastZip fz = new FastZip(); double archivesize = archiveFI.Length * 2; char driveLetter = archiveFI.FullName[0]; if (!CheckDiskSpaceQuota(archivesize, driveLetter)) return false; if (archiveFI.Extension == ".rar" || archiveFI.Extension == ".RAR") return ExtractRarArchive(archive, destination, archiveFI, rar); // ReSharper disable ConvertIfStatementToReturnStatement if (archiveFI.Extension == ".zip" || archiveFI.Extension == ".ZIP") // ReSharper restore ConvertIfStatementToReturnStatement return ExtractZipArchive(archive, destination, fz); //TODO: Should this return false? return true; }
private static void DeleteLeftOfMultiparts(Rar rar) { if (!Settings.DeleteArchiveAfterExtraction) return; if (rar.NumEntries <= 1) return; for (int i = 0; i < rar.NumEntries; i++) { RarEntry entry = rar.GetEntryByIndex(i); string filename = entry.Filename; #region TRY to delete the rar file try { File.Delete(filename); } catch (Exception e) { Debugger.LogMessageToFile("The extracted archive " + filename + " could not be deleted. The error was: " + e); } #endregion } }
public void FileSignatures_TestRarFile02() { Rar testFile = new Rar(Path.Combine(resourceDir, "FileSignature_Compression_RarFile.r02")); Assert.AreEqual(true, testFile.EntireFileIsValid); }