Introduce concept of official plugins

This commit is contained in:
JustArchi
2020-06-13 15:09:12 +02:00
parent 70bb1e865a
commit 4d1bca5e51
5 changed files with 47 additions and 9 deletions

View File

@@ -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;
}
}

View File

@@ -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<IPlugin> 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;
}