/// <summary> /// Calculate the full archive size for a file name. /// The archive can be split into several files. /// The size is returned in bytes. /// </summary> /// <param name="fileName">The file name of one of the archive files.</param> /// <returns>The archive file size in bytes.</returns> private long GetArchiveSize(string fileName) { long archiveSize = 0; FileInfo file = new FileInfo(fileName); IEnumerable <FileInfo> archiveFiles = null; // Match multipart archives. Match matchPartRar = REGEX_PART_RAR.Match(fileName); if (matchPartRar.Success) { string baseName = fileName.Substring(0, fileName.LastIndexOf(matchPartRar.Value)); Regex regexPartRar = new Regex(baseName.Replace("\\", "\\\\") + REGEX_PART_RAR.ToString(), RegexOptions.IgnoreCase); archiveFiles = file.Directory.GetFiles().Where(i => regexPartRar.Match(i.Name.ToLower()).Success).ToList(); } else { // Fetch all files with the base name with an extension of ".rar" or ".rXX" where xx is a number. string baseName = Path.GetFileNameWithoutExtension(file.Name); Regex regexRNumber = new Regex(baseName + REGEX_RAR_RNN.ToString()); archiveFiles = file.Directory.GetFiles().Where(i => regexRNumber.IsMatch(i.Name)); } if (archiveFiles != null) { foreach (var item in archiveFiles) { archiveSize += item.Length; } } return(archiveSize); }
/// <summary> /// Get the content of the provided queue item and add all files that are archives to UnpackQueue. /// </summary> /// <param name="item">The item to examine for archive files.</param> private void GetAndAddExtractedItems(QueueItem item) { string[] content = unpacker.GetArchiveContent(item.FileToExtract); foreach (var file in content) { if (REGEX_PART_RAR.IsMatch(file) || REGEX_RAR_RNN.IsMatch(file)) { // File is located in the extraction folder. this.AddToQueue(Path.Combine(item.Destination, file), item.Destination); } } }