コード例 #1
0
ファイル: ABHelp.cs プロジェクト: mengtest/TAccumulation
 /// <summary>
 /// 压缩文件
 /// </summary>
 /// <param name="filename"></param>
 /// <param name="sourcedirectory"></param>
 /// <param name="zipevent"></param>
 public static void ZipFile(string filename, string sourcedirectory, FastZipEvents zipevent = null)
 {
     try
     {
         if (File.Exists(filename))
         {
             File.Delete(filename);
         }
         FastZip fz;
         if (zipevent != null)
         {
             fz = new FastZip(zipevent);
         }
         else
         {
             fz = new FastZip();
         }
         fz.CreateEmptyDirectories = true;
         fz.CreateZip(filename, sourcedirectory, true, "");
         fz = null;
     }
     catch (Exception e)
     {
         Debug.LogError(e.Message + "  " + e.StackTrace);
     }
 }
コード例 #2
0
        /// <summary>
        /// When overridden in a derived class, executes the task.
        /// </summary>
        /// <returns>
        /// true if the task successfully executed; otherwise, false.
        /// </returns>
        public override bool Execute()
        {
            if (!File.Exists(_zipFileName))
            {
                Log.LogError(Properties.Resources.ZipFileNotFound, _zipFileName);
                return(false);
            }

            if (!Directory.Exists(_targetDirectory))
            {
                Directory.CreateDirectory(_targetDirectory);
            }

            FastZipEvents events = new FastZipEvents();

            events.ProcessDirectory = new ProcessDirectoryDelegate(ProcessDirectory);
            events.ProcessFile      = new ProcessFileDelegate(ProcessFile);

            FastZip zip = new FastZip(events);

            zip.CreateEmptyDirectories = false;

            Log.LogMessage(Properties.Resources.UnzipFileToDirectory, _zipFileName, _targetDirectory);
            zip.ExtractZip(_zipFileName, _targetDirectory, null);
            Log.LogMessage(Properties.Resources.UnzipSuccessfully, _zipFileName);

            return(true);
        }
コード例 #3
0
        private static void UnZipFile(string zipFilePath, string targetDir)
        {
            FastZipEvents evt = new FastZipEvents();
            FastZip       fz  = new FastZip(evt);

            fz.ExtractZip(zipFilePath, targetDir, "");
        }
コード例 #4
0
        public void SaveBackupToFile(string projectPath, string tempPath)
        {
            _fastZipEvents          = new FastZipEvents();
            _fastZipEvents.Progress = new ProgressHandler(ProcessProgressChange);


            backupProgressChanged.Invoke(BackupState.CopyingFiles, 0);
            foreach (string path in _foldersToAdd)
            {
                string relativePath    = path.Replace(projectPath + "\\", "");
                string destinationPath = Path.Combine(tempPath, "files", relativePath);

                if (!Directory.Exists(destinationPath))
                {
                    Directory.CreateDirectory(destinationPath);
                }

                DirectoryExtension.CopyRecursive(path, destinationPath);
            }

            foreach (string path in _filesToAdd)
            {
                File.Copy(path, Path.Combine(tempPath, "files", Path.GetFileName(path)), true);
            }

            FastZip fz = new FastZip(_fastZipEvents);

            fz.CreateZip(_backupPath, tempPath, true, "");
        }
コード例 #5
0
        private void MakePack(string save)
        {
            //TODO: 打包脚本
            CantStop = true;
            MainWindowVM.ShowStatus("打包...扫描文件");
            fileCount = fileCount ?? GetAllFileCount();
            var count = 0;
            //排除的文件和目录(包含版本文件)
            var fileFilter = string.Join(";",
                                         IgnoreHashs.Where(i => !i.EndsWith("/") && !i.Equals(VersionFileName))
                                         .Select(i => $"-^{(PackFolder + "\\" + i).ToRegPattern()}$"));
            var dirFilter = string.Join(";",
                                        IgnoreHashs.Where(i => i.EndsWith("/"))
                                        .Select(i => $"-^{(PackFolder + "\\" + i.TrimEnd('/')).ToRegPattern()}$"));
            //压缩
            var evt = new FastZipEvents
            {
                CompletedFile    = (sender, e) => count++,
                ProcessFile      = (sender, e) => MainWindowVM.ShowStatus("打包..." + e.Name.Remove(0, PackFolder.Length + 1), true, count * 100 / fileCount),
                ProgressInterval = TimeSpan.FromSeconds(1)
            };
            var fast = new FastZip(evt)
            {
                Password = Password
            };

            MainWindowVM.BeginStatusInterval();
            fast.CreateZip(save, PackFolder, true, fileFilter, dirFilter);
            MainWindowVM.EndStatusInterval();
            MainWindowVM.ShowStatus("打包...完成");
            CantStop = false;
            return;
        }
