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
abac8e37
Commit
abac8e37
authored
Jun 24, 2021
by
tr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1、自动更新程序优化:剔除冗余方法和文件
parent
751936b2
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
667 deletions
+88
-667
AutoUpdate.csproj
AutoUpdate/AutoUpdate.csproj
+0
-2
Form1.cs
AutoUpdate/Form1.cs
+88
-5
SmpDB.cs
AutoUpdate/SmpDB.cs
+0
-598
Utils.cs
AutoUpdate/Utils.cs
+0
-62
No files found.
AutoUpdate/AutoUpdate.csproj
View file @
abac8e37
...
@@ -59,8 +59,6 @@
...
@@ -59,8 +59,6 @@
</Compile>
</Compile>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"SmpDB.cs"
/>
<Compile
Include=
"Utils.cs"
/>
<EmbeddedResource
Include=
"Form1.resx"
>
<EmbeddedResource
Include=
"Form1.resx"
>
<DependentUpon>
Form1.cs
</DependentUpon>
<DependentUpon>
Form1.cs
</DependentUpon>
</EmbeddedResource>
</EmbeddedResource>
...
...
AutoUpdate/Form1.cs
View file @
abac8e37
using
System
;
using
ICSharpCode.SharpZipLib.Zip
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.ComponentModel
;
using
System.Data
;
using
System.Data
;
using
System.Data.SqlClient
;
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.Drawing
;
using
System.Drawing
;
using
System.IO
;
using
System.IO
;
...
@@ -69,8 +71,8 @@ namespace AutoUpdate
...
@@ -69,8 +71,8 @@ namespace AutoUpdate
private
void
AppUpdate
()
private
void
AppUpdate
()
{
{
string
link
=
Util
s
.
GetDbLinkString204
(
"FTT_Work"
);
string
link
=
thi
s
.
GetDbLinkString204
(
"FTT_Work"
);
DataTable
dt
=
new
SmpDB
()
.
GetDataTable
(
link
,
"SELECT TOP 1 * FROM dbo.FTT_AutoUpdate ORDER BY UDate DESC"
,
"FTT_AutoUpdate"
);
DataTable
dt
=
this
.
GetDataTable
(
link
,
"SELECT TOP 1 * FROM dbo.FTT_AutoUpdate ORDER BY UDate DESC"
,
"FTT_AutoUpdate"
);
if
(
dt
.
DefaultView
.
Count
>
0
)
if
(
dt
.
DefaultView
.
Count
>
0
)
{
{
//结束原进程
//结束原进程
...
@@ -94,7 +96,7 @@ namespace AutoUpdate
...
@@ -94,7 +96,7 @@ namespace AutoUpdate
File
.
WriteAllBytes
(
fileFullName
,
bytes
);
File
.
WriteAllBytes
(
fileFullName
,
bytes
);
this
.
AddProcessText
(
60
);
this
.
AddProcessText
(
60
);
//解压更新包到指定目录
//解压更新包到指定目录
Util
s
.
ZipDecompress
(
fileFullName
,
this
.
_path
);
thi
s
.
ZipDecompress
(
fileFullName
,
this
.
_path
);
this
.
AddProcessText
(
90
);
this
.
AddProcessText
(
90
);
//删除更新包
//删除更新包
File
.
Delete
(
fileFullName
);
File
.
Delete
(
fileFullName
);
...
@@ -106,6 +108,87 @@ namespace AutoUpdate
...
@@ -106,6 +108,87 @@ namespace AutoUpdate
this
.
textBox1
.
Text
+=
$"进度完成
{
value
}
%\r\n"
;
this
.
textBox1
.
Text
+=
$"进度完成
{
value
}
%\r\n"
;
}
}
#
region
工具方法
/// <summary>
/// 获取数据表
/// </summary>
/// <param name="strLink">数据库连接字串</param>
/// <param name="strSql">SQL语句</param>
/// <param name="strTableName">表名</param>
/// <param name="Schema">是否获取结构信息</param>
/// <returns></returns>
public
DataTable
GetDataTable
(
string
strLink
,
string
strSql
,
string
strTableName
,
bool
Schema
=
true
)
{
DataTable
dt
=
new
DataTable
(
strTableName
);
SqlConnection
conn
=
null
;
try
{
conn
=
new
SqlConnection
(
strLink
);
conn
.
Open
();
var
ada
=
new
SqlDataAdapter
(
strSql
,
conn
);
if
(
Schema
)
ada
.
FillSchema
(
dt
,
SchemaType
.
Mapped
);
//取出数据结构
ada
.
Fill
(
dt
);
//填充数据
}
catch
(
Exception
ex
)
{
if
(
conn
.
State
==
ConnectionState
.
Open
)
conn
.
Close
();
throw
(
new
Exception
(
"获取数据出错:\r\n"
+
ex
.
Message
));
}
return
dt
;
}
/// <summary>
/// 获取204的数据库链接
/// </summary>
/// <param name="dbName"></param>
/// <returns></returns>
public
string
GetDbLinkString204
(
string
dbName
)
{
return
$"Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=
{
dbName
}
;Data Source=jhdsoft.gicp.net,3204"
;
}
/// <summary>
/// Zip:解压文件
/// </summary>
/// <param name="zipFileName">压缩包路径</param>
/// <param name="outFilePath">解压文件路径(缺省时,默认为桌面路径)</param>
public
void
ZipDecompress
(
string
zipFileName
,
string
outFilePath
=
""
)
{
if
(!
File
.
Exists
(
zipFileName
))
{
MessageBox
.
Show
(
$"Cannot find file '
{
zipFileName
}
'"
);
return
;
}
if
(
string
.
IsNullOrEmpty
(
outFilePath
))
{
outFilePath
=
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
Desktop
);
}
using
ZipInputStream
zip
=
new
ZipInputStream
(
File
.
OpenRead
(
zipFileName
));
//zip.Password = "123";
byte
[]
buffer
=
new
byte
[
1024
];
//缓冲区大小
ZipEntry
entry
;
while
((
entry
=
zip
.
GetNextEntry
())
!=
null
)
{
string
directoryName
=
Path
.
GetDirectoryName
(
entry
.
Name
);
string
fileName
=
Path
.
GetFileName
(
entry
.
Name
);
if
(
string
.
IsNullOrEmpty
(
directoryName
)
||
string
.
IsNullOrEmpty
(
fileName
))
continue
;
//创建解压文件路径(压缩只考虑相对路径,所以这里创建时要加上输出路径)
Directory
.
CreateDirectory
(
$@"
{
outFilePath
}
\
{
directoryName
}
"
);
using
FileStream
fs
=
File
.
Create
(
$@"
{
outFilePath
}
\
{
entry
.
Name
}
"
);
//entry.Name <=> directoryName + fileName
//写入解压流
int
size
=
0
;
while
((
size
=
zip
.
Read
(
buffer
,
0
,
buffer
.
Length
))
>
0
)
{
fs
.
Write
(
buffer
,
0
,
size
);
}
}
}
#
endregion
}
}
}
}
AutoUpdate/SmpDB.cs
deleted
100644 → 0
View file @
751936b2
This diff is collapsed.
Click to expand it.
AutoUpdate/Utils.cs
deleted
100644 → 0
View file @
751936b2
using
ICSharpCode.SharpZipLib.Zip
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Windows.Forms
;
namespace
AutoUpdate
{
public
class
Utils
{
/// <summary>
/// 获取204的数据库链接
/// </summary>
/// <param name="dbName"></param>
/// <returns></returns>
public
static
string
GetDbLinkString204
(
string
dbName
)
{
return
$"Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=
{
dbName
}
;Data Source=jhdsoft.gicp.net,3204"
;
}
/// <summary>
/// Zip:解压文件
/// </summary>
/// <param name="zipFileName">压缩包路径</param>
/// <param name="outFilePath">解压文件路径(缺省时,默认为桌面路径)</param>
public
static
void
ZipDecompress
(
string
zipFileName
,
string
outFilePath
=
""
)
{
if
(!
File
.
Exists
(
zipFileName
))
{
MessageBox
.
Show
(
$"Cannot find file '
{
zipFileName
}
'"
);
return
;
}
if
(
string
.
IsNullOrEmpty
(
outFilePath
))
{
outFilePath
=
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
Desktop
);
}
using
ZipInputStream
zip
=
new
ZipInputStream
(
File
.
OpenRead
(
zipFileName
));
//zip.Password = "123";
byte
[]
buffer
=
new
byte
[
1024
];
//缓冲区大小
ZipEntry
entry
;
while
((
entry
=
zip
.
GetNextEntry
())
!=
null
)
{
string
directoryName
=
Path
.
GetDirectoryName
(
entry
.
Name
);
string
fileName
=
Path
.
GetFileName
(
entry
.
Name
);
if
(
string
.
IsNullOrEmpty
(
directoryName
)
||
string
.
IsNullOrEmpty
(
fileName
))
continue
;
//创建解压文件路径(压缩只考虑相对路径,所以这里创建时要加上输出路径)
Directory
.
CreateDirectory
(
$@"
{
outFilePath
}
\
{
directoryName
}
"
);
using
FileStream
fs
=
File
.
Create
(
$@"
{
outFilePath
}
\
{
entry
.
Name
}
"
);
//entry.Name <=> directoryName + fileName
//写入解压流
int
size
=
0
;
while
((
size
=
zip
.
Read
(
buffer
,
0
,
buffer
.
Length
))
>
0
)
{
fs
.
Write
(
buffer
,
0
,
size
);
}
}
}
}
}
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