diff --git a/PublishSite/PublishForm.cs b/PublishSite/PublishForm.cs index 49989ede..304817a7 100644 --- a/PublishSite/PublishForm.cs +++ b/PublishSite/PublishForm.cs @@ -1035,50 +1035,18 @@ namespace PublishSite //ZipFile.CreateFromDirectory(localSourceFolder, filePath, CompressionLevel.Fastest, false); - //var files = Directory.GetFiles(localSourceFolder, "*", SearchOption.AllDirectories); + var files = Directory.GetFiles(localSourceFolder, "*", SearchOption.AllDirectories); - //using (var fs = new FileStream(outputPath, FileMode.Create)) - //{ - // using (var archive = new ZipArchive()) - // { - // foreach (var file in files) - // { - // var entry = archive.AddEntry(Path.GetRelativePath(dirPath, file), file); - // entry.CompressionType = CompressionType.Deflate; - // } - - // archive.SaveTo(fs, new WriterOptions(CompressionType.Deflate)); - // } - //} - //using (PowerShell powerShell = PowerShell.Create()) - //{ - // // 设置PowerShell执行策略为Bypass以允许运行脚本 - // powerShell.AddScript("Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass"); - - // // 构造压缩命令 - // string compressCommand = String.Format("Compress-Archive -Path \"{0}\" -DestinationPath \"{1}\"", localSourceFolder, filePath); - - // // 添加压缩命令到PowerShell对象中 - // powerShell.AddScript(compressCommand); - - // WinformLog(compressCommand); - - // try - // { - // // 执行PowerShell脚本 - // Collection results = powerShell.Invoke(); - - // foreach (var result in results) - // { - // WinformLog(result.ToString()); - // } - // } - // catch (Exception ex) - // { - // WinformLog(ex.Message); - // } - //} + using (var archive = ZipArchive.Create()) + { + foreach (var file in files) + { + archive.AddEntry(Path.GetRelativePath(localSourceFolder, file), file); + } + archive.SaveTo(filePath, new WriterOptions(CompressionType.Deflate)); + } + WinformLog("文件已成功压缩为 " + filePath); });