private List <ExtractFileInfo> BuildExtractFileListFromSpecifiedFileList() { _progressController.SetIndeterminate(); var distinctFileList = new Dictionary <string, ExtractFileInfo>(); foreach (var file in this.FileList) { var fileInfo = distinctFileList.GetOrCreate(file, () => { var info = new ExtractFileInfo(); string packagePath, localPath; UnifiedPath.ParsePath(file, out packagePath, out localPath); info.PackagePath = packagePath; info.DestinationRoot = this.GetDestinationRoot(localPath); info.RelativePath = localPath; return(info); }); } var packageGroups = distinctFileList.Values.Aggregate(new Dictionary <string, List <ExtractFileInfo> >(), (dict, item) => { var list = dict.GetOrCreate(item.PackagePath.ToLower(), () => new List <ExtractFileInfo>()); list.Add(item); return(dict); }); var nonExistedFiles = new List <ExtractFileInfo>(); foreach (var item in packageGroups) { var zipFile = new ZipFile(File.OpenRead(item.Key)); foreach (var info in item.Value) { var entryIndex = zipFile.FindEntry(info.RelativePath, true); if (entryIndex == -1) { nonExistedFiles.Add(info); } else { info.Entry = zipFile[entryIndex]; info.ZipFile = zipFile; } } } // todo: handle non exisiting files return(packageGroups.Values.SelectMany(i => i).ToList()); }
private List <ExtractFileInfo> BuildExtractFileListFromPaths() { _progressController.SetIndeterminate(); var destinationRoot = this.GetDestinationRoot(this.LocalPath); // the root directory of output var zipFile = new ZipFile(File.OpenRead(this.PackagePath)); var entries = zipFile.Cast <ZipEntry>().Where(entry => entry.Name.StartsWith(this.LocalPath)).ToArray(); var fileList = new List <ExtractFileInfo>(); foreach (var entry in entries) { if (_progressController.IsCanceled) { _task = _task.ContinueWith(t => _progressController.CloseAsync().Wait()) .ContinueWith(t => this.EndAndDispose(this.L("package_support", "extract_state_cancelled"))); return(null); } string relativePath; if (this.UseRelativePath) { relativePath = PathEx.Relativize(entry.Name, this.LocalPath); if (relativePath[0] == '/') { relativePath = relativePath.Substring(1); } } else { relativePath = entry.Name; } var fileInfo = new ExtractFileInfo(); fileInfo.Entry = entry; fileInfo.ZipFile = zipFile; fileInfo.DestinationRoot = destinationRoot; fileInfo.RelativePath = relativePath; fileInfo.PackagePath = this.PackagePath; fileList.Add(fileInfo); } return(fileList); }