系统升级目录
This commit is contained in:
1 parent
892d7e1f6c
commit
106f60bcf8
7 files changed
+121
-110
No files matched your search
+48
-44
@@ -4,6 +4,7 @@ using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
@@ -36,8 +37,8 @@ namespace Update
|
||||
{
|
||||
if (lblMessage.Text == "升级完成,点击确定重启程序")
|
||||
{
|
||||
string mainPath = System.Environment.CurrentDirectory + "\\" + Program.softName + ".exe";
|
||||
System.Diagnostics.Process.Start(mainPath);
|
||||
string extPath = System.Environment.CurrentDirectory + "\\" + Program.softName;
|
||||
System.Diagnostics.Process.Start(extPath);
|
||||
Application.Exit();
|
||||
return;
|
||||
}
|
||||
@@ -53,17 +54,59 @@ namespace Update
|
||||
System.IO.Directory.CreateDirectory("upTemp");
|
||||
var upTempPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "upTemp";
|
||||
|
||||
// 清空文件夹准备下载
|
||||
foreach (string filePath in Directory.GetFiles(upTempPath))
|
||||
{
|
||||
File.Delete(filePath); // 删除文件
|
||||
}
|
||||
foreach (string dirPath in Directory.GetDirectories(upTempPath))
|
||||
{
|
||||
Directory.Delete(dirPath, true); // 删除子文件夹及其内容
|
||||
}
|
||||
|
||||
this.lblMessage.Text = "升级中请稍候...";
|
||||
progressBar1.Visible = true;
|
||||
progressBar1.Maximum = 1;//fileNameArr.Count();
|
||||
progressBar1.Maximum = 100;//fileNameArr.Count();
|
||||
progressBar1.Value = 0;
|
||||
new TaskFactory().StartNew(() =>
|
||||
{
|
||||
bool result = Program.DownloadFile(Program.updateUrl, upTempPath + "\\" + Program.updateUrl.Substring(Program.updateUrl.LastIndexOf("/") + 1));
|
||||
string tempFile = upTempPath + "\\" + Program.updateUrl.Substring(Program.updateUrl.LastIndexOf("/") + 1);
|
||||
bool result = Program.DownloadFile(Program.updateUrl, tempFile);
|
||||
|
||||
if (result)
|
||||
{
|
||||
{
|
||||
ZipFile.ExtractToDirectory(tempFile, upTempPath);
|
||||
File.Delete(tempFile);
|
||||
|
||||
string mainPath = System.Environment.CurrentDirectory;
|
||||
// 备份旧文件
|
||||
foreach (string filePath in Directory.GetFiles(upTempPath))
|
||||
{
|
||||
string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
|
||||
File.Copy(mainPath + "\\" + fileName, upBakPath + "\\" + fileName, true);
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
foreach (string dirPath in Directory.GetDirectories(upTempPath))
|
||||
{
|
||||
string fileName = dirPath.Substring(dirPath.LastIndexOf("\\") + 1);
|
||||
CopyDirectory(mainPath + "\\" + fileName, upBakPath + "\\" + fileName);
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
|
||||
// 替换旧文件
|
||||
foreach (string filePath in Directory.GetFiles(upTempPath))
|
||||
{
|
||||
string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
|
||||
File.Copy(upTempPath + "\\" + fileName, mainPath + "\\" + fileName, true);
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
foreach (string dirPath in Directory.GetDirectories(upTempPath))
|
||||
{
|
||||
string fileName = dirPath.Substring(dirPath.LastIndexOf("\\") + 1);
|
||||
CopyDirectory(upTempPath + "\\" + fileName, mainPath + "\\" + fileName);
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
|
||||
Thread.Sleep(50);
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
@@ -79,45 +122,6 @@ namespace Update
|
||||
btnOk.Enabled = true;
|
||||
}));
|
||||
}
|
||||
|
||||
//var fileNames = Program.updateUrl;
|
||||
//var fileNameArr = fileNames.Split(new string[] { ",", ";" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
//if (fileNameArr.Count() > 0)
|
||||
//{
|
||||
// foreach (var path in fileNameArr)
|
||||
// {
|
||||
// Thread.Sleep(new Random().Next(500, 1000));
|
||||
|
||||
// var localPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + path.Substring(path.LastIndexOf("/") + 1);
|
||||
// var tempPath = upBakPath + "\\" + path.Substring(path.LastIndexOf("/") + 1);
|
||||
// File.Copy(localPath, tempPath, true);
|
||||
|
||||
// if (!result)
|
||||
// {
|
||||
// Invoke(new Action(() =>
|
||||
// {
|
||||
// this.lblMessage.Text = "升级失败,请稍后点击确定重试";
|
||||
// btnOk.Enabled = true;
|
||||
// }));
|
||||
// return;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Invoke(new Action(() =>
|
||||
// {
|
||||
// if (progressBar1.Value < progressBar1.Maximum)
|
||||
// progressBar1.Value++;
|
||||
// }));
|
||||
// }
|
||||
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// this.lblMessage.Text = "升级失败,未获取到升级文件";
|
||||
// btnOk.Enabled = true;
|
||||
//}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Generated
+7
-8
@@ -43,7 +43,7 @@ namespace Update
|
||||
//
|
||||
// lblMessage
|
||||
//
|
||||
this.lblMessage.Location = new System.Drawing.Point(14, 12);
|
||||
this.lblMessage.Location = new System.Drawing.Point(14, 8);
|
||||
this.lblMessage.Name = "lblMessage";
|
||||
this.lblMessage.Size = new System.Drawing.Size(224, 69);
|
||||
this.lblMessage.TabIndex = 0;
|
||||
@@ -58,7 +58,7 @@ namespace Update
|
||||
this.btnOk.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.btnOk.Font = new System.Drawing.Font("微软雅黑", 11F);
|
||||
this.btnOk.ForeColor = System.Drawing.Color.White;
|
||||
this.btnOk.Location = new System.Drawing.Point(129, 137);
|
||||
this.btnOk.Location = new System.Drawing.Point(129, 127);
|
||||
this.btnOk.Name = "btnOk";
|
||||
this.btnOk.Size = new System.Drawing.Size(109, 30);
|
||||
this.btnOk.TabIndex = 9;
|
||||
@@ -74,14 +74,13 @@ namespace Update
|
||||
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.btnCancel.Font = new System.Drawing.Font("微软雅黑", 11F);
|
||||
this.btnCancel.ForeColor = System.Drawing.Color.Blue;
|
||||
this.btnCancel.Location = new System.Drawing.Point(14, 137);
|
||||
this.btnCancel.Location = new System.Drawing.Point(14, 127);
|
||||
this.btnCancel.Name = "btnCancel";
|
||||
this.btnCancel.Size = new System.Drawing.Size(109, 30);
|
||||
this.btnCancel.TabIndex = 10;
|
||||
this.btnCancel.TabStop = false;
|
||||
this.btnCancel.Text = "取 消";
|
||||
this.btnCancel.UseVisualStyleBackColor = false;
|
||||
this.btnCancel.Visible = false;
|
||||
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
|
||||
//
|
||||
// panel1
|
||||
@@ -91,7 +90,7 @@ namespace Update
|
||||
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.panel1.Location = new System.Drawing.Point(0, 0);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(256, 16);
|
||||
this.panel1.Size = new System.Drawing.Size(256, 24);
|
||||
this.panel1.TabIndex = 11;
|
||||
this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
|
||||
this.panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove);
|
||||
@@ -120,14 +119,14 @@ namespace Update
|
||||
this.panel2.Controls.Add(this.lblMessage);
|
||||
this.panel2.Controls.Add(this.btnOk);
|
||||
this.panel2.Controls.Add(this.btnCancel);
|
||||
this.panel2.Location = new System.Drawing.Point(2, 16);
|
||||
this.panel2.Location = new System.Drawing.Point(2, 24);
|
||||
this.panel2.Name = "panel2";
|
||||
this.panel2.Size = new System.Drawing.Size(252, 178);
|
||||
this.panel2.Size = new System.Drawing.Size(252, 170);
|
||||
this.panel2.TabIndex = 12;
|
||||
//
|
||||
// progressBar1
|
||||
//
|
||||
this.progressBar1.Location = new System.Drawing.Point(14, 95);
|
||||
this.progressBar1.Location = new System.Drawing.Point(14, 85);
|
||||
this.progressBar1.Name = "progressBar1";
|
||||
this.progressBar1.Size = new System.Drawing.Size(224, 23);
|
||||
this.progressBar1.TabIndex = 11;
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Update
|
||||
try
|
||||
{
|
||||
var text = File.ReadAllText("UpdateConfig.ini");
|
||||
File.Delete("UpdateConfig.ini");
|
||||
//File.Delete("UpdateConfig.ini");
|
||||
|
||||
var arr = text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (arr.Length > 3)
|
||||
|
||||
@@ -44,6 +44,8 @@
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.IO.Compression.FileSystem" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
|
||||
Reference in new issue
Block a user