예제 #1
0
        public void Unzip(string packageZipPath)
        {
            string tempFolderName = $".\\~temp_{Guid.NewGuid()}";

            using (var fs = File.OpenRead(packageZipPath))
            {
                ZipArchive archive = new ZipArchive(fs, ZipArchiveMode.Read);
                archive.ExtractToDirectory(tempFolderName);
            }

            string[] extractedFiles = Directory.GetFiles(tempFolderName);

            foreach (string extractedFilePath in extractedFiles)
            {
                string targetFilePath = $".\\{Path.GetFileName(extractedFilePath)}";
                if (File.Exists(targetFilePath))
                {
                    if (uiService.Ask($"{targetFilePath} already exist, overwrite?"))
                    {
                        File.Copy(extractedFilePath, targetFilePath, true);
                    }
                }
                else
                {
                    File.Copy(extractedFilePath, targetFilePath);
                }
            }

            Directory.Delete(tempFolderName, true);
        }