Skip to content

Commit 9b5edd8

Browse files
committed
Added logging on GithubPluginUpdater
1 parent 8721bf4 commit 9b5edd8

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

ASFFreeGames/ASFFreeGamesPlugin.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,15 @@ private async Task RemoveBot(Bot bot) {
212212
private void StartTimerIfNeeded() => CollectIntervalManager.StartTimerIfNeeded();
213213

214214
~ASFFreeGamesPlugin() => CollectIntervalManager.Dispose();
215-
public readonly GithubPluginUpdater Updater = new(new Lazy<Version>(GetVersion));
215+
216+
#region IGitHubPluginUpdates implementation
217+
private readonly GithubPluginUpdater Updater = new(new Lazy<Version>(GetVersion));
216218
string IGitHubPluginUpdates.RepositoryName => GithubPluginUpdater.RepositoryName;
217219

218220
bool IGitHubPluginUpdates.CanUpdate => Updater.CanUpdate;
219221

220222
Task<Uri?> IGitHubPluginUpdates.GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, bool stable, bool forced) => Updater.GetTargetReleaseURL(asfVersion, asfVariant, asfUpdate, stable, forced);
223+
#endregion
221224
}
222225

223226
#pragma warning restore CA1812 // ASF uses this class during runtime

ASFFreeGames/Github/GithubPluginUpdater.cs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,55 @@ public class GithubPluginUpdater(Lazy<Version> version) {
1414

1515
private Version CurrentVersion => version.Value;
1616

17+
private static void LogGenericError(string message) {
18+
if (string.IsNullOrEmpty(message)) {
19+
return;
20+
}
21+
22+
ArchiSteamFarm.Core.ASF.ArchiLogger.LogGenericError($"{nameof(GithubPluginUpdater)}: {message}");
23+
}
24+
25+
private static void LogGenericDebug(string message) {
26+
if (string.IsNullOrEmpty(message)) {
27+
return;
28+
}
29+
30+
ArchiSteamFarm.Core.ASF.ArchiLogger.LogGenericDebug($"{nameof(GithubPluginUpdater)}: {message}");
31+
}
32+
1733
public async Task<Uri?> GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, bool stable, bool forced) {
1834
ArgumentNullException.ThrowIfNull(asfVersion);
1935
ArgumentException.ThrowIfNullOrEmpty(asfVariant);
2036

2137
if (!CanUpdate) {
38+
LogGenericDebug("CanUpdate is false");
39+
2240
return null;
2341
}
2442

2543
if (string.IsNullOrEmpty(RepositoryName)) {
26-
//ArchiSteamFarm.Core.ASF.ArchiLogger.LogGenericError(Strings.FormatWarningFailedWithError(nameof(RepositoryName)));
44+
LogGenericError("RepositoryName is null or empty");
2745

2846
return null;
2947
}
3048

3149
ReleaseResponse? releaseResponse = await GitHubService.GetLatestRelease(RepositoryName).ConfigureAwait(false);
3250

3351
if (releaseResponse == null) {
52+
LogGenericError("GetLatestRelease returned null");
53+
3454
return null;
3555
}
3656

3757
if (releaseResponse.IsPreRelease) {
58+
LogGenericError("GetLatestRelease returned pre-release");
59+
3860
return null;
3961
}
4062

41-
if (stable && !((releaseResponse.PublishedAt - DateTime.UtcNow).Duration() > TimeSpan.FromHours(3))) {
42-
// Skip updates that are too recent
63+
if (stable && ((releaseResponse.PublishedAt - DateTime.UtcNow).Duration() < TimeSpan.FromHours(3))) {
64+
LogGenericDebug("GetLatestRelease returned too recent");
65+
4366
return null;
4467
}
4568

@@ -48,27 +71,25 @@ public class GithubPluginUpdater(Lazy<Version> version) {
4871
if (!forced && (CurrentVersion >= newVersion)) {
4972
// Allow same version to be re-updated when we're updating ASF release and more than one asset is found - potential compatibility difference
5073
if ((CurrentVersion > newVersion) || !asfUpdate || (releaseResponse.Assets.Count(static asset => asset.Name.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)) < 2)) {
51-
//ASF.ArchiLogger.LogGenericInfo(Strings.FormatPluginUpdateNotFound(Name, Version, newVersion));
52-
5374
return null;
5475
}
5576
}
5677

5778
if (releaseResponse.Assets.Count == 0) {
58-
//ASF.ArchiLogger.LogGenericWarning(Strings.FormatPluginUpdateNoAssetFound(Name, Version, newVersion));
79+
LogGenericError($"GetLatestRelease for version {newVersion} returned no assets");
5980

6081
return null;
6182
}
6283

6384
ReleaseAsset? asset = releaseResponse.Assets.FirstOrDefault(static asset => asset.Name.EndsWith(".zip", StringComparison.OrdinalIgnoreCase) && (asset.Size > (1 << 18)));
6485

6586
if ((asset == null) || !releaseResponse.Assets.Contains(asset)) {
66-
//ASF.ArchiLogger.LogGenericWarning(Strings.FormatPluginUpdateNoAssetFound(Name, Version, newVersion));
87+
LogGenericError($"GetLatestRelease for version {newVersion} returned no valid assets");
6788

6889
return null;
6990
}
7091

71-
//.ArchiLogger.LogGenericInfo(Strings.FormatPluginUpdateFound(Name, Version, newVersion));
92+
LogGenericDebug($"GetLatestRelease for version {newVersion} returned asset {asset.Name} with url {asset.DownloadURL}");
7293

7394
return asset.DownloadURL;
7495
}

0 commit comments

Comments
 (0)