系统升级目录
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;
|
||||
//}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user