Skip to content

Commit

Permalink
Implement auto-update
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudokhvist committed Sep 9, 2024
1 parent ea0437a commit d699442
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
31 changes: 30 additions & 1 deletion BirthdayPlugin/BirthdayPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Plugins.Interfaces;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Web.GitHub.Data;
using JetBrains.Annotations;

namespace BirthdayPlugin {
#pragma warning disable CA1812 // ASF uses this class during runtime
[UsedImplicitly]
internal sealed class BirthdayPlugin : IBotModules, IDisposable {
internal sealed class BirthdayPlugin : IBotModules, IDisposable, IGitHubPluginUpdates {
internal sealed class Birthday(DateTimeOffset date, string? name = null) {
public DateTimeOffset Date = date;
public string? Name = name;
Expand All @@ -26,6 +30,31 @@ internal sealed class Birthday(DateTimeOffset date, string? name = null) {
public string Name => nameof(BirthdayPlugin);
public Version Version => typeof(BirthdayPlugin).Assembly.GetName().Version ?? throw new InvalidOperationException(nameof(Version));

public string RepositoryName => "Rudokhvist/BirthdayPlugin";

public Task<ReleaseAsset?> GetTargetReleaseAsset(Version asfVersion, string asfVariant, Version newPluginVersion, IReadOnlyCollection<ReleaseAsset> releaseAssets) {
ArgumentNullException.ThrowIfNull(asfVersion);
ArgumentException.ThrowIfNullOrEmpty(asfVariant);
ArgumentNullException.ThrowIfNull(newPluginVersion);

if ((releaseAssets == null) || (releaseAssets.Count == 0)) {
throw new ArgumentNullException(nameof(releaseAssets));
}

Collection<ReleaseAsset?> matches = [.. releaseAssets.Where(r => r.Name.Equals(Name + ".zip", StringComparison.OrdinalIgnoreCase))];

if (matches.Count != 1) {
return Task.FromResult((ReleaseAsset?) null);
}

ReleaseAsset? release = matches[0];

return (Version.Major == newPluginVersion.Major && Version.Minor == newPluginVersion.Minor && Version.Build == newPluginVersion.Build) || asfVersion != Assembly.GetExecutingAssembly().GetName().Version
? Task.FromResult(release)
: Task.FromResult((ReleaseAsset?) null);
}


internal static readonly string[] ISO8601format = ["yyyy-MM-dd'T'HH:mm:ss.FFFK"];

private static void CalculateNextEvent() {
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<PropertyGroup>
<PluginName>BirthdayPlugin</PluginName>
<Version>0.0.1.0</Version>
<Version>1.0.0.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit d699442

Please sign in to comment.