/// <summary> /// Executes the specified rar filename. /// </summary> /// <param name="rarFilename">The rar filename.</param> /// <param name="destinationPath"></param> public void Execute(string rarFilename, string destinationPath) { IUnrar unrar = Is64BitMode() ? (IUnrar) new Unrar64() : (IUnrar) new Unrar(); unrar.ExtractionProgress += OnExtractionProgress; unrar.MissingVolume += OnMissingVolume; unrar.Open(rarFilename, Unrar.OpenMode.Extract); unrar.DestinationPath = destinationPath; while (unrar.ReadHeader()) { if (skip.Contains(unrar.CurrentFile.FileName)) { unrar.Skip(); } else { unrar.Extract(); } } unrar.Close(); }
/// <summary> /// Gets a list of all the files in the arcive. /// </summary> /// <param name="rarFilename"></param> /// <returns></returns> public List <ArchivedFile> GetFilesInArchive(string rarFilename) { var results = new List <ArchivedFile>(); IUnrar unrar = Is64BitMode() ? (IUnrar) new Unrar64() : (IUnrar) new Unrar(); unrar.ExtractionProgress += OnExtractionProgress; unrar.MissingVolume += OnMissingVolume; unrar.Open(rarFilename, Unrar.OpenMode.List); while (unrar.ReadHeader()) { var file = new ArchivedFile(); file.Filename = unrar.CurrentFile.FileName; file.FileSize = unrar.CurrentFile.UnpackedSize; results.Add(file); } unrar.Close(); return(results); }
/// <summary> /// Executes the specified rar filename. /// </summary> /// <param name="rarFilename"></param> /// <param name="filenames"></param> /// <param name="destFilenames"></param> /// <param name="destinationPath"></param> public void ExecuteFiles(string rarFilename, string[] filenames, string[] destFilenames, string destinationPath) { if (filenames == null || destFilenames == null || String.IsNullOrEmpty(destinationPath)) { throw new ArgumentNullException("One of the required arguments is missing"); } if (filenames.Length == 0 || destFilenames.Length == 0 || filenames.Length != destFilenames.Length) { throw new ArgumentException("Filenames or destFilenames parameters were empty or did not contain the same amount of strings"); } IUnrar unrar = Is64BitMode() ? (IUnrar) new Unrar64() : (IUnrar) new Unrar(); unrar.ExtractionProgress += OnExtractionProgress; unrar.MissingVolume += OnMissingVolume; unrar.Open(rarFilename, Unrar.OpenMode.Extract); unrar.DestinationPath = destinationPath; while (unrar.ReadHeader()) { string filenameInArchive = unrar.CurrentFile.FileName; string filename = Path.GetFileName(filenameInArchive); if (filenames.Contains(filename)) { // Get the target filename int index = Array.IndexOf(filenames, filenameInArchive); string targetFilename = destFilenames[index]; unrar.Extract(Path.Combine(destinationPath, targetFilename)); } } unrar.Close(); }