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
@@ -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