Test.EIImageViewer
parent
9f6e32d9be
commit
92dc65fa4f
|
@ -22,11 +22,14 @@ using System.IO;
|
||||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
|
||||||
using System.Management.Automation.Host;
|
using System.Management.Automation.Host;
|
||||||
using SharpCompress.Common;
|
using SharpCompress.Common;
|
||||||
using System.IO.Compression;
|
|
||||||
using MaterialSkin2DotNet.Controls;
|
using MaterialSkin2DotNet.Controls;
|
||||||
using MaterialSkin2DotNet;
|
using MaterialSkin2DotNet;
|
||||||
using Renci.SshNet.Compression;
|
using Renci.SshNet.Compression;
|
||||||
using SharpCompress.Archives;
|
using SharpCompress.Archives;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using SharpCompress.Writers;
|
||||||
|
using SharpCompress.Writers.Zip;
|
||||||
|
using SharpCompress.Archives.Zip;
|
||||||
|
|
||||||
namespace PublishSite
|
namespace PublishSite
|
||||||
{
|
{
|
||||||
|
@ -330,7 +333,7 @@ namespace PublishSite
|
||||||
|
|
||||||
if (stopServiceCommand.ExitStatus != 0)
|
if (stopServiceCommand.ExitStatus != 0)
|
||||||
{
|
{
|
||||||
WinformLog($"Failed to stop {serviceName}.",Color.Red);
|
WinformLog($"Failed to stop {serviceName}.", Color.Red);
|
||||||
}
|
}
|
||||||
|
|
||||||
Task.Delay(1000);
|
Task.Delay(1000);
|
||||||
|
@ -643,7 +646,7 @@ namespace PublishSite
|
||||||
{
|
{
|
||||||
//startServiceBtn.Enabled = false;
|
//startServiceBtn.Enabled = false;
|
||||||
|
|
||||||
|
|
||||||
uiContext.Post((state) =>
|
uiContext.Post((state) =>
|
||||||
{
|
{
|
||||||
// 访问控件并更新它们
|
// 访问控件并更新它们
|
||||||
|
@ -1027,49 +1030,58 @@ namespace PublishSite
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//await Task.Run( () =>
|
await Task.Run(() =>
|
||||||
//{
|
{
|
||||||
//将文件夹里的内容打包成压缩包
|
//ZipFile.CreateFromDirectory(localSourceFolder, filePath, CompressionLevel.Fastest, false);
|
||||||
//ZipFile.CreateFromDirectory(localSourceFolder, filePath,CompressionLevel.Fastest,true);
|
|
||||||
|
|
||||||
//Compress - Archive - Path "C:\Users\username\Documents\myfolder" - DestinationPath "C:\Users\username\Documents\myfolder.zip" - Force
|
|
||||||
|
|
||||||
//var processStartInfo = new ProcessStartInfo
|
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())
|
||||||
//{
|
//{
|
||||||
// FileName = "cmd.exe",
|
// // 设置PowerShell执行策略为Bypass以允许运行脚本
|
||||||
// RedirectStandardInput = true,
|
// powerShell.AddScript("Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass");
|
||||||
// UseShellExecute = false,
|
|
||||||
// CreateNoWindow = true
|
|
||||||
//};
|
|
||||||
|
|
||||||
//using (var process = new Process { StartInfo = processStartInfo })
|
// // 构造压缩命令
|
||||||
//{
|
// string compressCommand = String.Format("Compress-Archive -Path \"{0}\" -DestinationPath \"{1}\"", localSourceFolder, filePath);
|
||||||
// process.Start();
|
|
||||||
|
|
||||||
// using (var writer = process.StandardInput)
|
// // 添加压缩命令到PowerShell对象中
|
||||||
|
// powerShell.AddScript(compressCommand);
|
||||||
|
|
||||||
|
// WinformLog(compressCommand);
|
||||||
|
|
||||||
|
// try
|
||||||
// {
|
// {
|
||||||
// if (writer.BaseStream.CanWrite)
|
// // 执行PowerShell脚本
|
||||||
|
// Collection<PSObject> results = powerShell.Invoke();
|
||||||
|
|
||||||
|
// foreach (var result in results)
|
||||||
// {
|
// {
|
||||||
// // 执行命令:Compress-Archive -Path <sourceFolderPath> -DestinationPath <destinationZipPath> -Force
|
// WinformLog(result.ToString());
|
||||||
|
|
||||||
// var cmdCompress = $"Compress-Archive -Path \"{localSourceFolder}\" -DestinationPath \"{filePath}\" -Force";
|
|
||||||
// writer.WriteLine(cmdCompress);
|
|
||||||
|
|
||||||
// WinformLog(cmdCompress);
|
|
||||||
// writer.Close();
|
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
// catch (Exception ex)
|
||||||
// process.WaitForExit();
|
|
||||||
|
|
||||||
// if (process.ExitCode != 0)
|
|
||||||
// {
|
// {
|
||||||
// // 处理错误
|
// WinformLog(ex.Message);
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
WinformLog("文件已成功压缩为 " + filePath);
|
||||||
|
|
||||||
//});
|
});
|
||||||
|
|
||||||
WinformLog($"打包结束");
|
WinformLog($"打包结束");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue