public static RARFileInfo[] GetFiles(string rarPath) { lock (_readLock) { List<RARFileInfo> rarFileInfoList = new List<RARFileInfo>(); using (ClsUnrar unrar = new ClsUnrar()) { try { unrar.Open(rarPath, ClsUnrar.OpenMode.List); while (unrar.ReadHeader()) { if (!unrar.CurrentFile.IsDirectory) rarFileInfoList.Add(unrar.CurrentFile); unrar.Skip(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return rarFileInfoList.ToArray(); } } }
public static byte[] GetBytes(string rarPath, string filePath) { lock (_readLock) { using (ClsUnrar unrar = new ClsUnrar()) { try { //Unrar file in temporary directory string tempDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Temp"); unrar.DestinationPath = tempDir; unrar.Open(rarPath, ClsUnrar.OpenMode.Extract); // Get destination from user while (unrar.ReadHeader()) { if (unrar.CurrentFile.FileName.Equals(filePath)) { unrar.Extract(); break; } unrar.Skip(); } unrar.Close(); // string tempPath = System.IO.Path.Combine(tempDir, filePath); byte[] buffer = File.ReadAllBytes(tempPath); File.Delete(tempPath); //Remove file return buffer; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } return new byte[0]; } }