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

[13617]打包工具优化--增加合并sql

parent ba337e9e
using System.IO;
using System.Text;
namespace Ftt.PatchPack
{
public class EncodingHelper
{
#region 文件编码相关
/// <summary>
/// 获取文件的编码格式
/// </summary>
public static Encoding GetEncoding(string fileName)
{
using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
Encoding r = GetEncoding(fs);
fs.Close();
return r;
}
}
/// <summary>
/// 通过给定的文件流,判断文件的编码类型
/// </summary>
/// <param name="fs">文件流</param>
/// <returns>文件的编码类型</returns>
public static Encoding GetEncoding(FileStream fs)
{
//文件的字符集在Windows下有两种,一种是ANSI,一种Unicode。
//对于Unicode,Windows支持了它的三种编码方式,一种是小尾编码(Unicode),一种是大尾编码(BigEndianUnicode),一种是UTF - 8编码。
//byte[] Unicode = new byte[] { 0xFF, 0xFE };
//byte[] UnicodeBIG = new byte[] { 0xFE, 0xFF };
//byte[] UTF8 = new byte[] { 0xEF, 0xBB, 0xBF }; //BOM头
if (fs.Length < 3)
return Encoding.Default;
byte[] bytes = new byte[3];
fs.Read(bytes, 0, 3);
Encoding reVal = Encoding.GetEncoding("GB2312");
if (bytes[0] == 0xFE && bytes[1] == 0xFF)
{
reVal = Encoding.BigEndianUnicode;
}
else if (bytes[0] == 0xFF && bytes[1] == 0xFE)
{
reVal = Encoding.Unicode;
}
else
{
if (!(bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF))
{
fs.Position = 0;
}
if (IsUTF8Bytes(fs))
{
if (bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF)
reVal = new UTF8Encoding(false);
else
reVal = Encoding.UTF8;
}
}
return reVal;
}
private static byte UTF8_BYTE_MASK = 0b1100_0000;
private static byte UTF8_BYTE_VALID = 0b1000_0000;
private static bool IsUTF8Bytes(FileStream fs)
{
//BinaryReader r = new BinaryReader(fs);
byte[] bytes = new byte[1];
fs.Read(bytes, 0, 1);
//1字节 0xxxxxxx
//2字节 110xxxxx 10xxxxxx
//3字节 1110xxxx 10xxxxxx 10xxxxxx
//4字节 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
//5字节 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
//6字节 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
while (fs.Read(bytes, 0, 1) > 0)
{
if (bytes[0] < 0x80)
continue;
int cnt = 0;
byte b = bytes[0];
while ((b & 0b1000_0000) != 0)
{
cnt++;
b <<= 1;
}
cnt -= 1;
for (int i = 0; i < cnt; i++)
{
if (fs.Read(bytes, 0, 1) <= 0)
return false;
if ((bytes[0] & UTF8_BYTE_MASK) != UTF8_BYTE_VALID)
return false;
}
}
return true;
}
#endregion
/// <summary>
/// 读取文件内容
/// </summary>
/// <param name="filePath"></param>
/// <param name="encoding"></param>
/// <returns></returns>
public static string ReadAllText(string filePath, out Encoding encoding)
{
encoding = EncodingHelper.GetEncoding(filePath);
return File.ReadAllText(filePath, encoding);
}
}
}
...@@ -74,14 +74,16 @@ namespace Ftt.PatchPack ...@@ -74,14 +74,16 @@ namespace Ftt.PatchPack
res = res && Compresion(); res = res && Compresion();
res = res && DeleteDirectory(mPackDirectory);
return res; return res;
} }
catch (Exception ex) catch (Exception ex)
{ {
throw ex; throw ex;
} }
finally
{
ProjectHelp.DeleteDirectoryIfExists(mPackDirectory);
}
} }
#region 私有方法 #region 私有方法
...@@ -98,7 +100,7 @@ namespace Ftt.PatchPack ...@@ -98,7 +100,7 @@ namespace Ftt.PatchPack
try try
{ {
DeleteDirectory(path); ProjectHelp.DeleteDirectoryIfExists(path);
if (!Directory.Exists(path)) Directory.CreateDirectory(path); if (!Directory.Exists(path)) Directory.CreateDirectory(path);
} }
...@@ -167,22 +169,7 @@ namespace Ftt.PatchPack ...@@ -167,22 +169,7 @@ namespace Ftt.PatchPack
return true; return true;
} }
/// <summary>
/// 删除目录,并删除该目录中所有子目录和文件
/// </summary>
private bool DeleteDirectory(string path)
{
try
{
if (Directory.Exists(path)) Directory.Delete(path, true);
return true;
}
catch (Exception ex)
{
throw new Exception($"删除文件夹失败:{ex.Message}");
}
}
/// <summary> /// <summary>
/// 删除该包同名的历史包(名称相同,日期不同) /// 删除该包同名的历史包(名称相同,日期不同)
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
this.pnlLeft = new System.Windows.Forms.Panel(); this.pnlLeft = new System.Windows.Forms.Panel();
this.gpbLog = new System.Windows.Forms.GroupBox(); this.gpbLog = new System.Windows.Forms.GroupBox();
this.txtLog = new System.Windows.Forms.TextBox(); this.txtLog = new System.Windows.Forms.TextBox();
this.ckbMergeSql = new System.Windows.Forms.CheckBox();
this.pnlTop.SuspendLayout(); this.pnlTop.SuspendLayout();
this.pnlLeft.SuspendLayout(); this.pnlLeft.SuspendLayout();
this.gpbLog.SuspendLayout(); this.gpbLog.SuspendLayout();
...@@ -99,7 +100,7 @@ ...@@ -99,7 +100,7 @@
this.lstProject.RightToLeft = System.Windows.Forms.RightToLeft.No; this.lstProject.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.lstProject.RightToLeftLayout = true; this.lstProject.RightToLeftLayout = true;
this.lstProject.ShowGroups = false; this.lstProject.ShowGroups = false;
this.lstProject.Size = new System.Drawing.Size(573, 231); this.lstProject.Size = new System.Drawing.Size(672, 231);
this.lstProject.TabIndex = 10; this.lstProject.TabIndex = 10;
this.lstProject.UseCompatibleStateImageBehavior = false; this.lstProject.UseCompatibleStateImageBehavior = false;
this.lstProject.View = System.Windows.Forms.View.List; this.lstProject.View = System.Windows.Forms.View.List;
...@@ -111,12 +112,13 @@ ...@@ -111,12 +112,13 @@
this.lblNotes.Location = new System.Drawing.Point(0, 289); this.lblNotes.Location = new System.Drawing.Point(0, 289);
this.lblNotes.Name = "lblNotes"; this.lblNotes.Name = "lblNotes";
this.lblNotes.Padding = new System.Windows.Forms.Padding(12, 8, 0, 0); this.lblNotes.Padding = new System.Windows.Forms.Padding(12, 8, 0, 0);
this.lblNotes.Size = new System.Drawing.Size(573, 52); this.lblNotes.Size = new System.Drawing.Size(672, 52);
this.lblNotes.TabIndex = 11; this.lblNotes.TabIndex = 11;
this.lblNotes.Text = "注意:本工具只打包项目设定文件夹内通用文件。。。。。详细内容见源代码"; this.lblNotes.Text = "注意:本工具只打包项目设定文件夹内通用文件。。。。。详细内容见源代码";
// //
// pnlTop // pnlTop
// //
this.pnlTop.Controls.Add(this.ckbMergeSql);
this.pnlTop.Controls.Add(this.ckbShowLog); this.pnlTop.Controls.Add(this.ckbShowLog);
this.pnlTop.Controls.Add(this.ckbDelHisPack); this.pnlTop.Controls.Add(this.ckbDelHisPack);
this.pnlTop.Controls.Add(this.btnOpenDirectory); this.pnlTop.Controls.Add(this.btnOpenDirectory);
...@@ -128,7 +130,7 @@ ...@@ -128,7 +130,7 @@
this.pnlTop.Location = new System.Drawing.Point(0, 0); this.pnlTop.Location = new System.Drawing.Point(0, 0);
this.pnlTop.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pnlTop.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.pnlTop.Name = "pnlTop"; this.pnlTop.Name = "pnlTop";
this.pnlTop.Size = new System.Drawing.Size(573, 58); this.pnlTop.Size = new System.Drawing.Size(672, 58);
this.pnlTop.TabIndex = 12; this.pnlTop.TabIndex = 12;
// //
// ckbShowLog // ckbShowLog
...@@ -192,16 +194,16 @@ ...@@ -192,16 +194,16 @@
this.pnlLeft.Dock = System.Windows.Forms.DockStyle.Fill; this.pnlLeft.Dock = System.Windows.Forms.DockStyle.Fill;
this.pnlLeft.Location = new System.Drawing.Point(0, 0); this.pnlLeft.Location = new System.Drawing.Point(0, 0);
this.pnlLeft.Name = "pnlLeft"; this.pnlLeft.Name = "pnlLeft";
this.pnlLeft.Size = new System.Drawing.Size(573, 341); this.pnlLeft.Size = new System.Drawing.Size(672, 341);
this.pnlLeft.TabIndex = 13; this.pnlLeft.TabIndex = 13;
// //
// gpbLog // gpbLog
// //
this.gpbLog.Controls.Add(this.txtLog); this.gpbLog.Controls.Add(this.txtLog);
this.gpbLog.Dock = System.Windows.Forms.DockStyle.Right; this.gpbLog.Dock = System.Windows.Forms.DockStyle.Right;
this.gpbLog.Location = new System.Drawing.Point(573, 0); this.gpbLog.Location = new System.Drawing.Point(672, 0);
this.gpbLog.Name = "gpbLog"; this.gpbLog.Name = "gpbLog";
this.gpbLog.Size = new System.Drawing.Size(360, 341); this.gpbLog.Size = new System.Drawing.Size(352, 341);
this.gpbLog.TabIndex = 0; this.gpbLog.TabIndex = 0;
this.gpbLog.TabStop = false; this.gpbLog.TabStop = false;
this.gpbLog.Text = "************** 操作日志 **************"; this.gpbLog.Text = "************** 操作日志 **************";
...@@ -212,14 +214,26 @@ ...@@ -212,14 +214,26 @@
this.txtLog.Location = new System.Drawing.Point(3, 19); this.txtLog.Location = new System.Drawing.Point(3, 19);
this.txtLog.Multiline = true; this.txtLog.Multiline = true;
this.txtLog.Name = "txtLog"; this.txtLog.Name = "txtLog";
this.txtLog.Size = new System.Drawing.Size(354, 319); this.txtLog.Size = new System.Drawing.Size(346, 319);
this.txtLog.TabIndex = 0; this.txtLog.TabIndex = 0;
// //
// ckbMergeSql
//
this.ckbMergeSql.AutoSize = true;
this.ckbMergeSql.BackColor = System.Drawing.SystemColors.Control;
this.ckbMergeSql.ForeColor = System.Drawing.Color.Blue;
this.ckbMergeSql.Location = new System.Drawing.Point(573, 33);
this.ckbMergeSql.Name = "ckbMergeSql";
this.ckbMergeSql.Size = new System.Drawing.Size(93, 21);
this.ckbMergeSql.TabIndex = 14;
this.ckbMergeSql.Text = "合并Sql脚本";
this.ckbMergeSql.UseVisualStyleBackColor = false;
//
// FrmMain // FrmMain
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(933, 341); this.ClientSize = new System.Drawing.Size(1024, 341);
this.Controls.Add(this.pnlLeft); this.Controls.Add(this.pnlLeft);
this.Controls.Add(this.gpbLog); this.Controls.Add(this.gpbLog);
this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
...@@ -255,6 +269,7 @@ ...@@ -255,6 +269,7 @@
private System.Windows.Forms.CheckBox ckbShowLog; private System.Windows.Forms.CheckBox ckbShowLog;
private System.Windows.Forms.GroupBox gpbLog; private System.Windows.Forms.GroupBox gpbLog;
private System.Windows.Forms.TextBox txtLog; private System.Windows.Forms.TextBox txtLog;
private System.Windows.Forms.CheckBox ckbMergeSql;
} }
} }
...@@ -9,9 +9,6 @@ namespace Ftt.PatchPack ...@@ -9,9 +9,6 @@ namespace Ftt.PatchPack
{ {
public partial class FrmMain : Form public partial class FrmMain : Form
{ {
private const int WIDTH_LOG_AREA = 360;
Dictionary<string, Project> projects = new Dictionary<string, Project>(); Dictionary<string, Project> projects = new Dictionary<string, Project>();
/// <summary> /// <summary>
...@@ -30,6 +27,7 @@ namespace Ftt.PatchPack ...@@ -30,6 +27,7 @@ namespace Ftt.PatchPack
lblNotes.Text = builder.ToString(); lblNotes.Text = builder.ToString();
new ToolTip().SetToolTip(ckbDelHisPack, "勾选后、可自动清理对应包的历史包文件"); new ToolTip().SetToolTip(ckbDelHisPack, "勾选后、可自动清理对应包的历史包文件");
new ToolTip().SetToolTip(ckbMergeSql, "合并未使用Use XX指令的脚本,Use指令的脚本文件独立存在并间隔合并操作。");
} }
...@@ -41,7 +39,6 @@ namespace Ftt.PatchPack ...@@ -41,7 +39,6 @@ namespace Ftt.PatchPack
private void InitForm() private void InitForm()
{ {
gpbLog.Width = WIDTH_LOG_AREA;
LogVisible(false); LogVisible(false);
projects = ProjectHelp.Read(); projects = ProjectHelp.Read();
...@@ -124,6 +121,7 @@ namespace Ftt.PatchPack ...@@ -124,6 +121,7 @@ namespace Ftt.PatchPack
int success = 0; int success = 0;
Cursor.Current = Cursors.WaitCursor; Cursor.Current = Cursors.WaitCursor;
Project.MergeSqlFile = ckbMergeSql.Checked;
foreach (ListViewItem item in items) foreach (ListViewItem item in items)
{ {
...@@ -149,6 +147,7 @@ namespace Ftt.PatchPack ...@@ -149,6 +147,7 @@ namespace Ftt.PatchPack
} }
finally finally
{ {
ProjectHelp.DeleteDirectoryIfExists(project.MergeSqlTempFullPath);
Application.DoEvents(); Application.DoEvents();
} }
} }
......
...@@ -70,6 +70,7 @@ ...@@ -70,6 +70,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="EncodingHelper.cs" />
<Compile Include="FilePatch.cs" /> <Compile Include="FilePatch.cs" />
<Compile Include="FrmMain.cs"> <Compile Include="FrmMain.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
......
This diff is collapsed.
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