forked from bloxstraplabs/bloxstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLaunchSettings.cs
131 lines (98 loc) · 3.82 KB
/
LaunchSettings.cs
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using Bloxstrap.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Windows;
namespace Bloxstrap
{
public class LaunchSettings
{
public LaunchFlag MenuFlag { get; } = new("preferences,menu,settings");
public LaunchFlag WatcherFlag { get; } = new("watcher");
public LaunchFlag QuietFlag { get; } = new("quiet");
public LaunchFlag UninstallFlag { get; } = new("uninstall");
public LaunchFlag NoLaunchFlag { get; } = new("nolaunch");
public LaunchFlag TestModeFlag { get; } = new("testmode");
public LaunchFlag NoGPUFlag { get; } = new("nogpu");
public LaunchFlag UpgradeFlag { get; } = new("upgrade");
public LaunchFlag PlayerFlag { get; } = new("player");
public LaunchFlag StudioFlag { get; } = new("studio");
#if DEBUG
public bool BypassUpdateCheck => true;
#else
public bool BypassUpdateCheck => UninstallFlag.Active || WatcherFlag.Active;
#endif
public LaunchMode RobloxLaunchMode { get; set; } = LaunchMode.None;
public string RobloxLaunchArgs { get; set; } = "";
/// <summary>
/// Original launch arguments
/// </summary>
public string[] Args { get; private set; }
private readonly Dictionary<string, LaunchFlag> _flagMap = new();
public LaunchSettings(string[] args)
{
const string LOG_IDENT = "LaunchSettings";
Args = args;
// build flag map
foreach (var prop in this.GetType().GetProperties())
{
if (prop.PropertyType != typeof(LaunchFlag))
continue;
if (prop.GetValue(this) is not LaunchFlag flag)
continue;
foreach (string identifier in flag.Identifiers.Split(','))
_flagMap.Add(identifier, flag);
}
// infer roblox launch uris
if (Args.Length >= 1)
{
string arg = Args[0];
if (arg.StartsWith("roblox:", StringComparison.OrdinalIgnoreCase)
|| arg.StartsWith("roblox-player:", StringComparison.OrdinalIgnoreCase))
{
RobloxLaunchMode = LaunchMode.Player;
RobloxLaunchArgs = arg;
}
}
// parse
for (int i = 0; i < Args.Length; i++)
{
string arg = Args[i];
if (!arg.StartsWith('-'))
continue;
string identifier = arg[1..];
if (!_flagMap.TryGetValue(identifier, out LaunchFlag? flag) || flag is null)
continue;
flag.Active = true;
if (i < Args.Length - 1 && Args[i+1] is string nextArg && !nextArg.StartsWith('-'))
{
flag.Data = nextArg;
App.Logger.WriteLine(LOG_IDENT, $"Identifier '{identifier}' is active with data");
}
else
{
App.Logger.WriteLine(LOG_IDENT, $"Identifier '{identifier}' is active");
}
}
if (PlayerFlag.Active)
ParsePlayer(PlayerFlag.Data);
else if (StudioFlag.Active)
ParseStudio(StudioFlag.Data);
}
private void ParsePlayer(string? data)
{
RobloxLaunchMode = LaunchMode.Player;
if (!String.IsNullOrEmpty(data))
RobloxLaunchArgs = data;
}
private void ParseStudio(string? data)
{
RobloxLaunchMode = LaunchMode.Studio;
// TODO: do this later
}
}
}