fix: 修复 wpf gui 一些 resource path 读取

fix https://github.com/MaaAssistantArknights/MaaAssistantArknights/issues/14044
This commit is contained in:
MistEO
2025-09-09 00:12:11 +08:00
parent c9337f90f0
commit 523b496daa
2 changed files with 8 additions and 7 deletions

View File

@@ -78,13 +78,13 @@ namespace MaaWpfGui.Helper
private static void LoadBattleData()
{
const string FilePath = "resource/battle_data.json";
if (!File.Exists(FilePath))
string filePath = Path.Combine(AsstProxy.MainResourcePath(), "resource/battle_data.json");
if (!File.Exists(filePath))
{
return;
}
string jsonText = File.ReadAllText(FilePath);
string jsonText = File.ReadAllText(filePath);
var characterData = JsonConvert.DeserializeObject<Dictionary<string, CharacterInfo>>(JObject.Parse(jsonText)["chars"]?.ToString() ?? string.Empty) ?? [];
var characterNamesLangAdd = GetCharacterNamesAddAction(ConfigurationHelper.GetGlobalValue(ConfigurationKeys.Localization, LocalizationHelper.DefaultLanguage));

View File

@@ -24,6 +24,7 @@ using JetBrains.Annotations;
using MaaWpfGui.Constants;
using MaaWpfGui.Extensions;
using MaaWpfGui.Helper;
using MaaWpfGui.Main;
using MaaWpfGui.Models;
using MaaWpfGui.Properties;
using MaaWpfGui.Services;
@@ -157,13 +158,13 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase
{
bool isDefaultClient = new HashSet<string> { string.Empty, "Official", "Bilibili" }.Contains(clientType);
const string DefaultJsonPath = "resource/version.json";
string defaultJsonPath = Path.Combine(AsstProxy.MainResourcePath(), "resource/version.json");
var jsonPath = isDefaultClient
? DefaultJsonPath
? defaultJsonPath
: $"resource/global/{clientType}/resource/version.json";
string versionName;
if (!File.Exists(DefaultJsonPath) || (!isDefaultClient && !File.Exists(jsonPath)))
if (!File.Exists(defaultJsonPath) || (!isDefaultClient && !File.Exists(jsonPath)))
{
return (DateTime.MinValue, string.Empty);
}
@@ -174,7 +175,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase
var activityTime = (ulong?)versionJson?["activity"]?["time"]; // 活动的开始时间
var lastUpdated = isDefaultClient
? (string?)versionJson?["last_updated"]
: (string?)LoadJson(DefaultJsonPath)?["last_updated"];
: (string?)LoadJson(defaultJsonPath)?["last_updated"];
var dateTime = lastUpdated == null
? DateTime.MinValue