-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLauncherManager.cs
More file actions
54 lines (43 loc) · 1.5 KB
/
LauncherManager.cs
File metadata and controls
54 lines (43 loc) · 1.5 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
using System.IO;
using System.Text;
using Playnite.SDK.Models;
namespace GameTaskPlugin
{
public class LauncherManager
{
private readonly Logger logger;
private readonly string launchersFolder;
public LauncherManager(Logger logger, string pluginDataPath)
{
this.logger = logger;
launchersFolder = Path.Combine(pluginDataPath, "Launchers");
Directory.CreateDirectory(launchersFolder);
}
public string GetLauncherPath(Game game)
{
string safeName = Utils.MakeSafeFileName(game.Name);
return Path.Combine(launchersFolder, $"{safeName}.vbs");
}
public void CreateOrUpdateLauncher(Game game)
{
string launcherPath = GetLauncherPath(game);
string taskSafeName = Utils.MakeSafeTaskName(game.Name);
string taskName = $"GameTask_v1_{taskSafeName}";
string content =
$@"Set shell = CreateObject(""WScript.Shell"")
shell.Run ""schtasks /run /tn """"\GameTask\{taskName}"""" "", 0, False
";
File.WriteAllText(launcherPath, content, Encoding.ASCII);
logger.Log($"Launcher verified: {game.Name}");
}
public void RemoveLauncher(Game game)
{
string launcherPath = GetLauncherPath(game);
if (File.Exists(launcherPath))
{
File.Delete(launcherPath);
logger.Log($"Launcher removed: {game.Name}");
}
}
}
}