Example #1
0
        private void MakeArchive(string archiveFileName, TemporaryDirectory revisionsDirectory)
        {
            ZipFile zipFile = ZipFile.Create(archiveFileName);

            try
            {
                zipFile.BeginUpdate( );

                foreach (string filePath in Directory.GetFiles(revisionsDirectory.DirectoryPath, "*", SearchOption.AllDirectories))
                {
                    zipFile.Add(filePath, filePath.Replace(revisionsDirectory.DirectoryPath, ""));
                }

                zipFile.CommitUpdate( );
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);
                zipFile.AbortUpdate( );
            }
            finally
            {
                zipFile.Close( );
            }
        }
Example #2
0
        private void ZipOneFile(string sourceFilePath, string entryName, string zipFilePath)
        {
            ZipFile?zipFile = null;

            try
            {
                zipFile = new ZipFile(File.Open(zipFilePath, FileMode.OpenOrCreate));
                zipFile.BeginUpdate();

                if (zipFile.FindEntry(entryName, false) < 0)
                {
                    zipFile.Add(sourceFilePath, entryName);
                }

                zipFile.CommitUpdate();
            }
            catch (Exception e)
            {
                this.EventLogger.LogEvent($"Failed to Zip the File {sourceFilePath}. Error {e.Message}");
                zipFile?.AbortUpdate();
            }
            finally
            {
                zipFile?.Close();
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        public override void Close()
        {
            base.Close();

            if (this.mode == FileMode.Append || this.mode == FileMode.Create || this.mode == FileMode.CreateNew)
            {
                ZipFile zipFile   = this.zipFile.OpenZipFile();
                string  innerPath = this.zipFile.InnerPath.Substring(1);

                try {
                    this.zipFile.DispatchBeforeFileAction(FileAction.Update);

                    zipFile.BeginUpdate();

                    if (zipFile.GetEntry(innerPath) != null)
                    {
                        zipFile.Delete(this.zipFile.InnerPath.Substring(1));
                    }

                    zipFile.Add(new ZipDataSource(new MemoryStream(this.ToArray())), innerPath);

                    zipFile.CommitUpdate();

                    this.zipFile.DispatchFileAction(FileAction.Update);
                } finally {
                    zipFile.AbortUpdate();
                    zipFile.Close();
                }
            }
        }
Example #4
0
 /// <summary>
 /// 压缩包添加注释
 /// </summary>
 /// <param name="zipfile"></param>
 /// <param name="comment"></param>
 public static bool SetZipInfo(string zipfile, string comment)
 {
     try
     {
         using (ZipFile s = new ZipFile(zipfile))
         {
             s.BeginUpdate();
             s.SetComment(comment);
             s.CommitUpdate();
             s.AbortUpdate();
         }
         return(true);
     }
     catch (Exception ex)
     {
         Log.LogError("获取皮肤包信息", ex);
         return(false);
     }
 }
Example #5
0
        public override IAsyncOperation <BaseStorageFile> CreateFileAsync(string desiredName, CreationCollisionOption options)
        {
            return(AsyncInfo.Run <BaseStorageFile>(async(cancellationToken) =>
            {
                using (ZipFile zipFile = await OpenZipFileAsync(FileAccessMode.ReadWrite))
                {
                    if (zipFile == null)
                    {
                        return null;
                    }
                    zipFile.IsStreamOwner = true;

                    var znt = new ZipNameTransform(ContainerPath);
                    var zipDesiredName = znt.TransformFile(System.IO.Path.Combine(Path, desiredName));
                    var entry = zipFile.GetEntry(zipDesiredName);

                    zipFile.BeginUpdate(new MemoryArchiveStorage(FileUpdateMode.Direct));
                    if (entry != null)
                    {
                        if (options != CreationCollisionOption.ReplaceExisting)
                        {
                            zipFile.AbortUpdate();
                            return null;
                        }
                        zipFile.Delete(entry);
                    }
                    zipFile.Add(new FileDataSource()
                    {
                        Stream = new MemoryStream()
                    }, zipDesiredName);
                    zipFile.CommitUpdate();

                    var wnt = new WindowsNameTransform(ContainerPath);
                    return new ZipStorageFile(wnt.TransformFile(zipDesiredName), ContainerPath)
                    {
                        BackingFile = BackingFile
                    };
                }
            }));
        }
Example #6
0
        public override IAsyncOperation <BaseStorageFolder> CreateFolderAsync(string desiredName, CreationCollisionOption options)
        {
            return(AsyncInfo.Run <BaseStorageFolder>(async(cancellationToken) =>
            {
                var hFile = NativeFileOperationsHelper.OpenFileForRead(ContainerPath, true);
                if (hFile.IsInvalid)
                {
                    return null;
                }
                using (ZipFile zipFile = new ZipFile(new FileStream(hFile, FileAccess.ReadWrite)))
                {
                    zipFile.IsStreamOwner = true;

                    var znt = new ZipNameTransform(ContainerPath);
                    var zipDesiredName = znt.TransformDirectory(System.IO.Path.Combine(Path, desiredName));
                    var entry = zipFile.GetEntry(zipDesiredName);

                    zipFile.BeginUpdate(new MemoryArchiveStorage(FileUpdateMode.Direct));
                    if (entry != null)
                    {
                        if (options != CreationCollisionOption.ReplaceExisting)
                        {
                            zipFile.AbortUpdate();
                            return null;
                        }
                        zipFile.Delete(entry);
                    }
                    zipFile.AddDirectory(zipDesiredName);
                    zipFile.CommitUpdate();

                    var wnt = new WindowsNameTransform(ContainerPath);
                    return new ZipStorageFolder(wnt.TransformFile(zipDesiredName), ContainerPath)
                    {
                        ZipEncoding = ZipEncoding
                    };
                }
            }));
        }
Example #7
0
 public void StopProcessing()
 {
     _command.WriteWarning("Aborting: nothing done; stopping: " + _command.Stopping);
     _zip.AbortUpdate();
 }