-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActionManager.cs
More file actions
104 lines (82 loc) · 3 KB
/
ActionManager.cs
File metadata and controls
104 lines (82 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using Playnite;
using Playnite.SDK;
using Playnite.SDK.Models;
namespace GameTaskPlugin
{
public class ActionManager
{
private readonly Logger logger;
private readonly LauncherManager launcherManager;
private const string ActionName = "Play Without UAC";
public ActionManager(Logger logger, LauncherManager launcherManager)
{
this.logger = logger;
this.launcherManager = launcherManager;
}
public void CreateOrUpdatePlayAction(Game game, IPlayniteAPI api)
{
if (game.GameActions == null)
{
game.GameActions = new ObservableCollection<GameAction>();
}
string launcherPath = launcherManager.GetLauncherPath(game);
var action = game.GameActions.FirstOrDefault(a => a.Name == ActionName);
if (action == null)
{
action = new GameAction
{
Name = ActionName
};
game.GameActions.Add(action);
logger.Log($"Action created: {game.Name}");
}
else
{
logger.Log($"Action verified: {game.Name}");
}
action.Type = GameActionType.File;
action.Path = "wscript.exe";
action.Arguments = $"\"{launcherPath}\"";
action.IsPlayAction = true;
ConfigureOfficialPlayniteTracking(game, action);
api.Database.Games.Update(game);
}
public void RemovePlayAction(Game game, IPlayniteAPI api)
{
if (game.GameActions == null)
return;
var actions = game.GameActions
.Where(a => a.Name == ActionName)
.ToList();
foreach (var action in actions)
{
game.GameActions.Remove(action);
}
api.Database.Games.Update(game);
logger.Log($"Action removed: {game.Name}");
}
private void ConfigureOfficialPlayniteTracking(Game game, GameAction action)
{
string exePath = Utils.ResolveExecutablePath(game, ActionName);
if (string.IsNullOrWhiteSpace(exePath))
{
logger.Log($"Tracking not configured, EXE not found: {game.Name}");
return;
}
string processName = Path.GetFileNameWithoutExtension(exePath);
if (string.IsNullOrWhiteSpace(processName))
{
logger.Log($"Tracking not configured, invalid process: {game.Name}");
return;
}
action.TrackingMode = TrackingMode.ProcessName;
action.TrackingPath = processName;
action.InitialTrackingDelay = 3000;
action.TrackingFrequency = 2000;
logger.Log($"Official Playnite tracking configured: {game.Name} -> {processName}");
}
}
}