修改发布
parent
ba3964ccb6
commit
5cc93d4b3c
|
@ -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<PSObject> 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);
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue