예제 #1
0
파일: Shell.cs 프로젝트: 0x78654C/xTerminal
        //Entry point of shell
        public void Run(string[] args)
        {
            // Start keyhook event on background for CTRL+X .
            s_backgroundWorker         = new BackgroundWorker();
            s_backgroundWorker.DoWork += KeyHook;
            s_backgroundWorker.RunWorkerAsync();


            // Check if current path subkey exists in registry.
            RegistryManagement.CheckRegKeysStart(s_listReg, GlobalVariables.regKeyName, "", false);

            // Setting up the title.
            s_terminalTitle = s_terminalTitle.Substring(0, s_terminalTitle.Length - 2);
            Console.Title   = s_terminalTitle;

            if (ExecuteParamCommands(args))
            {
                return;
            }
            ;

            // We loop until exit commands is hit
            do
            {
                //Load predifined settings.
                SettingsLoad();

                // We se the color and user loged in on console.
                SetConsoleUserConnected(s_currentDirectory, s_accountName, s_computerName, s_regUI);

                //reading user imput
                s_input = Console.ReadLine();

                //cleaning input
                s_input = s_input.Trim();


                if (File.Exists(s_historyFile))
                {
                    WriteHistoryCommandFile(s_historyFile, s_input);

                    //rebooting the machine command
                    if (s_input == "reboot")
                    {
                        SystemCmd.RebootCmd();
                    }

                    //shuting down the machine command
                    else if (s_input == "shutdown")
                    {
                        SystemCmd.ShutDownCmd();
                    }
                    //log off the machine command
                    else if (s_input == "logoff")
                    {
                        SystemCmd.LogoffCmd();
                    }
                    else if (s_input == "lock")
                    {
                        SystemCmd.LockCmd();
                    }
                    else if (s_input.StartsWith("cmd"))
                    {
                        Execute(s_input, s_input);
                    }
                    else if (s_input.StartsWith("ps"))
                    {
                        Execute(s_input, s_input);
                    }
                }

                // New command implementation by Scott.
                if (GlobalVariables.autoSuggestion)
                {
                    GlobalVariables.autoSuggestion = false;
                }
                else
                {
                    ExecuteCommands(s_input);
                }

                GC.Collect();
            } while (s_input != "exit");
        }