Battlelogium.Installer.InstallerCommon.ExtractZipFile C# (CSharp) Method

ExtractZipFile() public static method

public static ExtractZipFile ( string fileName, string extractPath ) : System.Threading.Tasks.Task
fileName string
extractPath string
return System.Threading.Tasks.Task
        public static async Task ExtractZipFile(string fileName, string extractPath)
        {
            await Task.Run(() =>
            {
                using (ZipArchive package = ZipFile.OpenRead(fileName))
                {
                    foreach (var entry in package.Entries)
                    {
                        string fullPath = Path.Combine(extractPath, entry.FullName);
                        if(!Directory.Exists(Path.GetDirectoryName(fullPath))){
                            try
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
                            }catch (IOException){
                                
                            }
                        }
                        if (String.IsNullOrEmpty(entry.Name))
                        {
                            Directory.CreateDirectory(fullPath);
                        }
                        else
                        {
                            try
                            {
                                entry.ExtractToFile(fullPath, true);
                            }
                            catch (IOException ex)
                            {
                                Console.WriteLine(ex);
                            }
                        }
                    }
                }
            });

        }

Usage Example

        internal async Task BeginUpdate()
        {
            this.DownloadComplete += async(s, e) =>
            {
                await InstallerCommon.ExtractZipFile(e.completedFilePath, installPath);

                var completed = new UIComplete(installPath);
                completed.Show();
                completed.Activate();
                this.SyncCloseWindow();
            };
            this.Show();
            this.Start();
        }