generated from JustArchiNET/ASF-PluginTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement GitHub update checks for ASFFreeGamesPlugin (v1.8.0.0)
* **Implemented automatic update check via GitHub:** The `ASFFreeGamesPlugin` now supports checking for updates through GitHub. This feature is currently disabled by default (`CanUpdate` is initially set to `true`). * **Added `GithubPluginUpdater` class:** This class handles communication with GitHub to retrieve the latest release information. * **Updated version number:** The plugin version is bumped to `1.8.0.0`. * **Removed unnecessary dependencies:** The build process now excludes unnecessary DLLs from the final package. **Fixes issue #101.**
- Loading branch information
Showing
4 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using ArchiSteamFarm; | ||
using ArchiSteamFarm.Localization; | ||
using ArchiSteamFarm.Web.GitHub; | ||
using ArchiSteamFarm.Web.GitHub.Data; | ||
|
||
namespace Maxisoft.ASF.Github; | ||
|
||
public class GithubPluginUpdater(Lazy<Version> version) { | ||
public const string RepositoryName = "maxisoft/ASFFreeGames"; | ||
public bool CanUpdate { get; internal set; } = true; | ||
|
||
private Version CurrentVersion => version.Value; | ||
|
||
public async Task<Uri?> GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, bool stable, bool forced) { | ||
ArgumentNullException.ThrowIfNull(asfVersion); | ||
ArgumentException.ThrowIfNullOrEmpty(asfVariant); | ||
|
||
if (!CanUpdate) { | ||
return null; | ||
} | ||
|
||
if (string.IsNullOrEmpty(RepositoryName)) { | ||
//ArchiSteamFarm.Core.ASF.ArchiLogger.LogGenericError(Strings.FormatWarningFailedWithError(nameof(RepositoryName))); | ||
|
||
return null; | ||
} | ||
|
||
ReleaseResponse? releaseResponse = await GitHubService.GetLatestRelease(RepositoryName).ConfigureAwait(false); | ||
|
||
if (releaseResponse == null) { | ||
return null; | ||
} | ||
|
||
if (releaseResponse.IsPreRelease) { | ||
return null; | ||
} | ||
|
||
Version newVersion = new(releaseResponse.Tag.ToUpperInvariant().TrimStart('V')); | ||
|
||
if (!forced && (CurrentVersion >= newVersion)) { | ||
// Allow same version to be re-updated when we're updating ASF release and more than one asset is found - potential compatibility difference | ||
if ((CurrentVersion > newVersion) || !asfUpdate || (releaseResponse.Assets.Count(static asset => asset.Name.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)) < 2)) { | ||
//ASF.ArchiLogger.LogGenericInfo(Strings.FormatPluginUpdateNotFound(Name, Version, newVersion)); | ||
|
||
return null; | ||
} | ||
} | ||
|
||
if (releaseResponse.Assets.Count == 0) { | ||
//ASF.ArchiLogger.LogGenericWarning(Strings.FormatPluginUpdateNoAssetFound(Name, Version, newVersion)); | ||
|
||
return null; | ||
} | ||
|
||
ReleaseAsset? asset = releaseResponse.Assets.FirstOrDefault(static asset => asset.Name.EndsWith(".zip", StringComparison.OrdinalIgnoreCase) && (asset.Size > (1 << 18))); | ||
|
||
if ((asset == null) || !releaseResponse.Assets.Contains(asset)) { | ||
//ASF.ArchiLogger.LogGenericWarning(Strings.FormatPluginUpdateNoAssetFound(Name, Version, newVersion)); | ||
|
||
return null; | ||
} | ||
|
||
//.ArchiLogger.LogGenericInfo(Strings.FormatPluginUpdateFound(Name, Version, newVersion)); | ||
|
||
return asset.DownloadURL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters