mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 17:57:01 +08:00
feat: ota of all tasks resources (#3872)
- feat: support ota update of acitivity info (and any other resources) - fix: ota update wrong path & version - chore: remove DH resources (which will be ota)
This commit is contained in:
@@ -9,21 +9,6 @@
|
||||
"幻滅"
|
||||
]
|
||||
},
|
||||
"DH-Open": {
|
||||
"text": [
|
||||
"ドッソレス",
|
||||
"ホリデー",
|
||||
"復刻",
|
||||
"イベント",
|
||||
"催中"
|
||||
]
|
||||
},
|
||||
"DHChapterToDH": {
|
||||
"text": [
|
||||
"大会",
|
||||
"エントリー"
|
||||
]
|
||||
},
|
||||
"CharsNameOcrReplace": {
|
||||
"Doc": "该任务的 ocrReplace 被所有涉及干员名的日文识别任务复用 このタスクの「ocrReplace」は、オペレーター名に関連するすべての認識タスクで再利用されます",
|
||||
"replaceFull": true,
|
||||
|
||||
@@ -785,63 +785,6 @@
|
||||
"isAscii": true,
|
||||
"text": []
|
||||
},
|
||||
"DH-9": {
|
||||
"algorithm": "JustReturn",
|
||||
"action": "DoNothing",
|
||||
"sub": [
|
||||
"DH-Open"
|
||||
],
|
||||
"next": [
|
||||
"DH-9@SideStoryStage",
|
||||
"DH-9@SwipeToStage"
|
||||
]
|
||||
},
|
||||
"DH-Open": {
|
||||
"action": "ClickSelf",
|
||||
"algorithm": "OcrDetect",
|
||||
"text": [
|
||||
"假日",
|
||||
"复刻",
|
||||
"活动",
|
||||
"开放"
|
||||
],
|
||||
"roi": [
|
||||
0,
|
||||
500,
|
||||
500,
|
||||
150
|
||||
],
|
||||
"postDelay": 2000,
|
||||
"next": [
|
||||
"DHChapterToDH"
|
||||
]
|
||||
},
|
||||
"DHChapterToDH": {
|
||||
"algorithm": "OcrDetect",
|
||||
"action": "ClickSelf",
|
||||
"text": [
|
||||
"极限",
|
||||
"铁人",
|
||||
"大奖"
|
||||
],
|
||||
"roi": [
|
||||
934,
|
||||
280,
|
||||
234,
|
||||
124
|
||||
],
|
||||
"postDelay": 2000,
|
||||
"next": [
|
||||
"DHChapterToDH",
|
||||
"ChapterSwipeToTheRight"
|
||||
]
|
||||
},
|
||||
"DH-9@SideStoryStage": {
|
||||
"baseTask": "SideStoryStage",
|
||||
"text": [
|
||||
"DH-9"
|
||||
]
|
||||
},
|
||||
"GA-6": {
|
||||
"algorithm": "JustReturn",
|
||||
"action": "DoNothing",
|
||||
@@ -10781,7 +10724,6 @@
|
||||
"baseTask": "Reclamation@SkipAnnounce",
|
||||
"next": []
|
||||
},
|
||||
|
||||
"NavigateHome@Reclamation@Begin": {
|
||||
"algorithm": "JustReturn",
|
||||
"next": [
|
||||
@@ -10933,4 +10875,4 @@
|
||||
"Stop"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@ using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Documents;
|
||||
using MaaWpfGui.Helper;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Semver;
|
||||
@@ -75,8 +74,36 @@ namespace MaaWpfGui
|
||||
{ string.Empty, new StageInfo { Display = Localization.GetString("DefaultStage"), Value = string.Empty } },
|
||||
};
|
||||
|
||||
var stageApi = "StageActivity.json";
|
||||
var activity = fromWeb ? WebService.RequestMaaApiWithCache(stageApi) : WebService.LoadApiCache(stageApi);
|
||||
var clientType = ViewStatusStorage.Get("Start.ClientType", string.Empty);
|
||||
|
||||
// 官服和B服使用同样的资源
|
||||
if (clientType == "Bilibili" || clientType == string.Empty)
|
||||
{
|
||||
clientType = "Official";
|
||||
}
|
||||
|
||||
// Download the activities
|
||||
var stageApi = "gui/StageActivity.json";
|
||||
JObject activity = fromWeb ? WebService.RequestMaaApiWithCache(stageApi) : WebService.LoadApiCache(stageApi);
|
||||
|
||||
// Download the tasks resources into cache so MaaCore can load them later
|
||||
var tasksPath = "resource/tasks.json";
|
||||
JObject tasksJson = fromWeb ? WebService.RequestMaaApiWithCache(tasksPath) : WebService.LoadApiCache(tasksPath);
|
||||
|
||||
// Download the client specific resources only when the Official ones are successfully downloaded so that the client specific resource version is the actual version
|
||||
// TODO: There may be an issue when the CN resource is loaded from cache (e.g. network down) while global resource is downloaded (e.g. network up again)
|
||||
JObject tasksJsonClient = null;
|
||||
if (clientType != "Official" && tasksJson != null)
|
||||
{
|
||||
tasksPath = "resource/global/" + clientType + '/' + tasksPath;
|
||||
tasksJsonClient = fromWeb ? WebService.RequestMaaApiWithCache(tasksPath) : WebService.RequestMaaApiWithCache(tasksPath);
|
||||
}
|
||||
|
||||
bool isDebugVersion = Marshal.PtrToStringAnsi(AsstGetVersion()) == "DEBUG VERSION";
|
||||
bool curVerParsed = SemVersion.TryParse(Marshal.PtrToStringAnsi(AsstGetVersion()), SemVersionStyles.AllowLowerV, out var curVersionObj);
|
||||
bool curResourceVerParsed = SemVersion.TryParse(
|
||||
tasksJsonClient?["ResourceVersion"]?.ToString() ?? tasksJson?["ResourceVersion"]?.ToString() ?? string.Empty,
|
||||
SemVersionStyles.AllowLowerV, out var curResourceVersionObj);
|
||||
|
||||
var resourceCollection = new StageActivityInfo()
|
||||
{
|
||||
@@ -88,39 +115,32 @@ namespace MaaWpfGui
|
||||
"yyyy/MM/dd HH:mm:ss",
|
||||
CultureInfo.InvariantCulture).AddHours(-Convert.ToInt32(keyValuePairs?["TimeZone"].ToString() ?? "0"));
|
||||
|
||||
var clientType = ViewStatusStorage.Get("Start.ClientType", string.Empty);
|
||||
|
||||
// 官服和B服使用同样的资源
|
||||
if (clientType == "Bilibili" || clientType == string.Empty)
|
||||
{
|
||||
clientType = "Official";
|
||||
}
|
||||
|
||||
if (activity?[clientType] != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 资源全开放活动
|
||||
var resource = activity[clientType]["resourceCollection"];
|
||||
if (resource != null)
|
||||
var resourceCollectionData = activity[clientType]["resourceCollection"];
|
||||
if (resourceCollectionData != null)
|
||||
{
|
||||
resourceCollection.Tip = resource["Tip"]?.ToString();
|
||||
resourceCollection.UtcStartTime = GetDateTime(resource, "UtcStartTime");
|
||||
resourceCollection.UtcExpireTime = GetDateTime(resource, "UtcExpireTime");
|
||||
resourceCollection.Tip = resourceCollectionData["Tip"]?.ToString();
|
||||
resourceCollection.UtcStartTime = GetDateTime(resourceCollectionData, "UtcStartTime");
|
||||
resourceCollection.UtcExpireTime = GetDateTime(resourceCollectionData, "UtcExpireTime");
|
||||
}
|
||||
|
||||
// 活动关卡
|
||||
foreach (var stageObj in activity[clientType]["sideStoryStage"] ?? Enumerable.Empty<JToken>())
|
||||
{
|
||||
bool minimumRequiredPared = SemVersion.TryParse(stageObj?["MinimumRequired"]?.ToString() ?? string.Empty, SemVersionStyles.AllowLowerV, out var minimumRequiredObj);
|
||||
bool curParsed = SemVersion.TryParse(Marshal.PtrToStringAnsi(AsstGetVersion()), SemVersionStyles.AllowLowerV, out var curVersionObj);
|
||||
// MinimumResourceRequired is not necessarily provided in json, in which case it is ok even if there are no cached resources
|
||||
bool minResourceRequiredParsed = SemVersion.TryParse(stageObj?["MinimumResourceRequired"]?.ToString() ?? string.Empty, SemVersionStyles.AllowLowerV, out var minResourceRequiredObj);
|
||||
bool minRequiredParsed = SemVersion.TryParse(stageObj?["MinimumRequired"]?.ToString() ?? string.Empty, SemVersionStyles.AllowLowerV, out var minRequiredObj);
|
||||
|
||||
// DEBUG VISION
|
||||
// curParsed = SemVersion.TryParse("4.11.7", SemVersionStyles.AllowLowerV, out curVersionObj);
|
||||
var stageInfo = new StageInfo();
|
||||
if (curParsed && minimumRequiredPared)
|
||||
if ((isDebugVersion || (curVerParsed && minRequiredParsed)) && (!minResourceRequiredParsed || curResourceVerParsed))
|
||||
{
|
||||
if (curVersionObj.CompareSortOrderTo(minimumRequiredObj) < 0)
|
||||
// Debug Version will be considered satisfying min version requirement, but the resource version needs a comparison
|
||||
if ((isDebugVersion || (curVersionObj.CompareSortOrderTo(minRequiredObj) < 0)) &&
|
||||
(!minResourceRequiredParsed || curResourceVersionObj.CompareSortOrderTo(minResourceRequiredObj) < 0))
|
||||
{
|
||||
if (!tempStage.ContainsKey(Localization.GetString("UnsupportedStages")))
|
||||
{
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace MaaWpfGui.Helper
|
||||
}
|
||||
}
|
||||
|
||||
private const string CacheDir = "cache/gui/";
|
||||
private const string CacheDir = "cache/";
|
||||
private const string MaaApi = "https://ota.maa.plus/MaaAssistantArknights/api/";
|
||||
|
||||
// 如果请求失败,则读取缓存。否则写入缓存
|
||||
@@ -125,7 +125,8 @@ namespace MaaWpfGui.Helper
|
||||
try
|
||||
{
|
||||
var json = (JObject)JsonConvert.DeserializeObject(response);
|
||||
var cache = CacheDir + api.Replace('/', '_');
|
||||
var cache = CacheDir + api;
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(cache));
|
||||
File.WriteAllText(cache, response);
|
||||
|
||||
return json;
|
||||
@@ -138,7 +139,7 @@ namespace MaaWpfGui.Helper
|
||||
|
||||
public static JObject LoadApiCache(string api)
|
||||
{
|
||||
var cache = CacheDir + api.Replace('/', '_');
|
||||
var cache = CacheDir + api;
|
||||
if (!File.Exists(cache))
|
||||
{
|
||||
return null;
|
||||
|
||||
@@ -213,12 +213,18 @@ namespace MaaWpfGui
|
||||
}
|
||||
|
||||
loaded = AsstLoadResource(Directory.GetCurrentDirectory());
|
||||
|
||||
// Load the cached incremental resources
|
||||
loaded = loaded && AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache");
|
||||
}
|
||||
else if (_curResource == "Official" || _curResource == "Bilibili")
|
||||
{
|
||||
// Load basic resources for CN client first
|
||||
// Then load global incremental resources
|
||||
loaded = AsstLoadResource(Directory.GetCurrentDirectory() + "\\resource\\global\\" + _settingsViewModel.ClientType);
|
||||
|
||||
// Load the cached incremental resources
|
||||
loaded = loaded && AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache\\resource\\global\\" + _settingsViewModel.ClientType);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -226,6 +232,10 @@ namespace MaaWpfGui
|
||||
// Then load global incremental resources
|
||||
loaded = AsstLoadResource(Directory.GetCurrentDirectory())
|
||||
&& AsstLoadResource(Directory.GetCurrentDirectory() + "\\resource\\global\\" + _settingsViewModel.ClientType);
|
||||
|
||||
// Load the cached incremental resources
|
||||
loaded = loaded && AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache")
|
||||
&& AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache\\resource\\global\\" + _settingsViewModel.ClientType);
|
||||
}
|
||||
|
||||
if (!loaded)
|
||||
|
||||
Reference in New Issue
Block a user