Commit 68e8c561 authored by 段廷瑞's avatar 段廷瑞

Merge branch 'master' of http://192.168.1.181/root/Ftt_Common

parents d431b54d ba978659
......@@ -12,21 +12,49 @@ namespace Ftt.PatchPack
{
#region 私有变量
string directory;
string patchName;
List<PatchFileInfo> files;
/// <summary>
/// 打包根目录
/// </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
/// <summary>
/// 打包目录
/// 文件打包
/// </summary>
/// <param name="directory"></param>
public FilePack(string directory, string patchName, List<PatchFileInfo> files)
/// <param name="directory">目录,文件打包后会在该目录。</param>
/// <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;
this.patchName = $"{patchName}-{DateTime.Now.ToString("yyMMddHHmm")}";
this.files = files;
mPackBaseDirectory = directory;
mOriginalPatchName = patchName;
mFiles = files;
mDelHisPack = delHisPack;
var realPatchName = $"{mOriginalPatchName}-{DateTime.Now.ToString("yyMMddHHmm")}";
mPackDirectory = Path.Combine(mPackBaseDirectory, realPatchName);
}
......@@ -46,7 +74,7 @@ namespace Ftt.PatchPack
res = res && Compresion();
res = res && DeleteFileDirectory();
res = res && DeleteDirectory(mPackDirectory);
return res;
}
......@@ -59,16 +87,18 @@ namespace Ftt.PatchPack
#region 私有方法
/// <summary>
/// 准备打包目录
/// 准备打包目录.
/// <para>1、该目录已存在,为了保证文件的准确性,先删除整个目录。</para>
/// <para>2、创建一个新的空目录,备用</para>
/// </summary>
/// <returns></returns>
private bool PreparePatchDirectory()
{
string path = System.IO.Path.Combine(directory, patchName);
string path = mPackDirectory;
try
{
DeleteFileDirectory();
DeleteDirectory(path);
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
}
......@@ -89,13 +119,13 @@ namespace Ftt.PatchPack
{
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);
string destFileName = System.IO.Path.Combine(path, file.Name);
string destFileName = Path.Combine(path, file.Name);
File.Copy(file.FullName, destFileName, true);
}
......@@ -115,12 +145,16 @@ namespace Ftt.PatchPack
{
try
{
string startPath = Path.Combine(directory, patchName);
string zipPath = $"{Path.Combine(directory, patchName)}.zip";
string zipPath = $"{mPackDirectory}.zip";
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)
{
......@@ -131,14 +165,12 @@ namespace Ftt.PatchPack
}
/// <summary>
/// 删除
/// 删除目录,并删除该目录中所有子目录和文件
/// </summary>
private bool DeleteFileDirectory()
private bool DeleteDirectory(string path)
{
try
{
string path = System.IO.Path.Combine(directory, patchName);
if (Directory.Exists(path)) Directory.Delete(path, true);
return true;
......@@ -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
}
}
......@@ -35,8 +35,9 @@
this.lstProject = new System.Windows.Forms.ListView();
this.lblNotes = new System.Windows.Forms.Label();
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.btnDel = new System.Windows.Forms.Button();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
......@@ -57,7 +58,7 @@
//
this.btnPatch.BackColor = System.Drawing.SystemColors.Control;
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.Name = "btnPatch";
this.btnPatch.Size = new System.Drawing.Size(122, 27);
......@@ -110,6 +111,7 @@
//
// panel1
//
this.panel1.Controls.Add(this.ckbDelHisPack);
this.panel1.Controls.Add(this.btnOpenDirectory);
this.panel1.Controls.Add(this.btnDel);
this.panel1.Controls.Add(this.btnEdit);
......@@ -122,18 +124,19 @@
this.panel1.Size = new System.Drawing.Size(599, 58);
this.panel1.TabIndex = 12;
//
// btnDel
// ckbDelHisPack
//
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);
this.ckbDelHisPack.AutoSize = true;
this.ckbDelHisPack.BackColor = System.Drawing.SystemColors.Control;
this.ckbDelHisPack.Checked = true;
this.ckbDelHisPack.CheckState = System.Windows.Forms.CheckState.Checked;
this.ckbDelHisPack.ForeColor = System.Drawing.Color.Blue;
this.ckbDelHisPack.Location = new System.Drawing.Point(362, 34);
this.ckbDelHisPack.Name = "ckbDelHisPack";
this.ckbDelHisPack.Size = new System.Drawing.Size(111, 21);
this.ckbDelHisPack.TabIndex = 12;
this.ckbDelHisPack.Text = "删除项目历史包";
this.ckbDelHisPack.UseVisualStyleBackColor = false;
//
// btnOpenDirectory
//
......@@ -148,6 +151,19 @@
this.btnOpenDirectory.UseVisualStyleBackColor = false;
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
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
......@@ -167,6 +183,7 @@
this.Text = "Feteto更新包辅助工具";
this.Load += new System.EventHandler(this.FrmMain_Load);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false);
}
......@@ -180,6 +197,7 @@
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button btnDel;
private System.Windows.Forms.Button btnOpenDirectory;
private System.Windows.Forms.CheckBox ckbDelHisPack;
}
}
......@@ -20,6 +20,8 @@ namespace Ftt.PatchPack
builder.AppendLine("注意:本工具只打包项目设定文件夹内通用文件。如需其他文件请手动打包。");
builder.AppendLine("默认打包规则:*.dll,*.pdb 两天以内;*.xml,*.sql 30天以内。");
lblNotes.Text = builder.ToString();
new ToolTip().SetToolTip(ckbDelHisPack, "勾选后、可自动清理对应包的历史包文件");
}
......@@ -119,7 +121,7 @@ namespace Ftt.PatchPack
try
{
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();
item.Checked = false;
......
......@@ -117,6 +117,36 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</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" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
......
......@@ -11,8 +11,10 @@ namespace Ftt.PatchPack
{
#region 属性定义
private string exeName;
/// <summary>
/// exe 文件名
/// </summary>
private string mExeName;
/// <summary>
......@@ -28,11 +30,11 @@ namespace Ftt.PatchPack
{
get
{
if (string.IsNullOrEmpty(exeName)) exeName = "U6";
return exeName;
if (string.IsNullOrEmpty(mExeName)) mExeName = "U6";
return mExeName;
}
set { exeName = value; }
set { mExeName = value; }
}
......@@ -102,7 +104,7 @@ namespace Ftt.PatchPack
var files = strContainFiles.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var file in files) if (!ContainFiles.Contains(file)) ContainFiles.Add(file);
}
Int32.TryParse(ConfigurationManager.AppSettings["PatchTimeFrame_Dll"], out PatchTimeFrame_Dll);
Int32.TryParse(ConfigurationManager.AppSettings["PatchTimeFrame_Sql"], out PatchTimeFrame_Sql);
Int32.TryParse(ConfigurationManager.AppSettings["PatchTimeFrame_Xml"], out PatchTimeFrame_Xml);
......@@ -203,7 +205,6 @@ namespace Ftt.PatchPack
}
/// <summary>
/// 获取据库脚本补丁,返回有效的文件夹,一个月以内
/// </summary>
......@@ -343,8 +344,6 @@ namespace Ftt.PatchPack
/// <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