Compare commits

..

No commits in common. "master" and "v1.0" have entirely different histories.
master ... v1.0

14 changed files with 44 additions and 349 deletions

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="H5MotaUpdate.Properties.Settings1" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<H5MotaUpdate.Properties.Settings1>
<setting name="LastSourceFolderPath" serializeAs="String">
<value />
</setting>
<setting name="LastDestFolderPath" serializeAs="String">
<value />
</setting>
</H5MotaUpdate.Properties.Settings1>
</userSettings>
</configuration>

View File

@ -13,19 +13,4 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
</Project> </Project>

View File

@ -10,75 +10,26 @@
<Window.DataContext> <Window.DataContext>
<vm:MainViewModel></vm:MainViewModel> <vm:MainViewModel></vm:MainViewModel>
</Window.DataContext> </Window.DataContext>
<Grid> <Canvas>
<Grid.RowDefinitions> <TextBlock FontSize ="16" Height="20" Canvas.Left="10" Text="旧塔文件夹" Canvas.Top="15" Width="100" HorizontalAlignment="Center" VerticalAlignment="Top"/>
<RowDefinition Height="Auto"/> <TextBlock FontSize ="16" Height="20" Canvas.Left="10" Text="新样板文件夹" Canvas.Top="50" Width="100" HorizontalAlignment="Center" VerticalAlignment="Top"/>
<RowDefinition Height="Auto"/> <TextBlock FontSize ="16" Height="20" Canvas.Left="10" Text="旧塔版本号" Canvas.Top="85" Width="100" HorizontalAlignment="Center" VerticalAlignment="Top"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Margin="0,0,0,10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="15,10,0,10" FontSize ="16"
Text="旧塔文件夹" />
<TextBlock Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="15,10,0,10" FontSize ="14"
Width="500" TextWrapping ="Wrap"
Name ="InputFolderPath" Text="{Binding SourceRootDirectory}"/>
<Button Grid.Row="0" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="15,10,0,10" Padding="5,2,5,2" FontSize ="16"
Name ="BrowseSourceFolderButton" Content="浏览" Command="{Binding SelectSourceCommand}"/>
<TextBlock Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="15,10,0,10" <TextBlock Name ="InputFolderPath" FontSize ="14" Height="40" Canvas.Left="140" Canvas.Top="15" Width="500" TextWrapping ="Wrap" Text="{Binding SourceRootDirectory}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
Text="新样板文件夹" FontSize ="16" /> <TextBlock Name ="OutputFolderPath" FontSize ="14" Height="40" Canvas.Left="140" Canvas.Top="50" Width="500" TextWrapping ="Wrap" Text="{Binding DestRootDirectory}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBlock Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="15,10,0,10" FontSize ="14" <TextBlock FontSize ="16" Height="20" Canvas.Left="140" Text="{Binding VersionString}" Canvas.Top="85" Width="Auto" HorizontalAlignment="Left" VerticalAlignment="Center"/>
Width="500" TextWrapping ="Wrap"
Name ="OutputFolderPath" Text="{Binding DestRootDirectory}" />
<Button Grid.Row="1" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="15,10,0,10" Padding="5,2,5,2" FontSize ="16"
x:Name ="BrowseDestFolderButton" Content="浏览" Command="{Binding SelectDestCommand}"/>
<TextBlock Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="15,10,0,10" <Button Name ="BrowseSourceFolderButton" FontSize ="16" Content="浏览" Canvas.Left="680" Canvas.Top="10" Width="40" Command="{Binding SelectSourceCommand}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
Text="旧塔版本号" FontSize ="16"/> <Button x:Name ="BrowseDestFolderButton" FontSize ="16" Content="浏览" Canvas.Left="680" Canvas.Top="47" Width="40" Command="{Binding SelectDestCommand}" HorizontalAlignment="Center" VerticalAlignment="Top"/>
<Grid Grid.Row="2" Grid.Column="1"> <Button FontSize ="16" Content="开始迁移" Canvas.Left="30" Canvas.Top="127" Width="140" Command="{Binding MigrateCommand}" IsEnabled= "{Binding IsAvailable}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<Grid.ColumnDefinitions> <CheckBox Name ="MigrateConfig" Content="迁移配置表格" Height="26" Canvas.Left="426" Canvas.Top="134" Width="100" IsChecked="{Binding MigrateServerTable}"/>
<ColumnDefinition Width="Auto"/> <Button FontSize ="16" Content="查看帮助" Canvas.Left="223" Canvas.Top="127" Width="140" Command="{Binding HelpCommand}" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<ColumnDefinition Width="Auto"/> <ListBox Height="90" Canvas.Left="30" Canvas.Top="230" Width="690" ItemsSource="{Binding ErrorMessages}" HorizontalAlignment="Center" VerticalAlignment="Top">
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="40,10,40,10" FontSize ="16"
Text="{Binding VersionString}" Width="Auto" />
<TextBox Grid.Row="2" Grid.Column="1" Width="80" Height="25" Margin="40,10,10,10" FontSize ="16"
Text="{Binding VersionString, UpdateSourceTrigger=PropertyChanged}"/>
</Grid>
</Grid>
<Grid Grid.Row="1" Margin="0,0,0,30">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="50,10,0,10" Padding="10,5,10,5" FontSize ="16"
Content="开始迁移" Command="{Binding MigrateCommand}" IsEnabled= "{Binding IsAvailable}" />
<Button Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="50,10,0,10" Padding="10,5,10,5" FontSize ="16"
Content="查看帮助" Command="{Binding HelpCommand}"/>
<CheckBox Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="50,10,0,10" FontSize ="14"
Name ="MigrateConfig" Content="迁移配置表格" IsChecked="{Binding MigrateServerTable}"/>
</Grid>
<ListBox Grid.Row="2" Width="700" Height ="140" ItemsSource="{Binding ErrorMessages}" HorizontalAlignment="Center" VerticalAlignment="Center">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding Text}" Foreground="{Binding Color}" TextWrapping="Wrap"/> <TextBlock Text="{Binding Text}" Foreground="{Binding Color}" TextWrapping="Wrap"/>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
</Grid> </Canvas>
</Window> </Window>

View File

@ -1,50 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace H5MotaUpdate.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.11.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string LastSourceFolderPath {
get {
return ((string)(this["LastSourceFolderPath"]));
}
set {
this["LastSourceFolderPath"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string LastDestFolderPath {
get {
return ((string)(this["LastDestFolderPath"]));
}
set {
this["LastDestFolderPath"] = value;
}
}
}
}

View File

@ -1,12 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="H5MotaUpdate.Properties" GeneratedClassName="Settings1">
<Profiles />
<Settings>
<Setting Name="LastSourceFolderPath" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="LastDestFolderPath" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

View File

@ -6,6 +6,7 @@ using System.Windows.Input;
namespace H5MotaUpdate.ViewModels namespace H5MotaUpdate.ViewModels
{ {
//silverCoin->Wand
class MainViewModel : INotifyPropertyChanged class MainViewModel : INotifyPropertyChanged
{ {
private string? _sourceRootDirectory; private string? _sourceRootDirectory;
@ -84,44 +85,25 @@ namespace H5MotaUpdate.ViewModels
IsAvailable = true; IsAvailable = true;
} }
/// <summary>
/// 选择要翻新的旧塔的文件夹,会自动读取旧塔的版本号
/// </summary>
private void SelectSourceRootFolder() private void SelectSourceRootFolder()
{ {
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
{ {
// 设置初始路径为上一次选择的路径
folderBrowserDialog.SelectedPath = Properties.Settings.Default.LastSourceFolderPath;
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{ {
SourceRootDirectory = folderBrowserDialog.SelectedPath; SourceRootDirectory = folderBrowserDialog.SelectedPath;
// 保存本次选择的路径
Properties.Settings.Default.LastSourceFolderPath = SourceRootDirectory;
Properties.Settings.Default.Save();
} }
VersionString = VersionUtils.GetVersion(SourceRootDirectory); VersionString = VersionUtils.GetVersion(SourceRootDirectory);
} }
} }
/// <summary>
/// 选择新样板文件夹
/// </summary>
public void SelectDestRootFolder() public void SelectDestRootFolder()
{ {
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
{ {
// 设置初始路径为上一次选择的路径
folderBrowserDialog.SelectedPath = Properties.Settings.Default.LastDestFolderPath;
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{ {
DestRootDirectory = folderBrowserDialog.SelectedPath; DestRootDirectory = folderBrowserDialog.SelectedPath;
// 保存本次选择的路径
Properties.Settings.Default.LastDestFolderPath = DestRootDirectory;
Properties.Settings.Default.Save();
} }
} }
} }

View File

@ -152,7 +152,7 @@ namespace H5MotaUpdate.ViewModels
} }
if (heroData["equipment"] == null) if (heroData["equipment"] == null)
{ {
heroData["equipment"] = new JArray(); // 预防某些超级老样板没有hero.equipment heroData["equipment"] = new JArray(); // 预防某些超级老样板没有hero.equipment}
} }
heroData.Remove("experience"); heroData.Remove("experience");
@ -192,9 +192,7 @@ namespace H5MotaUpdate.ViewModels
shopId = shop["id"].ToString(), shopId = shop["id"].ToString(),
flagName_Time = "flag:" + shopId + "_times"; // 新设的购买次数变量flag:xxx flagName_Time = "flag:" + shopId + "_times"; // 新设的购买次数变量flag:xxx
string priceStr = shopNeed.Replace("times", flagName_Time); //商店价格字符串用新变量名取代times string priceStr = shopNeed.Replace("times", flagName_Time); //商店价格字符串用新变量名取代times
shop["text"] = StringUtils.ReplaceInBetweenCurlyBraces(shopText, "times", flagName_Time); shop["text"] = StringUtils.ReplaceInBetweenCurlyBraces(shopText, "times", flagName_Time);
shop["text"] = StringUtils.ReplaceInBetweenCurlyBraces(shopText, "need", priceStr);
shop["disablePreview"] = false; shop["disablePreview"] = false;
if (use == "experience") if (use == "experience")

View File

@ -120,14 +120,6 @@ namespace H5MotaUpdate.ViewModels
enemy["breakArmor"] = enemy["defValue"]; enemy["breakArmor"] = enemy["defValue"];
enemy.Remove("defValue"); enemy.Remove("defValue");
break; break;
case 9: //净化
enemy["purify"] = enemy["n"];
enemy.Remove("purify");
break;
case 11://吸血
enemy["vampire"] = enemy["value"];
enemy.Remove("value");
break;
case 15://领域 case 15://领域
enemy["zone"] = enemy["value"]; enemy["zone"] = enemy["value"];
enemy.Remove("value"); enemy.Remove("value");
@ -144,9 +136,6 @@ namespace H5MotaUpdate.ViewModels
enemy["haloRange"] = enemy["range"]; enemy["haloRange"] = enemy["range"];
enemy["haloSquare"] = enemy["zoneSquare"]; enemy["haloSquare"] = enemy["zoneSquare"];
enemy["haloAdd"] = enemy["add"]; enemy["haloAdd"] = enemy["add"];
enemy["hpBuff"] = enemy["value"];
enemy["atkBuff"] = enemy["atkValue"];
enemy["defBuff"] = enemy["defValue"];
enemy.Remove("range"); enemy.Remove("range");
enemy.Remove("zoneSquare"); enemy.Remove("zoneSquare");
enemy.Remove("add"); enemy.Remove("add");
@ -181,16 +170,6 @@ namespace H5MotaUpdate.ViewModels
enemy["breakArmor"] = enemy["defValue"]; enemy["breakArmor"] = enemy["defValue"];
if (!foundSpecialValues.Contains(21)) enemy.Remove("defValue"); if (!foundSpecialValues.Contains(21)) enemy.Remove("defValue");
} }
if (foundSpecialValues.Contains(9))
{
enemy["purify"] = enemy["n"];
if (!foundSpecialValues.Contains(6)) enemy.Remove("purify");
}
if (foundSpecialValues.Contains(11))
{
enemy["vampire"] = enemy["value"];
if (!foundSpecialValues.Contains(21)) enemy.Remove("value");
}
if (foundSpecialValues.Contains(15)) if (foundSpecialValues.Contains(15))
{ {
enemy["zone"] = enemy["value"]; enemy["zone"] = enemy["value"];
@ -211,9 +190,6 @@ namespace H5MotaUpdate.ViewModels
enemy["haloRange"] = enemy["range"]; enemy["haloRange"] = enemy["range"];
enemy["haloSquare"] = enemy["zoneSquare"]; enemy["haloSquare"] = enemy["zoneSquare"];
enemy["haloAdd"] = enemy["add"]; enemy["haloAdd"] = enemy["add"];
enemy["hpBuff"] = enemy["value"];
enemy["atkBuff"] = enemy["atkValue"];
enemy["defBuff"] = enemy["defValue"];
if (!foundSpecialValues.Contains(11)) enemy.Remove("add"); if (!foundSpecialValues.Contains(11)) enemy.Remove("add");
if (!foundSpecialValues.Contains(15)) if (!foundSpecialValues.Contains(15))
{ {

View File

@ -1,5 +1,4 @@
using H5MotaUpdate.ViewModels.Utils; using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Linq;
using System.IO; using System.IO;
using System.Text; using System.Text;
@ -93,12 +92,6 @@ namespace H5MotaUpdate.ViewModels
// 设置每张地图的尺寸。如果自己有就用自己的,否则设为默认长宽。 // 设置每张地图的尺寸。如果自己有就用自己的,否则设为默认长宽。
foreach (JProperty posEvent in jsonObject["events"])
{
JToken posEventValue = posEvent.Value;
MotaEventParser.parseMotaEvent(posEventValue);
}
int width, height; int width, height;
if (jsonObject["width"] != null && jsonObject["width"].Type == JTokenType.Integer) if (jsonObject["width"] != null && jsonObject["width"].Type == JTokenType.Integer)
@ -152,7 +145,7 @@ namespace H5MotaUpdate.ViewModels
jsonObject["images"] = new JArray(newImages); jsonObject["images"] = new JArray(newImages);
#endregion #endregion
#region #region
JArray mapMatrix = (JArray)jsonObject["map"]; JArray mapMatrix = (JArray)jsonObject["map"];
JArray zeroBgMatrix = StringUtils.CreateMatrix(width, height); JArray zeroBgMatrix = StringUtils.CreateMatrix(width, height);
for (int i = 0; i < mapMatrix.Count; i++) for (int i = 0; i < mapMatrix.Count; i++)

View File

@ -89,41 +89,11 @@ namespace H5MotaUpdate.ViewModels
{ {
string key = prop.Name; string key = prop.Name;
JObject perData = (JObject)prop.Value; JObject perData = (JObject)prop.Value;
if (perData["cls"].ToString() == "keys")
if (perData["cls"]?.ToString() == "keys")
{ {
perData["cls"] = "tools"; perData["cls"] = "tools";
perData["hideInToolbox"] = true; perData["hideInToolbox"] = true;
} }
if (perData["cls"]?.ToString() == "equips")
{
JObject equipValue = (JObject)perData["equip"];
if (equipValue != null)
{
JObject valueObj = new JObject();
// 装备属性的名字
string[] keysToMove = { "atk", "def", "mdef", "hp" };
foreach (string keyToMove in keysToMove)
{
if (equipValue.ContainsKey(keyToMove))
{
JToken val = equipValue[keyToMove];
valueObj[keyToMove] = val;
equipValue.Remove(keyToMove);
}
}
if (equipValue.ContainsKey("percentage") && equipValue["percentage"].Type == JTokenType.Boolean && (bool)equipValue["percentage"])
{
equipValue["percentage"] = valueObj;
}
else equipValue["value"] = valueObj;
perData["equip"] = equipValue;
}
}
} }
if (newItemDatas.ContainsKey("snow")) if (newItemDatas.ContainsKey("snow"))
{ {

View File

@ -143,26 +143,20 @@ namespace H5MotaUpdate.ViewModels
foreach (string filePath in files) foreach (string filePath in files)
{ {
string fileName = Path.GetFileName(filePath); string fileName = Path.GetFileName(filePath);
// 由于屡次导致工程爆炸icons.png就不复制了 if (fileName == "icons.png" && version < new Version(2, 5, 4)) //检查icons长度
if (fileName == "icons.png")
{ {
continue; 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 (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)) if (imagesList.Contains(fileName))
{ {
File.Copy(filePath, Path.Combine(newProjectDirectory, "images/" + fileName), true); File.Copy(filePath, Path.Combine(newProjectDirectory, "images/" + fileName), true);

View File

@ -1,50 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace H5MotaUpdate.ViewModels.Utils
{
internal static class MotaEventParser
{
public static void parseOneMotaEvent(JObject motaEvent)
{
// 如果type为openShop添加一个open:true的键
if (motaEvent["type"] is JValue typeValue && typeValue.Value is string typeString && typeString == "openShop")
{
motaEvent["open"] = true;
}
}
static void parseMotaEventArr(JArray motaEventArr)
{
foreach (JToken motaEventToken in motaEventArr)
{
// 只处理对象事件 字符串不计
if (motaEventToken.Type == JTokenType.Object)
{
JObject motaEvent = (JObject)motaEventToken;
parseOneMotaEvent(motaEvent);
}
}
}
public static void parseMotaEvent(JToken motaEvent)
{
if (motaEvent is JArray motaEventArr)
{
parseMotaEventArr(motaEventArr);
}
else if (motaEvent is JObject motaEventObj)
{ // 说明有覆盖触发器等data中才是真正的事件
if (motaEvent["data"] is JArray dataArr)
{
parseMotaEventArr(dataArr);
}
}
}
}
}

View File

@ -50,7 +50,7 @@ namespace H5MotaUpdate.ViewModels
// 获取匹配的内容,去掉 ${ 和 } // 获取匹配的内容,去掉 ${ 和 }
string content = match.Groups[1].Value; string content = match.Groups[1].Value;
// 在匹配的内容中替换 oldWord 为 newWord // 在匹配的内容中替换 oldWord 为 newWord
string modifiedContent = "(" + content.Replace(oldWord, newWord) + ")"; string modifiedContent = content.Replace(oldWord, newWord);
// 返回替换后的完整匹配字符串,包含 ${ 和 } // 返回替换后的完整匹配字符串,包含 ${ 和 }
return "${" + modifiedContent + "}"; return "${" + modifiedContent + "}";
}); });

View File

@ -16,54 +16,30 @@ namespace H5MotaUpdate.ViewModels
return true; return true;
} }
/// <summary>
/// 从给定路径的旧塔文件夹中读取版本号
/// </summary>
/// <param name="folderPath"></param>
/// <returns></returns>
public static string GetVersion(string? folderPath) public static string GetVersion(string? folderPath)
{ {
if (folderPath == null) return "文件夹路径不合法"; if (folderPath == null) return "文件夹路径不合法";
string filePath = Path.Combine(folderPath, "main.js"); string filePath = Path.Combine(folderPath, "main.js");
string version;
if (!File.Exists(filePath)) return "给定文件夹未找到文件main.js";
string fileContent;
try try
{ {
fileContent = File.ReadAllText(filePath); 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中未找到格式合法的版本号";
} }
catch (Exception ex) 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中未找到格式合法的版本号";
} }
} }
} }