private static string GetRARFileCRC(string rarVolumePath, string fileName) { if (!FileHandler.FileExists(rarVolumePath)) { return(string.Empty); } Unrar unrar = new Unrar(rarVolumePath); try { unrar.Open(); while (unrar.ReadHeader() && unrar.CurrentFile.FileName != fileName) { unrar.Skip(); } if (unrar.CurrentFile != null && unrar.CurrentFile.FileName == fileName) { return(unrar.CurrentFile.FileCRC.ToString("X8").ToLower()); } } finally { unrar.Close(); } return(string.Empty); }
public static CFolder GetFolder(string FileName) { if (FileName.Substring(FileName.Length - 4, 4).ToLower() != ".rar") { throw new Exception("File type did not match this Plugins!"); } char[] sp = { '\\' }; string[] TempStrs = FileName.Split(sp); CFolder TempFolder = new CFolder(); if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + " (x86)")) { Unrar64 rar = new Unrar64(FileName); rar.Open(Unrar64.OpenMode.List); TempFolder.Name = TempStrs[TempStrs.Length - 1]; Array.Clear(TempStrs, 0, TempStrs.Length); while (rar.ReadHeader()) { //if (!rar.CurrentFile.IsDirectory) //{ TempStrs = rar.CurrentFile.FileName.Split(sp); FillFolder(FileName, TempStrs, 0, TempFolder, rar.CurrentFile); //} rar.Skip(); } rar.Close(); rar = null; } else { Unrar rar = new Unrar(FileName); rar.Open(Unrar.OpenMode.List); TempFolder.Name = TempStrs[TempStrs.Length - 1]; Array.Clear(TempStrs, 0, TempStrs.Length); while (rar.ReadHeader()) { //if (!rar.CurrentFile.IsDirectory) //{ TempStrs = rar.CurrentFile.FileName.Split(sp); FillFolder(FileName, TempStrs, 0, TempFolder, rar.CurrentFile); //} rar.Skip(); } rar.Close(); rar = null; } TempFolder.SpecialItem = true; TempFolder.CreatedTime = (new FileInfo(FileName)).CreationTimeUtc; return(TempFolder); }
private void CheckFile(FiasFileInfo aFileInfo) { var folder = Path.GetDirectoryName(aFileInfo.FileName) + "\\Extracted"; if (!Directory.Exists(folder)) { aFileInfo.Extracted = false; return; } var files = Directory.GetFiles(folder).Select(Path.GetFileName).ToList(); using (var unrar = new Unrar()) { unrar.ArchivePathName = aFileInfo.FileName; unrar.Open(Unrar.OpenMode.List); while (unrar.ReadHeader()) { if (stopEvent.WaitOne(0)) { throw new StopException(); } if (OnCheckProgress != null) { OnCheckProgress(0, 0, string.Format("Проверка файла {0}", folder + "\\" + unrar.CurrentFile.FileName)); } if (!files.Contains(unrar.CurrentFile.FileName)) { aFileInfo.Extracted = false; return; } var crc32 = new Crc32(); uint hash; using (var fs = File.Open(folder + "\\" + unrar.CurrentFile.FileName, FileMode.Open)) { var byteHash = crc32.ComputeHash(fs); hash = BitConverter.ToUInt32(byteHash.Reverse().ToArray(), 0); } if (unrar.CurrentFile.FileCRC != hash) { aFileInfo.Extracted = false; return; } unrar.Skip(); } } aFileInfo.Extracted = true; }
public void ConvertToImage(string rarPath, string imageOutputDirPath) { try { Unrar tmp = new Unrar(rarPath); tmp.Open(Unrar.OpenMode.List); string[] files = tmp.ListFiles(); tmp.Close(); int total = files.Length; int done = 0; Unrar unrar = new Unrar(rarPath); unrar.Open(Unrar.OpenMode.Extract); unrar.DestinationPath = imageOutputDirPath; while (unrar.ReadHeader() && !cancelled) { if (unrar.CurrentFile.IsDirectory) { unrar.Skip(); } else { unrar.Extract(); ++done; if (this.ProgressChanged != null) { this.ProgressChanged(done, total); } } } unrar.Close(); if (this.ConvertSucceed != null) { this.ConvertSucceed(); } } catch (Exception ex) { if (this.ConvertFailed != null) { this.ConvertFailed(ex.Message); } } }
private void openRarFile(string fileName) { using (Unrar unrar = new Unrar()) { unrar.Open(fileName, Unrar.OpenMode.List); while (unrar.ReadHeader()) { if (!unrar.CurrentFile.IsDirectory) { addFile(unrar.CurrentFile); } else { addDirectory(unrar.CurrentFile); } unrar.Skip(); } unrar.Close(); } }
protected void unrar(string filename, string destination, List <string> extensions) { Unrar unrar = null; try { // Create new unrar class and attach event handlers for // progress, missing volumes, and password unrar = new Unrar(); //AttachHandlers(unrar); // Set destination path for all files unrar.DestinationPath = destination; // Open archive for extraction unrar.Open(filename, Unrar.OpenMode.Extract); // SEASON_NR_EXTRACTION_PATTERNS_KEY each file with subtitle extension while (unrar.ReadHeader()) { string extension = Path.GetExtension(unrar.CurrentFile.FileName).Substring(1).ToLower().Replace(".", ""); if (extensions.Contains(extension)) { unrar.Extract(); } else { unrar.Skip(); } } } catch (Exception ex) { Logger.Instance.LogMessage("Error during unpack of file: " + filename + " (" + ex.Message + ")", LogLevel.ERROR); } finally { if (unrar != null) { unrar.Close(); } } }
private void CheckFile(FiasFileInfo aFileInfo) { var folder = Path.GetDirectoryName(aFileInfo.FileName) + "\\Extracted"; if (!Directory.Exists(folder)) { aFileInfo.Extracted = false; return; } var files = Directory.GetFiles(folder).Select(Path.GetFileName).ToList(); using (var unrar = new Unrar()) { unrar.ArchivePathName = aFileInfo.FileName; unrar.Open(Unrar.OpenMode.List); while (unrar.ReadHeader()) { if (stopEvent.WaitOne(0)) throw new StopException(); if (OnCheckProgress != null) OnCheckProgress(0, 0, string.Format("Проверка файла {0}", folder + "\\" + unrar.CurrentFile.FileName)); if (!files.Contains(unrar.CurrentFile.FileName)) { aFileInfo.Extracted = false; return; } var crc32 = new Crc32(); uint hash; using (var fs = File.Open(folder + "\\" + unrar.CurrentFile.FileName, FileMode.Open)) { var byteHash = crc32.ComputeHash(fs); hash = BitConverter.ToUInt32(byteHash.Reverse().ToArray(), 0); } if (unrar.CurrentFile.FileCRC != hash) { aFileInfo.Extracted = false; return; } unrar.Skip(); } } aFileInfo.Extracted = true; }