コード例 #1
0
 private void gameExtractProgressChanged(object sender, ExtractProgressChangedEventArgs e)
 {
     lblStatus.Text   = $"Extracting... ({e.Progress}%)";
     pbProgress.Value = e.Progress;
 }
コード例 #2
0
        private async Task Start()
        {
            /*if (!Utils.hasWriteAccessToFolder(Path.GetDirectoryName(Path.GetFullPath(DestDir))))
             * {
             *  Utils.StartApplicationInAdminMode();
             *  return;
             * }*/

            ExtractProgressChangedEventHandler handler = ExtractProgressChanged;
            DirectoryInfo di = Directory.CreateDirectory(DestDir);
            string        destinationDirectoryFullpath = di.FullName;
            ZipArchive    source = ZipFile.OpenRead(ZipName);
            int           count  = 0;

            foreach (ZipArchiveEntry entry in source.Entries)
            {
                count++;
                string fileDestinationPath = Path.GetFullPath(Path.Combine(destinationDirectoryFullpath, entry.FullName));

                if (!fileDestinationPath.StartsWith(destinationDirectoryFullpath, StringComparison.OrdinalIgnoreCase))
                {
                    throw new IOException("File is extracting to outside of the folder specified.");
                }

                if (Path.GetFileName(fileDestinationPath).Length == 0)
                {
                    if (entry.Length != 0)
                    {
                        throw new IOException("Directory entry with data.");
                    }

                    Directory.CreateDirectory(fileDestinationPath);
                }
                else
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(fileDestinationPath));
                    await Task.Run(() => { entry.ExtractToFile(fileDestinationPath, overwrite: true); });
                }

                ExtractProgressChangedEventArgs args = new ExtractProgressChangedEventArgs(count, source.Entries.Count, entry);

                if (handler != null)
                {
                    handler?.Invoke(this, args);
                }
            }

            EventHandler eventHandler = ExtractCompleted;

            if (eventHandler != null)
            {
                eventHandler?.Invoke(this, new EventArgs());
            }

            source.Dispose();

            if (DeleteZip)
            {
                File.Delete(ZipName);
            }
        }