public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm) { try { var srcProfile = _srcModel.Profile as IDiskProfile; var destProfile = _destDirModel.Profile as IDiskProfile; var progress = pm.ContainsKey("Progress") ? pm["Progress"] as IProgress <TransferProgress> : NullTransferProgress.Instance; var destMapping = (_destDirModel.Profile as IDiskProfile).DiskIO.Mapper[_destDirModel]; var srcMapping = (_srcModel.Profile as IDiskProfile).DiskIO.Mapper[_srcModel]; string destName = PathFE.GetFileName(srcMapping.IOPath); string destFullName = destProfile.Path.Combine(_destDirModel.FullPath, destName); //PathFE.Combine(destMapping.IOPath, destName); if (_srcModel.IsDirectory) { Func <IEntryModel, bool> filter = em => !em.IsDirectory || (em is SzsRootModel); Func <IEntryModel, bool> lookupFilter = em => em.IsDirectory && !(em is SzsRootModel); return(WPFScriptCommands.List(_srcModel, filter, lookupFilter, true, ems => new SimpleScriptCommandAsync("BatchTransfer", pd => transferAsync(pm, ems, progress, new NotifyChangedCommand(_destDirModel.Profile, destFullName, _srcModel.Profile, _srcModel.FullPath, Defines.ChangeType.Changed))))); } else { return(IOScriptCommands.DiskTransfer(_srcModel, _destDirModel, _removeOriginal)); } return(ResultCommand.NoError); } catch (Exception ex) { return(ResultCommand.Error(ex)); } }
public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm) { Func <IEntryModel, bool> filter; if (pm.ContainsKey("Mask")) { string mask = pm["Mask"] as string; filter = (em => _filter(em) && PathFE.MatchFileMask(em.Name, mask)); } else { filter = _filter; } _lookupFilter = _lookupFilter ?? (em => em.IsDirectory); bool refresh = pm.ContainsKey("Refresh") && (bool)pm["Refresh"]; List <IEntryModel> result = new List <IEntryModel>(); foreach (var directory in _directories) { result.AddRange(await listAsync(directory, pm.CancellationToken, filter, _lookupFilter, refresh)); } return(_nextCommandFunc(result.ToArray())); }
public override IScriptCommand Execute(ParameterDic pm) { string path = pm.ReplaceVariableInsideBracketed(PathKey); string ext = (path.Contains(".") ? PathFE.GetExtension(path) : path).TrimStart('.'); pm.SetValue(DestinationKey, SevenZipWrapper.GetArchiveBytes(ext)); return(NextCommand); }
private void extract(SevenZipExtractor extractor, string mask, string toDir, string password) { if (extractor.FilesCount == 0) { return; } if (!extractor.IsSolid) { ExtractFileCallback callBack = (t) => { if (PathFE.MatchFileMask(t.ArchiveFileInfo.FileName, mask)) { if (t.Reason == ExtractFileCallbackReason.Start) { string outputFileName = PathFE.Combine(toDir, t.ArchiveFileInfo.FileName); string outputDir = PathFE.GetDirectoryName(outputFileName); if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } if (t.ArchiveFileInfo.IsDirectory) { if (!Directory.Exists(outputFileName)) { Directory.CreateDirectory(outputFileName); } } else { if (File.Exists(outputFileName)) { File.Delete(outputFileName); } t.ExtractToFile = outputFileName; } } } }; extractor.ExtractFiles(callBack); } else { List <int> indexes = new List <int>(); foreach (var afi in extractor.ArchiveFileData) { if (PathFE.MatchFileMask(afi.FileName, mask)) { indexes.Add(afi.Index); } } extractor.ExtractFiles(toDir, indexes.ToArray()); } }
private void setFilter(string value) { _selectedFilter = value; FileList.ProcessedEntries.SetFilters( ColumnFilter.CreateNew <IEntryModel>(value, "FullPath", e => e.IsDirectory || PathFE.MatchFileMasks( e.Profile.Path.GetFileName(e.FullPath), value))); NotifyOfPropertyChange(() => SelectedFilter); }
public static Stream NewTempStream(out string fileName, string ext) { if (ext.StartsWith(".")) { ext = ext.TrimStart('.'); } do { fileName = PathFE.Combine(Path.GetTempPath(), StringUtils.RandomString(8) + "." + ext); }while (File.Exists(fileName)); return(new FileStream(fileName, FileMode.CreateNew)); }
private async Task <IScriptCommand> transferScriptCommandAsync(ParameterDic pm, IEntryModel[] srcEntries, IEntryModel destEntry, string destinationKey) { var progress = pm.GetProgress() ?? NullTransferProgress.Instance; var srcProfile = srcEntries.First().Profile as IDiskProfile; var destProfile = destEntry.Profile as IDiskProfile; var srcMapper = srcProfile.DiskIO.Mapper; var destMapping = destProfile.DiskIO.Mapper[destEntry]; List <IScriptCommand> notifyChangeCommands = new List <IScriptCommand>(); List <string> changedPath = new List <string>(); progress.Report(TransferProgress.IncrementTotalEntries(srcEntries.Count())); foreach (var srcEntry in srcEntries) { var srcMapping = srcMapper[srcEntry]; string destName = PathFE.GetFileName(srcMapping.IOPath); string destFullName = destProfile.Path.Combine(destEntry.FullPath, destName); progress.Report(TransferProgress.From(srcEntry.FullPath, destEntry.FullPath)); if (srcEntry.IsDirectory) { await ScriptRunner.RunScriptAsync(pm, ScriptCommands.Assign("{DT-SrcDirectory}", srcEntry, false, ScriptCommands.Assign("{DT-DestProfile}", destEntry.Profile, false, CoreScriptCommands.DiskParseOrCreateFolder("{DT-DestProfile}", destFullName, "{DT-DestDirectory}", IOScriptCommands.DiskTransferChild("{DT-SrcDirectory}", "{DT-DestDirectory}", RemoveOriginal, AllowCustomImplementation, ScriptCommands.Reset(ResultCommand.NoError, "{DT-DestDirectory}", "{DT-SrcDirectory}")))))); } else { await ScriptRunner.RunScriptAsync(pm, ScriptCommands.Assign("{DT-SrcFile}", srcEntry, false, ScriptCommands.Assign("{DT-SrcProfile}", srcEntry.Profile, false, ScriptCommands.Assign("{DT-DestProfile}", destEntry.Profile, false, CoreScriptCommands.DiskParseOrCreateFile("{DT-DestProfile}", destFullName, "{DT-DestFile}", CoreScriptCommands.DiskCopyFile("{DT-SrcProfile}", "{DT-SrcFile}", "{DT-DestProfile}", "{DT-DestFile}", ScriptCommands.Reset(ResultCommand.NoError, "{DT-SrcFile}", "{DT-DestFile}"))))))); } progress.Report(TransferProgress.IncrementProcessedEntries()); } logger.Info(String.Format("{0} {1} -> {2} using ScriptCommand", RemoveOriginal ? "Move" : "Copy", srcEntries.GetDescription(), destEntry.Name)); return(await GetAssignDestinationCommandAsync(pm, srcEntries, destEntry, destinationKey, NextCommand)); }
public override IScriptCommand Execute(ParameterDic pm) { string path = pm.ReplaceVariableInsideBracketed(PathKey); switch (FilePartType) { case Script.FilePartType.FileName: pm.SetValue(DestinationKey, PathFE.GetFileName(path)); break; case Script.FilePartType.DirectoryName: pm.SetValue(DestinationKey, PathFE.GetDirectoryName(path)); break; default: throw new NotSupportedException("FilePartType=" + FilePartType.ToString()); } return(NextCommand); }
protected override bool exists(Stream stream, string pathOrMask, bool isFolder) { using (SevenZipExtractor extractor = getExtractor(stream)) { foreach (ArchiveFileInfo afi in extractor.ArchiveFileData) { if (PathFE.MatchFileMask(afi.FileName, pathOrMask) && (afi.IsDirectory == isFolder)) { return(true); } else if (afi.FileName.StartsWith(pathOrMask, StringComparison.InvariantCultureIgnoreCase)) { return(true); } } } return(false); }
public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm) { var destProfile = _destDirModel.Profile as IDiskProfile; var destMapping = (_destDirModel.Profile as IDiskProfile).DiskIO.Mapper[_destDirModel]; var srcMapping = (_srcModel.Profile as IDiskProfile).DiskIO.Mapper[_srcModel]; string destName = PathFE.GetFileName(srcMapping.IOPath); string destFullName = destProfile.Path.Combine(_destDirModel.FullPath, destName); //PathFE.Combine(destMapping.IOPath, destName); IEntryModel destModel = await _destDirModel.Profile.ParseAsync(destFullName); if (destModel == null) { destModel = await destProfile.DiskIO.CreateAsync(destFullName, true, pm.CancellationToken); destModel = (await _destDirModel.Profile.ListAsync(_destDirModel, CancellationToken.None, em => em.FullPath.Equals(destFullName, StringComparison.CurrentCultureIgnoreCase), true)).FirstOrDefault(); _destDirModel.Profile.Events.PublishOnUIThread(new EntryChangedEvent(ChangeType.Created, destFullName)); } if (destModel == null) { return(ResultCommand.Error(new Exception("Cannot construct destination " + destFullName))); } else { _progress.Report(TransferProgress.From(_srcModel.FullPath, destFullName)); _progress.Report(TransferProgress.IncrementProcessedEntries()); //dest directory created } var srcSubModels = (await _srcModel.Profile.ListAsync(_srcModel, CancellationToken.None)).ToList(); _progress.Report(TransferProgress.IncrementTotalEntries(srcSubModels.Count())); //source entries var resultCommands = srcSubModels.Select(m => (IScriptCommand) new FileTransferScriptCommand(m, destModel, _removeOriginal)).ToList(); resultCommands.Add(new NotifyChangedCommand(_destDirModel.Profile, destFullName, ChangeType.Created)); //if (_removeOriginal) // resultCommands.Add(new DeleteEntryCommand(_srcModel)); return(new RunInSequenceScriptCommand(resultCommands.ToArray())); }
public static OutArchiveFormat getArchiveFormat(string archiveName) { switch (PathFE.GetExtension(archiveName).ToLower()) { case ".7z": case ".7zip": return(OutArchiveFormat.SevenZip); case ".zip": return(OutArchiveFormat.Zip); case ".bzip": return(OutArchiveFormat.BZip2); case ".z": case ".gz": case ".gzip": return(OutArchiveFormat.GZip); case ".tar": return(OutArchiveFormat.Tar); default: throw new NotImplementedException(); } }
/// <summary> /// List entries that match the filterStr, the filterStr must be in format of RegexPatterns.SevenZipListPattern. /// </summary> /// <param name="filterStr"></param> /// <returns></returns> internal IEnumerable <ArchiveFileInfo> listCore(Stream stream, string pattern, bool listSubdir) { if (pattern.IndexOf("?<name>") == -1) { throw new ArgumentException(""); } if (pattern.IndexOf("?<trail>") == -1) { throw new ArgumentException(""); } if (pattern.IndexOf("?<parent>") == -1) { throw new ArgumentException(""); } List <string> returnedPathList = new List <string>(); List <ArchiveFileInfo> afiList; try { using (SevenZipExtractor extractor = getExtractor(stream)) { afiList = new List <ArchiveFileInfo>(extractor.ArchiveFileData); } } catch (Exception ex) { afiList = new List <ArchiveFileInfo>(); } foreach (ArchiveFileInfo afi in afiList) { Match match = new Regex(pattern).Match(afi.FileName); if (match.Success) { string parent = match.Groups["parent"].Value; string name = match.Groups["name"].Value; string trail = match.Groups["trail"].Value; if (!afi.IsDirectory && String.IsNullOrEmpty(trail)) { if (returnedPathList.IndexOf(afi.FileName.ToLower()) == -1) { yield return(afi); returnedPathList.Add(afi.FileName.ToLower()); } } else if (!String.IsNullOrEmpty(trail) || listSubdir) { string dirName = PathFE.Combine(parent, name); if (returnedPathList.IndexOf(dirName.ToLower()) == -1) { yield return(new ArchiveFileInfo() { FileName = dirName, IsDirectory = true }); returnedPathList.Add(dirName.ToLower()); } } } } }
public static bool IsArchiveWritable(string archiveName) { string ext = PathFE.GetExtension(archiveName).ToLower() + ","; return((ext != ",") && (archiveWriteFilter + ",").IndexOf(ext) != -1); }
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; //7z #endregion #region Methods public static bool IsZip(string archiveName) { string ext = PathFE.GetExtension(archiveName).ToLower(); return(ext == ".zip"); }
public static bool Delete(this ICompressorWrapper wrapper, string type, Stream stream, string path) { return(wrapper.Delete(type, stream, (p) => PathFE.MatchFileMask(p, path))); }
private async Task <IScriptCommand> transferSystemIOAsync(ParameterDic pm, IEntryModel[] srcEntries, IEntryModel destEntry, string destinationKey) { return(await Task.Run <IScriptCommand>(async() => { var progress = pm.ContainsKey("Progress") ? pm["Progress"] as IProgress <TransferProgress> : NullTransferProgress.Instance; var srcProfile = srcEntries.First().Profile as IDiskProfile; var destProfile = destEntry.Profile as IDiskProfile; var srcMapper = srcProfile.DiskIO.Mapper; var destMapping = destProfile.DiskIO.Mapper[destEntry]; List <string> createdPath = new List <string>(); List <string> changedPath = new List <string>(); progress.Report(TransferProgress.IncrementTotalEntries(srcEntries.Count())); foreach (var srcEntry in srcEntries) { var srcMapping = srcMapper[srcEntry]; string destName = PathFE.GetFileName(srcMapping.IOPath); string destFullName = destProfile.Path.Combine(destEntry.FullPath, destName); progress.Report(TransferProgress.From(srcEntry.FullPath, destEntry.FullPath)); if (srcEntry.IsDirectory) { if (Directory.Exists(destFullName)) { changedPath.Add(destFullName); //Directory.Delete(destFullName, true); } else { createdPath.Add(destFullName); } Directory.Move(srcMapping.IOPath, destFullName); //Move directly. progress.Report(TransferProgress.IncrementProcessedEntries()); } else { if (File.Exists(destFullName)) { changedPath.Add(destFullName); File.Delete(destFullName); } else { createdPath.Add(destFullName); } File.Move(srcMapping.IOPath, destFullName); } progress.Report(TransferProgress.IncrementProcessedEntries()); } logger.Info(String.Format("{0} {1} -> {2} using System.IO", RemoveOriginal ? "Move" : "Copy", srcEntries.GetDescription(), destEntry.Name)); return await GetAssignDestinationCommandAsync(pm, srcEntries, destEntry, destinationKey, ScriptCommands.RunParallel(NextCommand, CoreScriptCommands.NotifyEntryChangedPath(ChangeType.Created, destEntry.Profile, createdPath.ToArray()), CoreScriptCommands.NotifyEntryChangedPath(ChangeType.Changed, destEntry.Profile, changedPath.ToArray()) )); })); }
public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm) { try { var srcProfile = _srcModel.Profile as IDiskProfile; var destProfile = _destDirModel.Profile as IDiskProfile; var progress = pm.ContainsKey("Progress") ? pm["Progress"] as IProgress <TransferProgress> : NullTransferProgress.Instance; var destMapping = (_destDirModel.Profile as IDiskProfile).DiskIO.Mapper[_destDirModel]; var srcMapping = (_srcModel.Profile as IDiskProfile).DiskIO.Mapper[_srcModel]; string destName = PathFE.GetFileName(srcMapping.IOPath); string destFullName = destProfile.Path.Combine(_destDirModel.FullPath, destName); //PathFE.Combine(destMapping.IOPath, destName); if (!srcMapping.IsVirtual && !destMapping.IsVirtual && _removeOriginal) { //Disk based transfer progress.Report(TransferProgress.From(_srcModel.FullPath, destFullName)); if (_srcModel.IsDirectory) { if (Directory.Exists(destFullName)) { Directory.Delete(destFullName, true); } Directory.Move(srcMapping.IOPath, destFullName); //Move directly. progress.Report(TransferProgress.IncrementProcessedEntries()); } else { if (File.Exists(destFullName)) { File.Delete(destFullName); } File.Move(srcMapping.IOPath, destFullName); } progress.Report(TransferProgress.IncrementProcessedEntries()); return(new NotifyChangedCommand(_destDirModel.Profile, destFullName, _srcModel.Profile, _srcModel.FullPath, ChangeType.Moved)); } else { if (_srcModel.IsDirectory) { return(new CopyDirectoryTransferCommand(_srcModel, _destDirModel, _removeOriginal, progress)); } else { return(new StreamFileTransferCommand(_srcModel, _destDirModel, _removeOriginal, progress)); } } //switch (_transferMode) //{ // case DragDropEffects.Move: // // // case DragDropEffects.Copy: // Directory.CreateDirectory(destFullName); // _destDirModel.Profile.Events.Publish(new EntryChangedEvent(destFullName, ChangeType.Created)); // var destModel = (await _destDirModel.Profile.ListAsync(_destDirModel, em => // em.FullPath.Equals(destFullName, // StringComparison.CurrentCultureIgnoreCase))).FirstOrDefault(); // var srcSubModels = (await _srcModel.Profile.ListAsync(_srcModel)).ToList(); // var resultCommands = srcSubModels.Select(m => // (IScriptCommand)new FileTransferScriptCommand(m, destModel, _transferMode)).ToList(); // resultCommands.Insert(0, new NotifyChangedCommand(_destDirModel.Profile, destFullName, ChangeType.Created)); // return new RunInSequenceScriptCommand(resultCommands.ToArray()); // default: // throw new NotImplementedException(); //} //} //else //{ //} return(ResultCommand.NoError); } catch (Exception ex) { return(ResultCommand.Error(ex)); } }
private IEnumerable <tuple <int, string> > lookup(SevenZipExtractor extractor, string pathOrMask) { return(lookup(extractor, p => PathFE.MatchFileMask(p, pathOrMask))); }