summaryrefslogtreecommitdiff
path: root/Source/Applications/PaperWork/main.cpp
blob: 2fb40df842af1822e6b6dcb882e83ba5b7995a7e (plain) (blame)
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
#include <Binding/Process.class.h>
#include <String.class.h>

#define DEFAULT_SHELL "/Applications/Shell/Shell.app"

int main(Vector<String> args) {
	String act = "init";
	if (args.size() == 2) {
		if (args[1] == "login") {
			act = "login";
		} else if (args[1] == "init") {
			act = "init";
		}
	}

	if (act == "init") {
		while (1) {
			Process p = Process::run("/System/Applications/PaperWork.app");
			if (p.valid()) {
				p.setInVT(invt);
				p.setOutVT(outvt);
				p.pushArg("login");
				p.start();
				p.wait();	
			} else {
				return 1;
			}
		}
	} else if (act == "login") {
		outvt << "Logging in to Melon\n";
		String user, pw;
		while (1) {
			outvt << "Username: ";
			user = invt.readLine();
			outvt << "Password: ";
			pw = invt.readLine(false);
			if (!Process::get().authenticatePW(user, pw)) {
				outvt << "Authentication failed.\n\n";
				continue;
			}
			outvt << "What shell to run [" << DEFAULT_SHELL << "]? ";
			String sh = invt.readLine();
			if (sh == "") sh = DEFAULT_SHELL;
			Process p = Process::run(sh);
			if (p.valid()) {
				p.setInVT(invt);
				p.setOutVT(outvt);
				p.start();
				p.wait();	
				outvt << "\n\n";
			} else {
				return 1;
			}
			return 0;
		}
	}
}