示例#1
0
        public bool Starter(string stdin)
        {
            Formatters format = new Formatters();
            Executor   execute = new Executor();
            string     cmd, cmdLoc;

            //Converting command to lowercase
            if (format.Break(stdin) != null)
            {
                cmd = format.Break(stdin).ToLower();
            }
            else
            {
                return(false);
            }

            if (FindInternal(cmd) && this.PRIORITIZE_BUILTIN_SHELL)
            {
                execute.exec_in(cmd, format.getArguments());
                return(true);
            }

            cmdLoc = Find(cmd);

            if (!string.IsNullOrEmpty(cmdLoc))
            {
                execute.Execute(cmdLoc, format.getArguments());
            }
            else
            {
                execute.exec_in(cmd, format.getArguments());
            }

            return(true);
        }
示例#2
0
        /// <summary>
        /// Command Execution bootstrap.
        /// </summary>
        /// <param name="stdin">Takes the user's input as parameter.</param>
        /// <param name="cmd">Holds only to command program to executes.</param>
        /// <param name="cmdLoc">Holds the program to executes path location.</param>
        /// <returns></returns>
        public bool Starter(string stdin)
        {
            Formatters format  = new Formatters();
            Executor   execute = new Executor();

            string cmd, cmdLoc;

            //Converting command to lowercase
            if (format.Break(stdin) != null)
            {
                cmd = format.Break(stdin).ToLower();
            }
            else
            {
                return(false);
            }

            //If built-in command is to be prioritize, searches if the command exists then executes it.
            if (FindInternal(cmd) && this.PRIORITIZE_BUILTIN_SHELL)
            {
                execute.exec_in(cmd, format.getArguments());
                return(true);
            }

            cmdLoc = Find(cmd); //loads the path of the command to executes.

            if (!string.IsNullOrEmpty(cmdLoc))
            {
                execute.Execute(cmdLoc, format.getArguments());
            }
            else
            {
                execute.exec_in(cmd, format.getArguments());
            }

            return(true);
        }
示例#3
0
        /// <summary>
        /// Reads the configuration file and load the parameters
        /// </summary>
        /// <param name="FoundEnvi">Flag: Used to tell the program that en environment path is found.</param>
        /// <param name="FoundKnown">Flag: Used to tell the program that a executable extension is found.</param>
        /// <param name="Working_Dir">Tmp hold the DEF_WORKING_DIR path.</param>
        /// <param name="ElevationRequested">Whether Rights Elevation was required.</param>

        public bool Read()
        {
            bool   FoundEnvi          = false;
            bool   FoundKnown_Ex      = false;
            string Working_Dir        = null;
            bool   ElevationRequested = false;

Start:
            if (File.Exists(config_path))
            {
                StreamReader ConfigReader = new StreamReader(this.config_path);
                while (!ConfigReader.EndOfStream)
                {
                    string line = ConfigReader.ReadLine().ToUpper();
                    line = format.RemoveTab(line);
                    line = format.RemoveSpace(line);

                    if (!string.IsNullOrEmpty(line))
                    {
                        if (line.StartsWith("ENVIRONMENT_PATHS {"))
                        {
                            FoundEnvi = true;
                        }
                        else if (line.StartsWith("KNOWN_EXECUTABLES {"))
                        {
                            FoundKnown_Ex = true;
                        }
                        else if (line.StartsWith("DEF_WORKING_DIR ="))
                        {
                            if (line.EndsWith(";"))
                            {
                                Working_Dir = line.Substring(line.IndexOf("=") + 1, (line.Length - (line.IndexOf("=") + 1)) - 1);

                                if (!string.IsNullOrEmpty(Working_Dir) && !string.IsNullOrWhiteSpace(Working_Dir))
                                {
                                    Working_Dir = format.Break(Working_Dir);
                                    if (Directory.Exists(Working_Dir))
                                    {
                                        this.DEF_WORKING_DIR = Working_Dir;
                                    }
                                }
                            }
                        }
                        else if (line.StartsWith("ENABLE_EVT_LOGGING:"))
                        {
                            if (line.EndsWith(";"))
                            {
                                string log = null;
                                log = line.Substring(line.IndexOf(":") + 2, (line.Length - (line.IndexOf(":") + 1)) - 2);
                                if (log == "ON")
                                {
                                    this.ENABLE_EVT_LOG = true;
                                }
                                else if (log == "OFF")
                                {
                                    this.ENABLE_EVT_LOG = false;
                                }
                            }
                        }
                        else if (line.StartsWith("ENABLE_ERR_LOGGING:"))
                        {
                            if (line.EndsWith(";"))
                            {
                                string log = null;
                                log = line.Substring(line.IndexOf(":") + 2, (line.Length - (line.IndexOf(":") + 1)) - 2);
                                if (log == "ON")
                                {
                                    this.ENABLE_ERR_LOG = true;
                                }
                                else if (log == "OFF")
                                {
                                    this.ENABLE_ERR_LOG = false;
                                }
                            }
                        }
                        else if (line.StartsWith("PRIORITIZE_BUILTIN_SHELL:"))
                        {
                            if (line.EndsWith(";"))
                            {
                                string log = null;
                                log = line.Substring(line.IndexOf(":") + 2, (line.Length - (line.IndexOf(":") + 1)) - 2);
                                if (log == "ON")
                                {
                                    this.PRIORITIZE_BUILTIN_SHELL = true;
                                }
                                else if (log == "OFF")
                                {
                                    this.PRIORITIZE_BUILTIN_SHELL = false;
                                }
                            }
                        }
                        else if (line.StartsWith("WELCOME_MESSAGE:"))
                        {
                            if (line.EndsWith(";"))
                            {
                                string log = null;
                                log = line.Substring(line.IndexOf(":") + 2, (line.Length - (line.IndexOf(":") + 1)) - 2);
                                if (log == "ON")
                                {
                                    this.DISPLAY_WELCOME_MSG = true;
                                }
                                else if (log == "OFF")
                                {
                                    this.DISPLAY_WELCOME_MSG = false;
                                }
                            }
                        }
                        else if (FoundEnvi)
                        {
                            string envipath = null;
                            if (line.EndsWith(";") && line.Length > 1)
                            {
                                envipath = line.Substring(0, line.Length - 1);
                                envipath = format.Break(envipath);

                                if (Directory.Exists(envipath))
                                {
                                    this.EnvironmentPaths.Add(envipath);
                                }
                            }
                            else if (line == "}")
                            {
                                FoundEnvi = false;
                            }
                        }
                        else if (FoundKnown_Ex)
                        {
                            string extension = null;
                            if (line.EndsWith(";") && line.Length > 1)
                            {
                                extension = line.Substring(0, line.Length - 1);
                                if (extension.StartsWith("."))
                                {
                                    this.Known_Extensions.Add(extension);
                                }
                            }
                            else if (line == "}")
                            {
                                FoundKnown_Ex = false;
                            }
                        }
                    }
                }

                ConfigReader.Close();
            }
            else
            {
                try
                {
                    Generate();
                } catch (Exception e)
                {
                    if (e.ToString().Contains("requires elevation"))
                    {
                        if (!ElevationRequested)
                        {
                            try
                            {
                                ElevationRequested = true;
                                Rashell shell = new Rashell();
                                shell.restartAsAdmin();
                            } catch (Exception x)
                            {
                            }
                        }
                        else
                        {
                            Environment.Exit(1);
                        }
                    }
                }

                goto Start;
            }
            return(true);
        }