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

Commit

Permalink
- 修改汉化逻辑(增加被汉化文件备份,可以不打包之前还原英文从新打包并且不需要解包)
Browse files Browse the repository at this point in the history
- 修改还原逻辑(如果解包后文件夹app存在,则只还原被汉化后的备份文件,如果不存在,则还原.bak文件)(如果Clash开启状态,则可以一键关闭并还原)
- 修改打包逻辑(如果Clash开启状态,则可以一键关闭并打包)
- 修改替换路径和精简路径的检索文件(合并成一个文件PathList.ini)
- 修改历史列表的检索文件(我的文档\Clash Sinicization Tool\CacheList.ini)
- 增加备份文件的位置汉化(我的文档\Clash Sinicization Tool\backup_original)
- 界面增加GitHub直连(右下角)
- 修改ini文件检索逻辑
  • Loading branch information
BoyceLig committed Nov 5, 2021
1 parent 05a4d80 commit 2da4c76
Show file tree
Hide file tree
Showing 12 changed files with 4,605 additions and 1,095 deletions.
17 changes: 13 additions & 4 deletions ClashSinicizationTool/ClashSinicizationTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@
<UseWindowsForms>true</UseWindowsForms>
<Authors>Boyce Lig</Authors>
<StartupObject>ClashSinicizationTool.Program</StartupObject>
<Version>1.1.4</Version>
<Version>1.2.0</Version>
<Product>Clash Sinicization Tool</Product>
<Company>Boyce Lig</Company>
<PackageId>ClashSinicizationTool</PackageId>
<AssemblyName>Clash Sinicization Tool</AssemblyName>
<PackageIcon></PackageIcon>
<PackageIcon>logo.png</PackageIcon>
<PackageIconUrl />
<ApplicationIcon>Image\tray_normal.ico</ApplicationIcon>
<ApplicationIcon>Image\logo 拷贝.ico</ApplicationIcon>
<SignAssembly>false</SignAssembly>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>AnyCPU</Platforms>
<Copyright>Boyce Lig</Copyright>
<Copyright>Copyright © 2021</Copyright>
<Description>Clash for Windows 汉化程序</Description>
<PackageProjectUrl>https://github.com/BoyceLig/ClashSinicizationTool</PackageProjectUrl>
<RepositoryUrl>https://github.com/BoyceLig/ClashSinicizationTool.git</RepositoryUrl>
<RepositoryType>GithHub</RepositoryType>
<NeutralLanguage>zh-CN</NeutralLanguage>
<PackageReleaseNotes />
</PropertyGroup>

<ItemGroup>
Expand All @@ -35,6 +40,10 @@
<None Update="英汉对照.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Image\logo.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions ClashSinicizationTool/Form/MainForm.Designer.cs

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

126 changes: 82 additions & 44 deletions ClashSinicizationTool/Form/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
using Ini;
using System.Collections.Generic;
using System.Net;
using System.Threading;

