using ICSharpCode.SharpZipLib.Zip;
using System;
namespace Tiobon.PublishHelper
{
///
/// 压缩文件帮助类
///
public static class ZipHelper
{
///
/// zip压缩文件
///
/// filename生成的文件的名称,如:C\123\123.zip
/// directory要压缩的文件夹路径
///
public static void ZipFiles(string fname, string path)
{
try
{
FastZip fz = new FastZip
{
CreateEmptyDirectories = true
};
fz.CreateZip(fname, path, true, "");
}
catch (Exception ex)
{
Utility.SendLog("压缩", $"压缩文件失败:{ex}");
}
}
///
/// 添加压缩文件注释
///
///
///
public static void SetComment(string fname, string comment)
{
try
{
using (ZipFile entry = new ZipFile(fname))
{
entry.BeginUpdate();
entry.SetComment(comment);
entry.CommitUpdate();
Utility.SendLog("压缩", $"添加注释成功 {fname}");
}
}
catch (Exception ex)
{
Utility.SendLog("压缩", $"添加注释失败:{ex}");
}
}
}
}