| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using System.ComponentModel; |
| using System.ComponentModel; |
| using System.Diagnostics; |
| using System.Diagnostics; |
| 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; |
| |
| |
| namespace Playnite.SDK.Models |
| namespace Playnite.SDK.Models |
| { |
| { |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| public enum TrackingMode : int |
| public enum TrackingMode : int |
| { |
| { |
| /// <summary> |
| /// <summary> |
| /// Default tracking mode. Playnite will try to use the best one automatically. |
| /// Default tracking mode. Playnite will try to use the best one automatically. |
| /// </summary> |
| /// </summary> |
| [Description("LOCActionTrackingModeDefault")] |
| [Description("LOCActionTrackingModeDefault")] |
| Default = 0, |
| Default = 0, |
| /// <summary> |
| /// <summary> |
| /// Origin process and all started child processes are tracked. |
| /// Origin process and all started child processes are tracked. |
| /// </summary> |
| /// </summary> |
| [Description("LOCActionTrackingModeProcess")] |
| [Description("LOCActionTrackingModeProcess")] |
| Process = 1, |
| Process = 1, |
| /// <summary> |
| /// <summary> |
| /// Any process from specified directory is tracked. |
| /// Any process from specified directory is tracked. |
| /// </summary> |
| /// </summary> |
| [Description("LOCActionTrackingModeDirectory")] |
| [Description("LOCActionTrackingModeDirectory")] |
| Directory = 2, |
| Directory = 2, |
| /// <summary> |
| /// <summary> |
| /// Only originally started process is being tracked. |
| /// Only originally started process is being tracked. |
| /// </summary> |
| /// </summary> |
| [Description("LOCActionTrackingOriginalProcess")] |
| [Description("LOCActionTrackingOriginalProcess")] |
| OriginalProcess = 3, |
| OriginalProcess = 3, |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Represents game action type. |
| /// Represents game action type. |
| /// </summary> |
| /// </summary> |
| public enum GameActionType : int |
| public enum GameActionType : int |
| { |
| { |
| /// <summary> |
| /// <summary> |
| /// Game action executes a file. |
| /// Game action executes a file. |
| /// </summary> |
| /// </summary> |
| [Description("LOCGameActionTypeFile")] |
| [Description("LOCGameActionTypeFile")] |
| File = 0, |
| File = 0, |
| /// <summary> |
| /// <summary> |
| /// Game action navigates to a web based URL. |
| /// Game action navigates to a web based URL. |
| /// </summary> |
| /// </summary> |
| [Description("LOCGameActionTypeLink")] |
| [Description("LOCGameActionTypeLink")] |
| URL = 1, |
| URL = 1, |
| /// <summary> |
| /// <summary> |
| /// Game action starts an emulator. |
| /// Game action starts an emulator. |
| /// </summary> |
| /// </summary> |
| [Description("LOCGameActionTypeEmulator")] |
| [Description("LOCGameActionTypeEmulator")] |
| Emulator = 2, |
| Emulator = 2, |
| /// <summary> |
| /// <summary> |
| /// Game action startup is handled by a script. |
| /// Game action startup is handled by a script. |
| /// </summary> |
| /// </summary> |
| [Description("LOCGameActionTypeScript")] |
| [Description("LOCGameActionTypeScript")] |
| Script = 3 |
| Script = 3 |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Represents executable game action. |
| /// Represents executable game action. |
| /// </summary> |
| /// </summary> |
| public class GameAction : ObservableObject, IEquatable<GameAction> |
| public class GameAction : ObservableObject, IEquatable<GameAction> |
| { |
| { |
| private GameActionType type; |
| private GameActionType type; |
| /// <summary> |
| /// <summary> |
| /// Gets or sets task type. |
| /// Gets or sets task type. |
| /// </summary> |
| /// </summary> |
| public GameActionType Type |
| public GameActionType Type |
| { |
| { |
| get => type; |
| get => type; |
| set |
| set |
| { |
| { |
| type = value; |
| type = value; |
| OnPropertyChanged(); |
| OnPropertyChanged(); |
| } |
| } |
| } |
| } |
| |
| |
| private string arguments; |
| private string arguments; |
| /// <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 |
| public string Arguments |
| { |
| { |
| get => arguments; |
| get => arguments; |
| set |
| set |
| { |
| { |
| arguments = value; |
| arguments = value; |
| OnPropertyChanged(); |
| OnPropertyChanged(); |
| } |
| } |
| } |
| } |
| |
| |
| private string additionalArguments; |
| private string additionalArguments; |
| /// <summary> |
| /// <summary> |
| /// Gets or sets additional executable arguments used for Emulator action type. |
| /// Gets or sets additional executable arguments used for Emulator action type. |
| /// </summary> |
| /// </summary> |
| public string AdditionalArguments |
| public string AdditionalArguments |
| { |
| { |
| get => additionalArguments; |
| get => additionalArguments; |
| set |
| set |
| { |
| { |
| additionalArguments = value; |
| additionalArguments = value; |
| OnPropertyChanged(); |
| OnPropertyChanged(); |
| } |
| } |
| } |
| } |
| |
| |
| private bool overrideDefaultArgs; |
| private bool overrideDefaultArgs; |
| /// <summary> |
| /// <summary> |
| /// Gets or sets value indicating whether emulator arguments should be completely overwritten with action arguments. |
| /// Gets or sets value indicating whether emulator arguments should be completely overwritten with action arguments. |
| /// Applies only to Emulator action type. |
| /// Applies only to Emulator action type. |
| /// </summary> |
| /// </summary> |
| public bool OverrideDefaultArgs |
| public bool OverrideDefaultArgs |
| { |
| { |
| get => overrideDefaultArgs; |
| get => overrideDefaultArgs; |
| set |
| set |
| { |
| { |
| overrideDefaultArgs = value; |
| overrideDefaultArgs = value; |
| OnPropertyChanged(); |
| OnPropertyChanged(); |
| } |
| } |
| } |
| } |
| |
| |
| private string path; |
| private string path; |
| /// <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 |
| public string Path |
| { |
| { |
| get => path; |
| get => path; |
| set |
| set |
| { |
| { |
| path = value; |
| path = value; |
| OnPropertyChanged(); |
| OnPropertyChanged(); |
| } |
| } |
| } |
| } |
| |
| |
| private string workingDir; |
| private string workingDir; |
| /// <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 |
| public string WorkingDir |
| { |
| { |
| get => workingDir; |
| get => workingDir; |
| set |
| set |
| { |
| { |
| workingDir = value; |
| workingDir = value; |
| OnPropertyChanged(); |
| OnPropertyChanged(); |
| } |
| } |
| } |
| } |
| |
| |
| private string name; |
| private string name; |
| /// <summary> |
| /// <summary> |
| /// Gets or sets action name. |
| /// Gets or sets action name. |
| /// </summary> |
| /// </summary> |
| public string Name |
| public string Name |
| { |
| { |
| get => name; |
| get => name; |
| set |
| set |
| { |
| { |
| name = value; |
| name = value; |
| OnPropertyChanged(); |
| OnPropertyChanged(); |
| } |
| } |
| } |
| } |
| |
| |
| private bool isPlayAction; |
| private bool isPlayAction; |
| /// <summary> |
| /// <summary> |
| /// Gets or sets value indicating whether an action is play action. |
| /// Gets or sets value indicating whether an action is play action. |
| /// </summary> |
| /// </summary> |
| public bool IsPlayAction |
| public bool IsPlayAction |
| { |
| { |
| get => isPlayAction; |
| get => isPlayAction; |
| set |
| set |
| { |
| { |
| isPlayAction = value; |
| isPlayAction = value; |
| OnPropertyChanged(); |
| OnPropertyChanged(); |
| } |
| } |
| } |
| } |
| |
| |
| private Guid emulatorId; |
| private Guid emulatorId; |
| /// <summary> |
| /// <summary> |
| /// Gets or sets emulator id for Emulator action type execution. |
| /// Gets or sets emulator id for Emulator action type execution. |
| /// </summary> |
| /// </summary> |
| public Guid EmulatorId |
| public Guid EmulatorId |
| { |
| { |
| get => emulatorId; |
| get => emulatorId; |
| set |
| set |
| { |
| { |
| emulatorId = value; |
| emulatorId = value; |
| OnPropertyChanged(); |
| OnPropertyChanged(); |
| } |
| } |
| } |
| } |
| |
| |
| private string emulatorProfileId; |
| private string emulatorProfileId; |
| /// <summary> |
| /// <summary> |
| /// Gets or sets emulator profile id for Emulator action type execution. |
| /// Gets or sets emulator profile id for Emulator action type execution. |
| /// </summary> |
| /// </summary> |
| public string EmulatorProfileId |
| public string EmulatorProfileId |
| { |
| { |
| get => emulatorProfileId; |
| get => emulatorProfileId; |
| set |
| set |
| { |
| { |
| emulatorProfileId = value; |
| emulatorProfileId = value; |
| OnPropertyChanged(); |
| OnPropertyChanged(); |
| } |
| } |
| } |
| } |
| |
| |
| private TrackingMode trackingMode = TrackingMode.Default; |
| private TrackingMode trackingMode = TrackingMode.Default; |
| /// <summary> |
| /// <summary> |
| /// Gets or sets executable arguments for File type tasks. |
| /// Gets or sets executable arguments for File type tasks. |
| /// </summary> |
| /// </summary> |
| public TrackingMode TrackingMode |
| public TrackingMode TrackingMode |
| { |
| { |
| get => trackingMode; |
| get => trackingMode; |
| set |
| set |
| { |
| { |
| trackingMode = value; |
| trackingMode = value; |
| OnPropertyChanged(); |
| OnPropertyChanged(); |
| } |
| } |
| } |
| } |
| |
| |
| private string trackingPath; |
| private string trackingPath; |
| /// <summary> |
| /// <summary> |
| /// Gets or sets executable arguments for File type tasks. |
| /// Gets or sets executable arguments for File type tasks. |
| /// </summary> |
| /// </summary> |
| public string TrackingPath |
| public string TrackingPath |
| { |
| { |
| get => trackingPath; |
| get => trackingPath; |
| set |
| set |
| { |
| { |
| trackingPath = value; |
| trackingPath = value; |
| OnPropertyChanged(); |
| OnPropertyChanged(); |
| } |
| } |
| } |
| } |
| |
| |
| private string script; |
| private string script; |
| /// <summary> |
| /// <summary> |
| /// Gets or sets startup script. |
| /// Gets or sets startup script. |
| /// </summary> |
| /// </summary> |
| public string Script |
| public string Script |
| { |
| { |
| get => script; |
| get => script; |
| set |
| set |
| { |
| { |
| script = value; |
| script = value; |
| OnPropertyChanged(); |
| OnPropertyChanged(); |
| } |
| } |
| } |
| } |
| |
| |
. | |
| private int initialTrackingDelay = 0; |
| |
| /// <summary> |
| |
| /// Gets or sets delay in milliseconds before tracking actually starts. |
| |
| /// </summary> |
| |
| public int InitialTrackingDelay |
| |
| { |
| |
| get => initialTrackingDelay; |
| |
| set |
| |
| { |
| |
| initialTrackingDelay = value; |
| |
| OnPropertyChanged(); |
| |
| } |
| |
| } |
| |
| |
| |
| private int trackingFrequency = 2000; |
| |
| /// <summary> |
| |
| /// Gets or sets delay in milliseconds before tracking actually starts. |
| |
| /// </summary> |
| |
| public int TrackingFrequency |
| |
| { |
| |
| get => trackingFrequency; |
| |
| set |
| |
| { |
| |
| trackingFrequency = value; |
| |
| OnPropertyChanged(); |
| |
| } |
| |
| } |
| |
| |
| /// <inheritdoc/> |
| /// <inheritdoc/> |
| public override string ToString() |
| public override string ToString() |
| { |
| { |
| switch (Type) |
| switch (Type) |
| { |
| { |
| case GameActionType.File: |
| case GameActionType.File: |
| return $"File: {Path}, {Arguments}, {WorkingDir}"; |
| return $"File: {Path}, {Arguments}, {WorkingDir}"; |
| case GameActionType.URL: |
| case GameActionType.URL: |
| return $"Url: {Path}"; |
| return $"Url: {Path}"; |
| case GameActionType.Emulator: |
| case GameActionType.Emulator: |
| return $"Emulator: {EmulatorId}, {EmulatorProfileId}, {OverrideDefaultArgs}, {AdditionalArguments}"; |
| return $"Emulator: {EmulatorId}, {EmulatorProfileId}, {OverrideDefaultArgs}, {AdditionalArguments}"; |
| case GameActionType.Script: |
| case GameActionType.Script: |
| return "Script"; |
| return "Script"; |
| default: |
| default: |
| return Path; |
| return Path; |
| } |
| } |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Compares two <see cref="GameAction"/> objects for equality. |
| /// Compares two <see cref="GameAction"/> objects for equality. |
| /// </summary> |
| /// </summary> |
| /// <param name="obj1"></param> |
| /// <param name="obj1"></param> |
| /// <param name="obj2"></param> |
| /// <param name="obj2"></param> |
| /// <returns></returns> |
| /// <returns></returns> |
| public static bool Equals(GameAction obj1, GameAction obj2) |
| public static bool Equals(GameAction obj1, GameAction obj2) |
| { |
| { |
| if (obj1 == null && obj2 == null) |
| if (obj1 == null && obj2 == null) |
| { |
| { |
| return true; |
| return true; |
| } |
| } |
| else |
| else |
| { |
| { |
| return obj1?.Equals(obj2) == true; |
| return obj1?.Equals(obj2) == true; |
| } |
| } |
| } |
| } |
| |
| |
| /// <inheritdoc/> |
| /// <inheritdoc/> |
| public bool Equals(GameAction other) |
| public bool Equals(GameAction other) |
| { |
| { |
| if (other is null) |
| if (other is null) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| if (Type != other.Type) |
| if (Type != other.Type) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| if (!string.Equals(Arguments, other.Arguments, StringComparison.Ordinal)) |
| if (!string.Equals(Arguments, other.Arguments, StringComparison.Ordinal)) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| if (!string.Equals(AdditionalArguments, other.AdditionalArguments, StringComparison.Ordinal)) |
| if (!string.Equals(AdditionalArguments, other.AdditionalArguments, StringComparison.Ordinal)) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| if (!string.Equals(Path, other.Path, StringComparison.Ordinal)) |
| if (!string.Equals(Path, other.Path, StringComparison.Ordinal)) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| if (!string.Equals(WorkingDir, other.WorkingDir, StringComparison.Ordinal)) |
| if (!string.Equals(WorkingDir, other.WorkingDir, StringComparison.Ordinal)) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| if (!string.Equals(Name, other.Name, StringComparison.Ordinal)) |
| if (!string.Equals(Name, other.Name, StringComparison.Ordinal)) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| if (IsPlayAction != other.IsPlayAction) |
| if (IsPlayAction != other.IsPlayAction) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| if (EmulatorId != other.EmulatorId) |
| if (EmulatorId != other.EmulatorId) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| if (!string.Equals(EmulatorProfileId, other.EmulatorProfileId, StringComparison.Ordinal)) |
| if (!string.Equals(EmulatorProfileId, other.EmulatorProfileId, StringComparison.Ordinal)) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| if (OverrideDefaultArgs != other.OverrideDefaultArgs) |
| if (OverrideDefaultArgs != other.OverrideDefaultArgs) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| if (!string.Equals(TrackingPath, other.TrackingPath, StringComparison.Ordinal)) |
| if (!string.Equals(TrackingPath, other.TrackingPath, StringComparison.Ordinal)) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| if (TrackingMode != other.TrackingMode) |
| if (TrackingMode != other.TrackingMode) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| if (!string.Equals(Script, other.Script, StringComparison.Ordinal)) |
| if (!string.Equals(Script, other.Script, StringComparison.Ordinal)) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
. | |
| if (InitialTrackingDelay != other.InitialTrackingDelay) |
| |
| { |
| |
| return false; |
| |
| } |
| |
| |
| |
| if (TrackingFrequency != other.TrackingFrequency) |
| |
| { |
| |
| return false; |
| |
| } |
| |
| |
| return true; |
| return true; |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// |
| /// |
| /// </summary> |
| /// </summary> |
| /// <returns></returns> |
| /// <returns></returns> |
| public GameAction GetCopy() |
| public GameAction GetCopy() |
| { |
| { |
| return new GameAction |
| return new GameAction |
| { |
| { |
| AdditionalArguments = AdditionalArguments, |
| AdditionalArguments = AdditionalArguments, |
| Arguments = Arguments, |
| Arguments = Arguments, |
| EmulatorId = EmulatorId, |
| EmulatorId = EmulatorId, |
| EmulatorProfileId = EmulatorProfileId, |
| EmulatorProfileId = EmulatorProfileId, |
| IsPlayAction = IsPlayAction, |
| IsPlayAction = IsPlayAction, |
| Name = Name, |
| Name = Name, |
| OverrideDefaultArgs = OverrideDefaultArgs, |
| OverrideDefaultArgs = OverrideDefaultArgs, |
| Path = Path, |
| Path = Path, |
| Script = Script, |
| Script = Script, |
| TrackingMode = TrackingMode, |
| TrackingMode = TrackingMode, |
| TrackingPath = TrackingPath, |
| TrackingPath = TrackingPath, |
| Type = Type, |
| Type = Type, |
. | WorkingDir = WorkingDir |
| WorkingDir = WorkingDir, |
| |
| InitialTrackingDelay = InitialTrackingDelay, |
| |
| TrackingFrequency = TrackingFrequency |
| }; |
| }; |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |