| using Playnite.SDK.Models; |
| using Playnite.SDK.Models; |
| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using System.Linq; |
| using System.Linq; |
| using System.Text; |
| using System.Text; |
| using System.Threading; |
| using System.Threading; |
| using System.Threading.Tasks; |
| using System.Threading.Tasks; |
| |
| |
| namespace Playnite.SDK.Plugins |
| namespace Playnite.SDK.Plugins |
| { |
| { |
| /// <summary> |
| /// <summary> |
| /// Type of automatic play action |
| /// Type of automatic play action |
| /// </summary> |
| /// </summary> |
| public enum AutomaticPlayActionType : int |
| public enum AutomaticPlayActionType : int |
| { |
| { |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| File = 0, |
| File = 0, |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| Url = 1 |
| Url = 1 |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Represents controller for automatic handling of game startup. |
| /// Represents controller for automatic handling of game startup. |
| /// </summary> |
| /// </summary> |
| public sealed class AutomaticPlayController : PlayController |
| public sealed class AutomaticPlayController : PlayController |
| { |
| { |
| /// <summary> |
| /// <summary> |
| /// Gets or sets task type. |
| /// Gets or sets task type. |
| /// </summary> |
| /// </summary> |
| public AutomaticPlayActionType Type { get; set; } |
| public AutomaticPlayActionType Type { get; set; } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| public TrackingMode TrackingMode { get; set; } |
| public TrackingMode TrackingMode { get; set; } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| public string TrackingPath { get; set; } |
| public string TrackingPath { get; set; } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets or sets executable arguments for File type tasks. |
| /// Gets or sets executable arguments for File type tasks. |
| /// </summary> |
| /// </summary> |
| public string Arguments { get; set; } |
| public string Arguments { get; set; } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets or sets executable path for File action type or URL for URL action type. |
| /// Gets or sets executable path for File action type or URL for URL action type. |
| /// </summary> |
| /// </summary> |
| public string Path { get; set; } |
| public string Path { get; set; } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets or sets working directory for File action type executable. |
| /// Gets or sets working directory for File action type executable. |
| /// </summary> |
| /// </summary> |
| public string WorkingDir { get; set; } |
| public string WorkingDir { get; set; } |
| |
| |
| /// <summary> |
| /// <summary> |
. | |
| /// Gets or sets delay in milliseconds before tracking actually starts. |
| |
| /// </summary> |
| |
| public int InitialTrackingDelay { get; set; } = 0; |
| |
| |
| |
| /// <summary> |
| |
| /// Gets or sets tracking requency in milliseconds. |
| |
| /// </summary> |
| |
| public int TrackingFrequency { get; set; } = 2000; |
| |
| |
| |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| /// <param name="game"></param> |
| /// <param name="game"></param> |
| public AutomaticPlayController(Game game) : base(game) |
| public AutomaticPlayController(Game game) : base(game) |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| /// <param name="args"></param> |
| /// <param name="args"></param> |
| public override void Play(PlayActionArgs args) |
| public override void Play(PlayActionArgs args) |
| { |
| { |
| } |
| } |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| public abstract class ControllerBase : IDisposable |
| public abstract class ControllerBase : IDisposable |
| { |
| { |
| internal SynchronizationContext execContext; |
| internal SynchronizationContext execContext; |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets or sets controller name. |
| /// Gets or sets controller name. |
| /// </summary> |
| /// </summary> |
| public string Name { get; set; } |
| public string Name { get; set; } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets or sets game attached to a specific controller operation. |
| /// Gets or sets game attached to a specific controller operation. |
| /// </summary> |
| /// </summary> |
| public Game Game { get; set; } |
| public Game Game { get; set; } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| public ControllerBase(Game game) |
| public ControllerBase(Game game) |
| { |
| { |
| execContext = SynchronizationContext.Current; |
| execContext = SynchronizationContext.Current; |
| Game = game; |
| Game = game; |
| } |
| } |
| |
| |
| /// <inheritdoc/> |
| /// <inheritdoc/> |
| public virtual void Dispose() |
| public virtual void Dispose() |
| { |
| { |
| } |
| } |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Represents installation controller. |
| /// Represents installation controller. |
| /// </summary> |
| /// </summary> |
| public abstract class InstallController : ControllerBase |
| public abstract class InstallController : ControllerBase |
| { |
| { |
| internal event EventHandler<GameInstalledEventArgs> Installed; |
| internal event EventHandler<GameInstalledEventArgs> Installed; |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Creates new instance of <see cref="InstallController"/>. |
| /// Creates new instance of <see cref="InstallController"/>. |
| /// </summary> |
| /// </summary> |
| /// <param name="game"></param> |
| /// <param name="game"></param> |
| public InstallController(Game game) : base(game) |
| public InstallController(Game game) : base(game) |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Start installation. |
| /// Start installation. |
| /// </summary> |
| /// </summary> |
| public abstract void Install(InstallActionArgs args); |
| public abstract void Install(InstallActionArgs args); |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Invoke to signal that installation completed. |
| /// Invoke to signal that installation completed. |
| /// </summary> |
| /// </summary> |
| /// <param name="args"></param> |
| /// <param name="args"></param> |
| protected void InvokeOnInstalled(GameInstalledEventArgs args) |
| protected void InvokeOnInstalled(GameInstalledEventArgs args) |
| { |
| { |
| args.Source = this; |
| args.Source = this; |
| execContext.Send((a) => Installed?.Invoke(this, args), null); |
| execContext.Send((a) => Installed?.Invoke(this, args), null); |
| } |
| } |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Represents uninstallation controller. |
| /// Represents uninstallation controller. |
| /// </summary> |
| /// </summary> |
| public abstract class UninstallController : ControllerBase |
| public abstract class UninstallController : ControllerBase |
| { |
| { |
| internal event EventHandler<GameUninstalledEventArgs> Uninstalled; |
| internal event EventHandler<GameUninstalledEventArgs> Uninstalled; |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Creates new instance of <see cref="UninstallController"/>. |
| /// Creates new instance of <see cref="UninstallController"/>. |
| /// </summary> |
| /// </summary> |
| /// <param name="game"></param> |
| /// <param name="game"></param> |
| public UninstallController(Game game) : base(game) |
| public UninstallController(Game game) : base(game) |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Start uninstallation. |
| /// Start uninstallation. |
| /// </summary> |
| /// </summary> |
| public abstract void Uninstall(UninstallActionArgs args); |
| public abstract void Uninstall(UninstallActionArgs args); |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Invoke to signal that uninstallation completed. |
| /// Invoke to signal that uninstallation completed. |
| /// </summary> |
| /// </summary> |
| /// <param name="args"></param> |
| /// <param name="args"></param> |
| protected void InvokeOnUninstalled(GameUninstalledEventArgs args) |
| protected void InvokeOnUninstalled(GameUninstalledEventArgs args) |
| { |
| { |
| args.Source = this; |
| args.Source = this; |
| execContext.Send((a) => Uninstalled?.Invoke(this, args), null); |
| execContext.Send((a) => Uninstalled?.Invoke(this, args), null); |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Invoke to signal that uninstallation completed. |
| /// Invoke to signal that uninstallation completed. |
| /// </summary> |
| /// </summary> |
| protected void InvokeOnUninstalled() |
| protected void InvokeOnUninstalled() |
| { |
| { |
| InvokeOnUninstalled(new GameUninstalledEventArgs()); |
| InvokeOnUninstalled(new GameUninstalledEventArgs()); |
| } |
| } |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Represents play controller. |
| /// Represents play controller. |
| /// </summary> |
| /// </summary> |
| public abstract class PlayController : ControllerBase |
| public abstract class PlayController : ControllerBase |
| { |
| { |
| internal event EventHandler<GameStartedEventArgs> Started; |
| internal event EventHandler<GameStartedEventArgs> Started; |
| internal event EventHandler<GameStoppedEventArgs> Stopped; |
| internal event EventHandler<GameStoppedEventArgs> Stopped; |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Creates new instance of <see cref="PlayController"/>. |
| /// Creates new instance of <see cref="PlayController"/>. |
| /// </summary> |
| /// </summary> |
| /// <param name="game"></param> |
| /// <param name="game"></param> |
| public PlayController(Game game) : base(game) |
| public PlayController(Game game) : base(game) |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Play game. |
| /// Play game. |
| /// </summary> |
| /// </summary> |
| public abstract void Play(PlayActionArgs args); |
| public abstract void Play(PlayActionArgs args); |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Invoke to signal that game started running. |
| /// Invoke to signal that game started running. |
| /// </summary> |
| /// </summary> |
| /// <param name="args"></param> |
| /// <param name="args"></param> |
| protected void InvokeOnStarted(GameStartedEventArgs args) |
| protected void InvokeOnStarted(GameStartedEventArgs args) |
| { |
| { |
| args.Source = this; |
| args.Source = this; |
| execContext.Send((a) => Started?.Invoke(this, args), null); |
| execContext.Send((a) => Started?.Invoke(this, args), null); |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Invoke to signal that game started running. |
| /// Invoke to signal that game started running. |
| /// </summary> |
| /// </summary> |
| protected void InvokeOnStarted() |
| protected void InvokeOnStarted() |
| { |
| { |
| InvokeOnStarted(new GameStartedEventArgs()); |
| InvokeOnStarted(new GameStartedEventArgs()); |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Invoke to signal that game stopped running. |
| /// Invoke to signal that game stopped running. |
| /// </summary> |
| /// </summary> |
| /// <param name="args"></param> |
| /// <param name="args"></param> |
| protected void InvokeOnStopped(GameStoppedEventArgs args) |
| protected void InvokeOnStopped(GameStoppedEventArgs args) |
| { |
| { |
| args.Source = this; |
| args.Source = this; |
| execContext.Send((a) => Stopped?.Invoke(this, args), null); |
| execContext.Send((a) => Stopped?.Invoke(this, args), null); |
| } |
| } |
| |
| |
| /// <inheritdoc/> |
| /// <inheritdoc/> |
| public override string ToString() |
| public override string ToString() |
| { |
| { |
| return Name ?? base.ToString(); |
| return Name ?? base.ToString(); |
| } |
| } |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Represents arguments for installation action. |
| /// Represents arguments for installation action. |
| /// </summary> |
| /// </summary> |
| public class InstallActionArgs |
| public class InstallActionArgs |
| { |
| { |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| public InstallActionArgs() |
| public InstallActionArgs() |
| { |
| { |
| } |
| } |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Represents arguments for uninstallation actions. |
| /// Represents arguments for uninstallation actions. |
| /// </summary> |
| /// </summary> |
| public class UninstallActionArgs |
| public class UninstallActionArgs |
| { |
| { |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| public UninstallActionArgs() |
| public UninstallActionArgs() |
| { |
| { |
| } |
| } |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Represents arguments for play action. |
| /// Represents arguments for play action. |
| /// </summary> |
| /// </summary> |
| public class PlayActionArgs |
| public class PlayActionArgs |
| { |
| { |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| public PlayActionArgs() |
| public PlayActionArgs() |
| { |
| { |
| } |
| } |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Represents arguments for game started event. |
| /// Represents arguments for game started event. |
| /// </summary> |
| /// </summary> |
| public class GameStartedEventArgs |
| public class GameStartedEventArgs |
| { |
| { |
| internal PlayController Source { get; set; } |
| internal PlayController Source { get; set; } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets or sets started process ID. |
| /// Gets or sets started process ID. |
| /// </summary> |
| /// </summary> |
| public int StartedProcessId { get; set; } |
| public int StartedProcessId { get; set; } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| public GameStartedEventArgs() |
| public GameStartedEventArgs() |
| { |
| { |
| } |
| } |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Represents arguments for game stopped event. |
| /// Represents arguments for game stopped event. |
| /// </summary> |
| /// </summary> |
| public class GameStoppedEventArgs |
| public class GameStoppedEventArgs |
| { |
| { |
| internal PlayController Source { get; set; } |
| internal PlayController Source { get; set; } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| public ulong SessionLength { get; set; } |
| public ulong SessionLength { get; set; } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| public GameStoppedEventArgs() |
| public GameStoppedEventArgs() |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| /// <param name="sessionLength"></param> |
| /// <param name="sessionLength"></param> |
| public GameStoppedEventArgs(ulong sessionLength) |
| public GameStoppedEventArgs(ulong sessionLength) |
| { |
| { |
| SessionLength = sessionLength; |
| SessionLength = sessionLength; |
| } |
| } |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Represents arguments for game uninstalled event. |
| /// Represents arguments for game uninstalled event. |
| /// </summary> |
| /// </summary> |
| public class GameUninstalledEventArgs |
| public class GameUninstalledEventArgs |
| { |
| { |
| internal UninstallController Source { get; set; } |
| internal UninstallController Source { get; set; } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| public GameUninstalledEventArgs() |
| public GameUninstalledEventArgs() |
| { |
| { |
| } |
| } |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Represents data for game installation. |
| /// Represents data for game installation. |
| /// </summary> |
| /// </summary> |
| public class GameInstallationData |
| public class GameInstallationData |
| { |
| { |
| /// <summary> |
| /// <summary> |
| /// Gets or sets installation directory. |
| /// Gets or sets installation directory. |
| /// </summary> |
| /// </summary> |
| public string InstallDirectory { get; set; } |
| public string InstallDirectory { get; set; } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets or sets Roms. |
| /// Gets or sets Roms. |
| /// </summary> |
| /// </summary> |
| public List<GameRom> Roms { get; set; } |
| public List<GameRom> Roms { get; set; } |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Represents arguments for game installed event. |
| /// Represents arguments for game installed event. |
| /// </summary> |
| /// </summary> |
| public class GameInstalledEventArgs |
| public class GameInstalledEventArgs |
| { |
| { |
| internal InstallController Source { get; set; } |
| internal InstallController Source { get; set; } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets or sets data for newly installed game. |
| /// Gets or sets data for newly installed game. |
| /// </summary> |
| /// </summary> |
| public GameInstallationData InstalledInfo { get; set; } |
| public GameInstallationData InstalledInfo { get; set; } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| public GameInstalledEventArgs() |
| public GameInstalledEventArgs() |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| /// <param name="installData"></param> |
| /// <param name="installData"></param> |
| public GameInstalledEventArgs(GameInstallationData installData) |
| public GameInstalledEventArgs(GameInstallationData installData) |
| { |
| { |
| InstalledInfo = installData; |
| InstalledInfo = installData; |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |