예제 #1
0
        public override async Task DeleteAsync(IEntryModel entryModel, CancellationToken ct)
        {
            SzsProfile    profile       = Profile as SzsProfile;
            ISzsItemModel szsEntryModel = entryModel as ISzsItemModel;

            if (szsEntryModel is SzsRootModel)
            {
                IEntryModel rootFile = (szsEntryModel as SzsRootModel).ReferencedFile;
                await(rootFile.Profile as IDiskProfile)
                .DiskIO.DeleteAsync(rootFile, ct);
                return;
            }

            using (var releaser = await profile.WorkingLock.LockAsync())
                using (var stream = await profile.DiskIO.OpenStreamAsync(szsEntryModel.Root, Defines.FileAccess.ReadWrite, ct))
                {
                    string type = profile.Path.GetExtension(szsEntryModel.Root.Name);

                    profile.Wrapper.Delete(type, stream, szsEntryModel.RelativePath + (szsEntryModel.IsDirectory ? "\\*" : ""));

                    lock (profile.VirtualModels)
                        if (profile.VirtualModels.Contains(szsEntryModel))
                        {
                            profile.VirtualModels.Remove(szsEntryModel);
                        }
                }
        }
예제 #2
0
        public override async Task <IEntryModel> RenameAsync(IEntryModel entryModel, string newName, CancellationToken ct)
        {
            SevenZipWrapper wrapper  = (Profile as SzsProfile).Wrapper;
            string          destPath = Profile.Path.Combine(Profile.Path.GetDirectoryName(entryModel.FullPath), newName);

            SzsProfile    profile       = Profile as SzsProfile;
            ISzsItemModel szsEntryModel = entryModel as ISzsItemModel;
            string        type          = profile.Path.GetExtension(szsEntryModel.Root.Name);

            using (var releaser = await profile.WorkingLock.LockAsync())
                using (var stream = await profile.DiskIO.OpenStreamAsync(szsEntryModel.Root, Defines.FileAccess.ReadWrite, ct))
                    wrapper.Modify(type, stream, (entryModel as ISzsItemModel).RelativePath, newName,
                                   entryModel.IsDirectory && !(entryModel is SzsRootModel));

            lock (profile.VirtualModels)
            {
                if (profile.VirtualModels.Contains(szsEntryModel))
                {
                    profile.VirtualModels.Remove(szsEntryModel);
                }
            }

            Profile.NotifyEntryChanges(this, destPath, Defines.ChangeType.Moved, entryModel.FullPath);

            return(await Profile.ParseAsync(destPath));
        }
예제 #3
0
 public SzsDiskIOHelper(SzsProfile profile)
     : base(profile)
 {
     this.Mapper = new FileBasedDiskPathMapper(m =>
     {
         ISzsItemModel model = m as ISzsItemModel;
         return(model.Profile.Path.Combine(model.Root.FullPath, model.RelativePath));
     });
 }
예제 #4
0
        public SzsRootModel(IEntryModel referencedModel, SzsProfile profile)
            : base(profile)
        {
            if (!(referencedModel.Profile is IDiskProfile))
            {
                throw new ArgumentException("RefrencedModel.Profile must implement IDiskProfile.");
            }
            ReferencedFile = referencedModel;

            IsDirectory  = true;
            _isRenamable = referencedModel.IsRenamable;
            Label        = referencedModel.Label;
            Description  = referencedModel.Description;
            FullPath     = referencedModel.FullPath;

            if (referencedModel is DiskEntryModelBase)
            {
                Size = (referencedModel as DiskEntryModelBase).Size;
            }
        }