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中未找到格式合法的版本号!";
}
}
}