Esempio n. 1
0
        public override void ThreadExtract7z(string filePath, string outPath, ExtractCallback callback)
        {
            CompressTool ct = new CompressTool();

            ct.zipPath  = filePath;
            ct.tempPath = outPath;
            ct.Extract();
            callback(10, 10);
        }
Esempio n. 2
0
        public override void ThreadExtract7z(string filePath, string outPath, ExtractCallback callback)
        {
            var thread = new Thread(new ThreadStart(delegate()
            {
                IntPtr ptr = Marshal.GetFunctionPointerForDelegate(callback);
                int ret    = Extract(filePath, outPath, ptr);

                if (ret != 0)
                {
                    callback(-1, 0);
                }
            }));

            thread.Start();
        }
Esempio n. 3
0
        /// <summary>
        /// 加载依赖文件(暂时借用回调)
        /// </summary>
        public virtual void buildMainFest(ExtractCallback ecb)
        {
            //#if UNITY_EDITOR
            //ecb(1, 1);
            //#else
            ResLoadInfo resLoadInfo = new ResLoadInfo();

            string[] ss = new string[1];
            ss[0] = ResPathWWW + "res";
            Debug.Log("Extract" + ss[0]);
            resLoadInfo.start("AssetBundleManifest", ss, (ResLoadInfo res, object param) =>
            {
                mainfest = res.LoadAsset <AssetBundleManifest>();
                //Log.Info(mainfest == null ? "mainfest加载失败" : "mainfest加载成功");
                ecb(1, 1);
            });
        }
