Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
Ftt_Common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Ftt_Common
Commits
fc5d15e5
Commit
fc5d15e5
authored
Jan 13, 2024
by
罗显健
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[13617]打包工具优化--增加合并sql
parent
ba337e9e
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
283 additions
and
59 deletions
+283
-59
EncodingHelper.cs
Ftt.PatchPack/EncodingHelper.cs
+124
-0
FilePatch.cs
Ftt.PatchPack/FilePatch.cs
+5
-18
FrmMain.Designer.cs
Ftt.PatchPack/FrmMain.Designer.cs
+23
-8
FrmMain.cs
Ftt.PatchPack/FrmMain.cs
+3
-4
Ftt.PatchPack.csproj
Ftt.PatchPack/Ftt.PatchPack.csproj
+1
-0
Project.cs
Ftt.PatchPack/Project.cs
+127
-29
No files found.
Ftt.PatchPack/EncodingHelper.cs
0 → 100644
View file @
fc5d15e5
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
=
0
b1100_0000
;
private
static
byte
UTF8_BYTE_VALID
=
0
b1000_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
&
0
b1000_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
);
}
}
}
Ftt.PatchPack/FilePatch.cs
View file @
fc5d15e5
...
...
@@ -74,14 +74,16 @@ namespace Ftt.PatchPack
res
=
res
&&
Compresion
();
res
=
res
&&
DeleteDirectory
(
mPackDirectory
);
return
res
;
}
catch
(
Exception
ex
)
{
throw
ex
;
}
finally
{
ProjectHelp
.
DeleteDirectoryIfExists
(
mPackDirectory
);
}
}
#
region
私有方法
...
...
@@ -98,7 +100,7 @@ namespace Ftt.PatchPack
try
{
DeleteDirectory
(
path
);
ProjectHelp
.
DeleteDirectoryIfExists
(
path
);
if
(!
Directory
.
Exists
(
path
))
Directory
.
CreateDirectory
(
path
);
}
...
...
@@ -167,22 +169,7 @@ namespace Ftt.PatchPack
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>
/// 删除该包同名的历史包(名称相同,日期不同)
...
...
Ftt.PatchPack/FrmMain.Designer.cs
View file @
fc5d15e5
...
...
@@ -42,6 +42,7 @@
this
.
pnlLeft
=
new
System
.
Windows
.
Forms
.
Panel
();
this
.
gpbLog
=
new
System
.
Windows
.
Forms
.
GroupBox
();
this
.
txtLog
=
new
System
.
Windows
.
Forms
.
TextBox
();
this
.
ckbMergeSql
=
new
System
.
Windows
.
Forms
.
CheckBox
();
this
.
pnlTop
.
SuspendLayout
();
this
.
pnlLeft
.
SuspendLayout
();
this
.
gpbLog
.
SuspendLayout
();
...
...
@@ -99,7 +100,7 @@
this
.
lstProject
.
RightToLeft
=
System
.
Windows
.
Forms
.
RightToLeft
.
No
;
this
.
lstProject
.
RightToLeftLayout
=
true
;
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
.
UseCompatibleStateImageBehavior
=
false
;
this
.
lstProject
.
View
=
System
.
Windows
.
Forms
.
View
.
List
;
...
...
@@ -111,12 +112,13 @@
this
.
lblNotes
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
289
);
this
.
lblNotes
.
Name
=
"lblNotes"
;
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
.
Text
=
"注意:本工具只打包项目设定文件夹内通用文件。。。。。详细内容见源代码"
;
//
// pnlTop
//
this
.
pnlTop
.
Controls
.
Add
(
this
.
ckbMergeSql
);
this
.
pnlTop
.
Controls
.
Add
(
this
.
ckbShowLog
);
this
.
pnlTop
.
Controls
.
Add
(
this
.
ckbDelHisPack
);
this
.
pnlTop
.
Controls
.
Add
(
this
.
btnOpenDirectory
);
...
...
@@ -128,7 +130,7 @@
this
.
pnlTop
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
0
);
this
.
pnlTop
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
3
,
4
,
3
,
4
);
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
;
//
// ckbShowLog
...
...
@@ -192,16 +194,16 @@
this
.
pnlLeft
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
pnlLeft
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
0
);
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
;
//
// gpbLog
//
this
.
gpbLog
.
Controls
.
Add
(
this
.
txtLog
);
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
.
Size
=
new
System
.
Drawing
.
Size
(
3
60
,
341
);
this
.
gpbLog
.
Size
=
new
System
.
Drawing
.
Size
(
3
52
,
341
);
this
.
gpbLog
.
TabIndex
=
0
;
this
.
gpbLog
.
TabStop
=
false
;
this
.
gpbLog
.
Text
=
"************** 操作日志 **************"
;
...
...
@@ -212,14 +214,26 @@
this
.
txtLog
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
19
);
this
.
txtLog
.
Multiline
=
true
;
this
.
txtLog
.
Name
=
"txtLog"
;
this
.
txtLog
.
Size
=
new
System
.
Drawing
.
Size
(
3
54
,
319
);
this
.
txtLog
.
Size
=
new
System
.
Drawing
.
Size
(
3
46
,
319
);
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
//
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
7F
,
17F
);
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
.
gpbLog
);
this
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
...
...
@@ -255,6 +269,7 @@
private
System
.
Windows
.
Forms
.
CheckBox
ckbShowLog
;
private
System
.
Windows
.
Forms
.
GroupBox
gpbLog
;
private
System
.
Windows
.
Forms
.
TextBox
txtLog
;
private
System
.
Windows
.
Forms
.
CheckBox
ckbMergeSql
;
}
}
Ftt.PatchPack/FrmMain.cs
View file @
fc5d15e5
...
...
@@ -9,9 +9,6 @@ namespace Ftt.PatchPack
{
public
partial
class
FrmMain
:
Form
{
private
const
int
WIDTH_LOG_AREA
=
360
;
Dictionary
<
string
,
Project
>
projects
=
new
Dictionary
<
string
,
Project
>();
/// <summary>
...
...
@@ -30,6 +27,7 @@ namespace Ftt.PatchPack
lblNotes
.
Text
=
builder
.
ToString
();
new
ToolTip
().
SetToolTip
(
ckbDelHisPack
,
"勾选后、可自动清理对应包的历史包文件"
);
new
ToolTip
().
SetToolTip
(
ckbMergeSql
,
"合并未使用Use XX指令的脚本,Use指令的脚本文件独立存在并间隔合并操作。"
);
}
...
...
@@ -41,7 +39,6 @@ namespace Ftt.PatchPack
private
void
InitForm
()
{
gpbLog
.
Width
=
WIDTH_LOG_AREA
;
LogVisible
(
false
);
projects
=
ProjectHelp
.
Read
();
...
...
@@ -124,6 +121,7 @@ namespace Ftt.PatchPack
int
success
=
0
;
Cursor
.
Current
=
Cursors
.
WaitCursor
;
Project
.
MergeSqlFile
=
ckbMergeSql
.
Checked
;
foreach
(
ListViewItem
item
in
items
)
{
...
...
@@ -149,6 +147,7 @@ namespace Ftt.PatchPack
}
finally
{
ProjectHelp
.
DeleteDirectoryIfExists
(
project
.
MergeSqlTempFullPath
);
Application
.
DoEvents
();
}
}
...
...
Ftt.PatchPack/Ftt.PatchPack.csproj
View file @
fc5d15e5
...
...
@@ -70,6 +70,7 @@
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"EncodingHelper.cs"
/>
<Compile
Include=
"FilePatch.cs"
/>
<Compile
Include=
"FrmMain.cs"
>
<SubType>
Form
</SubType>
...
...
Ftt.PatchPack/Project.cs
View file @
fc5d15e5
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment