|
@@ -1,4 +1,5 @@
|
|
|
using System;
|
|
|
+using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
|
using System.Globalization;
|
|
|
using System.IO;
|
|
@@ -25,7 +26,7 @@ public class SystemOperations
|
|
|
|
|
|
public SystemOperations(Action<string> writeLog)
|
|
|
{
|
|
|
- //调试时注释掉手动设置路径
|
|
|
+ //todo 调试时注释掉手动设置路径
|
|
|
string basePath = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\');
|
|
|
var parentPath = Path.GetDirectoryName(basePath);
|
|
|
_installDirectory = Path.Combine(parentPath, "WingServer");
|
|
@@ -303,19 +304,29 @@ public class SystemOperations
|
|
|
JObject json = JObject.Parse(jsonString);
|
|
|
|
|
|
// 将传入的 JSON 字符串转换为 JObject 对象
|
|
|
- var upgradeSettings = JObject.Parse(upgradeSettingsJson)["UpgradeSetting"];
|
|
|
+ var upgradeSettings = JObject.Parse(upgradeSettingsJson);
|
|
|
|
|
|
// 修改 Upgrade 节点对应的项
|
|
|
var upgradeNode = json["Upgrade"];
|
|
|
+
|
|
|
+ // 使用一个临时列表存储要修改的属性
|
|
|
+ List<JProperty> propertiesToReplace = new List<JProperty>();
|
|
|
foreach (var property in upgradeNode)
|
|
|
{
|
|
|
- var newValue = upgradeSettings.SelectToken(property.Path);
|
|
|
+ var newValue = upgradeSettings.SelectToken(property.Path.Split('.')[1]);
|
|
|
if (newValue != null)
|
|
|
{
|
|
|
- property.Replace(newValue);
|
|
|
+ var newProperty = new JProperty(property.Path.Split('.')[1], newValue);
|
|
|
+ propertiesToReplace.Add(newProperty);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 遍历临时列表,替换原来的属性
|
|
|
+ foreach (var property in propertiesToReplace)
|
|
|
+ {
|
|
|
+ upgradeNode[property.Name] = property.Value;
|
|
|
+ }
|
|
|
+
|
|
|
// 将更改后的 JSON 数据写回文件
|
|
|
await File.WriteAllTextAsync(appSettingsPath, json.ToString(Formatting.Indented));
|
|
|
|