chore: 新增 MirrorChyan ErrorCode 提示 (#12202)

* chore: 新增 MirrorChyan ErrorCode 提示

* fix: 漏传显示参数

* fix: 显示错误
This commit is contained in:
uye
2025-03-28 17:01:51 +08:00
committed by GitHub
parent a145ddc5fc
commit d643bd332e
8 changed files with 133 additions and 14 deletions

View File

@@ -0,0 +1,76 @@
// <copyright file="Enums.cs" company="MaaAssistantArknights">
// MaaWpfGui - A part of the MaaCoreArknights project
// Copyright (C) 2021 MistEO and Contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License v3.0 only as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY
// </copyright>
namespace MaaWpfGui.Constants
{
public static class Enums
{
public enum MirrorChyanErrorCode
{
/// <summary>
/// 请求成功
/// </summary>
Success = 0,
/// <summary>
/// 参数不正确,请参考集成文档
/// </summary>
InvalidParams = 1001,
/// <summary>
/// CDK 已过期
/// </summary>
KeyExpired = 7001,
/// <summary>
/// CDK 错误
/// </summary>
KeyInvalid = 7002,
/// <summary>
/// CDK 今日下载次数已达上限
/// </summary>
ResourceQuotaExhausted = 7003,
/// <summary>
/// CDK 类型和待下载的资源不匹配
/// </summary>
KeyMismatched = 7004,
/// <summary>
/// 对应架构和系统下的资源不存在
/// </summary>
ResourceNotFound = 8001,
/// <summary>
/// 错误的系统参数
/// </summary>
InvalidOs = 8002,
/// <summary>
/// 错误的架构参数
/// </summary>
InvalidArch = 8003,
/// <summary>
/// 错误的更新通道参数
/// </summary>
InvalidChannel = 8004,
/// <summary>
/// 未区分的业务错误,以响应体 JSON 的 msg 为准
/// </summary>
Undivided = 1,
}
}
}

View File

@@ -147,9 +147,33 @@ namespace MaaWpfGui.Models
return (CheckUpdateRetT.UnknownError, null, null);
}
if (data["code"]?.ToString() != "0")
var errorCode = data["code"]?.ToObject<Enums.MirrorChyanErrorCode>() ?? Enums.MirrorChyanErrorCode.Undivided;
if (errorCode != Enums.MirrorChyanErrorCode.Success)
{
ToastNotification.ShowDirect(data["msg"]?.ToString() ?? LocalizationHelper.GetString("GameResourceFailed"));
switch (errorCode)
{
case Enums.MirrorChyanErrorCode.KeyExpired:
ToastNotification.ShowDirect(LocalizationHelper.GetString("MirrorChyanCdkExpired"));
break;
case Enums.MirrorChyanErrorCode.KeyInvalid:
ToastNotification.ShowDirect(LocalizationHelper.GetString("MirrorChyanCdkInvalid"));
break;
case Enums.MirrorChyanErrorCode.ResourceQuotaExhausted:
ToastNotification.ShowDirect(LocalizationHelper.GetString("MirrorChyanCdkQuotaExhausted"));
break;
case Enums.MirrorChyanErrorCode.KeyMismatched:
ToastNotification.ShowDirect(LocalizationHelper.GetString("MirrorChyanCdkMismatched"));
break;
case Enums.MirrorChyanErrorCode.InvalidParams:
case Enums.MirrorChyanErrorCode.ResourceNotFound:
case Enums.MirrorChyanErrorCode.InvalidOs:
case Enums.MirrorChyanErrorCode.InvalidArch:
case Enums.MirrorChyanErrorCode.InvalidChannel:
case Enums.MirrorChyanErrorCode.Undivided:
ToastNotification.ShowDirect(data["msg"]?.ToString() ?? LocalizationHelper.GetString("GameResourceFailed"));
break;
}
return (CheckUpdateRetT.UnknownError, null, null);
}

View File

