public override async Task <IEntryModel> CreateAsync(string fullPath, bool isDirectory, CancellationToken ct) { string parentPath = Profile.Path.GetDirectoryName(fullPath); string name = Profile.Path.GetFileName(fullPath); ISzsItemModel parentDir = await Profile.ParseAsync(parentPath) as ISzsItemModel; if (parentDir == null) { throw new Exception(String.Format("Parent dir {0} not exists.", parentPath)); } string relativePath = Profile.Path.Combine(parentDir.RelativePath, name); ISzsItemModel retEntryModel = new SzsChildModel(parentDir.Root, relativePath, isDirectory); (Profile as SzsProfile).VirtualModels.Add(retEntryModel); return(retEntryModel); }
public override async Task <IList <IEntryModel> > ListAsync(IEntryModel entry, System.Threading.CancellationToken ct, Func <IEntryModel, bool> filter = null, bool refresh = false) { var retList = new List <IEntryModel>(); using (var releaser = await WorkingLock.LockAsync()) { if (entry is ISzsItemModel) { filter = filter ?? (em => true); var szsEntry = entry as ISzsItemModel; var szsRoot = szsEntry.Root; var referencedEntry = szsRoot.ReferencedFile; var refEntryProfile = referencedEntry.Profile as IDiskProfile; if (refEntryProfile != null && !referencedEntry.IsDirectory) { string listPattern = String.Format(RegexPatterns.CompressionListPattern, Regex.Escape(szsEntry.RelativePath)); using (var stream = await refEntryProfile.DiskIO.OpenStreamAsync(referencedEntry, Defines.FileAccess.Read, CancellationToken.None)) foreach (object afi in _wrapper.List(stream, listPattern)) { var em = new SzsChildModel(szsRoot, (SevenZip.ArchiveFileInfo)afi); lock (VirtualModels) if (VirtualModels.Contains(em)) { VirtualModels.Remove(em); } if (filter(em)) { retList.Add(em); } } retList.AddRange(VirtualModels.Where(sem => Path.GetDirectoryName(sem.RelativePath).Equals(szsEntry.RelativePath) && filter(sem))); } } } return(retList); }