Commit ba978659 authored by 罗显健's avatar 罗显健

打包工具:1.增加删除历史包功能。2.代码优化整理。

parent 81d7c65c
...@@ -12,21 +12,49 @@ namespace Ftt.PatchPack ...@@ -12,21 +12,49 @@ namespace Ftt.PatchPack
{ {
#region 私有变量 #region 私有变量
string directory; /// <summary>
string patchName; /// 打包根目录
List<PatchFileInfo> files; /// </summary>
private readonly string mPackBaseDirectory;
/// <summary>
/// 原始包名(不包含追加的日期部分)
/// /// </summary>
private readonly string mOriginalPatchName;
/// <summary>
/// 打包目录 = 根目录 + 本次包名(不含后缀)
/// </summary>
private string mPackDirectory;
/// <summary>
/// 待打包的文件信息
/// </summary>
private List<PatchFileInfo> mFiles;
/// <summary>
/// 是否删除历史包
/// </summary>
private bool mDelHisPack;
#endregion #endregion
/// <summary> /// <summary>
/// 打包目录 /// 文件打包
/// </summary> /// </summary>
/// <param name="directory"></param> /// <param name="directory">目录,文件打包后会在该目录。</param>
public FilePack(string directory, string patchName, List<PatchFileInfo> files) /// <param name="patchName">包名(会自动在后面追加-yyMMddHHmm)</param>
/// <param name="files">打包的文件列表</param>
/// <param name="delHisPack">是否删除该包的历史包</param>
public FilePack(string directory, string patchName, List<PatchFileInfo> files, bool delHisPack = false)
{ {
this.directory = directory; mPackBaseDirectory = directory;
this.patchName = $"{patchName}-{DateTime.Now.ToString("yyMMddHHmm")}"; mOriginalPatchName = patchName;
this.files = files; mFiles = files;
mDelHisPack = delHisPack;
var realPatchName = $"{mOriginalPatchName}-{DateTime.Now.ToString("yyMMddHHmm")}";
mPackDirectory = Path.Combine(mPackBaseDirectory, realPatchName);
} }
...@@ -46,7 +74,7 @@ namespace Ftt.PatchPack ...@@ -46,7 +74,7 @@ namespace Ftt.PatchPack
res = res && Compresion(); res = res && Compresion();
res = res && DeleteFileDirectory(); res = res && DeleteDirectory(mPackDirectory);
return res; return res;
} }
...@@ -59,16 +87,18 @@ namespace Ftt.PatchPack ...@@ -59,16 +87,18 @@ namespace Ftt.PatchPack
#region 私有方法 #region 私有方法
/// <summary> /// <summary>
/// 准备打包目录 /// 准备打包目录.
/// <para>1、该目录已存在,为了保证文件的准确性,先删除整个目录。</para>
/// <para>2、创建一个新的空目录,备用</para>
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
private bool PreparePatchDirectory() private bool PreparePatchDirectory()
{ {
string path = System.IO.Path.Combine(directory, patchName); string path = mPackDirectory;
try try
{ {
DeleteFileDirectory(); DeleteDirectory(path);
if (!Directory.Exists(path)) Directory.CreateDirectory(path); if (!Directory.Exists(path)) Directory.CreateDirectory(path);
} }
...@@ -89,13 +119,13 @@ namespace Ftt.PatchPack ...@@ -89,13 +119,13 @@ namespace Ftt.PatchPack
{ {
try try
{ {
foreach (PatchFileInfo file in files) foreach (PatchFileInfo file in mFiles)
{ {
var path = System.IO.Path.Combine(directory, patchName, file.RelativePatchPath); var path = Path.Combine(mPackDirectory, file.RelativePatchPath);
if (!Directory.Exists(path)) Directory.CreateDirectory(path); if (!Directory.Exists(path)) Directory.CreateDirectory(path);
string destFileName = System.IO.Path.Combine(path, file.Name); string destFileName = Path.Combine(path, file.Name);
File.Copy(file.FullName, destFileName, true); File.Copy(file.FullName, destFileName, true);
} }
...@@ -115,12 +145,16 @@ namespace Ftt.PatchPack ...@@ -115,12 +145,16 @@ namespace Ftt.PatchPack
{ {
try try
{ {
string startPath = Path.Combine(directory, patchName); string zipPath = $"{mPackDirectory}.zip";
string zipPath = $"{Path.Combine(directory, patchName)}.zip";
if (File.Exists(zipPath)) File.Delete(zipPath); if (File.Exists(zipPath)) File.Delete(zipPath);
ZipFile.CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest, false); ZipFile.CreateFromDirectory(mPackDirectory, zipPath, CompressionLevel.Fastest, false);
if (mDelHisPack)
{
DelHistoricalPackage(zipPath);
}
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -131,14 +165,12 @@ namespace Ftt.PatchPack ...@@ -131,14 +165,12 @@ namespace Ftt.PatchPack
} }
/// <summary> /// <summary>
/// 删除 /// 删除目录,并删除该目录中所有子目录和文件
/// </summary> /// </summary>
private bool DeleteFileDirectory() private bool DeleteDirectory(string path)
{ {
try try
{ {
string path = System.IO.Path.Combine(directory, patchName);
if (Directory.Exists(path)) Directory.Delete(path, true); if (Directory.Exists(path)) Directory.Delete(path, true);
return true; return true;
...@@ -149,6 +181,25 @@ namespace Ftt.PatchPack ...@@ -149,6 +181,25 @@ namespace Ftt.PatchPack
} }
} }
/// <summary>
/// 删除该包同名的历史包(名称相同,日期不同)
/// </summary>
/// <param name="newPackName">最新包名,保留该包</param>
/// <returns></returns>
private bool DelHistoricalPackage(string newPackFullName)
{
var hisPack = Directory.GetFiles(mPackBaseDirectory, $"{mOriginalPatchName}-*.zip", SearchOption.TopDirectoryOnly);
Array.ForEach(hisPack, file =>
{
// 新包过滤掉不能删除。
if (file != newPackFullName)
// 能删就删,删不掉不影响打包功能。
try { File.Delete(file); } catch { }
});
return true;
}
#endregion #endregion
} }
} }
...@@ -35,8 +35,9 @@ ...@@ -35,8 +35,9 @@
this.lstProject = new System.Windows.Forms.ListView(); this.lstProject = new System.Windows.Forms.ListView();
this.lblNotes = new System.Windows.Forms.Label(); this.lblNotes = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel(); this.panel1 = new System.Windows.Forms.Panel();
this.btnDel = new System.Windows.Forms.Button(); this.ckbDelHisPack = new System.Windows.Forms.CheckBox();
this.btnOpenDirectory = new System.Windows.Forms.Button(); this.btnOpenDirectory = new System.Windows.Forms.Button();
this.btnDel = new System.Windows.Forms.Button();
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
...@@ -57,7 +58,7 @@ ...@@ -57,7 +58,7 @@
// //
this.btnPatch.BackColor = System.Drawing.SystemColors.Control; this.btnPatch.BackColor = System.Drawing.SystemColors.Control;
this.btnPatch.ForeColor = System.Drawing.SystemColors.WindowText; this.btnPatch.ForeColor = System.Drawing.SystemColors.WindowText;
this.btnPatch.Location = new System.Drawing.Point(358, 15); this.btnPatch.Location = new System.Drawing.Point(358, 4);
this.btnPatch.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.btnPatch.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.btnPatch.Name = "btnPatch"; this.btnPatch.Name = "btnPatch";
this.btnPatch.Size = new System.Drawing.Size(122, 27); this.btnPatch.Size = new System.Drawing.Size(122, 27);
...@@ -110,6 +111,7 @@ ...@@ -110,6 +111,7 @@
// //
// panel1 // panel1
// //
this.panel1.Controls.Add(this.ckbDelHisPack);
this.panel1.Controls.Add(this.btnOpenDirectory); this.panel1.Controls.Add(this.btnOpenDirectory);
this.panel1.Controls.Add(this.btnDel); this.panel1.Controls.Add(this.btnDel);
this.panel1.Controls.Add(this.btnEdit); this.panel1.Controls.Add(this.btnEdit);
...@@ -122,18 +124,19 @@ ...@@ -122,18 +124,19 @@
this.panel1.Size = new System.Drawing.Size(599, 58); this.panel1.Size = new System.Drawing.Size(599, 58);
this.panel1.TabIndex = 12; this.panel1.TabIndex = 12;
// //
// btnDel // ckbDelHisPack
// //
this.btnDel.BackColor = System.Drawing.SystemColors.Control; this.ckbDelHisPack.AutoSize = true;
this.btnDel.ForeColor = System.Drawing.SystemColors.WindowText; this.ckbDelHisPack.BackColor = System.Drawing.SystemColors.Control;
this.btnDel.Location = new System.Drawing.Point(220, 15); this.ckbDelHisPack.Checked = true;
this.btnDel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.ckbDelHisPack.CheckState = System.Windows.Forms.CheckState.Checked;
this.btnDel.Name = "btnDel"; this.ckbDelHisPack.ForeColor = System.Drawing.Color.Blue;
this.btnDel.Size = new System.Drawing.Size(97, 27); this.ckbDelHisPack.Location = new System.Drawing.Point(362, 34);
this.btnDel.TabIndex = 10; this.ckbDelHisPack.Name = "ckbDelHisPack";
this.btnDel.Text = "删除项目"; this.ckbDelHisPack.Size = new System.Drawing.Size(111, 21);
this.btnDel.UseVisualStyleBackColor = false; this.ckbDelHisPack.TabIndex = 12;
this.btnDel.Click += new System.EventHandler(this.btnDel_Click); this.ckbDelHisPack.Text = "删除项目历史包";
this.ckbDelHisPack.UseVisualStyleBackColor = false;
// //
// btnOpenDirectory // btnOpenDirectory
// //
...@@ -148,6 +151,19 @@ ...@@ -148,6 +151,19 @@
this.btnOpenDirectory.UseVisualStyleBackColor = false; this.btnOpenDirectory.UseVisualStyleBackColor = false;
this.btnOpenDirectory.Click += new System.EventHandler(this.btnOpenDirectory_Click); this.btnOpenDirectory.Click += new System.EventHandler(this.btnOpenDirectory_Click);
// //
// btnDel
//
this.btnDel.BackColor = System.Drawing.SystemColors.Control;
this.btnDel.ForeColor = System.Drawing.SystemColors.WindowText;
this.btnDel.Location = new System.Drawing.Point(220, 15);
this.btnDel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.btnDel.Name = "btnDel";
this.btnDel.Size = new System.Drawing.Size(97, 27);
this.btnDel.TabIndex = 10;
this.btnDel.Text = "删除项目";
this.btnDel.UseVisualStyleBackColor = false;
this.btnDel.Click += new System.EventHandler(this.btnDel_Click);
//
// FrmMain // FrmMain
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
...@@ -167,6 +183,7 @@ ...@@ -167,6 +183,7 @@
this.Text = "Feteto更新包辅助工具"; this.Text = "Feteto更新包辅助工具";
this.Load += new System.EventHandler(this.FrmMain_Load); this.Load += new System.EventHandler(this.FrmMain_Load);
this.panel1.ResumeLayout(false); this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
...@@ -180,6 +197,7 @@ ...@@ -180,6 +197,7 @@
private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button btnDel; private System.Windows.Forms.Button btnDel;
private System.Windows.Forms.Button btnOpenDirectory; private System.Windows.Forms.Button btnOpenDirectory;
private System.Windows.Forms.CheckBox ckbDelHisPack;
} }
} }
...@@ -20,6 +20,8 @@ namespace Ftt.PatchPack ...@@ -20,6 +20,8 @@ namespace Ftt.PatchPack
builder.AppendLine("注意:本工具只打包项目设定文件夹内通用文件。如需其他文件请手动打包。"); builder.AppendLine("注意:本工具只打包项目设定文件夹内通用文件。如需其他文件请手动打包。");
builder.AppendLine("默认打包规则:*.dll,*.pdb 两天以内;*.xml,*.sql 30天以内。"); builder.AppendLine("默认打包规则:*.dll,*.pdb 两天以内;*.xml,*.sql 30天以内。");
lblNotes.Text = builder.ToString(); lblNotes.Text = builder.ToString();
new ToolTip().SetToolTip(ckbDelHisPack, "勾选后、可自动清理对应包的历史包文件");
} }
...@@ -119,7 +121,7 @@ namespace Ftt.PatchPack ...@@ -119,7 +121,7 @@ namespace Ftt.PatchPack
try try
{ {
var files = project.GetAllPathFiles(); var files = project.GetAllPathFiles();
FilePack patch = new FilePack(AppDomain.CurrentDomain.BaseDirectory, project.Name, files); FilePack patch = new FilePack(AppDomain.CurrentDomain.BaseDirectory, project.Name, files, ckbDelHisPack.Checked);
patch.Pack(); patch.Pack();
item.Checked = false; item.Checked = false;
......
...@@ -117,6 +117,36 @@ ...@@ -117,6 +117,36 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="btnAdd.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="btnPatch.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="btnEdit.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="lstProject.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="lblNotes.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="panel1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ckbDelHisPack.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="btnOpenDirectory.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="btnDel.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
......
...@@ -11,8 +11,10 @@ namespace Ftt.PatchPack ...@@ -11,8 +11,10 @@ namespace Ftt.PatchPack
{ {
#region 属性定义 #region 属性定义
/// <summary>
private string exeName; /// exe 文件名
/// </summary>
private string mExeName;
/// <summary> /// <summary>
...@@ -28,11 +30,11 @@ namespace Ftt.PatchPack ...@@ -28,11 +30,11 @@ namespace Ftt.PatchPack
{ {
get get
{ {
if (string.IsNullOrEmpty(exeName)) exeName = "U6"; if (string.IsNullOrEmpty(mExeName)) mExeName = "U6";
return exeName; return mExeName;
} }
set { exeName = value; } set { mExeName = value; }
} }
...@@ -203,7 +205,6 @@ namespace Ftt.PatchPack ...@@ -203,7 +205,6 @@ namespace Ftt.PatchPack
} }
/// <summary> /// <summary>
/// 获取据库脚本补丁,返回有效的文件夹,一个月以内 /// 获取据库脚本补丁,返回有效的文件夹,一个月以内
/// </summary> /// </summary>
...@@ -343,8 +344,6 @@ namespace Ftt.PatchPack ...@@ -343,8 +344,6 @@ namespace Ftt.PatchPack
/// <summary> /// <summary>
/// 帮助类 /// 帮助类
/// </summary> /// </summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment