summaryrefslogblamecommitdiff
path: root/Source/Applications/PaperWork/PaperWork.cpp
blob: 4f9cb0e987bac72134564e782773325386131cbd (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                               
 

                                                     

                                   




                                                                                                   





                      
                            
                                          






                                                                                       
                                                     









                                                 
                                              
                                               
                                              




                                                                       
                                                                                  
                                                    
                                                          
                                                     












                                                  
#include <App/ShellApp.proto.h>

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

class PaperWork : public ShellApp {
	public:
	PaperWork() : ShellApp("PaperWork.app", "Melon's init/login manager") {
		addFlag("s", "shell", "Define the default shell to launch", FT_STR, DEFAULT_SHELL);
		addFlag("l", "login", "Act as a login manager");
		addFlag("i", "init", "Act as a init manager", FT_BOOL, "on");
	}
	int run();
};

APP(PaperWork);

int PaperWork::run() {
	String act = "init";
	if (bFlag("login")) act = "login";

	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 [" << sFlag("shell") << "]? ";
			String sh = invt.readLine();
			if (sh == "") sh = sFlag("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;
		}
	}
}