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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
/*
* MIT License
*
* Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
using ShiftOS.Engine;
namespace ShiftOS.WinForms
{
public partial class FakeSetupScreen : Form
{
private Oobe oobe = null;
public Action<bool> MUDUserFound = null;
public FakeSetupScreen(Oobe _oobe, int page = 0)
{
oobe = _oobe;
InitializeComponent();
currentPage = page;
SetupUI();
ServerManager.MessageReceived += (msg) =>
{
if (this.Visible == true)
{
if (msg.Name == "mud_notfound")
this.Invoke(new Action(() => { MUDUserFound?.Invoke(false); }));
else if (msg.Name == "mud_found")
this.Invoke(new Action(() => { MUDUserFound?.Invoke(true); }));
}
};
}
public event Action<string> TextSent;
bool isTyping = false;
private int currentPage = 0;
public void SetupUI()
{
btnback.Show();
pnlheader.Dock = DockStyle.Top;
pnlheader.Height = 50;
switch (currentPage)
{
case 0:
page1.BringToFront();
pnlheader.Dock = DockStyle.Left;
pnlheader.Width = 100;
btnback.Hide();
break;
case 1:
btnnext.Hide();
btnback.Hide();
page2.BringToFront();
pgformatprogress.Value = 0;
var dinf = new System.IO.DriveInfo("C:");
StartWipingInBackground(((dinf.TotalSize / 1024) / 1024) / 1024);
TextType($@"So I see you're progressing through.
I really hope you aren't one of those newbies who just next-next-next-finish their way through these things.
I see you've named your drive " + dinf.VolumeLabel + $@"
And it can contain up to {dinf.TotalSize} bytes of information.
And you've formatted this drive with a partition of type " + dinf.DriveFormat + $@".
Interesting...
Very interesting...");
break;
case 2:
btnnext.Show();
btnback.Hide();
TextType(@"Now it's all gone. Now I need some user input so I can install ShiftOS.
Firstly, please enter a username, password, and system name.
Make the username and system name unique so I can identify exactly who you are. You're not the only one here.
Also, make sure the password is secure... There have been people known to breach users' accounts in ShiftOS and steal their stuff.
So make sure your password is secure enough that it can't be guessed, but easy for you to remember, and don't put any personal information in your account.");
page3.BringToFront();
break;
case 3:
if (string.IsNullOrEmpty(txtnewusername.Text))
{
TextType("You must specify a valid username!");
currentPage--;
//SetupUI();
break;
}
if (string.IsNullOrEmpty(txtnewpassword.Text))
{
TextType("A password would seriously be recommended.");
currentPage--;
//SetupUI();
break;
}
if (string.IsNullOrEmpty(txtnewsysname.Text))
{
TextType("You must name your computer.");
currentPage--;
//SetupUI();
break;
}
MUDUserFound = (val) =>
{
if(val == true)
{
TextType("I have just verified that your username and password already exists on my end. Please choose another.");
currentPage--;
//SetupUI();
}
else
{
TextType("I am going to keep that info on my checklist for installing ShiftOS on your system. Now, onto some legal stuff. I highly suggest you read this.");
currentPage++;
oobe.MySave.Username = txtnewusername.Text;
oobe.MySave.Password = txtnewpassword.Text;
oobe.MySave.SystemName = txtnewsysname.Text;
SetupUI();
}
};
ServerManager.SendMessage("mud_checkuserexists", $@"{{
username: ""{txtnewusername.Text}"",
password: ""{txtnewpassword.Text}""
}}");
break;
case 4:
page4.BringToFront();
txtlicenseagreement.Rtf = Properties.Resources.ShiftOS;
break;
case 5:
CanClose = true;
this.Close();
break;
case 7:
btnnext.Show();
btnback.Hide();
pgrereg.BringToFront();
TextType("You have two choices - either you can migrate your local user file to this multi-user domain, or you can restart with 0 Codepoints, no upgrades, and still keep your files.");
break;
case 8:
btnnext.Hide();
ServerMessageReceived rc = null;
rc = (msg) =>
{
if(msg.Name == "mud_found")
{
TextType("That username and password already exists in this multi-user domain. Please choose another.");
currentPage = 7;
}
else if(msg.Name == "mud_notfound")
{
currentPage = 9;
SetupUI();
}
ServerManager.MessageReceived -= rc;
};
if (string.IsNullOrEmpty(txtruname.Text))
{
TextType("You must provide a username.");
currentPage = 7;
}
if (string.IsNullOrEmpty(txtrpass.Text))
{
TextType("You must provide a password.");
currentPage = 7;
}
if (string.IsNullOrEmpty(txtrsys.Text))
{
TextType("You must provide a system hostname.");
currentPage = 7;
}
if (currentPage == 7)
return;
ServerManager.MessageReceived += rc;
ServerManager.SendMessage("mud_checkuserexists", $@"{{
username: ""{txtruname.Text}"",
password: ""{txtrpass.Text}""
}}");
break;
case 9:
UserReregistered?.Invoke(txtruname.Text, txtrpass.Text, txtrsys.Text);
this.CanClose = true;
this.Close();
break;
case 10:
btnnext.Show();
btnback.Hide();
pglogin.BringToFront();
break;
case 11:
btnnext.Hide();
ServerMessageReceived login = null;
login = (msg) =>
{
if (msg.Name == "mud_found")
{
this.Invoke(new Action(() =>
{
currentPage = 12;
SetupUI();
}));
ServerManager.MessageReceived -= login;
}
else if (msg.Name == "mud_notfound")
{
this.Invoke(new Action(() =>
{
currentPage = 10;
SetupUI();
}));
ServerManager.MessageReceived -= login;
}
};
ServerManager.MessageReceived += login;
if(!string.IsNullOrWhiteSpace(txtluser.Text) && !string.IsNullOrWhiteSpace(txtlpass.Text))
{
ServerManager.SendMessage("mud_checkuserexists", JsonConvert.SerializeObject(new
{
username = txtluser.Text,
password = txtlpass.Text
}));
}
break;
case 12:
btnnext.Hide();
ServerMessageReceived getsave = null;
getsave = (msg) =>
{
if (msg.Name == "mud_savefile")
{
this.Invoke(new Action(() =>
{
SaveSystem.CurrentSave = JsonConvert.DeserializeObject<ShiftOS.Objects.Save>(msg.Contents);
SaveSystem.SaveGame();
CreateNewSave = false;
DoneLoggingIn?.Invoke();
this.CanClose = true;
this.Close();
}));
}
else if (msg.Name == "mud_notfound")
{
this.Invoke(new Action(() =>
{
currentPage = 10;
SetupUI();
}));
}
ServerManager.MessageReceived -= getsave;
};
ServerManager.MessageReceived += getsave;
ServerManager.SendMessage("mud_login", JsonConvert.SerializeObject(new
{
username = txtluser.Text,
password = txtlpass.Text
}));
break;
}
}
public event Action DoneLoggingIn;
public bool CreateNewSave = true;
public event Action<string, string, string> UserReregistered;
public void StartWipingInBackground(long arbitraryAmountOfBytes)
{
pgformatprogress.Maximum = (int)arbitraryAmountOfBytes;
var t = new Thread(() =>
{
for(long i = 0; i <= arbitraryAmountOfBytes; i++)
{
Thread.Sleep(40);
this.Invoke(new Action(() =>
{
pgformatprogress.Value = (int)i;
lbbyteszeroed.Text = $"Gigabytes zeroed: {i}/{arbitraryAmountOfBytes}";
}));
}
this.Invoke(new Action(() =>
{
currentPage++;
SetupUI();
}));
});
t.IsBackground = true;
t.Start();
}
private void TextType(string text)
{
new Thread(() =>
{
while(isTyping == true)
{
}
isTyping = true;
TextSent?.Invoke(text);
isTyping = false;
}).Start();
}
bool CanClose = false;
private void FakeSetupScreen_FormClosing(object sender, FormClosingEventArgs e)
{
if (CanClose)
{
}
else
{
e.Cancel = true;
TextType("Don't try to close the dialog. It's a futile attempt.");
}
}
private void btnback_Click(object sender, EventArgs e)
{
currentPage--;
SetupUI();
}
private void btnnext_Click(object sender, EventArgs e)
{
currentPage++;
SetupUI();
}
private void button1_Click(object sender, EventArgs e)
{
ShiftOS.Objects.ShiftFS.Utils.Delete(Paths.GetPath("user.dat"));
System.IO.File.WriteAllText(Paths.SaveFile, ShiftOS.Objects.ShiftFS.Utils.ExportMount(0));
SaveSystem.NewSave();
this.CanClose = true;
this.Close();
}
private void btnnlogin_Click(object sender, EventArgs e)
{
currentPage = 10;
SetupUI();
}
}
}
|