forked from Flawkee/FlyffUniverse-WebClient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArgumentManager.cs
105 lines (98 loc) · 3.63 KB
/
ArgumentManager.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
using System;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Drawing;
namespace FlyffUniverse_WebClient
{
public sealed class ArgumentManager
{
private static ArgumentManager _instance;
public static string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
public static string profilePath = appData + @"\FlyffUniverse\DefaultProfile";
private string[] userArgs;
FlyffWCForm mainForm = FlyffWCForm.Instance;
// conditions
bool profileCheck = false;
bool resCheck = false;
bool fsCheck = false;
bool pixelCheck = false;
bool disCheck = false;
private ArgumentManager()
{
}
public static ArgumentManager Instance { get { if (_instance == null) { _instance = new ArgumentManager(); } return _instance; } }
public void InitializeArguments()
{
userArgs = Environment.GetCommandLineArgs();
foreach (string arg in userArgs)
{
if (!profileCheck) { ProfileArg(arg); }
if (!resCheck) { ResolutionArg(arg); }
if (!fsCheck) { FullscreenArg(arg); }
if (!pixelCheck) { PixelLocationArg(arg); }
if (!disCheck) { DisplaySelectionArg(arg); }
}
}
private void ProfileArg(string arg)
{
string rg = @"/ProfileName=(.+)";
GroupCollection gc = regexCheck(arg, rg);
if (gc != null) { profilePath = appData + @"\FlyffUniverse\" + gc[1].Value; profileCheck = true; }
}
private void ResolutionArg(string arg)
{
string rg = @"/Resolution=([0-9]{1,4})x([0-9]{1,4})";
GroupCollection gc = regexCheck(arg, rg);
if (gc != null) {
int width, height;
Int32.TryParse(gc[1].Value, out width);
Int32.TryParse(gc[2].Value, out height);
mainForm.Size = new Size(width, height);
resCheck = true;
}
}
private void FullscreenArg(string arg)
{
string rg = @"(/Fullscreen)";
GroupCollection gc = regexCheck(arg, rg);
if (gc != null)
{
mainForm.WindowState = FormWindowState.Maximized;
mainForm.FormBorderStyle = FormBorderStyle.None;
fsCheck = true;
}
}
private void PixelLocationArg(string arg)
{
string rg = @"/PixelLocation=(.+)\,(.+)";
GroupCollection gc = regexCheck(arg, rg);
if (gc != null)
{
int x = 0, y = 0;
Int32.TryParse(gc[1].Value, out x);
Int32.TryParse(gc[2].Value, out y);
mainForm.Location = new Point(x, y);
pixelCheck = true;
}
}
private void DisplaySelectionArg(string arg)
{
string rg = @"/DisplayID=([0-9])";
GroupCollection gc = regexCheck(arg, rg);
if (gc != null)
{
int id;
Int32.TryParse(gc[1].Value, out id);
if (Screen.AllScreens.Length >= id) { mainForm.Location = Screen.AllScreens[id - 1].WorkingArea.Location; }
disCheck = true;
}
}
private GroupCollection regexCheck(string arg ,string rg)
{
Regex r = new Regex(rg, RegexOptions.IgnoreCase);
Match m = r.Match(arg);
if (m.Success) { return m.Groups; }
else { return null; }
}
}
}