Esempio n. 4
0
        /// <summary>
        /// Extract all frames of animation
        /// </summary>
        /// <param name="animationFile">File name</param>
        /// <param name="destinationFolder">Output folder</param>
        public async Task ExtractFramesAsync(string animationFile, string destinationFolder, ExtractCallback callback)
        {
            //initiate class

            _isAnimating     = false;
            _filename        = animationFile;
            _desFolder       = destinationFolder;
            _extractFinished = callback;

            await Task.Run(() => {
                _img = new Bitmap(animationFile);
                _i   = 1;

                //begin extract
                AnimateImage();
            }).ConfigureAwait(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Extract all frames of animation
        /// </summary>
        /// <param name="animationFile">File name</param>
        /// <param name="destinationFolder">Output folder</param>
        public void ExtractAllFrames(string animationFile, string destinationFolder, ExtractCallback callback)
        {
            //initiate class

            _isAnimating     = false;
            _filename        = animationFile;
            _desFolder       = destinationFolder;
            _extractFinished = callback;

            Task.Run(() => {
                _img = new Bitmap(animationFile);
                _i   = 1;

                //begin extract
                AnimateImage();
            });
        }
Esempio n. 6
0
        public override void ThreadExtract7z(string filePath, string outPath, ExtractCallback callback)
        {
            //var thread = new Thread(new ThreadStart(delegate()
            //{
            //    IntPtr ptr = Marshal.GetFunctionPointerForDelegate(callback);
            //    int ret = Extract(filePath, outPath, ptr);

            //    if (ret != 0)
            //        Log.Error("ThreadExtract7z error: "+ret);
            //}));

            //thread.Start();

            var thread = new Thread(new ThreadStart(delegate()
            {
                ZipHelper.UnZip(filePath, outPath, callback);
            }));

            thread.Start();
        }
Esempio n. 7
0
        /// <summary>
        /// Save current frame
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveFrames(object sender, EventArgs e)
        {
            if (!_isAnimating)
            {
                return;
            }

            var frameCount  = System.Drawing.Image.FromFile(_filename).GetFrameCount(FrameDimension.Time);
            var numberIndex = frameCount.ToString().Length;

            // Check current frame
            if (_i > frameCount)
            {
                _isAnimating = false;
                ImageAnimator.StopAnimate(_img, null);

                // Issue #565 callback to let the user know the extract has finished
                _extractFinished?.Invoke();
                _extractFinished = null;
                return;
            }

            //Begin the animation.
            AnimateImage();

            //Get the next frame ready for rendering.
            ImageAnimator.UpdateFrames();

            //Draw the next frame in the animation.
            _img.Save(
                Path.Combine(
                    _desFolder,
                    Path.GetFileNameWithoutExtension(_filename) + " - " +
                    _i.ToString($"D{numberIndex}") + ".png"
                    ),
                ImageFormat.Png
                );

            //go to next frame
            _i += 1;
        }
Esempio n. 8
0
        public void Extract()
        {
            try {
                using (var ar = new Archive(archive, this, format)) {
                    var indices = new List <uint>();
                    var files   = new Dictionary <uint, IArchiveEntry>();
                    var e       = ar.GetNumberOfItems();
                    for (uint i = 0; i < e; ++i)
                    {
                        var name = ar.GetProperty(i, ItemPropId.Path).GetString();
                        if (format == FormatSplit)
                        {
                            name = Path.GetFileName(name);
                        }
                        if (!items.ContainsKey(name))
                        {
                            continue;
                        }

                        var entry = items[name];
                        if (entry.Destination == null)
                        {
                            continue;
                        }
                        indices.Add(i);
                        files[i] = entry;
                    }
                    using (var callback = new ExtractCallback(this, files)) {
                        ar.Extract(indices.ToArray(), (uint)indices.Count, ExtractMode.Extract, callback);
                    }
                }
            }
            finally {
                CloseStreams();
            }
        }
Esempio n. 9
0
 /// <summary>
 /// 解压7zip文件
 /// </summary>
 /// <param name="filePath"></param>
 /// <param name="outPath"></param>
 /// <returns></returns>
 public abstract void ThreadExtract7z(string filePath, string outPath, ExtractCallback callback);
Esempio n. 10
0
 public override void ThreadExtract7z(string filePath, string outPath, ExtractCallback callback)
 {
     callback(10, 10);
 }
Esempio n. 11
0
        public void Open(IEnumerator<string> passwords)
        {
            if (passwords == null) {
            throw new ArgumentNullException("passwords");
              }
              var opened = false;
              try {
            this.passwordCollection = passwords;
            var formats = new Dictionary<Guid, bool>();
            formats.Add(format, false);
            foreach (Guid f in AllFormats) {
              formats[f] = false;
            }
            foreach (Guid f in formats.Keys) {
              if (opened) {
            break;
              }
              for (; !passwordDefined; ) {
            try {
              using (var ar = new Archive(archive, this, f)) {
                nextPassword = true;
                IArchiveEntry minCrypted = null;
                uint minIndex = 0;
                var e = ar.GetNumberOfItems();
                if (e != 0) {
                  format = f;
                  opened = true;
                  passwordDefined = !string.IsNullOrEmpty(currentPassword);
                }
                else {
                  if (!passwordRequested) {
                    break;
                  }
                }
                for (uint i = 0; i < e; ++i) {
                  if (ar.GetProperty(i, ItemPropId.IsDir).GetBool()) {
                    continue;
                  }
                  var name = ar.GetProperty(i, ItemPropId.Path).GetString();
                  if (format == FormatSplit) {
                    name = Path.GetFileName(name);
                  }

                  var size = ar.GetProperty(i, ItemPropId.Size).GetUlong();
                  var packedSize = ar.GetProperty(i, ItemPropId.PackedSize).GetUlong();
                  if (packedSize == 0) {
                    packedSize = size;
                  }
                  var isCrypted = ar.GetProperty(i, ItemPropId.Encrypted).GetBool();
                  var crc = ar.GetProperty(i, ItemPropId.CRC).GetUint();
                  IArchiveEntry entry = new SevenZipItemInfo(name, crc, isCrypted, size, packedSize);
                  items[name] = entry;
                  if (isCrypted && (minCrypted == null || minCrypted.CompressedSize > packedSize)) {
                    minCrypted = entry;
                    minIndex = i;
                  }
                }
                if (minCrypted != null && !passwordDefined) {
                  passwords.Reset();
                  var files = new Dictionary<uint, IArchiveEntry>();
                  files[minIndex] = minCrypted;
                  for (; !passwordDefined; ) {
                    using (var callback = new ExtractCallback(this, files)) {
                      try {
                        ar.Extract(new uint[] { minIndex }, 1, ExtractMode.Test, callback);
                        passwordDefined = true;
                      }
                      catch (IOException) {
                        nextPassword = true;
                        continue;
                      }
                    }
                  }
                }
                else {
                  if (items.Count != 0) {
                    passwordDefined = true;
                  }
                  else {
                    if (!passwordRequested) {
                      opened = false;
                      break;
                    }
                  }
                }
              }
            }
            catch (IndexOutOfRangeException) {
              throw new ArchiveException("Password missing");
            }
              }
            }
              }
              finally {
            CloseStreams();
              }
              if (!opened) {
            throw new ArchiveException("Invalid archive!");
              }
        }
Esempio n. 12
0
        public void Extract()
        {
            try {
            using (var ar = new Archive(archive, this, format)) {
              var indices = new List<uint>();
              var files = new Dictionary<uint, IArchiveEntry>();
              var e = ar.GetNumberOfItems();
              for (uint i = 0; i < e; ++i) {
            var name = ar.GetProperty(i, ItemPropId.Path).GetString();
            if (format == FormatSplit) {
              name = Path.GetFileName(name);
            }
            if (!items.ContainsKey(name)) {
              continue;
            }

            var entry = items[name];
            if (entry.Destination == null) {
              continue;
            }
            indices.Add(i);
            files[i] = entry;
              }
              using (var callback = new ExtractCallback(this, files)) {
            ar.Extract(indices.ToArray(), (uint)indices.Count, ExtractMode.Extract, callback);
              }
            }
              }
              finally {
            CloseStreams();
              }
        }
Esempio n. 13
0
        public void Open(IEnumerator <string> passwords)
        {
            if (passwords == null)
            {
                throw new ArgumentNullException("passwords");
            }
            var opened = false;

            try {
                this.passwordCollection = passwords;
                var formats = new Dictionary <Guid, bool>();
                formats.Add(format, false);
                foreach (Guid f in AllFormats)
                {
                    formats[f] = false;
                }
                foreach (Guid f in formats.Keys)
                {
                    if (opened)
                    {
                        break;
                    }
                    for (; !passwordDefined;)
                    {
                        try {
                            using (var ar = new Archive(archive, this, f)) {
                                nextPassword = true;
                                IArchiveEntry minCrypted = null;
                                uint          minIndex   = 0;
                                var           e          = ar.GetNumberOfItems();
                                if (e != 0)
                                {
                                    format          = f;
                                    opened          = true;
                                    passwordDefined = !string.IsNullOrEmpty(currentPassword);
                                }
                                else
                                {
                                    if (!passwordRequested)
                                    {
                                        break;
                                    }
                                }
                                for (uint i = 0; i < e; ++i)
                                {
                                    if (ar.GetProperty(i, ItemPropId.IsDir).GetBool())
                                    {
                                        continue;
                                    }
                                    var name = ar.GetProperty(i, ItemPropId.Path).GetString();
                                    if (format == FormatSplit)
                                    {
                                        name = Path.GetFileName(name);
                                    }

                                    var size       = ar.GetProperty(i, ItemPropId.Size).GetUlong();
                                    var packedSize = ar.GetProperty(i, ItemPropId.PackedSize).GetUlong();
                                    if (packedSize == 0)
                                    {
                                        packedSize = size;
                                    }
                                    var           isCrypted = ar.GetProperty(i, ItemPropId.Encrypted).GetBool();
                                    var           crc       = ar.GetProperty(i, ItemPropId.CRC).GetUint();
                                    IArchiveEntry entry     = new SevenZipItemInfo(name, crc, isCrypted, size, packedSize);
                                    items[name] = entry;
                                    if (isCrypted && (minCrypted == null || minCrypted.CompressedSize > packedSize))
                                    {
                                        minCrypted = entry;
                                        minIndex   = i;
                                    }
                                }
                                if (minCrypted != null && !passwordDefined)
                                {
                                    passwords.Reset();
                                    var files = new Dictionary <uint, IArchiveEntry>();
                                    files[minIndex] = minCrypted;
                                    for (; !passwordDefined;)
                                    {
                                        using (var callback = new ExtractCallback(this, files)) {
                                            try {
                                                ar.Extract(new uint[] { minIndex }, 1, ExtractMode.Test, callback);
                                                passwordDefined = true;
                                            }
                                            catch (IOException) {
                                                nextPassword = true;
                                                continue;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (items.Count != 0)
                                    {
                                        passwordDefined = true;
                                    }
                                    else
                                    {
                                        if (!passwordRequested)
                                        {
                                            opened = false;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        catch (IndexOutOfRangeException) {
                            throw new ArchiveException("Password missing");
                        }
                    }
                }
            }
            finally {
                CloseStreams();
            }
            if (!opened)
            {
                throw new ArchiveException("Invalid archive!");
            }
        }
Esempio n. 14
0
 public override void buildMainFest(ExtractCallback ecb)
 {
     ecb(1, 1);
 }