Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #20 from LightAPIs/update_fix
Browse files Browse the repository at this point in the history
修复更新程序
  • Loading branch information
Light authored Sep 10, 2022
2 parents b02adbc + 20d45bb commit cc7633c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 28 deletions.
4 changes: 2 additions & 2 deletions ClashSinicizationTool/Form/DownloadForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private async void Downloading()
}

if (isCompleted)
{ //! ÏÂÔØÍê³É
{ //! 下载完成
if (Directory.Exists(tempDir))
{
Directory.Delete(tempDir, true);
Expand All @@ -78,7 +78,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();
Expand Down
2 changes: 1 addition & 1 deletion ClashSinicizationToolCLI/ClashSinicizationToolCLI.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
2 changes: 1 addition & 1 deletion ClashSinicizationToolUpgrade/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ClashSinicizationToolUpgrade
namespace ClashSinicizationToolUpgrade
{
internal static class Program
{
Expand Down
44 changes: 30 additions & 14 deletions ClashSinicizationToolUpgrade/UpgradeMainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 33 additions & 10 deletions ClashSinicizationToolUpgrade/UpgradeMainForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
Expand All @@ -19,20 +19,21 @@ public UpgradeMainForm(string appPath)
{
InitializeComponent();

this.appPath = appPath;
this.appPath = appPath.Replace("\"", "");
}

private void UpgradeMainForm_Load(object sender, EventArgs e)
{
this.ContentLabel.Text = "正在升级主程序...";
this.PathLabel.Text = "程序路径: " + appPath;
this.ContentLabel.Text = "正在升级主程序...";
this.RunButton.Enabled = false;
if (CloseMainProgram())
{
Upgrading();
}
else
{
this.ContentLabel.Text = "无法退出主程序!";
this.ContentLabel.Text = "无法退出主程序!";
}
}

Expand All @@ -59,21 +60,43 @@ 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.ContentLabel.Text = "升级完成!";
this.RunButton.Enabled = true;
}
else
{
this.ContentLabel.Text = "程序目录不存在!";
this.ContentLabel.Text = "程序目录不存在!";
}
}

private string[] GetFiles(string dirPath)
{
List<string> files = new List<string>();
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");
Expand All @@ -100,7 +123,7 @@ private void RunButton_Click(object sender, EventArgs e)
{
run = false;
p.Close();
this.ContentLabel.Text = "主程序启动失败!";
this.ContentLabel.Text = "主程序启动失败!";
}

if (run)
Expand Down

0 comments on commit cc7633c

Please sign in to comment.