Ejemplo n.º 1
0
            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="wait">Wait for the process to finish</param>
            /// <param name="path">Path to 7z executable</param>
            /// <param name="args">Arguments to the 7z executable</param>
            /// <param name="callback">Callback method for completion</param>
            public _7zComp(bool wait, string path, CompressionEventArgs args, CompressionCompleteHandler callback)
            {
                this._errorOccured = false;
                this._callback     = callback;
                this._args         = args;
                this._path         = path;

                Thread t = null;

                if (args.Operation == Action.Compress)
                {
                    t = new Thread(new ParameterizedThreadStart(this._Compress));
                }
                else if (args.Operation == Action.Extract)
                {
                    t = new Thread(new ParameterizedThreadStart(this._Extract));
                }
                t.Name = "_7zThread";
                t.Start(args);

                if (wait)
                {
                    t.Join();
                }
            }
Ejemplo n.º 2
0
            /// <summary>
            /// Prepares and launches the 7z executable for extraction
            /// </summary>
            /// <param name="args">CompressionEventArgs object representing the arguments</param>
            /// <remarks>args.IncludeFiles[0] is used to contain the output directory</remarks>
            private void _Extract(object args)
            {
                CompressionEventArgs e = args as CompressionEventArgs;
                // e.IncludeFiles[0] is the output directory
                string pwd = (e.Password != null && e.Password.Trim() != "") ? ("-p" + e.Password) : "";

                this._Launch(string.Format("x -t{1} \"{0}\" -mx{2} {3} -o\"{4}\"", e.TargetFile, this.FromType(e.FileType), this.FromCompression(e.Compression), pwd, e.IncludeFiles[0]));
            }
Ejemplo n.º 3
0
            /// <summary>
            /// Prepares and launches the 7z executable for compression
            /// </summary>
            /// <param name="args">CompressionEventArgs object representing the arguments</param>
            private void _Compress(object args)
            {
                CompressionEventArgs e = args as CompressionEventArgs;

                string excl = "";
                string incl = "";
                string pwd  = "";

                string t;

                // Compute ignore files
                if (e.ExcludeFiles != null)
                {
                    foreach (string s in e.ExcludeFiles)
                    {
                        if ((t = s.Trim()) != String.Empty)
                        {
                            excl += string.Format("-xr!\"{0}\" ", t);
                        }
                    }
                }
                // Compute include files
                foreach (string s in e.IncludeFiles)
                {
                    if ((t = s.Trim()) != String.Empty)
                    {
                        incl += string.Format("\"{0}\" ", t);
                    }
                }

                if (e.Password != null && e.Password.Trim() != "")
                {
                    pwd = "-p" + e.Password;
                }

                this._Launch(string.Format("u -t{1} \"{0}.{1}\" {3} -mx{2} {4} {5}", e.TargetFile, this.FromType(e.FileType), this.FromCompression(e.Compression), incl.TrimEnd(), excl.TrimEnd(), pwd));
            }