From 4d1bca5e5155bf30ef65d4fbc19d9ca3dce4d380 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sat, 13 Jun 2020 15:09:12 +0200 Subject: [PATCH] Introduce concept of official plugins --- .../SteamTokenDumperPlugin.cs | 8 ++--- ArchiSteamFarm/AssemblyInfo.cs | 1 + ArchiSteamFarm/Plugins/OfficialPlugin.cs | 32 +++++++++++++++++++ ArchiSteamFarm/Plugins/PluginsCore.cs | 13 +++++--- ArchiSteamFarm/SharedInfo.cs | 2 +- 5 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 ArchiSteamFarm/Plugins/OfficialPlugin.cs diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs index 996549681..f3f54cbea 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs @@ -36,7 +36,7 @@ using SteamKit2; namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { [Export(typeof(IPlugin))] [UsedImplicitly] - internal sealed class SteamTokenDumperPlugin : IASF, IBot, IBotSteamClient, ISteamPICSChanges { + internal sealed class SteamTokenDumperPlugin : OfficialPlugin, IASF, IBot, IBotSteamClient, ISteamPICSChanges { private static readonly ConcurrentDictionary BotSubscriptions = new ConcurrentDictionary(); private static readonly ConcurrentDictionary BotSynchronizations = new ConcurrentDictionary(); private static readonly SemaphoreSlim SubmissionSemaphore = new SemaphoreSlim(1, 1); @@ -45,9 +45,9 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { private static GlobalCache GlobalCache; private static bool IsEnabled; - public string Name => nameof(SteamTokenDumperPlugin); + public override string Name => nameof(SteamTokenDumperPlugin); - public Version Version => typeof(SteamTokenDumperPlugin).Assembly.GetName().Version ?? throw new ArgumentNullException(nameof(Version)); + public override Version Version => typeof(SteamTokenDumperPlugin).Assembly.GetName().Version ?? throw new ArgumentNullException(nameof(Version)); public Task GetPreferredChangeNumberToStartFrom() => Task.FromResult(IsEnabled ? GlobalCache?.LastChangeNumber ?? 0 : 0); @@ -146,7 +146,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { public IReadOnlyCollection OnBotSteamHandlersInit(Bot bot) => null; - public void OnLoaded() { } + public override void OnLoaded() { } public async void OnPICSChanges(uint currentChangeNumber, IReadOnlyDictionary appChanges, IReadOnlyDictionary packageChanges) { if ((currentChangeNumber == 0) || (appChanges == null) || (packageChanges == null)) { diff --git a/ArchiSteamFarm/AssemblyInfo.cs b/ArchiSteamFarm/AssemblyInfo.cs index b862f54a9..469d39317 100644 --- a/ArchiSteamFarm/AssemblyInfo.cs +++ b/ArchiSteamFarm/AssemblyInfo.cs @@ -22,3 +22,4 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("ArchiSteamFarm.Tests")] +[assembly: InternalsVisibleTo("ArchiSteamFarm.OfficialPlugins.SteamTokenDumper")] diff --git a/ArchiSteamFarm/Plugins/OfficialPlugin.cs b/ArchiSteamFarm/Plugins/OfficialPlugin.cs new file mode 100644 index 000000000..a871aa150 --- /dev/null +++ b/ArchiSteamFarm/Plugins/OfficialPlugin.cs @@ -0,0 +1,32 @@ +// _ _ _ ____ _ _____ +// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ +// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ +// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| +// | +// Copyright 2015-2020 Ɓukasz "JustArchi" Domeradzki +// Contact: JustArchi@JustArchi.net +// | +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// | +// http://www.apache.org/licenses/LICENSE-2.0 +// | +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; + +namespace ArchiSteamFarm.Plugins { + internal abstract class OfficialPlugin : IPlugin { + public abstract string Name { get; } + public abstract Version Version { get; } + public abstract void OnLoaded(); + + internal bool HasSameVersion() => Version == SharedInfo.Version; + } +} diff --git a/ArchiSteamFarm/Plugins/PluginsCore.cs b/ArchiSteamFarm/Plugins/PluginsCore.cs index 3d4510842..7bea824a8 100644 --- a/ArchiSteamFarm/Plugins/PluginsCore.cs +++ b/ArchiSteamFarm/Plugins/PluginsCore.cs @@ -37,7 +37,9 @@ using SteamKit2; namespace ArchiSteamFarm.Plugins { internal static class PluginsCore { - internal static bool HasActivePluginsLoaded => ActivePlugins?.Count > 0; + internal static bool HasCustomPluginsLoaded => !HasActivePluginsLoaded || ActivePlugins.All(plugin => plugin is OfficialPlugin officialPlugin && officialPlugin.HasSameVersion()); + + private static bool HasActivePluginsLoaded => ActivePlugins?.Count > 0; [ImportMany] private static ImmutableHashSet ActivePlugins { get; set; } @@ -147,10 +149,13 @@ namespace ArchiSteamFarm.Plugins { } ActivePlugins = activePlugins.ToImmutableHashSet(); - ASF.ArchiLogger.LogGenericInfo(Strings.PluginsWarning); - // Loading plugins changes the program identifier, refresh the console title - Console.Title = SharedInfo.ProgramIdentifier; + if (HasCustomPluginsLoaded) { + ASF.ArchiLogger.LogGenericInfo(Strings.PluginsWarning); + + // Loading plugins changes the program identifier, refresh the console title + Console.Title = SharedInfo.ProgramIdentifier; + } return invalidPlugins.Count == 0; } diff --git a/ArchiSteamFarm/SharedInfo.cs b/ArchiSteamFarm/SharedInfo.cs index e3fdd175e..12285f57f 100644 --- a/ArchiSteamFarm/SharedInfo.cs +++ b/ArchiSteamFarm/SharedInfo.cs @@ -85,7 +85,7 @@ namespace ArchiSteamFarm { internal static string ProgramIdentifier => PublicIdentifier + " V" + Version + " (" + BuildInfo.Variant + "/" + ModuleVersion + " | " + OS.Variant + ")"; [NotNull] - internal static string PublicIdentifier => AssemblyName + (BuildInfo.IsCustomBuild ? "-custom" : PluginsCore.HasActivePluginsLoaded ? "-modded" : ""); + internal static string PublicIdentifier => AssemblyName + (BuildInfo.IsCustomBuild ? "-custom" : PluginsCore.HasCustomPluginsLoaded ? "-modded" : ""); [NotNull] internal static Version Version => Assembly.GetEntryAssembly()?.GetName().Version ?? throw new ArgumentNullException(nameof(Version));