Beispiel #1
0
        protected override void BeforeRun()
        {
            Sys.FileSystem.VFS.VFSManager.RegisterVFS(fs);
            Console.Clear();

            //Filesystem.SetToBegin();

            //Check for settings
            if (File.Exists(Variables.settingsFile) == false)
            {
                //Create Settings File
                File.Create(Variables.settingsFile);
                File.WriteAllText(Variables.settingsFile, "first_start=true");
            }

            //Check if the Filesystem includes everything
            if (Filesystem.CheckFileSystem() == false)
            {
                if (File.Exists(Variables.settingsFile) == true)
                {
                    string[] sLines = File.ReadAllLines(Variables.settingsFile);
                    if (sLines[0].ToString() == "first_start=true")
                    {
                        //First OS start, let's create our Filesystem
                        Console.WriteLine("Creating Filesystem, this could take a moment....");
                        Filesystem.CreateFileSystem();
                    }
                    else
                    {
                        Console.WriteLine("Error while checking the Filesystem!");
                        Sys.Global.mFileSystemDebugger.Break();
                    }
                }
            }

            //Loading Filesystem was successfully
            Console.WriteLine("Successfully loaded important files!");

            //User Login
            bool foundUserName = false;
            bool foundPassword = false;

            string userName     = "";
            string userPassword = "";

            try
            {
                while (foundUserName == false)
                {
                    Console.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine + "Username: "******"")
                    {
                        string[] userLines = File.ReadAllLines(Variables.usersFile);
                        for (int i = 0; i < userLines.Length && foundUserName == false; i++)
                        {
                            if (userLines[i].Split('=')[0].ToString() == userName)
                            {
                                foundUserName = true;
                            }
                        }
                    }
                    if (foundUserName == false)
                    {
                        Console.WriteLine("This user does not exists!");
                    }
                }

                while (foundPassword == false)
                {
                    Console.Write("Password: "******"")
                    {
                        string[] userLines = File.ReadAllLines(Variables.usersFile);
                        for (int i = 0; i < userLines.Length && foundPassword == false; i++)
                        {
                            if (userLines[i].Split('=')[1].ToString() == userPassword)
                            {
                                foundPassword = true;
                            }
                        }
                    }
                    if (foundPassword == false)
                    {
                        Console.WriteLine("Wrong password for user: "******"";
                string[] groupsLines = File.ReadAllLines(Variables.groupsFile);
                for (int i = 0; i < groupsLines.Length; i++)
                {
                    if (groupsLines[i].ToString().Contains(userName))
                    {
                        userGroup = groupsLines[i].ToString().Split(':')[0];
                        userPower = Int32.Parse(groupsLines[i].ToString().Split(':')[1].Split('=')[0]);
                    }
                }

                //Create new User Class
                User newUser = new User();
                newUser.InitilizeUser(userName, userPower, userGroup);
                Variables.curUser = newUser;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message.ToString());
            }

            Console.WriteLine("Successfully logged in!");
        }