-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainForm.cs
157 lines (135 loc) · 4.92 KB
/
MainForm.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
namespace QuickLaunch;
public partial class MainForm : Form
{
private readonly QuickLaunch quickLaunch;
public MainForm()
{
InitializeComponent();
quickLaunch = new QuickLaunch();
foreach (var account in quickLaunch.Accounts)
AddAccount(account);
if (quickLaunch.GameExecutable != null)
textBox1.Text = quickLaunch.GameExecutable;
}
private void AddAccount(Account account)
{
var li = new ListViewItem(account.Email);
li.SubItems.Add(account.CookieExpiration.ToString());
li.SubItems.Add("");
li.Tag = account;
listView1.Items.Add(li);
}
private void button1_Click(object sender, EventArgs e)
{
foreach (ListViewItem li in listView1.SelectedItems)
{
quickLaunch.RemoveAccount((Account)li.Tag);
listView1.Items.Remove(li);
}
}
private void button2_Click_1(object sender, EventArgs e)
{
string email = "";
if (InputBox("Add Account", "Email:", ref email) != DialogResult.OK)
return;
var acc = new Account(email);
quickLaunch.AddAccount(acc);
AddAccount(acc);
}
private void button3_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
quickLaunch.GameExecutable = openFileDialog1.FileName;
quickLaunch.Save();
}
}
private async void listView1_DoubleClick(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count == 0)
return;
if (quickLaunch.GameExecutable == null)
{
MessageBox.Show("Please set the game path.");
return;
}
var li = listView1.SelectedItems[0];
li.SubItems[2].Text = "Launching...";
var account = (Account)li.Tag;
try
{
if (!await quickLaunch.Launch(account))
{
var loginView = new LoginView();
loginView.LoginEmail = account.Email;
loginView.ShowDialog(this);
if (loginView.NxLCookie != null)
{
account.Cookie = loginView.NxLCookie.Value;
account.CookieExpiration = loginView.NxLCookie.Expires;
quickLaunch.Save();
li.SubItems[1].Text = account.CookieExpiration.ToString();
if (!await quickLaunch.Launch(account))
{
li.SubItems[2].Text = "Failed";
MessageBox.Show("Launch attempt failed");
}
else
{
li.SubItems[2].Text = "Launched";
}
}
loginView.Dispose();
}
else
{
li.SubItems[2].Text = "Launched";
}
}
catch (Exception ex)
{
li.SubItems[2].Text = $"Error: {ex.Message}";
}
}
private void listView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
listView1_DoubleClick(sender, e);
}
public DialogResult InputBox(string title, string promptText, ref string value)
{
Form form = new Form();
Label label = new Label();
TextBox textBox = new TextBox();
Button buttonOk = new Button();
Button buttonCancel = new Button();
form.Text = title;
label.Text = promptText;
textBox.Text = value;
buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;
label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
buttonOk.SetBounds(228, 72, 75, 23);
buttonCancel.SetBounds(309, 72, 75, 23);
label.AutoSize = true;
textBox.Anchor |= AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
form.ClientSize = new Size(396, 107);
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterParent;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;
DialogResult dialogResult = form.ShowDialog(this);
value = textBox.Text;
return dialogResult;
}
}