@@ -255,6 +255,10 @@ You can cancel this popup by clicking the Settings - About Us - Issue Reporting
<system:String x:Key="MirrorChyanCdkPlaceholder">Fill after switching source</system:String>
<system:String x:Key="MirrorChyanSoftwareUpdateTip">Software update detected. Please go to 「Settings - Update Settings」 to configure MirrorChyan CDK or switch to Global Source.</system:String>
<system:String x:Key="MirrorChyanResourceUpdateTip">Resource update {0} detected. Please go to 「Settings- Update Settings- Resource Update」 to update manually, or fill in MirrorChayn CDK to update automatically.</system:String>
<system:String x:Key="MirrorChyanCdkExpired">The CDK has expired. Please use a new CDK for authorization.</system:String>
<system:String x:Key="MirrorChyanCdkInvalid">The CDK is invalid. Please check if the input is correct.</system:String>
<system:String x:Key="MirrorChyanCdkQuotaExhausted">The CDK has reached the maximum download limit for today. Please try again tomorrow.</system:String>
<system:String x:Key="MirrorChyanCdkMismatched">The CDK type does not match the resource to be downloaded. Please check the CDK's applicable scope.</system:String>
<system:String x:Key="NewVersionFoundTitle">New Version Found</system:String>
<system:String x:Key="NewVersionFoundDescDownloadingWithGlobalSource">Downloading from 「Global Source」...</system:String>
<system:String x:Key="NewVersionFoundDescDownloadingWithMirrorChyan">Downloading from 「MirrorChyan」...</system:String>

View File

@@ -255,6 +255,10 @@
<system:String x:Key="MirrorChyanCdkPlaceholder">更新ソース切替後入力</system:String>
<system:String x:Key="MirrorChyanSoftwareUpdateTip">ソフトウェア更新が検出されました。「設定 - 更新設定」に移動して MirrorChyan CDK を設定するか、グローバル ソースに切り替えてください。</system:String>
<system:String x:Key="MirrorChyanResourceUpdateTip">リソース更新 {0} が検出されました。「設定 - 更新設定 - リソース更新」に移動して手動で更新するか、MirrorChayn CDK を入力して自動的に更新してください。</system:String>
<system:String x:Key="MirrorChyanCdkExpired">CDK の有効期限が切れました。新しい CDK を使用して認証してください。</system:String>
<system:String x:Key="MirrorChyanCdkInvalid">CDK が無効です。入力が正しいか確認してください。</system:String>
<system:String x:Key="MirrorChyanCdkQuotaExhausted">CDK の本日のダウンロード回数が上限に達しました。明日もう一度お試しください。</system:String>
<system:String x:Key="MirrorChyanCdkMismatched">CDK の種類がダウンロード対象のリソースと一致しません。CDK の適用範囲を確認してください。</system:String>
<system:String x:Key="NewVersionFoundTitle">新しいバージョンが見つかりました</system:String>
<system:String x:Key="NewVersionFoundDescDownloadingWithGlobalSource">「Global Source」からダウンロード中...</system:String>
<system:String x:Key="NewVersionFoundDescDownloadingWithMirrorChyan">「MirrorChyan」からダウンロード中...</system:String>

View File

@@ -255,6 +255,10 @@
<system:String x:Key="MirrorChyanCdkPlaceholder">소스 전환 후 입력</system:String>
<system:String x:Key="MirrorChyanSoftwareUpdateTip">소프트웨어 업데이트가 감지되었습니다. 「설정 - 업데이트 설정」으로 이동하여 MirrorChyan CDK를 구성하거나 글로벌 소스로 전환하세요.</system:String>
<system:String x:Key="MirrorChyanResourceUpdateTip">리소스 업데이트 {0}이 감지되었습니다. 「설정 - 업데이트 설정 - 리소스 업데이트」로 이동하여 수동으로 업데이트하거나 MirrorChayn CDK를 입력하여 자동으로 업데이트하세요.</system:String>
<system:String x:Key="MirrorChyanCdkExpired">CDK가 만료되었습니다. 새 CDK를 사용하여 인증하세요.</system:String>
<system:String x:Key="MirrorChyanCdkInvalid">CDK가 유효하지 않습니다. 입력이 올바른지 확인하세요.</system:String>
<system:String x:Key="MirrorChyanCdkQuotaExhausted">CDK의 오늘 다운로드 횟수가 제한에 도달했습니다. 내일 다시 시도하세요.</system:String>
<system:String x:Key="MirrorChyanCdkMismatched">CDK 유형이 다운로드할 리소스와 일치하지 않습니다. CDK의 적용 범위를 확인하세요.</system:String>
<system:String x:Key="NewVersionFoundTitle">새로운 버전 확인</system:String>
<system:String x:Key="NewVersionFoundDescDownloadingWithGlobalSource">「Global Source」에서 다운로드 중...</system:String>
<system:String x:Key="NewVersionFoundDescDownloadingWithMirrorChyan">「MirrorChyan」에서 다운로드 중...</system:String>

View File

