|
1 | 1 | using ArchiSteamFarm.Core; |
2 | 2 | using ArchiSteamFarm.Plugins.Interfaces; |
3 | 3 | using ArchiSteamFarm.Steam; |
| 4 | +using ArchiSteamFarm.Web.GitHub; |
4 | 5 | using ASFOAuth.Data; |
5 | 6 | using System.ComponentModel; |
6 | 7 | using System.Composition; |
7 | 8 | using System.Reflection; |
8 | 9 | using System.Text; |
9 | 10 | using System.Text.Json; |
| 11 | +using static ArchiSteamFarm.Storage.GlobalConfig; |
10 | 12 |
|
11 | 13 | namespace ASFOAuth; |
12 | 14 |
|
13 | 15 | [Export(typeof(IPlugin))] |
14 | | -internal sealed class ASFOAuth : IASF, IBotCommand2 |
| 16 | +internal sealed class ASFOAuth : IASF, IBotCommand2, IGitHubPluginUpdates |
15 | 17 | { |
16 | 18 | public string Name => "ASF OAuth"; |
17 | 19 | public Version Version => MyVersion; |
18 | 20 |
|
| 21 | + public bool CanUpdate => true; |
| 22 | + public string RepositoryName => "chr233/ASFOAuth"; |
| 23 | + |
| 24 | + |
19 | 25 | private bool ASFEBridge; |
20 | 26 |
|
21 | 27 | public static PluginConfig Config => Utils.Config; |
@@ -226,4 +232,60 @@ public Task OnLoaded() |
226 | 232 | return ex.StackTrace; |
227 | 233 | } |
228 | 234 | } |
| 235 | + |
| 236 | + /// <inheritdoc/> |
| 237 | + public async Task<Uri?> GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, EUpdateChannel updateChannel, bool forced) |
| 238 | + { |
| 239 | + var releaseResponse = await GitHubService.GetLatestRelease(RepositoryName, updateChannel == EUpdateChannel.Stable, default).ConfigureAwait(false); |
| 240 | + if (releaseResponse == null) |
| 241 | + { |
| 242 | + return null; |
| 243 | + } |
| 244 | + |
| 245 | + //Version newVersion = new(releaseResponse.Tag); |
| 246 | + //if (!forced && (Version >= newVersion)) |
| 247 | + //{ |
| 248 | + // ASFLogger.LogGenericInfo(string.Format(Langs.UpdatePluginListItemName, Name, Langs.AlreadyLatest)); |
| 249 | + // return null; |
| 250 | + //} |
| 251 | + |
| 252 | + //if (releaseResponse.Assets.Count == 0) |
| 253 | + //{ |
| 254 | + // ASFLogger.LogGenericWarning(Langs.NoAssetFoundInReleaseInfo); |
| 255 | + // return null; |
| 256 | + //} |
| 257 | + |
| 258 | + //ASFLogger.LogGenericInfo(string.Format(Langs.UpdatePluginListItemName, Name, Langs.CanUpdate)); |
| 259 | + //ASFLogger.LogGenericInfo(string.Format(Langs.UpdatePluginListItemVersion, Version, newVersion)); |
| 260 | + //if (!string.IsNullOrEmpty(releaseResponse.MarkdownBody)) |
| 261 | + //{ |
| 262 | + // ASFLogger.LogGenericInfo(string.Format(Langs.UpdatePluginListItemReleaseNote, releaseResponse.MarkdownBody)); |
| 263 | + //} |
| 264 | + |
| 265 | + if (releaseResponse.Assets.Count == 0) |
| 266 | + { |
| 267 | + return null; |
| 268 | + } |
| 269 | + |
| 270 | + //优先下载当前语言的版本 |
| 271 | + foreach (var asset in releaseResponse.Assets) |
| 272 | + { |
| 273 | + if (asset.Name.Contains(Langs.CurrentLanguage)) |
| 274 | + { |
| 275 | + return asset.DownloadURL; |
| 276 | + } |
| 277 | + } |
| 278 | + |
| 279 | + //优先下载英文版本 |
| 280 | + foreach (var asset in releaseResponse.Assets) |
| 281 | + { |
| 282 | + if (asset.Name.Contains("en-US")) |
| 283 | + { |
| 284 | + return asset.DownloadURL; |
| 285 | + } |
| 286 | + } |
| 287 | + |
| 288 | + //如果没有找到当前语言的版本, 则下载第一个 |
| 289 | + return releaseResponse.Assets.FirstOrDefault()?.DownloadURL; |
| 290 | + } |
229 | 291 | } |
0 commit comments