コード例 #6
0
            void Work()
            {
                try
                {
                    ICSharpCode.SharpZipLib.Zip.ZipFile zipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(m_ZipFilePath);
                    m_FileTotalCount = zipFile.Count;
                    zipFile.Close();

                    FastZipEvents zipEvent = new FastZipEvents();
                    zipEvent.Progress      = OnProcess;
                    zipEvent.CompletedFile = OnCompletedFile;

                    FastZip fastZip = new FastZip(zipEvent);
                    fastZip.CreateEmptyDirectories = true;
                    fastZip.ExtractZip(m_ZipFilePath, m_OutDirPath, null);
                    m_IsFinish = true;
                }
                catch (Exception exception)
                {
                    //Log.e(exception.Message);
                    m_ErrorMsg = exception.Message;
                    m_IsError  = true;
                    m_IsFinish = true;
                }
            }
コード例 #7
0
            void Work()
            {
                try
                {
                    ZipFile zipFile = new ZipFile(mZipFilePath);
                    mFileTotalCount = zipFile.Count;
                    zipFile.Close();

                    FastZipEvents zipEvent = new FastZipEvents();
                    zipEvent.Progress      = OnProcess;
                    zipEvent.CompletedFile = OnCompletedFile;

                    FastZip fastZip = new FastZip(zipEvent);
                    fastZip.CreateEmptyDirectories = true;
                    fastZip.ExtractZip(mZipFilePath, mOutDirPath, null);
                    mFinish = true;
                }
                catch (Exception exception)
                {
                    Log.E(exception.Message);
                    mErrorMsg = exception.Message;
                    mIsError  = true;
                    mFinish   = true;
                }
            }
コード例 #8
0
    /// <summary>
    /// 解压zip文件
    /// </summary>
    /// <param name="_zipFile">需要解压的zip路径+名字</param>
    /// <param name="_outForlder">解压路径</param>
    public void UnZipFile(string _zipFile, string _outForlder)
    {
        if (Directory.Exists(_outForlder))
        {
            Directory.Delete(_outForlder, true);
        }
        Directory.CreateDirectory(_outForlder);
        progress = progressOverall = 0;
        Thread thread = new Thread(delegate()
        {
            int fileCount        = (int)new ZipFile(_zipFile).Count;
            int fileCompleted    = 0;
            FastZipEvents events = new FastZipEvents();
            events.Progress      = new ProgressHandler((object sender, ProgressEventArgs e) =>
            {
                progress = e.PercentComplete;
                if (progress == 100)
                {
                    fileCompleted++; progressOverall = 100 * fileCompleted / fileCount;
                }
            });
            events.ProgressInterval = TimeSpan.FromSeconds(progressUpdateTime);
            events.ProcessFile      = new ProcessFileHandler(
                (object sender, ScanEventArgs e) => { });
            FastZip fastZip = new FastZip(events);
            fastZip.ExtractZip(_zipFile, _outForlder, "");
        });

        thread.IsBackground = true;
        thread.Start();
    }
コード例 #9
0
ファイル: ZipHelper.cs プロジェクト: wxl2012/TicketClient
        /// <summary>
        /// 快速解压
        /// </summary>
        /// <param name="zipFilePath">压缩文件路径</param>
        /// <param name="extractPath">解压路径</param>
        /// <param name="pwd">密码</param>
        /// <param name="progressFun">进程</param>
        /// <param name="seconds">触发时间</param>
        /// <param name="completeFun">压缩过程中执行的函数</param>
        public static void UnZip(string zipFilePath, string extractPath, string pwd, ProgressHandler progressFun, double seconds, CompletedFileHandler completeFun)
        {
            FastZipEvents events = new FastZipEvents();

            if (progressFun != null)
            {
                events.Progress         = progressFun;
                events.ProgressInterval = TimeSpan.FromSeconds(seconds);
            }
            if (completeFun != null)
            {
                events.CompletedFile = completeFun;
            }
            FastZip zip = new FastZip(events);

            zip.CreateEmptyDirectories = true;
            if (!string.IsNullOrEmpty(pwd))
            {
                zip.Password = pwd;
            }
            zip.UseZip64 = UseZip64.On;
            zip.RestoreAttributesOnExtract = true;
            zip.RestoreDateTimeOnExtract   = true;
            zip.ExtractZip(zipFilePath, extractPath, FastZip.Overwrite.Always, null, "", "", true);
        }
