fix:读取版本号时优先读取this.__VERSION__; 可手动修改版本号; 重排布局; 为防止炸样板, icons.js不再进行迁移
This commit is contained in:
1 parent
3f3d29a734
commit
a96b7ad67e
4 files changed
+123
-39
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择要翻新的旧塔的文件夹,会自动读取旧塔的版本号
|
||||
/// </summary>
|
||||
private void SelectSourceRootFolder()
|
||||
{
|
||||
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
|
||||
@@ -97,6 +99,9 @@ namespace H5MotaUpdate.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择新样板文件夹
|
||||
/// </summary>
|
||||
public void SelectDestRootFolder()
|
||||
{
|
||||
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -16,30 +16,54 @@ namespace H5MotaUpdate.ViewModels
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从给定路径的旧塔文件夹中读取版本号
|
||||
/// </summary>
|
||||
/// <param name="folderPath"></param>
|
||||
/// <returns></returns>
|
||||
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中未找到格式合法的版本号!";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user