@@ -255,6 +255,10 @@
<system:String x:Key="MirrorChyanCdkPlaceholder">切换更新源后填写</system:String>
<system:String x:Key="MirrorChyanSoftwareUpdateTip">检测到软件更新。请前往「设置-更新设置」配置 Mirror酱 CDK 或切换海外源。</system:String>
<system:String x:Key="MirrorChyanResourceUpdateTip">检测到资源更新{0}。请前往「设置-更新设置-资源更新」手动更新,或配置 Mirror酱 CDK 以自动更新。</system:String>
<system:String x:Key="MirrorChyanCdkExpired">CDK 已过期,请使用新的 CDK 进行授权。</system:String>
<system:String x:Key="MirrorChyanCdkInvalid">CDK 无效,请检查输入是否正确。</system:String>
<system:String x:Key="MirrorChyanCdkQuotaExhausted">CDK 今日下载次数已达上限,请明日再试。</system:String>
<system:String x:Key="MirrorChyanCdkMismatched">CDK 类型与待下载的资源不匹配,请检查 CDK 适用范围。</system:String>
<system:String x:Key="NewVersionFoundTitle">检测到新版本</system:String>
<system:String x:Key="NewVersionFoundDescDownloadingWithGlobalSource">正在使用「海外源」下载……</system:String>
<system:String x:Key="NewVersionFoundDescDownloadingWithMirrorChyan">正在使用「Mirror酱」下载……</system:String>

View File

@@ -255,6 +255,10 @@
<system:String x:Key="MirrorChyanCdkPlaceholder">切換更新源後填寫</system:String>
<system:String x:Key="MirrorChyanSoftwareUpdateTip">偵測到軟體更新。請前往「設定-更新設定」設定 MirrorChyan CDK 或切換到全域來源。</system:String>
<system:String x:Key="MirrorChyanResourceUpdateTip">偵測到資源更新{0}。請前往「設定-更新設定-資源更新」手動更新,或設定 MirrorChayn CDK 以自動更新。</system:String>
<system:String x:Key="MirrorChyanCdkExpired">CDK 已過期,請使用新的 CDK 進行授權。</system:String>
<system:String x:Key="MirrorChyanCdkInvalid">CDK 無效,請檢查輸入是否正確。</system:String>
<system:String x:Key="MirrorChyanCdkQuotaExhausted">CDK 今日下載次數已達上限,請明日再試。</system:String>
<system:String x:Key="MirrorChyanCdkMismatched">CDK 類型與待下載的資源不匹配,請檢查 CDK 適用範圍。</system:String>
<system:String x:Key="NewVersionFoundTitle">檢測到新版本</system:String>
<system:String x:Key="NewVersionFoundDescDownloadingWithGlobalSource">正在使用「全域來源」下載…</system:String>
<system:String x:Key="NewVersionFoundDescDownloadingWithMirrorChyan">正在使用「MirrorChyan」下載…</system:String>

View File

@@ -686,15 +686,10 @@ public class VersionUpdateViewModel : Screen
using var toast = new ToastNotification((otaFound ? LocalizationHelper.GetString("NewVersionFoundTitle") : LocalizationHelper.GetString("NewVersionFoundButNoPackageTitle")) + " : " + UpdateTag);
if (goDownload)
{
OutputDownloadProgress(downloading: false, output: LocalizationHelper.GetString("NewVersionDownloadPreparing"));
if (globalSource)
{
toast.AppendContentText(LocalizationHelper.GetString("NewVersionFoundDescDownloadingWithGlobalSource"));
}
else
{
toast.AppendContentText(LocalizationHelper.GetString("NewVersionFoundDescDownloadingWithMirrorChyan"));
}
OutputDownloadProgress(LocalizationHelper.GetString("NewVersionDownloadPreparing"), false, globalSource);
toast.AppendContentText(globalSource
? LocalizationHelper.GetString("NewVersionFoundDescDownloadingWithGlobalSource")
: LocalizationHelper.GetString("NewVersionFoundDescDownloadingWithMirrorChyan"));
}
if (!otaFound)
@@ -1092,17 +1087,21 @@ public class VersionUpdateViewModel : Screen
OutputDownloadProgress(progress + $" {speedDisplay}");
}
private static void OutputDownloadProgress(string output, bool downloading = true, bool globalSource = true)
private static bool _globalSource = true;
private static void OutputDownloadProgress(string output, bool downloading = true, bool? globalSource = null)
{
globalSource ??= _globalSource;
_globalSource = globalSource.Value;
if (_logItemViewModels == null)
{
return;
}
string fullText = string.Empty;
string fullText;
if (downloading)
{
string key = globalSource ? "NewVersionFoundDescDownloadingWithGlobalSource" : "NewVersionFoundDescDownloadingWithMirrorChyan";
string key = globalSource.Value ? "NewVersionFoundDescDownloadingWithGlobalSource" : "NewVersionFoundDescDownloadingWithMirrorChyan";
fullText = LocalizationHelper.GetString(key) + "\n" + output;
}
else