FastZipEvents supports all events applicable to FastZip operations.
Exemplo n.º 1
1
 /// <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();
 }
Exemplo n.º 2
0
 /// <summary>
 /// 压缩文件夹
 /// </summary>
 /// <param name="_fileForlder">文件夹路径</param>
 /// <param name="_outZip">zip文件路径+名字</param>
 public void ZipFolder(string _fileFolder, string _outZip)
 {
     string directory = _outZip.Substring(0, _outZip.LastIndexOf('/'));
     if (!Directory.Exists(directory))
         Directory.CreateDirectory(directory);
     if (File.Exists(_outZip))
         File.Delete(_outZip);
     progress = progressOverall = 0;
     Thread thread = new Thread(delegate ()
     {
         int fileCount = FileCount(_fileFolder);
         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.CreateZip(_outZip, _fileFolder, true, "");
     });
     thread.IsBackground = true;
     thread.Start();
 }
Exemplo n.º 3
0
 public FastZip(FastZipEvents events)
 {
     this.password               = null;
     this.restoreDateTime        = false;
     this.createEmptyDirectories = false;
     this.events = events;
 }
Exemplo n.º 4
0
        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);
                    }
                }
            });
        }
Exemplo n.º 5
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 { }
        }
Exemplo n.º 6
0
        //This is actually the whole process MadCow uses after Downloading source.
        public static void Uncompress()
        {
            var events = new FastZipEvents();

            var z = new FastZip(events);
            var stream = new FileStream(Path.GetTempPath() + @"\MadCow.zip", FileMode.Open, FileAccess.Read);
            var zip = new ZipFile(stream);
            zip.IsStreamOwner = true; //Closes parent stream when ZipFile.Close is called
            zip.Close();

            Task task = Task.Factory.StartNew(() => z.ExtractZip(Path.GetTempPath() + @"\MadCow.zip", Path.GetTempPath() + @"\" + @"MadCow\",null));
            task.Wait();

            Form1.GlobalAccess.Invoke(new Action(() =>
            {
                Form1.GlobalAccess.UncompressSuccessDot.Visible = true;
                Form1.GlobalAccess.UncompressingLabel.ForeColor = Color.Green;
            }));
        }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
0
        void Run(string[] args)
        {
            bool recurse = false;
            string arg1 = null;
            string arg2 = null;
            string fileFilter = null;
            string dirFilter = null;
            bool verbose = false;
            bool restoreDates = false;
            bool restoreAttributes = false;
            bool progress = false;
            TimeSpan interval = TimeSpan.FromSeconds(1);

            bool createEmptyDirs = false;
            FastZip.Overwrite overwrite = FastZip.Overwrite.Always;
            FastZip.ConfirmOverwriteDelegate confirmOverwrite = null;
			
            Operation op = Operation.Unknown;
            int argCount = 0;
			
            for ( int i = 0; i < args.Length; ++i ) {
                if ( args[i][0] == '-' ) {
                    string option = args[i].Substring(1).ToLower();
                    string optArg = "";
	
                    int parameterIndex = option.IndexOf('=');
	
                    if (parameterIndex >= 0)
                    {
                        if (parameterIndex < option.Length - 1) {
                            optArg = option.Substring(parameterIndex + 1);
                        }
                        option = option.Substring(0, parameterIndex);
                    }
					
                    switch ( option ) {
                        case "e":
                        case "empty":
                            createEmptyDirs = true;
                            break;
							
                        case "x":
                        case "extract":
                            if ( op == Operation.Unknown ) {
                                op = Operation.Extract;
                            }
                            else {
                                Console.WriteLine("Only one operation at a time is permitted");
                                op = Operation.Error;
                            }
                            break;
							
                        case "c":
                        case "create":
                            if ( op == Operation.Unknown ) {
                                op = Operation.Create;
                            }
                            else {
                                Console.WriteLine("Only one operation at a time is permitted");
                                op = Operation.Error;
                            }
                            break;

                        case "l":
                        case "list":
                            if ( op == Operation.Unknown ) {
                                op = Operation.List;
                            }
                            else {
                                Console.WriteLine("Only one operation at a time is permitted");
                                op = Operation.Error;
                            }
                            break;

							
                        case "p":
                        case "progress":
                            progress = true;
                            verbose = true;
                            break;

                        case "r":
                        case "recurse":
                            recurse = true;
                            break;
							
                        case "v":
                        case "verbose":
                            verbose = true;
                            break;

                        case "i":
                            if (optArg.Length > 0) {
                                interval = TimeSpan.FromSeconds(int.Parse(optArg));
                            }
                            break;

                        case "file":
                            if ( NameFilter.IsValidFilterExpression(optArg) ) {
                                fileFilter = optArg;
                            }
                            else {
                                Console.WriteLine("File filter expression contains an invalid regular expression");
                                op = Operation.Error;
                            }
                            break;
							
                        case "dir":
                            if ( NameFilter.IsValidFilterExpression(optArg) ) {
                                dirFilter = optArg;
                            }
                            else {
                                Console.WriteLine("Path filter expression contains an invalid regular expression");
                                op = Operation.Error;
                            }
                            break;
							
                        case "o":
                        case "overwrite":
                            switch ( optArg )
                            {
                                case "always":
                                    overwrite = FastZip.Overwrite.Always;
                                    confirmOverwrite = null;
                                    break;
									
                                case "never":
                                    overwrite = FastZip.Overwrite.Never;
                                    confirmOverwrite = null;
                                    break;
									
                                case "prompt":
                                    overwrite = FastZip.Overwrite.Prompt;
                                    confirmOverwrite = new FastZip.ConfirmOverwriteDelegate(ConfirmOverwrite);
                                    break;
									
                                default:
                                    Console.WriteLine("Invalid overwrite option");
                                    op = Operation.Error;
                                    break;
                            }
                            break;
							
                        case "oa":
                            restoreAttributes = true;
                            break;
							
                        case "od":
                            restoreDates = true;
                            break;
							
                        default:
                            Console.WriteLine("Unknown option {0}", args[i]);
                            op = Operation.Error;
                            break;
                    }
                }
                else if ( arg1 == null ) {
                    arg1 = args[i];
                    ++argCount;
                }
                else if ( arg2 == null ) {
                    arg2 = args[i];
                    ++argCount;
                }
            }

            FastZipEvents events = null;
			
            if ( verbose ) {
                events = new FastZipEvents();
                events.ProcessDirectory = new ProcessDirectoryHandler(ProcessDirectory);
                events.ProcessFile = new ProcessFileHandler(ProcessFile);

                if (progress)
                {
                    events.Progress = new ProgressHandler(ShowProgress);
                    events.ProgressInterval = interval;
                }
            }
			
            FastZip fastZip = new FastZip(events);
            fastZip.CreateEmptyDirectories = createEmptyDirs;
            fastZip.RestoreAttributesOnExtract = restoreAttributes;
            fastZip.RestoreDateTimeOnExtract = restoreDates;
			
            switch ( op ) {
                case Operation.Create:
                    if ( argCount == 2 ) {
                        Console.WriteLine("Creating Zip");

                        fastZip.CreateZip(arg1, arg2, recurse, fileFilter, dirFilter);
                    }
                    else
                        Console.WriteLine("Invalid arguments");
                    break;
					
                case Operation.Extract:
                    if ( argCount == 2 ) {
                        Console.WriteLine("Extracting Zip");
                        fastZip.ExtractZip(arg1, arg2, overwrite, confirmOverwrite, fileFilter, dirFilter, restoreDates);
                    }
                    else
                        Console.WriteLine("zipfile and target directory not specified");
                    break;
					
                case Operation.List:
                    if ( File.Exists(arg1) ) {
                        ListZipFile(arg1, fileFilter, dirFilter);
                    }
                    else if ( Directory.Exists(arg1) ) {
                        ListFileSystem(arg1, recurse, fileFilter, dirFilter);
                    }
                    else {
                        Console.WriteLine("No valid list file or directory");
                    }
                    break;
					
                case Operation.Unknown:
                    Console.WriteLine(
                        "FastZip v0.5\n"
                        +  "  Usage: FastZip {options} operation args\n"
                        +  "Operation Options: (only one permitted)\n"
                        +  "  -x zipfile targetdir : Extract files from Zip\n"
                        +  "  -c zipfile sourcedir : Create zip file\n"
                        +  "  -l zipfile|dir       : List elements\n"
                        +  "\n"
                        +  "Behavioural options:\n"
                        +  "  -dir={dirFilter}\n"
                        +  "  -file={fileFilter}\n"
                        +  "  -e Process empty directories\n"
                        +  "  -i Progress interval in seconds\n"
                        +  "  -p Show file progress\n"
                        +  "  -r Recurse directories\n"
                        +  "  -v Verbose output\n"
                        +  "  -oa Restore file attributes on extract\n"
                        +  "  -ot Restore file date time on extract\n"
                        +  "  -overwrite=prompt|always|never   : Overwrite on extract handling\n"
                        );
                    break;
				
                case Operation.Error:
                    // Do nothing for now...
                    break;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Upgrades the site using with any new components
        /// </summary>
        private void PerformUpgradeIfRequired()
        {
            try
            {
                // TODO might want to consider clearing out folder before starting

                Assembly assembly = Assembly.GetExecutingAssembly();
                AssemblyName assemName = assembly.GetName();
                string zipFileName = System.IO.Path.GetTempPath() + @"OSA_Web_" + assemName.Version.ToString() + ".zip";
                string outputFolder = Common.ApiPath + @"\wwwroot\";

                // TODO consider using OSAP file to determine version
                //if (!File.Exists(zipFileName))
                {
                    //logging.AddToLog("Did not find a Zip with Version: " + assemName.Version.ToString() + " Performing upgrade", true);

                    ExtractZipFromResource(zipFileName);

                    FastZipEvents events = new FastZipEvents();
                    FastZip fastZip = new FastZip(events);

                    fastZip.ExtractZip(zipFileName,
                        outputFolder,
                        FastZip.Overwrite.Always,
                        null,
                        null,
                        null,
                        true);
                    logging.AddToLog("Extracting file to : " + outputFolder, true);
                    logging.AddToLog("Upgrade Complete", true);

                }
                // else
                {
                   // logging.AddToLog("File with verison: " + zipFileName + " upgrade not required", true);
                }
            }
            catch (Exception ex)
            {
                logging.AddToLog("Upgrade failed: " + ex.Message, true);
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Initialise a new instance of <see cref="FastZip"/>
 /// </summary>
 /// <param name="events"></param>
 public FastZip(FastZipEvents events)
 {
     this.events = events;
 }
Exemplo n.º 11
0
		/// <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 IsolatedFastZip(FastZipEvents events)
		{
			events_ = events;
		}
Exemplo n.º 12
0
 private static IsolatedFastZip GetZipper(IProgress<double> FractionProgress)
 {
     var events = new FastZipEvents();
     events.ProgressInterval = TimeSpan.FromSeconds(1);
     events.Progress = (s, args) =>
     {
         FractionProgress.Report(args.PercentComplete / 100.0);
     };
     IsolatedFastZip zipper = new IsolatedFastZip(events)
     {
         CreateEmptyDirectories = true,
         RestoreAttributesOnExtract = true,
         RestoreDateTimeOnExtract = true
     };
     return zipper;
 }
Exemplo n.º 13
0
 public FastZip(FastZipEvents events)
 {
     this.entryFactory_ = new ZipEntryFactory();
     this.events_       = events;
 }
Exemplo n.º 14
0
 public FastZip(FastZipEvents events)
 {
     this.entryFactory_ = new ZipEntryFactory();
     this.useZip64_     = ICSharpCode.SharpZipLib.Zip.UseZip64.Dynamic;
     this.events_       = events;
 }
Exemplo n.º 15
0
		/// <summary>
		/// Initialise a new instance of <see cref="FastZip"/>
		/// </summary>
		/// <param name="events"></param>
		public FastZip(FastZipEvents events)
		{
			this.events = events;
		}
Exemplo n.º 16
0
 /// <summary>
 /// Initialize a default instance of FastZip.
 /// </summary>
 public FastZip()
 {
     this.events = null;
 }
Exemplo n.º 17
0
 /// <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;
 }
Exemplo n.º 18
0
 private void ExtractZip(string packFilePath, string dir)
 {
     var events = new FastZipEvents();
     var zip = new FastZip(events);
     zip.ExtractZip(packFilePath, dir, FastZip.Overwrite.Always, null, "", "", false);
 }
Exemplo n.º 19
0
 private void CreateZip()
 {
     var events = new FastZipEvents();
     var zip = new FastZip(events);
     var terminals = new StringBuilder();
     foreach (var terminal in PackInfo.TerminalToCodes)
     {
         terminals.AppendFormat("T{0}", terminal);
     }
     zip.CreateZip(Path.Combine(workingPackPath, string.Format(kPackNameFromat, PackInfo.ModuleCode, terminals, PackInfo.Stamp.ToString("yyyyMMddhhmmss"))), PackInfo.WorkingDirectory, true, "");
 }
Exemplo n.º 20
0
        private void ExtractZipFile(string zipPackage, string archive)
        {
            var events = new FastZipEvents();

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

            new FastZip(events).ExtractZip(zipPackage, archive, null);
        }
Exemplo n.º 21
0
 public FastZip(FastZipEvents events)
 {
     this.entryFactory_ = new ZipEntryFactory();
     this.useZip64_ = ICSharpCode.SharpZipLib.Zip.UseZip64.Dynamic;
     this.events_ = events;
 }
Exemplo n.º 22
0
 /// <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;
 }
Exemplo n.º 23
0
        private void ExtractLibrary(string __file)
        {
            bool __foundSRC = false;

            using (ZipInputStream s = new ZipInputStream(File.OpenRead(__file)))
            {

                ZipEntry theEntry;
                while ((theEntry = s.GetNextEntry()) != null)
                {
                    if (Path.GetDirectoryName(theEntry.Name).ToLower() == "src")
                        __foundSRC = true;
                }
            }
            FastZipEvents events = new FastZipEvents();
            events.ProcessFile = ProcessFileMethod;
            FastZip __fastZip = new FastZip(events);
            string __fileFilter = @"+\.as$";
            string __directoryFilter;

            if (__foundSRC)
            {
                __directoryFilter = @"src";
                __fastZip.ExtractZip(__file, GetPath(), FastZip.Overwrite.Prompt, OverwritePrompt, __fileFilter, __directoryFilter, true);

                //MessageBox.Show(GetPath() + "/classes/");
                if (Directory.Exists(GetPath() + "/classes/"))
                {
                    Directory.Move(GetPath() + "/src/", GetPath() + "/classes/");
                }
                else if (settingObject.SrcPath.Replace("/", "").Replace("\\", "").ToLower() != "src")
                {
                    Directory.Move(GetPath() + "/src/", GetPath() + settingObject.SrcPath);
                }
            }
            else
            {
                __directoryFilter = null;
                //MessageBox.Show(Directory.Exists(GetPath() + "/classes/").ToString());
                if (Directory.Exists(GetPath() + "/classes/"))
                {
                    __fastZip.ExtractZip(__file, GetPath() + "/classes/", FastZip.Overwrite.Prompt, OverwritePrompt, __fileFilter, __directoryFilter, true);
                }
                else
                {
                    __fastZip.ExtractZip(__file, GetPath() + settingObject.SrcPath, FastZip.Overwrite.Prompt, OverwritePrompt, __fileFilter, __directoryFilter, true);
                }
            }

            //PluginBase.MainForm.EditorMenu.Hide();
            /*using (ZipInputStream s = new ZipInputStream(File.OpenRead(__file)))
            {

                ZipEntry theEntry;
                while ((theEntry = s.GetNextEntry()) != null)
                {

                    string directoryName = Path.GetDirectoryName(theEntry.Name);
                    if (isDirectoryAllowed(directoryName))
                    {
                        string fileName = Path.GetFileName(theEntry.Name);
                        if (isFileAllowed(Path.GetExtension(theEntry.Name)))
                        {

                            // create directory
                            if (directoryName.Length > 0)
                            {
                                Directory.CreateDirectory(GetPath() + settingObject.SrcPath + directoryName);
                            }

                            if (fileName != String.Empty)
                            {
                                using (FileStream streamWriter = File.Create(GetPath() + settingObject.SrcPath + theEntry.Name))
                                {

                                    int size = 2048;
                                    byte[] data = new byte[2048];
                                    while (true)
                                    {
                                        size = s.Read(data, 0, data.Length);
                                        if (size > 0)
                                        {
                                            streamWriter.Write(data, 0, size);
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }*/
        }