コード例 #10
0
    /// <summary>
    /// 多线程中解压
    /// </summary>
    /// <param name="sourceFilePath"></param>
    /// <param name="destinationZipFilePath"></param>
    /// <param name="events"></param>
    /// <param name="recurse"></param>
    /// <param name="fileFilter"></param>
    public static void ExtractZipThread(string zipFileName, string targetDirectory, FastZipEvents events = null, string fileFilter = "")
    {
        Thread thread = new Thread(new ThreadStart(() => {
            ExtractZip(zipFileName, targetDirectory, events, fileFilter);
        }));

        thread.Start();
    }
コード例 #11
0
ファイル: Program.cs プロジェクト: thachgiasoft/shuijin
        public static void ExtractZip()
        {
            FastZipEvents fastZipEvents = new FastZipEvents();

            fastZipEvents.Progress += OnProgressHandler;
            FastZip fastZip = new FastZip(fastZipEvents);

            fastZip.ExtractZip("C:/Users/Joyan/Desktop/MOVA0069.zip", "C:/Users/Joyan/Desktop/MOVA0069(new)", "");
        }
コード例 #12
0
        //This is actually the whole process MadCow uses after Downloading source.
        #region RunProcedure
        public static void RunWholeProcedure()
        {
            Compile.currentMooegeExePath         = Program.programPath + @"\" + @"Repositories\" + ParseRevision.developerName + "-" + ParseRevision.branchName + "-" + ParseRevision.lastRevision + @"\src\Mooege\bin\Debug\Mooege.exe";
            Compile.currentMooegeDebugFolderPath = Program.programPath + @"\" + @"Repositories\" + ParseRevision.developerName + "-" + ParseRevision.branchName + "-" + ParseRevision.lastRevision + @"\src\Mooege\bin\Debug\";
            Compile.mooegeINI = Program.programPath + @"\" + @"Repositories\" + ParseRevision.developerName + "-" + ParseRevision.branchName + "-" + ParseRevision.lastRevision + @"\src\Mooege\bin\Debug\config.ini";

            ZipFile zip    = null;
            var     events = new FastZipEvents();

            if (ProcessFinder.FindProcess("Mooege") == true)
            {
                ProcessFinder.KillProcess("Mooege");
            }

            FastZip z = new FastZip(events);

            Console.WriteLine("Uncompressing zip file...");
            var stream = new FileStream(Program.programPath + @"\Repositories\" + @"\Mooege.zip", FileMode.Open, FileAccess.Read);

            zip = new ZipFile(stream);
            zip.IsStreamOwner = true; //Closes parent stream when ZipFile.Close is called
            zip.Close();

            var t1 = Task.Factory.StartNew(() => z.ExtractZip(Program.programPath + @"\Repositories\" + @"\Mooege.zip", Program.programPath + @"\" + @"Repositories\", null))
                     .ContinueWith(delegate
            {
                //Comenting the lines below because I haven't tested this new way over XP VM or even normal XP.
                //RefreshDesktop.RefreshDesktopPlease(); //Sends a refresh call to desktop, probably this is working for Windows Explorer too, so i'll leave it there for now -wesko
                //Thread.Sleep(2000); //<-This and ^this is needed for madcow to work on VM XP, you need to wait for Windows Explorer to refresh folders or compiling wont find the new mooege folder just uncompressed.
                Console.WriteLine("Uncompress Complete.");
                if (File.Exists(Program.madcowINI))
                {
                    IConfigSource source = new IniConfigSource(Program.madcowINI);
                    String Src           = source.Configs["Balloons"].Get("ShowBalloons");

                    if (Src.Contains("1"))
                    {
                        Form1.GlobalAccess.MadCowTrayIcon.ShowBalloonTip(1000, "MadCow", "Uncompress Complete!", ToolTipIcon.Info);
                    }
                }
                Form1.GlobalAccess.Invoke((MethodInvoker) delegate { Form1.GlobalAccess.generalProgressBar.PerformStep(); });
                Compile.compileSource(); //Compile solution projects.
                Form1.GlobalAccess.Invoke((MethodInvoker) delegate { Form1.GlobalAccess.generalProgressBar.PerformStep(); });
                Form1.GlobalAccess.Invoke((MethodInvoker) delegate { Form1.GlobalAccess.generalProgressBar.PerformStep(); });
                Console.WriteLine("[Process Complete!]");
                if (File.Exists(Program.madcowINI))
                {
                    IConfigSource source = new IniConfigSource(Program.madcowINI);
                    String Src           = source.Configs["Balloons"].Get("ShowBalloons");

                    if (Src.Contains("1"))
                    {
                        Form1.GlobalAccess.MadCowTrayIcon.ShowBalloonTip(1000, "MadCow", "Process Complete!", ToolTipIcon.Info);
                    }
                }
            });
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: thachgiasoft/shuijin
        public static void CreateZip()
        {
            FastZipEvents fastZipEvents = new FastZipEvents();

            fastZipEvents.Progress += OnProgressHandler;
            FastZip fastZip = new FastZip(fastZipEvents);

            fastZip.CreateZip("C:/Users/Joyan/Desktop/MOVA0069.zip", "C:/Users/Joyan/Desktop/MOVA0069", true, ".*");
        }
コード例 #14
0
        private Task ZipFolder()
        {
            var evt = new FastZipEvents();

            evt.Progress         += (sender, args) => _reporter.ReportProgress((int)(args.PercentComplete));
            evt.DirectoryFailure += (sender, args) => { };
            FastZip zip = new FastZip(evt);

            // TODO: explore current mod version, read modinfo file ?
            return(Task.Run(() => zip.CreateZip($"nqMod.v0.zip", _config.ModFolder, true, string.Empty)));
        }
コード例 #15
0
        private Task UnzipFolder()
        {
            var evt = new FastZipEvents();

            evt.Progress         += (sender, args) => _reporter.ReportProgress((int)(args.PercentComplete));
            evt.DirectoryFailure += (sender, args) => { };

            FastZip zip = new FastZip(evt);

            return(Task.Run(() => zip.ExtractZip(_patchFileName, _config.ModFolder, string.Empty)));
        }
コード例 #16
0
        private void ExtractZipFile(string zipPackage, string archive)
        {
            var events = new FastZipEvents();

            if (_verbose)
            {
                events.ProcessFile = ProcessFile;
            }

            new FastZip(events).ExtractZip(zipPackage, archive, null);
        }
コード例 #17
0
ファイル: ZipUtil.cs プロジェクト: yomunsam/TinaX.Core
        /// <summary>
        /// Create Zip file by directory , with process callback
        /// </summary>
        /// <param name="directory"></param>
        /// <param name="output_filename"></param>
        /// <param name="callback">string arg: file name</param>
        public static void ZipDirectory(string directory, string output_filename, Action <string> callback) //带数据回调
        {
            TinaX.IO.XFile.DeleteIfExists(output_filename);
            FastZipEvents events = new FastZipEvents();

            events.ProcessFile = (sender, args) =>
            {
                callback?.Invoke(args.Name);
            };
            var fastzip = new FastZip(events);

            fastzip.CreateZip(output_filename, directory, true, "");
        }
コード例 #18
0
        public void UnZip(string zipName, string FolderDestination)
        {
            label1.SafeInvoke(d => d.Text = "Extracting files to folder " + FolderDestination + ". Wait!");
            try
            {
                FastZipEvents zipevents = new FastZipEvents();
                zipevents.ProcessFile = new ProcessFileHandler(ProcessFile);

                FastZip fz = new FastZip(zipevents);
                fz.CreateEmptyDirectories = true;
                fz.ExtractZip(zipName, FolderDestination, "");
            }
            catch { }
        }
コード例 #19
0
        public static string CompressStream(string filePath, string outPath, string fileName, Action <float> action)
        {
            var    compressProgress = 0f;
            var    progress         = 0f;
            string zipFile          = outPath + "/" + fileName + ".zip";

            if (!Directory.Exists(outPath))
            {
                Directory.CreateDirectory(outPath);
            }
            if (File.Exists(zipFile))
            {
                File.Delete(zipFile);
            }
            Thread thread = new Thread(delegate()
            {
                int fileCount        = RecursiveFile(filePath);
                int finishCount      = 0;
                FastZipEvents events = new FastZipEvents
                {
                    Progress = new ProgressHandler((object sender, ProgressEventArgs e) =>
                    {
                        progress = e.PercentComplete;
                        if (progress == 100)
                        {
                            finishCount++;
                            compressProgress = finishCount / (float)fileCount;
                            if (action != null)
                            {
                                action(compressProgress);
                            }
                        }
                    }),
                    ProgressInterval = TimeSpan.FromSeconds(_progressInterval),
                    ProcessFile      = new ProcessFileHandler((object sender, ScanEventArgs e) => { })
                };
                using (Stream stream = File.Create(zipFile))
                {
                    FastZip zip = new FastZip(events);
                    zip.CreateZip(stream, outPath, true, "", "");
                    stream.Close();
                }
            })
            {
                IsBackground = true
            };

            thread.Start();
            return(zipFile);
        }
コード例 #20
0
ファイル: Program.cs プロジェクト: geniussheep/MyTest
        public void TestFastZipCreate(string backupFolderPath)
        {
            _totalFileCount = FolderContentsCount(backupFolderPath);

            FastZipEvents events = new FastZipEvents();

            events.ProcessFile = ProcessFileMethod;
            FastZip fastZip = new FastZip(events);

            fastZip.CreateEmptyDirectories = true;

            string zipFileName = Directory.GetParent(backupFolderPath).FullName + "\\ZipTest.zip";

            fastZip.CreateZip(zipFileName, backupFolderPath, true, "");
        }
コード例 #21
0
ファイル: ZipUtil.cs プロジェクト: baby-Jie/StudyResources
        /// <summary>
        /// 异步压缩文件 产生进度事件
        /// </summary>
        /// <param name="sourceDirectory"></param>
        /// <param name="zipFileName"></param>
        public async void ZipFileAsync(string sourceDirectory, string zipFileName)
        {
            _totalZipFileCount = FolderContentsCount(sourceDirectory);

            FastZipEvents events = new FastZipEvents();

            events.ProcessFile = ZipProcessFileMethod;
            FastZip fastZip = new FastZip(events);

            //FindEntry

            fastZip.CreateEmptyDirectories = true;

            await Task.Run(() => { fastZip.CreateZip(zipFileName, sourceDirectory, true, ""); });
        }
コード例 #22
0
ファイル: Extractor.cs プロジェクト: ExtTS/generator
        protected void extractBaseDir()
        {
            string        zipFullPath = this.processor.SourcePackageFullPath;
            string        targetDir   = this.processor.Store.TmpFullPath;
            FastZipEvents events      = new FastZipEvents();

            events.Progress = this.unzipProgressHandler;
            FastZip fastZip = new FastZip(events);

            fastZip.ExtractZip(
                zipFullPath,
                targetDir,
                @"ext([^/]+)/" + this.extractingBaseDirName + @"/(.*)\.js$"
                );
        }
コード例 #23
0
        private static string ExtractRepositoryFile(string zipPath)
        {
            FastZipEvents events = new FastZipEvents();

            events.Progress += (sender, args) => EditorUtility.DisplayProgressBar("Unzipping", args.Name, args.PercentComplete);
            FastZip zip = new FastZip(events);

            string targetDirectory = Directory.GetParent(zipPath).ToString();

            zip.ExtractZip(zipPath, targetDirectory, null);

            Debug.Log($"Extracted repository zip to path: {targetDirectory}");
            EditorUtility.ClearProgressBar();

            return(Path.Combine(targetDirectory, _extractedDirectoryName));
        }
コード例 #24
0
        /// <summary>文件解压方法
        ///
        /// </summary>
        /// <param name="zipFilePath">要解压的文件的名称的路径,ex:Application.StartupPath + "\\UploadFile\\1.rar"</param>
        /// <param name="targetDir">解压到哪个文件,ex:Application.StartupPath + "\\UploadFile\\"</param>
        public static bool CompressFile(string zipFilePath, string targetDir)
        {
            bool flag;

            try
            {
                FastZipEvents fz = new FastZipEvents();
                FastZip       fs = new FastZip(fz);
                fs.ExtractZip(zipFilePath, targetDir, "");
                flag = true;
            }
            catch (Exception)
            {
                flag = false;
            }
            return(flag);
        }
コード例 #25
0
ファイル: ZipHelper.cs プロジェクト: wxytkzc/GitHubCode
        /// <summary>
        /// 解压目录
        /// </summary>
        /// <param name="zipPath">压缩文件路径</param>
        /// <param name="folderPath">解压目录</param>
        public static void ExtractFolder(string zipPath, string folderPath)
        {
            FastZipEvents args = new FastZipEvents();
            //args.Progress = new ICSharpCode.SharpZipLib.Core.ProgressHandler((o, e) =>
            //{
            //    Debug.WriteLine(DateTime.Now + "进度=" + e.PercentComplete);
            //});
            //args.ProcessFile = new ProcessFileHandler((o, e) =>
            //{
            //    Debug.WriteLine(DateTime.Now + "名称=" + e.Name);
            //});
            FastZip fastZip = new FastZip(args);

            fastZip.CreateEmptyDirectories     = true;
            fastZip.RestoreAttributesOnExtract = true;
            fastZip.RestoreDateTimeOnExtract   = true;
            fastZip.ExtractZip(zipPath, folderPath, "");
        }
コード例 #26
0
    /// <summary>
    /// 解压
    /// </summary>
    /// <param name="zipFileName"></param>
    /// <param name="targetDirectory"></param>
    /// <param name="fileFilter"></param>
    public static void ExtractZip(string zipFileName, string targetDirectory, FastZipEvents events = null, string fileFilter = "")
    {
        if (string.IsNullOrEmpty(zipFileName))
        {
            throw new ArgumentNullException("ZIPFileName");
        }
        if (!File.Exists(zipFileName))
        {
            throw new FileNotFoundException("zipFileName");
        }
        if (Path.GetExtension(zipFileName).ToUpper() != ".ZIP")
        {
            throw new ArgumentException("ZipFileName is not Zip ");
        }
        FastZip fastZip = new FastZip(events);

        fastZip.ExtractZip(zipFileName, targetDirectory, fileFilter);
    }
コード例 #27
0
ファイル: UZip.cs プロジェクト: ThisisGame/UZip
        public void DeCompress(string zipFileName, string targetDirectory, string password, Action <string, string, string, float> OnProgress, Action <string, string> OnComplete, Action <string, string, Exception> OnError)
        {
            //新建任务;
            task            = new UZipTask();
            task.status     = UZipTask.TaskStatus.None;
            task.srcPath    = zipFileName;
            task.targetPath = targetDirectory;
            task.OnProgress = OnProgress;
            task.OnComplete = OnComplete;
            task.OnError    = OnError;

            //开启子线程
            thread = new Thread(() =>
            {
                try
                {
                    ZipFile fileInfo = new ZipFile(zipFileName);
                    totalCount       = (int)fileInfo.Count;
                    Debug.Log("totalCount=" + totalCount);

                    FastZipEvents events    = new FastZipEvents();
                    events.ProcessFile      = this.OnFileProgress;
                    events.Progress         = this.OnProgress;
                    events.ProcessDirectory = this.OnDirectoryProgress;
                    events.FileFailure      = this.OnFileFailed;
                    events.DirectoryFailure = this.OnDirectoryFailed;
                    events.CompletedFile    = this.OnFileCompleted;

                    FastZip zipHelper = new FastZip(events);

                    zipHelper.Password = password;
                    zipHelper.ExtractZip(zipFileName, targetDirectory, "");
                    task.status = UZipTask.TaskStatus.Done;
                }
                catch (Exception ex)
                {
                    Debug.LogError("DeCompress Thread Error: " + ex);
                    task.status    = UZipTask.TaskStatus.Error;
                    task.exception = ex;
                }
            });
            thread.Start();
        }
コード例 #28
0
ファイル: UZip.cs プロジェクト: ThisisGame/UZip
        int totalCount = 0; //需要压缩的文件数量;

        public void Compress(string sourceDirectory, string zipFileName, string password, Action <string, string, string, float> OnProgress, Action <string, string> OnComplete, Action <string, string, Exception> OnError)
        {
            //新建任务;
            task            = new UZipTask();
            task.status     = UZipTask.TaskStatus.None;
            task.srcPath    = sourceDirectory;
            task.targetPath = zipFileName;
            task.OnProgress = OnProgress;
            task.OnComplete = OnComplete;
            task.OnError    = OnError;

            //开启子线程
            thread = new Thread(() =>
            {
                try
                {
                    totalCount = Directory.GetFiles(sourceDirectory, "*.*", SearchOption.AllDirectories).Length;
                    Debug.Log("totalCount=" + totalCount);


                    FastZipEvents events    = new FastZipEvents();
                    events.ProcessFile      = this.OnFileProgress;
                    events.ProcessDirectory = this.OnDirectoryProgress;
                    events.FileFailure      = this.OnFileFailed;
                    events.DirectoryFailure = this.OnDirectoryFailed;
                    events.CompletedFile    = this.OnFileCompleted;

                    FastZip zipHelper  = new FastZip(events);
                    zipHelper.Password = password;
                    zipHelper.CreateEmptyDirectories = true;
                    zipHelper.CreateZip(zipFileName, sourceDirectory, true, "");

                    task.status = UZipTask.TaskStatus.Done;
                }
                catch (Exception ex)
                {
                    Debug.LogError("Compress Thread Error: " + ex);
                    task.status    = UZipTask.TaskStatus.Error;
                    task.exception = ex;
                }
            });
            thread.Start();
        }
コード例 #29
0
        public static string Compress(string filePath, string outPath, string fileName, Action <float> action)
        {
            var compressProgress = 0f;
            var progress         = 0f;
            var zipFile          = $"{outPath}/{fileName}.zip";

            if (!Directory.Exists(outPath))
            {
                Directory.CreateDirectory(outPath);
            }
            if (File.Exists(zipFile))
            {
                File.Delete(zipFile);
            }
            var thread = new Thread(delegate()
            {
                var fileCount   = RecursiveFile(filePath);
                var finishCount = 0;
                var events      = new FastZipEvents
                {
                    Progress = new ProgressHandler((object sender, ProgressEventArgs e) =>
                    {
                        progress = e.PercentComplete;
                        if (progress == 100)
                        {
                            finishCount++;
                            compressProgress = finishCount / (float)fileCount;
                            action?.Invoke(compressProgress);
                        }
                    }),
                    ProgressInterval = TimeSpan.FromSeconds(_progressInterval),
                    ProcessFile      = new ProcessFileHandler((object sender, ScanEventArgs e) => { })
                };
                var zip = new FastZip(events);
                zip.CreateZip(zipFile, filePath, true, "");
            })
            {
                IsBackground = true
            };

            thread.Start();
            return(zipFile);
        }
コード例 #30
0
 private void OnExtractFile(List <object> evParams)
 {
     if (evParams.Count == 2)
     {
         try
         {
             string zipFileName     = evParams[0] as string;
             string targetDirectory = evParams[1] as string;
             if (this.fzEvents == null)
             {
                 this.fzEvents = new FastZipEvents();
                 FastZipEvents expr_42 = this.fzEvents;
                 expr_42.CompletedFile = (CompletedFileHandler)Delegate.Combine(expr_42.CompletedFile, new CompletedFileHandler(this.FileCompleteListener));
                 FastZipEvents expr_69 = this.fzEvents;
                 expr_69.Progress = (ProgressHandler)Delegate.Combine(expr_69.Progress, new ProgressHandler(this.ProgressChangeListener));
             }
             if (this.fz == null)
             {
                 this.fz = new FastZip(this.fzEvents);
             }
             this.fz.ExtractZip(zipFileName, targetDirectory, null);
         }
         catch (Exception ex)
         {
             NotiData data = new NotiData("ExtractFailed", ex.Message, null);
             if (this.m_SyncEvent != null)
             {
                 this.m_SyncEvent(data);
             }
         }
     }
     else
     {
         string   text  = "Invalid parameter count in extract zip file";
         NotiData data2 = new NotiData("ExtractFailed", text, null);
         if (this.m_SyncEvent != null)
         {
             this.m_SyncEvent(data2);
         }
         Debug.LogError(text);
     }
 }
コード例 #31
0
ファイル: FastZip.cs プロジェクト: modulexcite/graveyard
 /// <summary>
 /// Initialise a new instance of <see cref="FastZip"/>
 /// </summary>
 /// <param name="events">The <see cref="FastZipEvents">events</see> to use during operations.</param>
 public FastZip(FastZipEvents events)
 {
     events_ = events;
 }