. | using Newtonsoft.Json; |
| using Playnite.SDK.Data; |
| using Playnite.SDK.Events; |
| using Playnite.SDK.Events; |
| using Playnite.SDK.Models; |
| using Playnite.SDK.Models; |
| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using System.IO; |
| using System.IO; |
| using System.Linq; |
| using System.Linq; |
| using System.Text; |
| using System.Text; |
| using System.Threading.Tasks; |
| using System.Threading.Tasks; |
. | |
| using System.Windows; |
| using System.Windows.Controls; |
| using System.Windows.Controls; |
| |
| |
| namespace Playnite.SDK.Plugins |
| namespace Playnite.SDK.Plugins |
| { |
| { |
| /// <summary> |
| /// <summary> |
. | |
| /// |
| |
| /// </summary> |
| |
| public class GetPlayActionsArgs |
| |
| { |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| public Game Game { get; set; } |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| public class GetInstallActionsArgs |
| |
| { |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| public Game Game { get; set; } |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| public class GetUninstallActionsArgs |
| |
| { |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| public Game Game { get; set; } |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// When used, specific plugin class will be loaded by Playnite. |
| |
| /// </summary> |
| |
| public class LoadPluginAttribute : Attribute |
| |
| { |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// When used, specific plugin class won't be loaded by Playnite. |
| |
| /// </summary> |
| |
| public class IgnorePluginAttribute : Attribute |
| |
| { |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| public class GetGameViewControlArgs |
| |
| { |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| public string Name { get; set; } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| public ApplicationMode Mode { get; set; } |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| public class AddCustomElementSupportArgs |
| |
| { |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| public List<string> ElementList { get; set; } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| public string SourceName { get; set; } |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| public class AddSettingsSupportArgs |
| |
| { |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| public string SourceName { get; set; } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| public string SettingsRoot { get; set; } |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// Represents plugin properties. |
| |
| /// </summary> |
| |
| public abstract class PluginProperties |
| |
| { |
| |
| /// <summary> |
| |
| /// Gets or sets value indicating that the plugin provides user settings view. |
| |
| /// </summary> |
| |
| public bool HasSettings { get; set; } |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// Represents <see cref="GenericPlugin"/> plugin properties. |
| |
| /// </summary> |
| |
| public class GenericPluginProperties : PluginProperties |
| |
| { |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// Represents generic plugin. |
| |
| /// </summary> |
| |
| public abstract class GenericPlugin : Plugin |
| |
| { |
| |
| /// <summary> |
| |
| /// Gets plugin's properties. |
| |
| /// </summary> |
| |
| public GenericPluginProperties Properties { get; protected set; } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| /// <param name="playniteAPI"></param> |
| |
| public GenericPlugin(IPlayniteAPI playniteAPI) : base(playniteAPI) |
| |
| { |
| |
| } |
| |
| } |
| |
| |
| |
| /// <summary> |
| /// Represents base Playnite plugin. |
| /// Represents base Playnite plugin. |
| /// </summary> |
| /// </summary> |
| public abstract class Plugin : IDisposable, IIdentifiable |
| public abstract class Plugin : IDisposable, IIdentifiable |
| { |
| { |
| private const string pluginSettingFileName = "config.json"; |
| private const string pluginSettingFileName = "config.json"; |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets instance of runtime <see cref="IPlayniteAPI"/>. |
| /// Gets instance of runtime <see cref="IPlayniteAPI"/>. |
| /// </summary> |
| /// </summary> |
| public readonly IPlayniteAPI PlayniteApi; |
| public readonly IPlayniteAPI PlayniteApi; |
| |
| |
| /// <summary> |
| /// <summary> |
| /// <inheritdoc/> |
| /// <inheritdoc/> |
| /// </summary> |
| /// </summary> |
| public abstract Guid Id { get; } |
| public abstract Guid Id { get; } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Creates new instance of <see cref="Plugin"/>. |
| /// Creates new instance of <see cref="Plugin"/>. |
| /// </summary> |
| /// </summary> |
| /// <param name="playniteAPI">Instance of Playnite API to be injected.</param> |
| /// <param name="playniteAPI">Instance of Playnite API to be injected.</param> |
| public Plugin(IPlayniteAPI playniteAPI) |
| public Plugin(IPlayniteAPI playniteAPI) |
| { |
| { |
| PlayniteApi = playniteAPI; |
| PlayniteApi = playniteAPI; |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// <inheritdoc/> |
| /// <inheritdoc/> |
| /// </summary> |
| /// </summary> |
| public virtual void Dispose() |
| public virtual void Dispose() |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets plugin settings or null if plugin doesn't provide any settings. |
| /// Gets plugin settings or null if plugin doesn't provide any settings. |
| /// </summary> |
| /// </summary> |
| public virtual ISettings GetSettings(bool firstRunSettings) |
| public virtual ISettings GetSettings(bool firstRunSettings) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets plugin settings view or null if plugin doesn't provide settings view. |
| /// Gets plugin settings view or null if plugin doesn't provide settings view. |
| /// </summary> |
| /// </summary> |
| public virtual UserControl GetSettingsView(bool firstRunView) |
| public virtual UserControl GetSettingsView(bool firstRunView) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
. | /// Returns list of plugin functions. |
| |
| /// </summary> |
| |
| /// <returns></returns> |
| |
| [Obsolete("Use GetGameMenuItems and GetMainMenuItems methods.")] |
| |
| public virtual IEnumerable<ExtensionFunction> GetFunctions() |
| |
| { |
| |
| return null; |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// Called before game is started. |
| /// Called before game is started. |
| /// </summary> |
| /// </summary> |
. | /// <param name="game">Game that will be started.</param> |
| public virtual void OnGameStarting(OnGameStartingEventArgs args) |
| public virtual void OnGameStarting(Game game) |
| |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Called when game has started. |
| /// Called when game has started. |
| /// </summary> |
| /// </summary> |
. | /// <param name="game">Game that started.</param> |
| public virtual void OnGameStarted(OnGameStartedEventArgs args) |
| public virtual void OnGameStarted(Game game) |
| |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Called when game stopped running. |
| /// Called when game stopped running. |
| /// </summary> |
| /// </summary> |
. | /// <param name="game">Game that stopped running.</param> |
| public virtual void OnGameStopped(OnGameStoppedEventArgs args) |
| /// <param name="ellapsedSeconds">Time in seconds of how long the game was running.</param> |
| |
| public virtual void OnGameStopped(Game game, long ellapsedSeconds) |
| |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Called when game has been installed. |
| /// Called when game has been installed. |
| /// </summary> |
| /// </summary> |
. | /// <param name="game">Game that's been installed.</param> |
| public virtual void OnGameInstalled(OnGameInstalledEventArgs args) |
| public virtual void OnGameInstalled(Game game) |
| |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Called when game has been uninstalled. |
| /// Called when game has been uninstalled. |
| /// </summary> |
| /// </summary> |
. | /// <param name="game">Game that's been uninstalled.</param> |
| public virtual void OnGameUninstalled(OnGameUninstalledEventArgs args) |
| public virtual void OnGameUninstalled(Game game) |
| |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Called when game selection changed. |
| /// Called when game selection changed. |
| /// </summary> |
| /// </summary> |
. | /// <param name="args"></param> |
| public virtual void OnGameSelected(OnGameSelectedEventArgs args) |
| public virtual void OnGameSelected(GameSelectionEventArgs args) |
| |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Called when appliaction is started and initialized. |
| /// Called when appliaction is started and initialized. |
| /// </summary> |
| /// </summary> |
. | public virtual void OnApplicationStarted() |
| public virtual void OnApplicationStarted(OnApplicationStartedEventArgs args) |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Called when appliaction is stutting down. |
| /// Called when appliaction is stutting down. |
| /// </summary> |
| /// </summary> |
. | public virtual void OnApplicationStopped() |
| public virtual void OnApplicationStopped(OnApplicationStoppedEventArgs args) |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Called library update has been finished. |
| /// Called library update has been finished. |
| /// </summary> |
| /// </summary> |
. | public virtual void OnLibraryUpdated() |
| public virtual void OnLibraryUpdated(OnLibraryUpdatedEventArgs args) |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets list of items to be displayed in game's context menu. |
| /// Gets list of items to be displayed in game's context menu. |
| /// </summary> |
| /// </summary> |
| /// <param name="args">Contextual arguments.</param> |
| /// <param name="args">Contextual arguments.</param> |
| /// <returns>List of menu items to be displayed in game menu.</returns> |
| /// <returns>List of menu items to be displayed in game menu.</returns> |
. | public virtual List<GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args) |
| public virtual IEnumerable<GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets list of items to be displayed in Playnite's main menu. |
| /// Gets list of items to be displayed in Playnite's main menu. |
| /// </summary> |
| /// </summary> |
| /// <param name="args">Contextual arguments.</param> |
| /// <param name="args">Contextual arguments.</param> |
| /// <returns>List of menu items to be displayed in Playnite's main menu.</returns> |
| /// <returns>List of menu items to be displayed in Playnite's main menu.</returns> |
. | public virtual List<MainMenuItem> GetMainMenuItems(GetMainMenuItemsArgs args) |
| public virtual IEnumerable<MainMenuItem> GetMainMenuItems(GetMainMenuItemsArgs args) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets path dedicated for plugins to store data. |
| /// Gets path dedicated for plugins to store data. |
| /// </summary> |
| /// </summary> |
| /// <returns>Full directory path.</returns> |
| /// <returns>Full directory path.</returns> |
| public string GetPluginUserDataPath() |
| public string GetPluginUserDataPath() |
| { |
| { |
| var path = Path.Combine(PlayniteApi.Paths.ExtensionsDataPath, Id.ToString()); |
| var path = Path.Combine(PlayniteApi.Paths.ExtensionsDataPath, Id.ToString()); |
| if (!Directory.Exists(path)) |
| if (!Directory.Exists(path)) |
| { |
| { |
| Directory.CreateDirectory(path); |
| Directory.CreateDirectory(path); |
| } |
| } |
| |
| |
| return path; |
| return path; |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets plugin configuration stored in plugin.cfg file. |
| /// Gets plugin configuration stored in plugin.cfg file. |
| /// </summary> |
| /// </summary> |
| /// <typeparam name="TConfig">Plugin configuration type.</typeparam> |
| /// <typeparam name="TConfig">Plugin configuration type.</typeparam> |
| /// <returns>Plugin configuration.</returns> |
| /// <returns>Plugin configuration.</returns> |
| public TConfig GetPluginConfiguration<TConfig>() where TConfig : class |
| public TConfig GetPluginConfiguration<TConfig>() where TConfig : class |
| { |
| { |
| var pluginDir = Path.GetDirectoryName(GetType().Assembly.Location); |
| var pluginDir = Path.GetDirectoryName(GetType().Assembly.Location); |
| var pluginConfig = Path.Combine(pluginDir, "plugin.cfg"); |
| var pluginConfig = Path.Combine(pluginDir, "plugin.cfg"); |
| if (File.Exists(pluginConfig)) |
| if (File.Exists(pluginConfig)) |
| { |
| { |
. | return JsonConvert.DeserializeObject<TConfig>(File.ReadAllText(pluginConfig)); |
| return Serialization.FromJsonFile<TConfig>(pluginConfig); |
| } |
| } |
| else |
| else |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets plugin settings. |
| /// Gets plugin settings. |
| /// </summary> |
| /// </summary> |
| /// <typeparam name="TSettings">Plugin settings type.</typeparam> |
| /// <typeparam name="TSettings">Plugin settings type.</typeparam> |
| /// <returns>Plugin settings.</returns> |
| /// <returns>Plugin settings.</returns> |
| public TSettings LoadPluginSettings<TSettings>() where TSettings : class |
| public TSettings LoadPluginSettings<TSettings>() where TSettings : class |
| { |
| { |
| var setFile = Path.Combine(GetPluginUserDataPath(), pluginSettingFileName); |
| var setFile = Path.Combine(GetPluginUserDataPath(), pluginSettingFileName); |
| if (File.Exists(setFile)) |
| if (File.Exists(setFile)) |
| { |
| { |
. | var strConf = File.ReadAllText(setFile); |
| return Serialization.FromJsonFile<TSettings>(setFile); |
| return JsonConvert.DeserializeObject<TSettings>(strConf); |
| |
| } |
| } |
| else |
| else |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Saves plugin settings. |
| /// Saves plugin settings. |
| /// </summary> |
| /// </summary> |
| /// <typeparam name="TSettings">Plugin settings type.</typeparam> |
| /// <typeparam name="TSettings">Plugin settings type.</typeparam> |
| /// <param name="settings">Source plugin.</param> |
| /// <param name="settings">Source plugin.</param> |
| public void SavePluginSettings<TSettings>(TSettings settings) where TSettings : class |
| public void SavePluginSettings<TSettings>(TSettings settings) where TSettings : class |
| { |
| { |
| var setDir = GetPluginUserDataPath(); |
| var setDir = GetPluginUserDataPath(); |
| var setFile = Path.Combine(setDir, pluginSettingFileName); |
| var setFile = Path.Combine(setDir, pluginSettingFileName); |
| if (!Directory.Exists(setDir)) |
| if (!Directory.Exists(setDir)) |
| { |
| { |
| Directory.CreateDirectory(setDir); |
| Directory.CreateDirectory(setDir); |
| } |
| } |
| |
| |
. | var strConf = JsonConvert.SerializeObject(settings, Formatting.Indented); |
| var strConf = Serialization.ToJson(settings, true); |
| File.WriteAllText(setFile, strConf); |
| File.WriteAllText(setFile, strConf); |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Opens plugin's settings view. Only works in Desktop application mode! |
| /// Opens plugin's settings view. Only works in Desktop application mode! |
| /// </summary> |
| /// </summary> |
| /// <returns>True if user saved any changes, False if dialog was canceled.</returns> |
| /// <returns>True if user saved any changes, False if dialog was canceled.</returns> |
| public bool OpenSettingsView() |
| public bool OpenSettingsView() |
| { |
| { |
| if (PlayniteApi.ApplicationInfo.Mode == ApplicationMode.Fullscreen) |
| if (PlayniteApi.ApplicationInfo.Mode == ApplicationMode.Fullscreen) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| return PlayniteApi.MainView.OpenPluginSettings(Id); |
| return PlayniteApi.MainView.OpenPluginSettings(Id); |
. | |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| /// <param name="args"></param> |
| |
| /// <returns></returns> |
| |
| public virtual IEnumerable<PlayController> GetPlayActions(GetPlayActionsArgs args) |
| |
| { |
| |
| yield break; |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| /// <param name="args"></param> |
| |
| /// <returns></returns> |
| |
| public virtual IEnumerable<InstallController> GetInstallActions(GetInstallActionsArgs args) |
| |
| { |
| |
| yield break; |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| /// <param name="args"></param> |
| |
| /// <returns></returns> |
| |
| public virtual IEnumerable<UninstallController> GetUninstallActions(GetUninstallActionsArgs args) |
| |
| { |
| |
| yield break; |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| /// <param name="args"></param> |
| |
| /// <returns></returns> |
| |
| public virtual Control GetGameViewControl(GetGameViewControlArgs args) |
| |
| { |
| |
| return null; |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| /// <param name="args"></param> |
| |
| public void AddCustomElementSupport(AddCustomElementSupportArgs args) |
| |
| { |
| |
| PlayniteApi.AddCustomElementSupport(this, args); |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| /// <param name="args"></param> |
| |
| public void AddSettingsSupport(AddSettingsSupportArgs args) |
| |
| { |
| |
| PlayniteApi.AddSettingsSupport(this, args); |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// Gets sidebar items provided by this plugin. |
| |
| /// </summary> |
| |
| /// <returns></returns> |
| |
| public virtual IEnumerable<SidebarItem> GetSidebarItems() |
| |
| { |
| |
| yield break; |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| ///Gets top panel items provided by this plugin. |
| |
| /// </summary> |
| |
| /// <returns></returns> |
| |
| public virtual IEnumerable<TopPanelItem> GetTopPanelItems() |
| |
| { |
| |
| yield break; |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |