From a96b7ad67ea709f4f603fd2ebd22542f579164dc Mon Sep 17 00:00:00 2001
From: lizhuoyuan <2820814112@qq.com>
Date: Tue, 27 May 2025 17:04:29 +0800
Subject: [PATCH] =?UTF-8?q?fix:=E8=AF=BB=E5=8F=96=E7=89=88=E6=9C=AC?=
=?UTF-8?q?=E5=8F=B7=E6=97=B6=E4=BC=98=E5=85=88=E8=AF=BB=E5=8F=96this.=5F?=
=?UTF-8?q?=5FVERSION=5F=5F;=20=E5=8F=AF=E6=89=8B=E5=8A=A8=E4=BF=AE?=
=?UTF-8?q?=E6=94=B9=E7=89=88=E6=9C=AC=E5=8F=B7;=20=E9=87=8D=E6=8E=92?=
=?UTF-8?q?=E5=B8=83=E5=B1=80;=20=E4=B8=BA=E9=98=B2=E6=AD=A2=E7=82=B8?=
=?UTF-8?q?=E6=A0=B7=E6=9D=BF=EF=BC=8C=20icons.js=E4=B8=8D=E5=86=8D?=
=?UTF-8?q?=E8=BF=9B=E8=A1=8C=E8=BF=81=E7=A7=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
MainWindow.xaml | 77 ++++++++++++++++++----
ViewModels/MainViewModel.cs | 7 +-
ViewModels/Migrator/MediaSourceMigrator.cs | 28 ++++----
ViewModels/Utils/VersionUtils.cs | 50 ++++++++++----
4 files changed, 123 insertions(+), 39 deletions(-)
diff --git a/MainWindow.xaml b/MainWindow.xaml
index 54e2bf9..b27c308 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -10,26 +10,75 @@
-
+
+
diff --git a/ViewModels/MainViewModel.cs b/ViewModels/MainViewModel.cs
index bbddf87..9ff7680 100644
--- a/ViewModels/MainViewModel.cs
+++ b/ViewModels/MainViewModel.cs
@@ -6,7 +6,6 @@ using System.Windows.Input;
namespace H5MotaUpdate.ViewModels
{
- //silverCoin->Wand
class MainViewModel : INotifyPropertyChanged
{
private string? _sourceRootDirectory;
@@ -85,6 +84,9 @@ namespace H5MotaUpdate.ViewModels
IsAvailable = true;
}
+ ///
+ /// 选择要翻新的旧塔的文件夹,会自动读取旧塔的版本号
+ ///
private void SelectSourceRootFolder()
{
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
@@ -97,6 +99,9 @@ namespace H5MotaUpdate.ViewModels
}
}
+ ///
+ /// 选择新样板文件夹
+ ///
public void SelectDestRootFolder()
{
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
diff --git a/ViewModels/Migrator/MediaSourceMigrator.cs b/ViewModels/Migrator/MediaSourceMigrator.cs
index c0fb57e..c4025db 100644
--- a/ViewModels/Migrator/MediaSourceMigrator.cs
+++ b/ViewModels/Migrator/MediaSourceMigrator.cs
@@ -143,20 +143,26 @@ namespace H5MotaUpdate.ViewModels
foreach (string filePath in files)
{
string fileName = Path.GetFileName(filePath);
- if (fileName == "icons.png" && version < new Version(2, 5, 4)) //检查icons长度
+ // 由于屡次导致工程爆炸,icons.png就不复制了
+ if (fileName == "icons.png")
{
- using (Bitmap image = new Bitmap(filePath))
- {
- int width = image.Width;
- int height = image.Height;
- if (height < 1120)
- {
- ErrorLogger.LogError("警告:原塔的icons.png长度不足!请对照最新样板使用PS工具补齐数字键和Alt图标等。", "red");
- MessageBox.Show("警告:原塔的icons.png长度不足!请对照最新样板使用PS工具补齐数字键和Alt图标等。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
- }
+ continue;
}
+ //if (fileName == "icons.png" && version < new Version(2, 5, 4)) //检查icons长度
+ //{
+ // using (Bitmap image = new Bitmap(filePath))
+ // {
+ // int width = image.Width;
+ // int height = image.Height;
+ // if (height < 1120)
+ // {
+ // ErrorLogger.LogError("警告:原塔的icons.png长度不足!请对照最新样板使用PS工具补齐数字键和Alt图标等。", "red");
+ // MessageBox.Show("警告:原塔的icons.png长度不足!请对照最新样板使用PS工具补齐数字键和Alt图标等。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+ // }
+ // }
+ //}
+
if (imagesList.Contains(fileName))
{
File.Copy(filePath, Path.Combine(newProjectDirectory, "images/" + fileName), true);
diff --git a/ViewModels/Utils/VersionUtils.cs b/ViewModels/Utils/VersionUtils.cs
index 6ef58bd..ac6026d 100644
--- a/ViewModels/Utils/VersionUtils.cs
+++ b/ViewModels/Utils/VersionUtils.cs
@@ -16,30 +16,54 @@ namespace H5MotaUpdate.ViewModels
return true;
}
+ ///
+ /// 从给定路径的旧塔文件夹中读取版本号
+ ///
+ ///
+ ///
public static string GetVersion(string? folderPath)
{
if (folderPath == null) return "文件夹路径不合法";
string filePath = Path.Combine(folderPath, "main.js");
- string version;
+
+ if (!File.Exists(filePath)) return "给定文件夹未找到文件main.js";
+
+ string fileContent;
try
{
- if (!File.Exists(filePath)) return "给定文件夹未找到文件main.js";
-
- string fileContent = File.ReadAllText(filePath);
-
- Regex versionRegex = new Regex(@"this\.version\s*=\s*['""](\d+(\.\d+)+)['""];");
- Match match = versionRegex.Match(fileContent);
-
- if (!match.Success) return "文件 main.js中未找到版本号!";
- version = match.Groups[1].Value;
- if (!IsValidVersion(version)) return "文件 main.js中未找到格式合法的版本号!";
+ fileContent = File.ReadAllText(filePath);
}
catch (Exception ex)
{
- return "读取版本号失败,原因: " + ex.Message;
+ return "读取文件内容失败,原因: " + ex.Message;
}
- return version;
+
+ string version = null;
+
+ // 优先匹配 this.__VERSION__ = "...";
+ Regex specialVersionRegex = new Regex(
+ @"this\s*\.\s*__VERSION__\s*=\s*['""](\d+(\.\d+)+)['""]\s*;?");
+ Match specialMatch = specialVersionRegex.Match(fileContent);
+ if (specialMatch.Success)
+ {
+ version = specialMatch.Groups[1].Value;
+ if (IsValidVersion(version))
+ return version;
+ }
+
+ // 回退到原来的方式:this.version = "x.x.x"
+ Regex normalVersionRegex = new Regex(@"this\.version\s*=\s*['""](\d+(\.\d+)+)['""];?");
+ Match normalVersionMatch = normalVersionRegex.Match(fileContent);
+
+ if (normalVersionMatch.Success)
+ {
+ version = normalVersionMatch.Groups[1].Value;
+ if (IsValidVersion(version))
+ return version;
+ }
+
+ return "文件 main.js中未找到格式合法的版本号!";
}
}
}