系统升级目录

This commit is contained in:
wule committed 2025-07-14 11:11:08 +08:00
1 parent 892d7e1f6c
commit 106f60bcf8
7 files changed
+121 -110

No files matched your search

-1
View File
@@ -25,7 +25,6 @@ namespace TemuKJD
//安装客户端必备字体
InstallFont(Application.StartupPath + @"\Fonts\STZHONGS.TTF");
StartUp.CheckUpdate();
System.Threading.Tasks.Task.Run(() =>
{
new Initialization().Get();
-55
View File
@@ -504,60 +504,5 @@ namespace TemuKJD
if (ViolateRuleParam.LstViolateRuleNameSelect != null)
NaiBa.Util.Helper.ConfigHelper.SaveConfig<List<string>>("violate_rule_name_select", ViolateRuleParam.LstViolateRuleNameSelect);
}
public static void CheckUpdate()
{
try
{
// while (true)
{
string updatefilepath = System.Environment.CurrentDirectory + "\\Update.exe";
var url = BaseClass.BuildObjString("update/get_update");
var data = UserLogin.GetSignaturex();
var html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
return;
var updateExeChk = BaseRegex.GetStringJson(ref html, "exe_check").ParseToString();
var updateExeAddress = BaseRegex.GetStringJson(ref html, "exe_address");
var updateFileAddress = BaseRegex.GetStringJson(ref html, "file_address");
var newVersion = BaseRegex.GetIntJson(ref html, "next_version").ParseToInt();
if (File.Exists(updatefilepath))
{
string fc = BaseClass.GetFileMd5(updatefilepath);
if (fc != updateExeChk)
{
NaiBa.Util.Helper.HttpHelper.DownloadFile(updateExeAddress, updatefilepath);
}
}
else // 如果自动更新exe文件不存在,则强制更新exe文件
NaiBa.Util.Helper.HttpHelper.DownloadFile(updateExeAddress, updatefilepath);
if (newVersion > BaseClass.VersionCount)
{
try
{
if (File.Exists(updatefilepath))
{
File.WriteAllText(System.Environment.CurrentDirectory + "\\UpdateConfig.ini",
"TemuKJD.exe\r\n" +
BaseClass.VersionCount + "\r\n" +
newVersion + "\r\n" +
updateFileAddress);
Process.Start(updatefilepath);
}
}
catch (Exception ex)
{
BaseMsgForm.ShowError(ex.Message);
}
}
//Thread.Sleep(1000 * 60 * 60);
}
}
catch (Exception ex) { BaseMsgForm.ShowError(ex.Message); }
}
}
}
+48 -44
View File
@@ -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;
//}
});
}
+7 -8
View File
@@ -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;
+1 -1
View File
@@ -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)
+2
View File
@@ -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" />
+63 -1
View File
@@ -19,6 +19,7 @@ using System.Net;
using System.Collections;
using System.Linq;
using System.Threading.Tasks;
using NaiBa.Util.Extension;
namespace Work
{
@@ -84,7 +85,8 @@ prefixTextPara,;shopthreadCountPara,3;singeThreadCountPara,1;singleUploadPara,50
offCountPara,false;offProductPara,100;IrregularitiesPara,true;noNeerPara,true;noNeerDaysPara,3;limitReplacePara,true;replaceCountPara,3;errorDownPara,false;apiPara,false";
CheckXmlValue(checkvalue, ConfigFilePach);
Task.Run(() => { Update(); InitProgress(1); });
//Task.Run(() => { Update(); InitProgress(1); });
Task.Run(() => { CheckUpdate(); InitProgress(1); });
Task.Run(() => { GetAuthConfig(); InitProgress(1); });
Task.Run(() => { CheckFiles(); IsCheckFilesFinish = true; InitProgress(1); });
//Task.Run(() => { CheckUpdataFile(); });
@@ -302,6 +304,66 @@ offCountPara,false;offProductPara,100;IrregularitiesPara,true;noNeerPara,true;no
InitProgress(1);
}
public static void CheckUpdate()
{
try
{
// while (true)
{
string updatefilepath = System.Environment.CurrentDirectory + "\\Update.exe";
var url = BaseClass.BuildObjString("update/get_update");
var data = UserLogin.GetSignaturex();
var html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
return;
var updateExeChk = BaseRegex.GetStringJson(ref html, "exe_check").ParseToString();
var updateExeAddress = BaseRegex.GetStringJson(ref html, "exe_address");
var updateFileAddress = BaseRegex.GetStringJson(ref html, "file_address");
var newVersion = BaseRegex.GetIntJson(ref html, "next_version").ParseToInt();
if (File.Exists(updatefilepath))
{
string fc = BaseClass.GetFileMd5(updatefilepath);
if (fc != updateExeChk)
{
NaiBa.Util.Helper.HttpHelper.DownloadFile(updateExeAddress, updatefilepath);
}
}
else // 如果自动更新exe文件不存在,则强制更新exe文件
NaiBa.Util.Helper.HttpHelper.DownloadFile(updateExeAddress, updatefilepath);
if (newVersion > BaseClass.VersionCount)
{
try
{
if (File.Exists(updatefilepath))
{
File.WriteAllText(System.Environment.CurrentDirectory + "\\UpdateConfig.ini",
"TemuKJD.exe\r\n" +
BaseClass.VersionCount + "\r\n" +
newVersion + "\r\n" +
updateFileAddress);
Process.Start(updatefilepath);
}
}
catch (Exception ex)
{
//BaseMsgForm.ShowError(ex.Message);
}
}
//Thread.Sleep(1000 * 60 * 60);
}
}
catch (Exception ex)
{
//BaseMsgForm.ShowError(ex.Message);
}
InitProgress(1);
}
/// <summary>
/// 获取签名验证配置
/// </summary>