Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34418f7556 | ||
|
|
69b3e787d3 | ||
|
|
4a0c3cbb56 | ||
|
|
420776768f | ||
|
|
2bf426809b | ||
|
|
75c492a44f | ||
|
|
885d5997b1 | ||
|
|
b42898cfc2 | ||
|
|
0fae5ebab3 |
No files matched your search
@@ -74,7 +74,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
repository: zaodonganqi/bettergi-script-web
|
||||
repository: huiyadanli/bettergi-scripts-web
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<AssemblyName>BetterGI</AssemblyName>
|
||||
<Version>0.52.0</Version>
|
||||
<Version>0.51.1-alpha.2</Version>
|
||||
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
|
||||
@@ -42,9 +42,9 @@
|
||||
<PackageReference Include="BehaviourTree" Version="1.0.73" />
|
||||
|
||||
<PackageReference Include="BetterGI.VCRuntime" Version="14.44.35208" />
|
||||
<PackageReference Include="BetterGI.Assets.Map" Version="1.0.13" />
|
||||
<PackageReference Include="BetterGI.Assets.Map" Version="1.0.12" />
|
||||
<PackageReference Include="BetterGI.Assets.Model" Version="1.0.12" />
|
||||
<PackageReference Include="BetterGI.Assets.Other" Version="1.0.10" />
|
||||
<PackageReference Include="BetterGI.Assets.Other" Version="1.0.9" />
|
||||
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
|
||||
<PackageReference Include="DeviceId" Version="6.9.0" />
|
||||
@@ -52,7 +52,6 @@
|
||||
<PackageReference Include="DeviceId.Windows.Wmi" Version="6.9.0" />
|
||||
<PackageReference Include="Emoji.Wpf" Version="0.3.4" />
|
||||
<PackageReference Include="LibGit2Sharp" Version="0.31.0" />
|
||||
<PackageReference Include="MailKit" Version="4.14.0" />
|
||||
<PackageReference Include="Meziantou.Framework.Win32.CredentialManager" Version="1.7.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.4" />
|
||||
@@ -64,7 +63,6 @@
|
||||
<PackageReference Include="Microsoft.ML.OnnxRuntime.Managed" Version="1.21.0" />
|
||||
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2592.51" />
|
||||
<PackageReference Include="MimeKit" Version="4.14.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" />
|
||||
<PackageReference Include="OpenCvSharp4.WpfExtensions" Version="4.11.0.20250507" />
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
using BetterGenshinImpact.Core.Script.Utils;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using OpenCvSharp;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Script.Dependence;
|
||||
|
||||
public class Http
|
||||
{
|
||||
private readonly ILogger<Http> _logger = App.GetLogger<Http>();
|
||||
|
||||
private void CheckHttpPermission(string url)
|
||||
{
|
||||
var currentProject = TaskContext.Instance().CurrentScriptProject;
|
||||
if (!currentProject?.AllowJsHTTP ?? false)
|
||||
{
|
||||
throw new UnauthorizedAccessException("当前JS脚本不允许使用HTTP请求,请在调度器通用设置中启用“JS HTTP权限”");
|
||||
}
|
||||
var allowedUrls = currentProject?.Project?.Manifest.HttpAllowedUrls ?? [];
|
||||
if (allowedUrls.Length == 0)
|
||||
{
|
||||
throw new UnauthorizedAccessException("当前JS脚本没有配置允许请求的URL,请在脚本的manifest.json中配置http_allowed_urls");
|
||||
}
|
||||
if (allowedUrls.Any(allowedUrl =>
|
||||
{
|
||||
// fuzzy match
|
||||
var pattern = "^" + System.Text.RegularExpressions.Regex.Escape(allowedUrl).Replace("\\*", ".*") + "$";
|
||||
_logger.LogDebug($"[HTTP] 检查URL {url} 是否符合: {pattern}");
|
||||
var regex = new System.Text.RegularExpressions.Regex(pattern);
|
||||
return regex.IsMatch(url);
|
||||
}))
|
||||
{
|
||||
return;
|
||||
}
|
||||
throw new UnauthorizedAccessException($"当前JS脚本不允许请求此URL: {url},请在脚本的manifest.json中配置http_allowed_urls,当前允许的URL列表: [{string.Join(", ", allowedUrls)}]");
|
||||
}
|
||||
|
||||
public class HttpReponse
|
||||
{
|
||||
public int status_code { get; set; }
|
||||
public Dictionary<string, string> headers { get; set; } = new();
|
||||
public string body { get; set; } = "";
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 执行HTTP请求
|
||||
/// </summary>
|
||||
/// <param name="method">HTTP方法</param>
|
||||
/// <param name="url">请求URL</param>
|
||||
/// <param name="body">请求体</param>
|
||||
/// <param name="headersJson">请求头,JSON格式</param>
|
||||
/// <returns></returns>
|
||||
public async Task<HttpReponse> Request(string method, string url, string? body = null, string? headersJson = null)
|
||||
{
|
||||
_logger.LogDebug($"[HTTP] 发送HTTP请求: {method} {url} Body: {(body != null ? body : "null")} Headers: {(headersJson != null ? headersJson : "null")}");
|
||||
CheckHttpPermission(url);
|
||||
|
||||
var dictHeaders = new Dictionary<string, string>();
|
||||
if (!string.IsNullOrWhiteSpace(headersJson))
|
||||
{
|
||||
try
|
||||
{
|
||||
var headers = JsonSerializer.Deserialize<Dictionary<string, string>>(headersJson);
|
||||
if (headers != null)
|
||||
{
|
||||
dictHeaders = headers;
|
||||
}
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
throw new ArgumentException("Headers JSON格式错误");
|
||||
}
|
||||
}
|
||||
|
||||
// header全部小写
|
||||
dictHeaders = dictHeaders.ToDictionary(kvp => kvp.Key.ToLowerInvariant(), kvp => kvp.Value);
|
||||
|
||||
// 提前取出来Content-Type,防止被覆盖
|
||||
string contentType = "application/json";
|
||||
if (dictHeaders.TryGetValue("content-type", out var ct))
|
||||
{
|
||||
contentType = ct;
|
||||
dictHeaders.Remove("content-type");
|
||||
}
|
||||
|
||||
// 使用HttpClient发送请求
|
||||
using var httpClient = new HttpClient();
|
||||
httpClient.DefaultRequestHeaders.Clear();
|
||||
foreach (var header in dictHeaders)
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
|
||||
}
|
||||
|
||||
var content = body == null ? null : new StringContent(body, Encoding.UTF8, contentType);
|
||||
var response = await httpClient.SendAsync(new HttpRequestMessage(new HttpMethod(method), url) { Content = content });
|
||||
|
||||
var responseCode = (int)response.StatusCode;
|
||||
var responseHeaders = response.Headers.ToDictionary(h => h.Key, h => h.Value.First()); // 只取第一个值
|
||||
var responseBody = await response.Content.ReadAsStringAsync();
|
||||
return new HttpReponse
|
||||
{
|
||||
status_code = responseCode,
|
||||
headers = responseHeaders,
|
||||
body = responseBody,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,6 @@ public class EngineExtend
|
||||
engine.AddHostObject("genshin", new Dependence.Genshin());
|
||||
engine.AddHostObject("log", new Log());
|
||||
engine.AddHostObject("file", new LimitedFile(workDir)); // 限制文件访问
|
||||
engine.AddHostObject("http", new Http()); // 限制文件访问
|
||||
engine.AddHostObject("notification", new Notification());
|
||||
|
||||
// 任务调度器
|
||||
|
||||
@@ -106,22 +106,6 @@ public partial class ScriptGroupProject : ObservableObject
|
||||
[ObservableProperty]
|
||||
private bool? _allowJsNotification = true;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _allowJsHTTPHash = "";
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许JS脚本发送HTTP请求,通过验证Hash来控制
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool AllowJsHTTP
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetHttpAllowedUrlsHash() == AllowJsHTTPHash;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ScriptGroupProject()
|
||||
{
|
||||
}
|
||||
@@ -179,19 +163,6 @@ public partial class ScriptGroupProject : ObservableObject
|
||||
Project = new ScriptProject(FolderName);
|
||||
}
|
||||
|
||||
public string GetHttpAllowedUrlsHash()
|
||||
{
|
||||
if (Project == null)
|
||||
{
|
||||
BuildScriptProjectRelation();
|
||||
}
|
||||
if (Project == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return string.Join("|", Project.Manifest.HttpAllowedUrls);
|
||||
}
|
||||
|
||||
public async Task Run()
|
||||
{
|
||||
//执行记录
|
||||
|
||||
@@ -26,7 +26,6 @@ public class Manifest
|
||||
public string[] Scripts { get; set; } = [];
|
||||
public string[] Library { get; set; } = [];
|
||||
public string[] SavedFiles { get; set; } = [];
|
||||
public string[] HttpAllowedUrls { get; set; } = [];
|
||||
|
||||
public static Manifest FromJson(string json)
|
||||
{
|
||||
|
||||
@@ -176,8 +176,7 @@ public class AutoDomainTask : ISoloTask
|
||||
{
|
||||
combatScenes = new CombatScenes().InitializeTeam(CaptureToRectArea());
|
||||
}
|
||||
|
||||
RetryTeamInit(combatScenes); // 队伍没初始化成功则重试
|
||||
RetryTeamInit(combatScenes);// 队伍没初始化成功则重试
|
||||
|
||||
// 0. 切换到第一个角色
|
||||
var combatCommands = FindCombatScriptAndSwitchAvatar(combatScenes);
|
||||
@@ -275,12 +274,12 @@ public class AutoDomainTask : ISoloTask
|
||||
if ("芬德尼尔之顶".Equals(_taskParam.DomainName))
|
||||
{
|
||||
menuFound = await NewRetry.WaitForElementAppear(
|
||||
AutoPickAssets.Instance.PickRo,
|
||||
() => Simulation.SendInput.SimulateAction(GIActions.MoveBackward, KeyType.KeyDown),
|
||||
_ct,
|
||||
20,
|
||||
500
|
||||
);
|
||||
AutoPickAssets.Instance.PickRo,
|
||||
() => Simulation.SendInput.SimulateAction(GIActions.MoveBackward, KeyType.KeyDown),
|
||||
_ct,
|
||||
20,
|
||||
500
|
||||
);
|
||||
Simulation.SendInput.SimulateAction(GIActions.MoveBackward, KeyType.KeyUp);
|
||||
}
|
||||
else if ("无妄引咎密宫".Equals(_taskParam.DomainName))
|
||||
@@ -297,13 +296,14 @@ public class AutoDomainTask : ISoloTask
|
||||
500
|
||||
);
|
||||
Simulation.SendInput.SimulateAction(GIActions.MoveLeft, KeyType.KeyUp);
|
||||
|
||||
}
|
||||
else if ("太山府".Equals(_taskParam.DomainName))
|
||||
{
|
||||
menuFound = await NewRetry.WaitForElementAppear(
|
||||
AutoPickAssets.Instance.PickRo,
|
||||
() => { },
|
||||
_ct,
|
||||
_ct,
|
||||
20,
|
||||
500
|
||||
);
|
||||
@@ -311,11 +311,11 @@ public class AutoDomainTask : ISoloTask
|
||||
else
|
||||
{
|
||||
menuFound = await NewRetry.WaitForElementAppear(
|
||||
AutoPickAssets.Instance.PickRo,
|
||||
() => Simulation.SendInput.SimulateAction(GIActions.MoveForward, KeyType.KeyDown),
|
||||
_ct,
|
||||
20,
|
||||
500
|
||||
AutoPickAssets.Instance.PickRo,
|
||||
() => Simulation.SendInput.SimulateAction(GIActions.MoveForward, KeyType.KeyDown),
|
||||
_ct,
|
||||
20,
|
||||
500
|
||||
);
|
||||
Simulation.SendInput.SimulateAction(GIActions.MoveForward, KeyType.KeyUp);
|
||||
}
|
||||
@@ -336,6 +336,7 @@ public class AutoDomainTask : ISoloTask
|
||||
{
|
||||
throw new Exception("请检查是否已进入秘境页面");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -466,7 +467,6 @@ public class AutoDomainTask : ISoloTask
|
||||
ra2.Dispose();
|
||||
Logger.LogInformation("自动秘境:点击 {Text}", "单人挑战");
|
||||
}
|
||||
|
||||
using var confirmRectArea2 = ra.Find(RecognitionObject.Ocr(ra.Width * 0.263, ra.Height * 0.32,
|
||||
ra.Width - ra.Width * 0.263 * 2, ra.Height - ra.Height * 0.32 - ra.Height * 0.353));
|
||||
if (confirmRectArea2.IsExist() && confirmRectArea2.Text.Contains("是否仍要挑战该秘境"))
|
||||
@@ -483,7 +483,10 @@ public class AutoDomainTask : ISoloTask
|
||||
// 等待队伍选择界面出现
|
||||
var teamUiFound = await NewRetry.WaitForElementAppear(
|
||||
ElementAssets.Instance.PartyBtnChooseView,
|
||||
() => { Logger.LogInformation("自动秘境:进入 {Text}", "队伍选择界面"); },
|
||||
() =>
|
||||
{
|
||||
Logger.LogInformation("自动秘境:进入 {Text}", "队伍选择界面");
|
||||
},
|
||||
_ct,
|
||||
10,
|
||||
1000
|
||||
@@ -517,7 +520,6 @@ public class AutoDomainTask : ISoloTask
|
||||
{
|
||||
Logger.LogWarning("开始挑战按钮未出现或未能点击。");
|
||||
}
|
||||
|
||||
// 载入
|
||||
await Delay(1000, _ct);
|
||||
}
|
||||
@@ -554,7 +556,6 @@ public class AutoDomainTask : ISoloTask
|
||||
done.Dispose();
|
||||
Logger.LogInformation("自动秘境:点击 {Text}", done.Text);
|
||||
}
|
||||
|
||||
// 检查左下角区域是否还存在目标文字,消失则继续,存在则结束
|
||||
using var leftBottom = CaptureToRectArea();
|
||||
var leftBottomOcr = leftBottom.Find(AutoFightAssets.Instance.AbnormalIconRa);
|
||||
@@ -1119,13 +1120,13 @@ public class AutoDomainTask : ISoloTask
|
||||
bool resinUsed = false;
|
||||
if (resinStatus.CondensedResinCount > 0)
|
||||
{
|
||||
(resinUsed, _) = PressUseResin(ra3, "浓缩树脂");
|
||||
resinUsed = PressUseResin(ra3, "浓缩树脂");
|
||||
resinStatus.CondensedResinCount -= 1;
|
||||
}
|
||||
else if (resinStatus.OriginalResinCount >= 20)
|
||||
{
|
||||
(resinUsed, var num) = PressUseResin(ra3, "原粹树脂");
|
||||
resinStatus.OriginalResinCount -= num;
|
||||
resinUsed = PressUseResin(ra3, "原粹树脂");
|
||||
resinStatus.OriginalResinCount -= 20;
|
||||
}
|
||||
|
||||
if (!resinUsed)
|
||||
@@ -1149,15 +1150,11 @@ public class AutoDomainTask : ISoloTask
|
||||
var failCount = 0;
|
||||
foreach (var record in _resinPriorityListWhenSpecifyUse)
|
||||
{
|
||||
if (record.RemainCount > 0)
|
||||
if (record.RemainCount > 0 && PressUseResin(textListInPrompt2, record.Name))
|
||||
{
|
||||
var (success, _) = PressUseResin(textListInPrompt2, record.Name);
|
||||
if (success)
|
||||
{
|
||||
record.RemainCount -= 1;
|
||||
Logger.LogInformation("自动秘境:{Name} 刷取 {Re}/{Max}", record.Name, record.MaxCount - record.RemainCount, record.MaxCount);
|
||||
break;
|
||||
}
|
||||
record.RemainCount -= 1;
|
||||
Logger.LogInformation("自动秘境:{Name} 刷取 {Re}/{Max}", record.Name, record.MaxCount - record.RemainCount, record.MaxCount);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1233,7 +1230,6 @@ public class AutoDomainTask : ISoloTask
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1253,13 +1249,13 @@ public class AutoDomainTask : ISoloTask
|
||||
Bv.ClickBlackConfirmButton(CaptureToRectArea());
|
||||
}
|
||||
|
||||
public static (bool, int) PressUseResin(ImageRegion ra, string resinName)
|
||||
private bool PressUseResin(ImageRegion ra, string resinName)
|
||||
{
|
||||
var regionList = ra.FindMulti(RecognitionObject.Ocr(ra.Width * 0.25, ra.Height * 0.2, ra.Width * 0.5, ra.Height * 0.6));
|
||||
return PressUseResin(regionList, resinName);
|
||||
}
|
||||
|
||||
public static (bool, int) PressUseResin(List<Region> regionList, string resinName)
|
||||
private bool PressUseResin(List<Region> regionList, string resinName)
|
||||
{
|
||||
var resinKey = regionList.FirstOrDefault(t => t.Text.Contains(resinName));
|
||||
if (resinKey != null)
|
||||
@@ -1276,11 +1272,10 @@ public class AutoDomainTask : ISoloTask
|
||||
// 点击使用
|
||||
useKey.Click();
|
||||
// 解决水龙王按下左键后没松开,然后后续点击按下就没反应了。使用双击
|
||||
Sleep(60);
|
||||
Sleep(60, _ct);
|
||||
useKey.Click();
|
||||
var num = GetResinNum(resinKey, resinName);
|
||||
Logger.LogInformation("自动秘境:使用 {ResinName}, 数量:{Num}", resinName, num);
|
||||
return (true, num);
|
||||
Logger.LogInformation("自动秘境:使用 {ResinName}", resinName);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1293,41 +1288,13 @@ public class AutoDomainTask : ISoloTask
|
||||
}
|
||||
}
|
||||
|
||||
return (false, 0);
|
||||
}
|
||||
|
||||
private static int GetResinNum(Region region, string resinName)
|
||||
{
|
||||
if (resinName == "原粹树脂")
|
||||
{
|
||||
if (region.Text.Contains("20"))
|
||||
{
|
||||
return 20;
|
||||
}
|
||||
else if (region.Text.Contains("40"))
|
||||
{
|
||||
return 40;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning("自动秘境:未识别到原粹树脂消耗体力数量,默认按20计算");
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
else if (resinName == "浓缩树脂" || resinName == "脆弱树脂" || resinName == "须臾树脂")
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("未知的树脂名称");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断两个区域在垂直方向上是否有重叠
|
||||
/// </summary>
|
||||
private static bool IsHeightOverlap(Region region1, Region region2)
|
||||
private bool IsHeightOverlap(Region region1, Region region2)
|
||||
{
|
||||
int region1Top = region1.Y;
|
||||
int region1Bottom = region1.Y + region1.Height;
|
||||
@@ -1338,7 +1305,7 @@ public class AutoDomainTask : ISoloTask
|
||||
return (region1Top <= region2Bottom && region1Bottom >= region2Top);
|
||||
}
|
||||
|
||||
private async Task ArtifactSalvage()
|
||||
private async Task ArtifactSalvage()
|
||||
{
|
||||
if (!_taskParam.AutoArtifactSalvage)
|
||||
{
|
||||
@@ -1352,4 +1319,4 @@ public class AutoDomainTask : ISoloTask
|
||||
|
||||
await new AutoArtifactSalvageTask(new AutoArtifactSalvageTaskParam(star, javaScript: null, artifactSetFilter: null, maxNumToCheck: null, recognitionFailurePolicy: null)).Start(_ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,7 +380,7 @@ public class CombatScenes : IDisposable
|
||||
/// 推荐使用
|
||||
/// 失败后自动刷新编号框位置
|
||||
/// </summary>
|
||||
/// <param name="imageRegion"></param>l
|
||||
/// <param name="imageRegion"></param>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public int GetActiveAvatarIndex(ImageRegion imageRegion, AvatarActiveCheckContext context)
|
||||
@@ -391,7 +391,6 @@ public class CombatScenes : IDisposable
|
||||
if (index > 0)
|
||||
{
|
||||
LastActiveAvatarIndex = index;
|
||||
return index;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -413,7 +412,7 @@ public class CombatScenes : IDisposable
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
return LastActiveAvatarIndex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -637,9 +637,9 @@ public class PathExecutor
|
||||
{
|
||||
tpTask = new TpTask(ct);
|
||||
}
|
||||
|
||||
|
||||
// 最小5分钟间隔
|
||||
if ( _combatScenes?.CurrentMultiGameStatus?.IsInMultiGame == true && (DateTime.UtcNow - _lastGetExpeditionRewardsTime).TotalMinutes < 5)
|
||||
if ((DateTime.UtcNow - _lastGetExpeditionRewardsTime).TotalMinutes < 5)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -652,6 +652,7 @@ public class PathExecutor
|
||||
if (!RunnerContext.Instance.isAutoFetchDispatch && adventurersGuildCountry != "无")
|
||||
{
|
||||
var ra1 = CaptureToRectArea();
|
||||
|
||||
var textRect = new Rect(60, 20, 160, 260);
|
||||
var textMat = new Mat(ra1.SrcMat, textRect);
|
||||
string text = OcrFactory.Paddle.Ocr(textMat);
|
||||
|
||||
@@ -26,7 +26,6 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.GameTask.AutoDomain;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
using static Vanara.PInvoke.User32;
|
||||
using BetterGenshinImpact.GameTask.AutoFight;
|
||||
@@ -427,13 +426,13 @@ public class AutoStygianOnslaughtTask : ISoloTask
|
||||
bool resinUsed = false;
|
||||
if (resinStatus.CondensedResinCount > 0)
|
||||
{
|
||||
(resinUsed, _) = AutoDomainTask.PressUseResin(ra3, "浓缩树脂");
|
||||
resinUsed = PressUseResin(ra3, "浓缩树脂");
|
||||
resinStatus.CondensedResinCount -= 1;
|
||||
}
|
||||
else if (resinStatus.OriginalResinCount >= 20)
|
||||
{
|
||||
(resinUsed, var num) = AutoDomainTask.PressUseResin(ra3, "原粹树脂");
|
||||
resinStatus.OriginalResinCount -= num;
|
||||
resinUsed = PressUseResin(ra3, "原粹树脂");
|
||||
resinStatus.OriginalResinCount -= 20;
|
||||
}
|
||||
|
||||
if (!resinUsed)
|
||||
@@ -457,15 +456,11 @@ public class AutoStygianOnslaughtTask : ISoloTask
|
||||
var failCount = 0;
|
||||
foreach (var record in _resinPriorityListWhenSpecifyUse)
|
||||
{
|
||||
if (record.RemainCount > 0)
|
||||
if (record.RemainCount > 0 && PressUseResin(textListInPrompt2, record.Name))
|
||||
{
|
||||
var (success, _) = AutoDomainTask.PressUseResin(textListInPrompt2, record.Name);
|
||||
if (success)
|
||||
{
|
||||
record.RemainCount -= 1;
|
||||
Logger.LogInformation("自动秘境:{Name} 刷取 {Re}/{Max}", record.Name, record.MaxCount - record.RemainCount, record.MaxCount);
|
||||
break;
|
||||
}
|
||||
record.RemainCount -= 1;
|
||||
_logger.LogInformation("自动秘境:{Name} 刷取 {Re}/{Max}", record.Name, record.MaxCount - record.RemainCount, record.MaxCount);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -557,6 +552,62 @@ public class AutoStygianOnslaughtTask : ISoloTask
|
||||
await ExitDomain(new BvPage(_ct));
|
||||
}
|
||||
|
||||
private bool PressUseResin(ImageRegion ra, string resinName)
|
||||
{
|
||||
var regionList = ra.FindMulti(RecognitionObject.Ocr(ra.Width * 0.25, ra.Height * 0.2, ra.Width * 0.5, ra.Height * 0.6));
|
||||
return PressUseResin(regionList, resinName);
|
||||
}
|
||||
|
||||
private bool PressUseResin(List<Region> regionList, string resinName)
|
||||
{
|
||||
var resinKey = regionList.FirstOrDefault(t => t.Text.Contains(resinName));
|
||||
if (resinKey != null)
|
||||
{
|
||||
// 找到树脂名称对应的按键,关键词为使用,是同一行的(高度相交)
|
||||
var useList = regionList.Where(t => t.Text.Contains("使用")).ToList();
|
||||
if (useList.Count != 0)
|
||||
{
|
||||
// 找到使用按键
|
||||
var useKey = useList.FirstOrDefault(t => t.X > TaskContext.Instance().SystemInfo.ScaleMax1080PCaptureRect.Width / 2
|
||||
&& IsHeightOverlap(t, resinKey));
|
||||
if (useKey != null)
|
||||
{
|
||||
// 点击使用
|
||||
useKey.Click();
|
||||
// 解决水龙王按下左键后没松开,然后后续点击按下就没反应了。使用双击
|
||||
Sleep(60, _ct);
|
||||
useKey.Click();
|
||||
_logger.LogInformation("自动秘境:使用 {ResinName}", resinName);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("自动秘境:未找到 {ResinName} 的使用按键", resinName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("自动秘境:未找到 {ResinName} 的使用按键", resinName);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断两个区域在垂直方向上是否有重叠
|
||||
/// </summary>
|
||||
private bool IsHeightOverlap(Region region1, Region region2)
|
||||
{
|
||||
int region1Top = region1.Y;
|
||||
int region1Bottom = region1.Y + region1.Height;
|
||||
int region2Top = region2.Y;
|
||||
int region2Bottom = region2.Y + region2.Height;
|
||||
|
||||
// 检查区域是否在垂直方向上重叠
|
||||
return (region1Top <= region2Bottom && region1Bottom >= region2Top);
|
||||
}
|
||||
|
||||
private async Task ArtifactSalvage()
|
||||
{
|
||||
if (!_taskParam.AutoArtifactSalvage)
|
||||
|
||||
@@ -13202,25 +13202,6 @@
|
||||
"name": "传送锚点",
|
||||
"area": "银月之庭"
|
||||
},
|
||||
{
|
||||
"id": "1750",
|
||||
"gadgetId": "70600003",
|
||||
"gadgetType": "TransPointSecond",
|
||||
"type": "Teleport",
|
||||
"position": [
|
||||
3278.798828125,
|
||||
0,
|
||||
10179.552734375
|
||||
],
|
||||
"tranPosition": [
|
||||
3268.82958984375,
|
||||
0,
|
||||
10170.6865234375
|
||||
],
|
||||
"country": "挪德卡莱",
|
||||
"name": "传送锚点",
|
||||
"area": "月矩力试验设计局"
|
||||
},
|
||||
{
|
||||
"id": "1751",
|
||||
"gadgetId": "70600003",
|
||||
|
||||
@@ -25,7 +25,6 @@ public class MapLazyAssets : Singleton<MapLazyAssets>
|
||||
{ "须弥", [2877, -374] },
|
||||
{ "枫丹", [4515, 3631] },
|
||||
{ "纳塔", [8973.5, -1879.1] },
|
||||
{ "挪德卡莱", [9542.25, 1661.84] },
|
||||
};
|
||||
|
||||
public readonly Dictionary<string, GiTpPosition> DomainPositionMap = new();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Service.Notification.Model;
|
||||
using BetterGenshinImpact.Service.Notifier.Exception;
|
||||
using BetterGenshinImpact.Service.Notifier.Interface;
|
||||
using MailKit.Security;
|
||||
using MimeKit;
|
||||
using SixLabors.ImageSharp;
|
||||
|
||||
namespace BetterGenshinImpact.Service.Notifier
|
||||
@@ -38,6 +38,10 @@ namespace BetterGenshinImpact.Service.Notifier
|
||||
_fromEmail = fromEmail;
|
||||
_fromName = fromName;
|
||||
ToEmail = toEmail;
|
||||
|
||||
// 忽略SSL证书验证错误
|
||||
ServicePointManager.ServerCertificateValidationCallback =
|
||||
delegate { return true; };
|
||||
}
|
||||
|
||||
// 收件人邮箱
|
||||
@@ -51,105 +55,81 @@ namespace BetterGenshinImpact.Service.Notifier
|
||||
throw new NotifierException("收件人邮箱地址为空");
|
||||
}
|
||||
|
||||
// 创建邮件消息
|
||||
var message = new MimeMessage();
|
||||
message.From.Add(new MailboxAddress(_fromName, _fromEmail));
|
||||
message.To.Add(new MailboxAddress("", ToEmail));
|
||||
message.Subject = FormatEmailSubject(content);
|
||||
|
||||
var bodyBuilder = new BodyBuilder
|
||||
// 创建一个新的SmtpClient实例(不复用)
|
||||
using (var smtpClient = new SmtpClient())
|
||||
{
|
||||
HtmlBody = FormatEmailBody(content)
|
||||
};
|
||||
|
||||
// 添加图片附件(如果存在)
|
||||
if (content.Screenshot != null)
|
||||
{
|
||||
using var memoryStream = new MemoryStream();
|
||||
// 将图片保存到内存流
|
||||
await content.Screenshot.SaveAsJpegAsync(memoryStream);
|
||||
memoryStream.Position = 0; // 重置流位置
|
||||
|
||||
// 添加附件
|
||||
var attachment = await bodyBuilder.Attachments.AddAsync("screenshot.jpg", memoryStream, ContentType.Parse("image/jpeg"));
|
||||
attachment.ContentId = "screenshot";
|
||||
}
|
||||
|
||||
message.Body = bodyBuilder.ToMessageBody();
|
||||
|
||||
// 使用 MailKit 发送邮件
|
||||
using var smtpClient = new MailKit.Net.Smtp.SmtpClient();
|
||||
try
|
||||
{
|
||||
// 根据服务器和端口选择合适的连接方式
|
||||
var secureSocketOptions = GetSecureSocketOptions();
|
||||
|
||||
await smtpClient.ConnectAsync(_smtpServer, _smtpPort, secureSocketOptions);
|
||||
|
||||
// 如果服务器需要认证,则进行登录
|
||||
if (!string.IsNullOrEmpty(_smtpUsername))
|
||||
try
|
||||
{
|
||||
await smtpClient.AuthenticateAsync(_smtpUsername, _smtpPassword);
|
||||
// 配置SMTP客户端
|
||||
smtpClient.Host = _smtpServer;
|
||||
smtpClient.Port = _smtpPort;
|
||||
smtpClient.EnableSsl = true;
|
||||
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
smtpClient.UseDefaultCredentials = false;
|
||||
smtpClient.Credentials = new NetworkCredential(_smtpUsername, _smtpPassword);
|
||||
smtpClient.Timeout = 30000; // 30秒超时
|
||||
|
||||
// 创建邮件
|
||||
using (var mailMessage = new MailMessage())
|
||||
{
|
||||
mailMessage.From = new MailAddress(_fromEmail, _fromName);
|
||||
mailMessage.To.Add(ToEmail);
|
||||
mailMessage.Subject = FormatEmailSubject(content);
|
||||
mailMessage.Body = FormatEmailBody(content);
|
||||
mailMessage.IsBodyHtml = true;
|
||||
mailMessage.BodyEncoding = Encoding.UTF8;
|
||||
mailMessage.SubjectEncoding = Encoding.UTF8;
|
||||
|
||||
// 添加图片附件(如果存在)
|
||||
if (content.Screenshot != null)
|
||||
{
|
||||
var tempPath = Path.GetTempFileName() + ".jpg";
|
||||
try
|
||||
{
|
||||
// 保存图片到临时文件
|
||||
await content.Screenshot.SaveAsJpegAsync(tempPath);
|
||||
|
||||
// 从文件添加附件
|
||||
var attachment = new Attachment(tempPath);
|
||||
mailMessage.Attachments.Add(attachment);
|
||||
|
||||
// 发送邮件
|
||||
await smtpClient.SendMailAsync(mailMessage);
|
||||
|
||||
// 清理附件和临时文件
|
||||
attachment.Dispose();
|
||||
if (File.Exists(tempPath)) File.Delete(tempPath);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
// 尝试清理临时文件
|
||||
try
|
||||
{
|
||||
if (File.Exists(tempPath)) File.Delete(tempPath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
/* 忽略清理错误 */
|
||||
}
|
||||
|
||||
throw new NotifierException($"发送邮件失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 没有图片时直接发送
|
||||
await smtpClient.SendMailAsync(mailMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
var errorMessage = $"发送邮件失败: {ex.Message}";
|
||||
throw new NotifierException(errorMessage);
|
||||
}
|
||||
|
||||
await smtpClient.SendAsync(message);
|
||||
await smtpClient.DisconnectAsync(true);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
var errorMessage = $"发送邮件失败: {ex.Message}";
|
||||
throw new NotifierException(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据服务器地址和端口号选择合适的 SecureSocketOptions
|
||||
/// </summary>
|
||||
private SecureSocketOptions GetSecureSocketOptions()
|
||||
{
|
||||
// 对于已知的特殊服务器配置
|
||||
if (IsKnownServerWithSpecialRequirements(_smtpServer, _smtpPort, out var secureSocketOption))
|
||||
{
|
||||
return secureSocketOption;
|
||||
}
|
||||
|
||||
// 通用规则
|
||||
return _smtpPort switch
|
||||
{
|
||||
465 => SecureSocketOptions.SslOnConnect,
|
||||
587 => SecureSocketOptions.StartTls, // 大多数服务商使用 STARTTLS
|
||||
25 => SecureSocketOptions.None,
|
||||
_ => SecureSocketOptions.Auto // 其他端口让 MailKit 自动协商
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否是已知有特殊要求的服务器
|
||||
/// </summary>
|
||||
private bool IsKnownServerWithSpecialRequirements(string server, int port, out SecureSocketOptions option)
|
||||
{
|
||||
option = SecureSocketOptions.Auto;
|
||||
|
||||
// 网易邮箱系列 - 587 端口使用 SSL
|
||||
if ((server.Contains("163.com") ||
|
||||
server.Contains("126.com") ||
|
||||
server.Contains("yeah.net")) && port == 587)
|
||||
{
|
||||
option = SecureSocketOptions.SslOnConnect;
|
||||
return true;
|
||||
}
|
||||
|
||||
// 可以继续添加其他已知的特殊配置
|
||||
// 例如:
|
||||
// if (server.Contains("some-special-server.com") && port == 587)
|
||||
// {
|
||||
// option = SecureSocketOptions.SslOnConnect;
|
||||
// return true;
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private string FormatEmailSubject(BaseNotificationData content)
|
||||
{
|
||||
// 可以根据实际需求自定义邮件主题格式
|
||||
@@ -179,13 +159,9 @@ namespace BetterGenshinImpact.Service.Notifier
|
||||
}
|
||||
|
||||
// 添加提示信息
|
||||
if (content.Screenshot != null)
|
||||
{
|
||||
builder.AppendLine("<p><em>截图已作为附件添加到邮件中。</em></p>");
|
||||
}
|
||||
|
||||
builder.AppendLine("<p><em>如有截图,请查看附件。</em></p>");
|
||||
builder.AppendLine("</body></html>");
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -486,7 +486,6 @@ public partial class ScriptService : IScriptService
|
||||
target.JsScriptSettingsObject = source.JsScriptSettingsObject;
|
||||
target.GroupInfo = source.GroupInfo;
|
||||
target.AllowJsNotification = source.AllowJsNotification;
|
||||
target.AllowJsHTTPHash = source.AllowJsHTTPHash;
|
||||
target.SkipFlag = source.SkipFlag;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:editable="clr-namespace:BetterGenshinImpact.ViewModel.Windows.Editable"
|
||||
xmlns:sys="clr-namespace:System;assembly=System.Runtime"
|
||||
MinWidth="350"
|
||||
MinHeight="300"
|
||||
Width="200"
|
||||
Height="300"
|
||||
d:DesignHeight="200"
|
||||
d:DesignWidth="350"
|
||||
d:DesignWidth="300"
|
||||
mc:Ignorable="d">
|
||||
<UserControl.Resources>
|
||||
<ObjectDataProvider x:Key="StatusDescriptionsProvider"
|
||||
@@ -50,47 +50,6 @@
|
||||
Visibility="{Binding IsJsScript, Converter={StaticResource BoolToVisConverter}}">
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock Margin="0,10,0,5" Text="JS HTTP权限"
|
||||
Visibility="{Binding IsJsScript, Converter={StaticResource BoolToVisConverter}}"/>
|
||||
<TextBlock Margin="0,0,0,5"
|
||||
Text="允许脚本发送HTTP请求,可能会带来安全风险,请谨慎开启。"
|
||||
Foreground="Orange"
|
||||
Visibility="{Binding IsJsScript, Converter={StaticResource BoolToVisConverter}}"/>
|
||||
<TextBlock Margin="0,0,0,5"
|
||||
Text="注意:脚本更新http_allowed_urls后,需手动重新启用权限。"
|
||||
Foreground="Orange"
|
||||
Visibility="{Binding IsJsScript, Converter={StaticResource BoolToVisConverter}}"/>
|
||||
<ItemsControl Margin="0,0,0,0" ItemsSource="{Binding JsHTTPInfoText}"
|
||||
Visibility="{Binding IsJsScript, Converter={StaticResource BoolToVisConverter}}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Text}"
|
||||
Foreground="{Binding Color}"
|
||||
FontSize="11"
|
||||
TextWrapping="NoWrap"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<ItemsControl Margin="0,0,0,10" ItemsSource="{Binding JsHTTPInfo}"
|
||||
Visibility="{Binding IsJsScript, Converter={StaticResource BoolToVisConverter}}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBox Text="{Binding Text}"
|
||||
IsReadOnly="True"
|
||||
Foreground="{Binding Color}"
|
||||
FontSize="11"
|
||||
FontFamily="Consolas"
|
||||
TextWrapping="NoWrap"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<ComboBox DisplayMemberPath="Value"
|
||||
ItemsSource="{Binding JsNotificationOptions}"
|
||||
SelectedValue="{Binding AllowJsHTTP, Mode=TwoWay}"
|
||||
SelectedValuePath="Key"
|
||||
Visibility="{Binding IsJsScript, Converter={StaticResource BoolToVisConverter}}">
|
||||
</ComboBox>
|
||||
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -16,8 +16,6 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Globalization;
|
||||
using System.Windows.Navigation;
|
||||
using Wpf.Ui.Violeta.Controls;
|
||||
|
||||
@@ -26,20 +24,6 @@ namespace BetterGenshinImpact.View.Windows;
|
||||
[ObservableObject]
|
||||
public partial class ScriptRepoWindow
|
||||
{
|
||||
// 转换器类
|
||||
public class InverseBooleanConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value is bool b ? !b : value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value is bool b ? !b : value;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新渠道类
|
||||
public class RepoChannel
|
||||
{
|
||||
@@ -130,6 +114,8 @@ public partial class ScriptRepoWindow
|
||||
{
|
||||
new("CNB", "https://cnb.cool/bettergi/bettergi-scripts-list"),
|
||||
new("GitCode", "https://gitcode.com/huiyadanli/bettergi-scripts-list"),
|
||||
// 暂时无法使用
|
||||
// new("Gitee", "https://gitee.com/babalae/bettergi-scripts-list"),
|
||||
new("GitHub", "https://github.com/babalae/bettergi-scripts-list"),
|
||||
new("自定义", "https://example.com/custom-repo")
|
||||
};
|
||||
@@ -151,33 +137,10 @@ public partial class ScriptRepoWindow
|
||||
private void OnConfigSelectedRepoUrlChanged()
|
||||
{
|
||||
// 如果配置中的URL与当前选中渠道不一致,更新选中渠道
|
||||
if (string.IsNullOrEmpty(Config.SelectedRepoUrl))
|
||||
if (string.IsNullOrEmpty(SelectedRepoChannel?.Url) || SelectedRepoChannel.Url != Config.SelectedRepoUrl)
|
||||
{
|
||||
SelectedRepoChannel = _repoChannels[0];
|
||||
Config.SelectedRepoUrl = SelectedRepoChannel.Url;
|
||||
return;
|
||||
}
|
||||
|
||||
// 尝试找到匹配的预定义渠道
|
||||
var matchedChannel = _repoChannels.FirstOrDefault(c =>
|
||||
c.Name != "自定义" && c.Url == Config.SelectedRepoUrl);
|
||||
|
||||
if (matchedChannel != null)
|
||||
{
|
||||
SelectedRepoChannel = matchedChannel;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 没有匹配的预定义渠道,选择自定义渠道
|
||||
var customChannel = _repoChannels.FirstOrDefault(c => c.Name == "自定义");
|
||||
if (customChannel != null)
|
||||
{
|
||||
SelectedRepoChannel = customChannel;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedRepoChannel = _repoChannels[0];
|
||||
}
|
||||
SelectedRepoChannel = _repoChannels.FirstOrDefault(c => c.Url == Config.SelectedRepoUrl) ??
|
||||
_repoChannels.FirstOrDefault(c => c.Name == "自定义") ?? _repoChannels[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +157,7 @@ public partial class ScriptRepoWindow
|
||||
// 更新配置中的选中仓库URL
|
||||
if (SelectedRepoChannel.Name != "自定义")
|
||||
{
|
||||
// 如果不是自定义渠道,使用选中渠道的URL
|
||||
// 如果不是自定义渠道,直接使用选中渠道的URL
|
||||
Config.SelectedRepoUrl = SelectedRepoChannel.Url;
|
||||
}
|
||||
}
|
||||
@@ -207,41 +170,11 @@ public partial class ScriptRepoWindow
|
||||
Toast.Warning("请选择一个脚本仓库更新渠道。");
|
||||
return;
|
||||
}
|
||||
|
||||
// 确定要使用的URL
|
||||
string repoUrl;
|
||||
if (SelectedRepoChannel.Name == "自定义")
|
||||
{
|
||||
// 使用配置中的自定义URL
|
||||
repoUrl = Config.SelectedRepoUrl;
|
||||
|
||||
// 验证自定义URL
|
||||
if (string.IsNullOrWhiteSpace(repoUrl))
|
||||
{
|
||||
Toast.Warning("请输入自定义仓库URL。");
|
||||
return;
|
||||
}
|
||||
|
||||
if (repoUrl == "https://example.com/custom-repo")
|
||||
{
|
||||
Toast.Warning("请修改默认的自定义URL为有效的仓库地址。");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 使用预定义渠道的URL
|
||||
repoUrl = SelectedRepoChannel.Url;
|
||||
}
|
||||
|
||||
if (!Uri.TryCreate(repoUrl, UriKind.Absolute, out _))
|
||||
{
|
||||
Toast.Warning("请输入有效的URL地址。");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 使用选定渠道的URL进行更新
|
||||
string repoUrl = SelectedRepoChannel.Url;
|
||||
|
||||
// 显示更新中提示
|
||||
Toast.Information("正在更新脚本仓库,请耐心等待...");
|
||||
|
||||
@@ -249,8 +182,7 @@ public partial class ScriptRepoWindow
|
||||
IsUpdating = true;
|
||||
UpdateProgressValue = 0;
|
||||
UpdateProgressText = "准备更新,请耐心等待...";
|
||||
|
||||
// 执行更新
|
||||
// 执行更新 (repoPath, updated)
|
||||
var (_, updated) = await ScriptRepoUpdater.Instance.UpdateCenterRepoByGit(repoUrl,
|
||||
(path, steps, totalSteps) =>
|
||||
{
|
||||
@@ -260,6 +192,7 @@ public partial class ScriptRepoWindow
|
||||
UpdateProgressText = $"{path}";
|
||||
});
|
||||
|
||||
|
||||
// 更新结果提示
|
||||
if (updated)
|
||||
{
|
||||
@@ -272,7 +205,7 @@ public partial class ScriptRepoWindow
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await MessageBox.ErrorAsync($"更新失败,可尝试重置仓库后重新更新。失败原因:{ex.Message}");
|
||||
await MessageBox.ErrorAsync($"更新失败,可尝试重置仓库后重新更新。失败原因:: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -197,12 +197,6 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
{
|
||||
WindowHelper.ApplyThemeToWindow(Application.Current.MainWindow, themeType);
|
||||
}
|
||||
|
||||
// 根据当前主题更新兑换码按钮的默认前景色(若无更新高亮)
|
||||
if (_redeemCodeUpdateNewVersion == null)
|
||||
{
|
||||
UpdateRedeemCodeButtonDefaultForeground();
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -221,9 +215,7 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
if (_redeemCodeUpdateNewVersion != null)
|
||||
{
|
||||
Config.CommonConfig.RedeemCodeFeedsUpdateVersion = _redeemCodeUpdateNewVersion;
|
||||
// 重置为主题默认前景色,避免浅色主题下显示为白色
|
||||
UpdateRedeemCodeButtonDefaultForeground();
|
||||
_redeemCodeUpdateNewVersion = null;
|
||||
RedeemCodeButtonForeground = Brushes.White;
|
||||
}
|
||||
|
||||
var feedWindow = new FeedWindow(new FeedWindowViewModel());
|
||||
@@ -473,28 +465,4 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
_logger.LogDebug(ex, $"获取兑换码是否存在更新失败");
|
||||
}
|
||||
}
|
||||
|
||||
// 更新兑换码按钮在当前主题下的默认前景色
|
||||
private void UpdateRedeemCodeButtonDefaultForeground()
|
||||
{
|
||||
try
|
||||
{
|
||||
var brush = Application.Current.TryFindResource("TextFillColorPrimaryBrush") as Brush;
|
||||
if (brush != null)
|
||||
{
|
||||
RedeemCodeButtonForeground = brush;
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 忽略资源查找异常,走回退逻辑
|
||||
}
|
||||
|
||||
// 回退:根据当前主题类型使用黑/白色
|
||||
var isLightTheme = Config.CommonConfig.CurrentThemeType == ThemeType.LightNone
|
||||
|| Config.CommonConfig.CurrentThemeType == ThemeType.LightMica
|
||||
|| Config.CommonConfig.CurrentThemeType == ThemeType.LightAcrylic;
|
||||
RedeemCodeButtonForeground = isLightTheme ? Brushes.Black : Brushes.White;
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
using BetterGenshinImpact.Core.Script.Group;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.Service.Notification;
|
||||
@@ -37,79 +35,6 @@ public class ScriptGroupProjectEditorViewModel : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
public bool? AllowJsHTTP
|
||||
{
|
||||
get
|
||||
{
|
||||
return _project.AllowJsHTTP;
|
||||
}
|
||||
set
|
||||
{
|
||||
// 为了避免误用,AllowJsHTTP禁止set,通过更新Hash来控制
|
||||
// 脚本作者更新时,如果Hash变更会自动禁用http权限,避免安全风险
|
||||
if (value == null || value == false)
|
||||
{
|
||||
_project.AllowJsHTTPHash = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
_project.AllowJsHTTPHash = _project.GetHttpAllowedUrlsHash();
|
||||
}
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public record JsText(string Text, Brush Color);
|
||||
public List<JsText> JsHTTPInfoText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_project.Project == null)
|
||||
{
|
||||
_project.BuildScriptProjectRelation();
|
||||
}
|
||||
if (_project.Project == null)
|
||||
{
|
||||
return new List<JsText>
|
||||
{
|
||||
new JsText("当前脚本项目未加载", Brushes.Red)
|
||||
};
|
||||
}
|
||||
var urls = _project.Project.Manifest?.HttpAllowedUrls ?? [];
|
||||
if (urls.Length == 0)
|
||||
{
|
||||
return new List<JsText>
|
||||
{
|
||||
new JsText("当前脚本无需使用HTTP资源", Brushes.Green)
|
||||
};
|
||||
}
|
||||
return new List<JsText>
|
||||
{
|
||||
new JsText($"当前脚本使用 {urls.Length} 个HTTP资源", Brushes.OrangeRed)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public record JsLine(string Text, Brush Color);
|
||||
|
||||
public List<JsLine> JsHTTPInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_project.Project == null)
|
||||
{
|
||||
_project.BuildScriptProjectRelation();
|
||||
}
|
||||
var urls = _project.Project?.Manifest?.HttpAllowedUrls ?? [];
|
||||
var blocks = new List<JsLine>();
|
||||
foreach (var url in urls)
|
||||
{
|
||||
blocks.Add(new JsLine(url, Brushes.OrangeRed));
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
}
|
||||
|
||||
public string Status
|
||||
{
|
||||
get => _project.Status;
|
||||
@@ -133,10 +58,6 @@ public class ScriptGroupProjectEditorViewModel : ObservableObject
|
||||
{
|
||||
OnPropertyChanged(nameof(AllowJsNotification));
|
||||
}
|
||||
if (e.PropertyName == nameof(ScriptGroupProject.AllowJsHTTPHash))
|
||||
{
|
||||
OnPropertyChanged(nameof(AllowJsHTTP));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user