namespace ClashSinicizationTool
{
public partial class MainForm : Form
{
string
clashPath,
cacheList = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\Clash Sinicization Tool\CacheList.ini";
cacheList = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\Clash Sinicization Tool\CacheList.ini",
backup_original = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\Clash Sinicization Tool\backup_original";

Version newVersion, currentVersion;
Version currentVersion;

public MainForm()
{
Expand All @@ -26,10 +28,10 @@ public MainForm()
//加载时执行
private void MainForm_Load(object sender, EventArgs e)
{
currentVersion = new Version(Application.ProductVersion.ToString());

#region 标题
//增加版本号标注
currentVersion = new Version(Application.ProductVersion.ToString());

if (Environment.Is64BitProcess)
{
//64位
Expand All @@ -42,26 +44,10 @@ private void MainForm_Load(object sender, EventArgs e)
}
#endregion

#region 自动更新
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(GlobalData.versionPath);
WebResponse response = request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(resStream, Encoding.UTF8);
newVersion = new Version(streamReader.ReadLine());
if (newVersion > currentVersion)
{
if (MessageBox.Show($"当前版本 {currentVersion},有新版本 {newVersion},是否更新至新版本?", "新版本提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
UpdateForm updateForm = new UpdateForm();
updateForm.ShowDialog();
}
}
#endregion

//检查文件是否存在
if (!File.Exists(GlobalData.iniFilePath))
{
if (MessageBox.Show(GlobalData.iniFilePath + " 列表文件不存在,无法进行汉化,请找回配置文件后再次尝试") == DialogResult.OK)
if (MessageBox.Show(GlobalData.iniFilePath + " 列表文件不存在,无法进行汉化,请找回配置文件后再次尝试", "提示") == DialogResult.OK)
{
Environment.Exit(0);
}
Expand Down Expand Up @@ -212,13 +198,13 @@ private void unpackButton_Click(object sender, EventArgs e)
}
else
{
MessageBox.Show("解包失败!但是不知道问题出在了哪里,请自行查找");
MessageBox.Show("解包失败!但是不知道问题出在了哪里,请自行查找", "提示");
logTextBox.AppendText("解包失败!但是不知道问题出在了哪里,请自行查找" + Environment.NewLine);
}
}
else
{
MessageBox.Show("解包失败!npm文件夹检测不存在,请在TG群组求助");
MessageBox.Show("解包失败!npm文件夹检测不存在,请在TG群组求助", "提示");
logTextBox.AppendText("解包失败!npm文件夹检测不存在,请在TG群组求助" + Environment.NewLine);
}
}
Expand Down Expand Up @@ -260,7 +246,7 @@ private void sinicizationButton_Click(object sender, EventArgs e)
string[] replacePaths = iniList.GetSectionValue("Replace Path", GlobalData.iniFilePath).ToArray();
if (File.ReadAllText(clashPath + @"\resources\app\dist\electron\main.js").Contains("退出"))
{
MessageBox.Show("您已汉化,不需要二次汉化");
MessageBox.Show("您已汉化,不需要二次汉化", "提示");
logTextBox.AppendText("您已汉化,不需要二次汉化" + Environment.NewLine);
}
else
Expand All @@ -269,13 +255,25 @@ private void sinicizationButton_Click(object sender, EventArgs e)
{
if (File.Exists("moment-with-CN.js"))
{
//创建备份目录
if (!Directory.Exists(backup_original))
{
Directory.CreateDirectory(backup_original);
}
//备份
File.Copy(clashPath + @"\resources\app\node_modules\moment\moment.js", backup_original + @"\moment.js", true);
logTextBox.AppendText("已备份文件 " + clashPath + @"\resources\app\node_modules\moment\moment.js" + Environment.NewLine);
File.Copy("moment-with-CN.js", clashPath + @"\resources\app\node_modules\moment\moment.js", true);
logTextBox.AppendText("已替换文件 " + clashPath + @"\resources\app\node_modules\moment\moment.js" + Environment.NewLine);
CharacterReplacement characterReplacement = new CharacterReplacement();
for (int i = 0; i < replacePaths.Length; i++)
{
if (File.Exists(clashPath + replacePaths[i]))
{
string[] s = replacePaths[i].Split(@"\");
string fileName = s[s.Length - 1];
File.Copy(clashPath + replacePaths[i], backup_original + @"\" + fileName, true);
logTextBox.AppendText("已备份文件 " + clashPath + replacePaths[i] + Environment.NewLine);
characterReplacement.CharacterReplace(translationScriptText, clashPath + replacePaths[i], logTextBox);
}
else
Expand All @@ -293,7 +291,7 @@ private void sinicizationButton_Click(object sender, EventArgs e)
else
{
logTextBox.AppendText("尚未解包,请按步骤操作" + Environment.NewLine);
MessageBox.Show("尚未解包,请按步骤操作");
MessageBox.Show("尚未解包,请按步骤操作", "提示");
}
}
}
Expand Down Expand Up @@ -323,24 +321,32 @@ private void simplifyButton_Click(object sender, EventArgs e)
else
{
logTextBox.AppendText("尚未解包,请按步骤操作" + Environment.NewLine);
MessageBox.Show("尚未解包,请按步骤操作");
MessageBox.Show("尚未解包,请按步骤操作", "提示");
}
}

//打包app.asar
private void packButton_Click(object sender, EventArgs e)
{
if (Directory.Exists(clashPath + @"\resources\app"))
foreach (Process p in Process.GetProcesses())
{
foreach (Process p in Process.GetProcesses())
if (p.ProcessName == GlobalData.clashProcessName)
{
if (p.ProcessName == GlobalData.clashProcessName)
if (MessageBox.Show("Clash for Windows 已开启,是否关闭 Clash for Windows?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
CloseClashButton_Click(sender, e);
break;
}
else
{
MessageBox.Show("Clash for Windows已开启,请关闭后重试。");
logTextBox.AppendText("Clash for Windows已开启,请关闭Clash for Windows后重试。" + Environment.NewLine);
goto c;
}
}
}
Thread.Sleep(2000);
if (Directory.Exists(clashPath + @"\resources\app"))
{
//打包命令
CMDCommand command = new CMDCommand();
command.Pack(clashPath);
Expand All @@ -350,7 +356,7 @@ private void packButton_Click(object sender, EventArgs e)
else
{
logTextBox.AppendText("尚未解包,请按步骤操作" + Environment.NewLine);
MessageBox.Show("尚未解包,请按步骤操作");
MessageBox.Show("尚未解包,请按步骤操作", "提示");
}
c:;
}
Expand All @@ -374,19 +380,52 @@ private void openClashBrowseButton_Click(object sender, EventArgs e)
//还原按钮
private void revertButton_Click(object sender, EventArgs e)
{
if (File.Exists(clashPath + @"\resources\app.asar.bak"))
foreach (Process p in Process.GetProcesses())
{
foreach (Process p in Process.GetProcesses())
if (p.ProcessName == GlobalData.clashProcessName)
{
if (p.ProcessName == GlobalData.clashProcessName)
if (MessageBox.Show("Clash for Windows 已开启,是否关闭 Clash for Windows?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
CloseClashButton_Click(sender, e);
break;
}
else
{
MessageBox.Show("Clash for Windows已开启,请关闭后重试。");
logTextBox.AppendText("Clash for Windows已开启,请关闭Clash for Windows后重试。" + Environment.NewLine);
goto c;
}
}
File.Move(clashPath + @"\resources\app.asar.bak", clashPath + @"\resources\app.asar", true);
logTextBox.AppendText("已还原英文版" + Environment.NewLine);
}
if (Directory.Exists(clashPath + @"\resources\app"))
{
IniList ini = new IniList();
string[] replacePath = ini.GetSectionValue("Replace Path", GlobalData.iniFilePath).ToArray();
File.Copy(backup_original + @"\moment.js", clashPath + @"\resources\app\node_modules\moment\moment.js", true);
logTextBox.AppendText("已还原被汉化文件" + clashPath + @"\resources\app\node_modules\moment\moment.js" + Environment.NewLine);
foreach (string item in replacePath)
{
string[] s = item.Split(@"\");
string fileName = s[s.Length - 1];
File.Copy(backup_original + @"\" + fileName, clashPath + item, true);
logTextBox.AppendText("已还原被汉化文件 " + clashPath + item + Environment.NewLine);
}
MessageBox.Show("文件还原完毕,已还原至已解包状态,可以继续汉化。", "提示");
logTextBox.AppendText("文件还原完毕,已还原至已解包状态,可以继续汉化。" + Environment.NewLine);
}
else if (File.Exists(clashPath + @"\resources\app.asar.bak"))
{
Thread.Sleep(2000);
try
{
File.Delete(clashPath + @"\resources\app.asar");
File.Move(clashPath + @"\resources\app.asar.bak", clashPath + @"\resources\app.asar", true);
logTextBox.AppendText("已还原英文版" + Environment.NewLine);
}
catch (Exception)
{
logTextBox.AppendText("无法还原," + clashPath + @"\resources\app.asar.bak" + "文件丢失,请下载原版自行替换app.asar。" + Environment.NewLine);
throw;
}
}
else
{
Expand All @@ -403,7 +442,7 @@ private void OpenClashButton_Click(object sender, EventArgs e)
if (vProc.ProcessName == GlobalData.clashProcessName)
{
logTextBox.AppendText(GlobalData.clashProcessName + " 已开启,无需重复开启" + Environment.NewLine);
MessageBox.Show(GlobalData.clashProcessName + " 已开启,无需重复开启");
MessageBox.Show(GlobalData.clashProcessName + " 已开启,无需重复开启", "提示");
goto c;
}
}
Expand Down Expand Up @@ -439,14 +478,14 @@ private void CloseClashButton_Click(object sender, EventArgs e)
catch (Exception)
{
logTextBox.AppendText("关闭 " + GlobalData.clashProcessName + " 失败,请手动关闭" + Environment.NewLine);
MessageBox.Show(GlobalData.clashProcessName + "关闭 " + GlobalData.clashProcessName + " 失败,请手动关闭");
MessageBox.Show(GlobalData.clashProcessName + "关闭 " + GlobalData.clashProcessName + " 失败,请手动关闭", "提示");
goto c;
throw;
}
}
}
logTextBox.AppendText(GlobalData.clashProcessName + " 未开启,无需关闭" + Environment.NewLine);
MessageBox.Show(GlobalData.clashProcessName + " 未开启,无需关闭");
MessageBox.Show(GlobalData.clashProcessName + " 未开启,无需关闭", "提示");
c:;
}

Expand Down Expand Up @@ -476,7 +515,7 @@ private void autoCkeckClashPathButton_Click(object sender, EventArgs e)
catch (Exception)
{
logTextBox.AppendText("关闭 " + GlobalData.clashProcessName + " 失败,请手动关闭" + Environment.NewLine);
MessageBox.Show(GlobalData.clashProcessName + "关闭 " + GlobalData.clashProcessName + " 失败,请手动关闭");
MessageBox.Show(GlobalData.clashProcessName + "关闭 " + GlobalData.clashProcessName + " 失败,请手动关闭", "提示");
throw;
}

Expand Down Expand Up @@ -505,7 +544,7 @@ private void autoCkeckClashPathButton_Click(object sender, EventArgs e)
}
}
logTextBox.AppendText(GlobalData.clashProcessName + " 未开启 Clash for Windows ,请打开 Clash for Windows 后重试" + Environment.NewLine);
MessageBox.Show(GlobalData.clashProcessName + " 未开启 Clash for Windows ,请打开 Clash for Windows 后重试");
MessageBox.Show(GlobalData.clashProcessName + " 未开启 Clash for Windows ,请打开 Clash for Windows 后重试", "提示");
c:;
}
#endregion
Expand Down Expand Up @@ -642,7 +681,6 @@ private void MainForm_KeyDown(object sender, KeyEventArgs e)
{
saveTranslationScriptButton_Click(sender, e);
}
logTextBox.AppendText("已保存列表文件" + Environment.NewLine);
}
}

Expand All @@ -666,7 +704,7 @@ private void CleanToolStripMenuItem_Click(object sender, EventArgs e)
//GitHub链接点击进入
private void githubToolStripStatusLabel_Click(object sender, EventArgs e)
{
Process.Start("explorer.exe", "https://github.com/BoyceLig/ClashSinicizationTool");
Process.Start("explorer.exe", GlobalData.projectAddress);
}
}
}
Expand Down
Loading

0 comments on commit 2da4c76

Please sign in to comment.