public static void ExtractEntry(LifEntry entry, string destination, CancellationToken cancellationToken, ExtractionProgressReportDelegate progressReport) { ExtractEntries(new LifEntry[] { entry }, destination, cancellationToken, progressReport); }
/// <summary> /// Extract a file or folder, including its children, to a specified directory. /// </summary> /// <param name="destination"></param> /// <param name="cancellationToken"></param> /// <param name="progressReport"></param> public virtual void ExtractToDirectory( string destination, CancellationToken cancellationToken, ExtractionProgressReportDelegate progressReport) { ExtractEntry(this, destination, cancellationToken, progressReport); }
public ProgresHandler(LifFile lif, ExtractionProgressReportDelegate reportDelegate, CancellationToken cancellationToken) { Lif = lif; ReportDelegate = reportDelegate; CancellationToken = cancellationToken; CurrentEntryName = string.Empty; CurrentTargetPath = string.Empty; ExtractedFiles = 0; TotalFiles = 0; BytesExtracted = 0; TotalBytes = 0; }
public static void ExtractEntries( IEnumerable <LifEntry> entries, string destination, CancellationToken cancellationToken, ExtractionProgressReportDelegate progressReport) { if (!entries.Any()) { return; } var ownerLif = entries.First().Lif; var topLevel = entries.Max(x => x.GetLevel()); var entryList = entries.Where(x => x.GetLevel() == topLevel).Distinct().ToList(); if (!Directory.Exists(destination)) { Directory.CreateDirectory(destination); } var allFileEntries = entryList.OfType <FolderEntry>().SelectMany(x => x.GetAllFiles()) .Concat(entryList.OfType <FileEntry>()); var progressHandler = new ProgresHandler(ownerLif, progressReport, cancellationToken); progressHandler.TotalFiles = allFileEntries.Count(); progressHandler.TotalBytes = allFileEntries.Sum(x => x.FileSize); progressHandler.ReportProgress(); foreach (var fileEntry in entryList.OfType <FileEntry>()) { if (progressHandler.IsCancellationRequested) { break; } ExtractFileEntry(fileEntry, destination, ref progressHandler); } foreach (var folderEntry in entryList.OfType <FolderEntry>()) { if (progressHandler.IsCancellationRequested) { break; } ExtractFolderEntry(folderEntry, destination, ref progressHandler); } }
/// <summary> /// Extracts the content of the lif in a temporary folder and moves the content into the specified directory. /// <br/>The files are moved by the system so it won't crash if the destination folder requires admin rights (e.g. program files) /// </summary> /// <param name="destination"></param> /// <param name="cancellationToken"></param> /// <param name="progressReport"></param> public void ExtractTempTo(string destination, CancellationToken cancellationToken, ExtractionProgressReportDelegate progressReport) { string tmpTargetDir = "LIF" + StringUtils.GenerateUID(8); tmpTargetDir = Path.Combine(Path.GetTempPath(), tmpTargetDir); Directory.CreateDirectory(tmpTargetDir); ExtractEntry(RootFolder, tmpTargetDir, cancellationToken, progressReport); FileHelper.MoveFile(tmpTargetDir, destination, false); }
/// <summary> /// Extracts the content of the lif to the specified directory. /// </summary> /// <param name="destination"></param> /// <param name="cancellationToken"></param> /// <param name="progressReport"></param> public void ExtractTo(string destination, CancellationToken cancellationToken, ExtractionProgressReportDelegate progressReport) { ExtractEntry(RootFolder, destination, cancellationToken, progressReport); }
/// <summary> /// Extract the contained entries to a destination folder /// </summary> /// <param name="destination"></param> /// <param name="cancellationToken"></param> /// <param name="progressReport"></param> public void ExtractContent(string destination, CancellationToken cancellationToken, ExtractionProgressReportDelegate progressReport) { ExtractEntries(Entries, destination, cancellationToken, progressReport); }