From 548295ea899d46803937dc582276994b9ad4786c Mon Sep 17 00:00:00 2001 From: Light <47911535+LightAPIs@users.noreply.github.com> Date: Sat, 10 Sep 2022 19:09:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=AA=97=E5=8F=A3=E5=86=85=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=BA=E4=B9=B1=E7=A0=81=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ClashSinicizationTool/Form/DownloadForm.cs | 4 ++-- .../ClashSinicizationToolCLI.csproj | 2 +- ClashSinicizationToolUpgrade/Program.cs | 2 +- ClashSinicizationToolUpgrade/UpgradeMainForm.cs | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ClashSinicizationTool/Form/DownloadForm.cs b/ClashSinicizationTool/Form/DownloadForm.cs index f0bb321..3a99200 100644 --- a/ClashSinicizationTool/Form/DownloadForm.cs +++ b/ClashSinicizationTool/Form/DownloadForm.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -68,7 +68,7 @@ private async void Downloading() } if (isCompleted) - { //! + { //! 下载完成 if (Directory.Exists(tempDir)) { Directory.Delete(tempDir, true); diff --git a/ClashSinicizationToolCLI/ClashSinicizationToolCLI.csproj b/ClashSinicizationToolCLI/ClashSinicizationToolCLI.csproj index e1473bb..fce385e 100644 --- a/ClashSinicizationToolCLI/ClashSinicizationToolCLI.csproj +++ b/ClashSinicizationToolCLI/ClashSinicizationToolCLI.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/ClashSinicizationToolUpgrade/Program.cs b/ClashSinicizationToolUpgrade/Program.cs index df66a1a..f64f263 100644 --- a/ClashSinicizationToolUpgrade/Program.cs +++ b/ClashSinicizationToolUpgrade/Program.cs @@ -1,4 +1,4 @@ -namespace ClashSinicizationToolUpgrade +namespace ClashSinicizationToolUpgrade { internal static class Program { diff --git a/ClashSinicizationToolUpgrade/UpgradeMainForm.cs b/ClashSinicizationToolUpgrade/UpgradeMainForm.cs index b8a8f32..3a7a384 100644 --- a/ClashSinicizationToolUpgrade/UpgradeMainForm.cs +++ b/ClashSinicizationToolUpgrade/UpgradeMainForm.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -24,7 +24,7 @@ public UpgradeMainForm(string appPath) private void UpgradeMainForm_Load(object sender, EventArgs e) { - this.ContentLabel.Text = "..."; + this.ContentLabel.Text = "正在升级主程序..."; this.RunButton.Enabled = false; if (CloseMainProgram()) { @@ -32,7 +32,7 @@ private void UpgradeMainForm_Load(object sender, EventArgs e) } else { - this.ContentLabel.Text = "޷˳"; + this.ContentLabel.Text = "无法退出主程序!"; } } @@ -65,12 +65,12 @@ private void Upgrading() { File.Copy(file, Path.Combine(appPath, Path.GetRelativePath(Directory.GetCurrentDirectory(), file)), true); } - this.ContentLabel.Text = "ɣ"; + this.ContentLabel.Text = "升级完成!"; this.RunButton.Enabled = true; } else { - this.ContentLabel.Text = "Ŀ¼ڣ"; + this.ContentLabel.Text = "程序目录不存在!"; } } @@ -100,7 +100,7 @@ private void RunButton_Click(object sender, EventArgs e) { run = false; p.Close(); - this.ContentLabel.Text = "ʧܣ"; + this.ContentLabel.Text = "主程序启动失败!"; } if (run) From 905867f52629ffbd9494a3b822c75733570681f4 Mon Sep 17 00:00:00 2001 From: Light <47911535+LightAPIs@users.noreply.github.com> Date: Sat, 10 Sep 2022 21:29:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E4=BC=9A=E6=9B=B4=E6=96=B0=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 同时在升级过程中显示主程序路径 --- ClashSinicizationTool/Form/DownloadForm.cs | 2 +- .../UpgradeMainForm.Designer.cs | 44 +++++++++++++------ .../UpgradeMainForm.cs | 31 +++++++++++-- 3 files changed, 58 insertions(+), 19 deletions(-) diff --git a/ClashSinicizationTool/Form/DownloadForm.cs b/ClashSinicizationTool/Form/DownloadForm.cs index 3a99200..fa74231 100644 --- a/ClashSinicizationTool/Form/DownloadForm.cs +++ b/ClashSinicizationTool/Form/DownloadForm.cs @@ -84,7 +84,7 @@ private async void Downloading() { Process upApp = new Process(); upApp.StartInfo.FileName = tempExe; - upApp.StartInfo.Arguments = Directory.GetCurrentDirectory(); + upApp.StartInfo.Arguments = "\"\"\"" + Directory.GetParent(Application.StartupPath).Parent.FullName + "\"\"\""; upApp.StartInfo.WorkingDirectory = tempDir; upApp.Start(); upApp.Close(); diff --git a/ClashSinicizationToolUpgrade/UpgradeMainForm.Designer.cs b/ClashSinicizationToolUpgrade/UpgradeMainForm.Designer.cs index 0f9b178..a24edd3 100644 --- a/ClashSinicizationToolUpgrade/UpgradeMainForm.Designer.cs +++ b/ClashSinicizationToolUpgrade/UpgradeMainForm.Designer.cs @@ -29,6 +29,7 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.PathLabel = new System.Windows.Forms.Label(); this.ContentLabel = new System.Windows.Forms.Label(); this.RunButton = new System.Windows.Forms.Button(); this.tableLayoutPanel1.SuspendLayout(); @@ -39,27 +40,41 @@ private void InitializeComponent() this.tableLayoutPanel1.ColumnCount = 2; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); - this.tableLayoutPanel1.Controls.Add(this.ContentLabel, 0, 0); - this.tableLayoutPanel1.Controls.Add(this.RunButton, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.PathLabel, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.ContentLabel, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.RunButton, 0, 2); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; - this.tableLayoutPanel1.RowCount = 2; - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 55.55556F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 44.44444F)); - this.tableLayoutPanel1.Size = new System.Drawing.Size(192, 81); + this.tableLayoutPanel1.RowCount = 3; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 35F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 35F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(399, 112); this.tableLayoutPanel1.TabIndex = 0; // + // PathLabel + // + this.PathLabel.AutoSize = true; + this.tableLayoutPanel1.SetColumnSpan(this.PathLabel, 2); + this.PathLabel.Dock = System.Windows.Forms.DockStyle.Fill; + this.PathLabel.Location = new System.Drawing.Point(3, 0); + this.PathLabel.Name = "PathLabel"; + this.PathLabel.Size = new System.Drawing.Size(393, 39); + this.PathLabel.TabIndex = 4; + this.PathLabel.Text = "Label"; + this.PathLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // // ContentLabel // this.ContentLabel.AutoSize = true; this.tableLayoutPanel1.SetColumnSpan(this.ContentLabel, 2); this.ContentLabel.Dock = System.Windows.Forms.DockStyle.Fill; - this.ContentLabel.Location = new System.Drawing.Point(3, 0); + this.ContentLabel.ForeColor = System.Drawing.Color.DarkCyan; + this.ContentLabel.Location = new System.Drawing.Point(3, 39); this.ContentLabel.Name = "ContentLabel"; - this.ContentLabel.Size = new System.Drawing.Size(186, 45); + this.ContentLabel.Size = new System.Drawing.Size(393, 39); this.ContentLabel.TabIndex = 3; this.ContentLabel.Text = "Label"; this.ContentLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -68,10 +83,10 @@ private void InitializeComponent() // this.tableLayoutPanel1.SetColumnSpan(this.RunButton, 2); this.RunButton.Dock = System.Windows.Forms.DockStyle.Fill; - this.RunButton.Location = new System.Drawing.Point(50, 50); - this.RunButton.Margin = new System.Windows.Forms.Padding(50, 5, 50, 5); + this.RunButton.Location = new System.Drawing.Point(125, 83); + this.RunButton.Margin = new System.Windows.Forms.Padding(125, 5, 125, 5); this.RunButton.Name = "RunButton"; - this.RunButton.Size = new System.Drawing.Size(92, 26); + this.RunButton.Size = new System.Drawing.Size(149, 24); this.RunButton.TabIndex = 1; this.RunButton.Text = "启动程序"; this.RunButton.UseVisualStyleBackColor = true; @@ -81,7 +96,7 @@ private void InitializeComponent() // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(192, 81); + this.ClientSize = new System.Drawing.Size(399, 112); this.Controls.Add(this.tableLayoutPanel1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; @@ -103,5 +118,6 @@ private void InitializeComponent() private TableLayoutPanel tableLayoutPanel1; private Button RunButton; private Label ContentLabel; + private Label PathLabel; } } \ No newline at end of file diff --git a/ClashSinicizationToolUpgrade/UpgradeMainForm.cs b/ClashSinicizationToolUpgrade/UpgradeMainForm.cs index 3a7a384..a1145bb 100644 --- a/ClashSinicizationToolUpgrade/UpgradeMainForm.cs +++ b/ClashSinicizationToolUpgrade/UpgradeMainForm.cs @@ -19,11 +19,12 @@ public UpgradeMainForm(string appPath) { InitializeComponent(); - this.appPath = appPath; + this.appPath = appPath.Replace("\"", ""); } private void UpgradeMainForm_Load(object sender, EventArgs e) { + this.PathLabel.Text = "程序路径: " + appPath; this.ContentLabel.Text = "正在升级主程序..."; this.RunButton.Enabled = false; if (CloseMainProgram()) @@ -59,11 +60,13 @@ private bool CloseMainProgram() private void Upgrading() { - if (Directory.Exists(appPath)) + var mainInfo = Directory.GetParent(Application.StartupPath); + if (Directory.Exists(appPath) && mainInfo != null && mainInfo.Parent != null) { - foreach (string file in Directory.GetFiles(Directory.GetCurrentDirectory())) + string mainPath = mainInfo.Parent.FullName; + foreach (string file in GetFiles(mainPath)) { - File.Copy(file, Path.Combine(appPath, Path.GetRelativePath(Directory.GetCurrentDirectory(), file)), true); + File.Copy(file, Path.Combine(appPath, Path.GetRelativePath(mainPath, file)), true); } this.ContentLabel.Text = "升级完成!"; this.RunButton.Enabled = true; @@ -74,6 +77,26 @@ private void Upgrading() } } + private string[] GetFiles(string dirPath) + { + List files = new List(); + DirectoryInfo dirInfo = new DirectoryInfo(dirPath); + foreach (FileInfo file in dirInfo.GetFiles()) + { + files.Add(file.FullName); + } + + foreach (DirectoryInfo dir in dirInfo.GetDirectories()) + { + foreach (string subFile in GetFiles(dir.FullName)) + { + files.Add(subFile); + } + } + + return files.ToArray(); + } + private void DeleteItSelfByCMD() { ProcessStartInfo psi = new ProcessStartInfo("cmd.exe", "/C ping 1.1.1.1 -n 1 -w 1000 > Nul & RD /S /Q " + Directory.GetParent(Application.ExecutablePath) + " & exit");