Esempio n. 1
0
            /// <summary>
            ///     Add a new known process.
            /// </summary>
            /// <remarks>If the process already exists it is overwritten.</remarks>
            /// <param name="name">The name of the new process</param>
            /// <param name="process">Information about the process</param>
            protected void newProcess(string name, ProcessData process)
            {
                log.Info("Added new process: " + name);
                log.Debug("\t-Executable path: " + process.ExePath);
                log.Debug("\t-Start folder: " + process.StartFolder);
                log.Debug("\t-New shell: " + (process.Shell ? "Yes" : "No"));
                log.Debug("\t-Real executable path: " + process.StartPath);
                log.Debug("\t-Arguments: " + String.Join<string>(", ", process.StartArguments));

                try {
                    mProcesses.Add(name, process);
                } catch (ArgumentException) {
                    log.WarnFormat("A key with the same name (\"{0}\") already exists. It will be overwritten.", name);
                    mProcesses.Remove(name);
                    mProcesses.Add(name, process);
                }
            }
Esempio n. 2
0
 /// <summary>
 ///     Parses process arguments.
 /// </summary>
 /// <param name="process">The information about the process</param>
 /// <param name="line">The line of data from the config file</param>
 /// <param name="i">The current index</param>
 private void parseArguments(ProcessData process, string line, int i)
 {
     while (i < line.Length) {
         string arg = nextParameterToken(line, ref i);
         if (arg != String.Empty)
             process.addArgument(arg);
     }
 }
Esempio n. 3
0
            /// <summary>
            ///     Parses the configuration file.
            /// </summary>
            public override void parseConfig()
            {
                TextReader inStream = new StreamReader(new FileStream(mFileName, FileMode.Open, FileAccess.Read));
                uint l = 0;

                while (true) {
                    string line = inStream.ReadLine();
                    l++;

                    if (line == null)
                        break;

                    // Ignores lines starting with another character than space. May be used for comments:
                    if (!line.StartsWith(" ")) {
                        log.DebugFormat("Ignored line \"{0}\"", line);
                        continue;
                    }

                    ProcessData process = new ProcessData();
                    string name = String.Empty;

                    try {
                        int i = 0;
                        // Find name:
                        name = nextToken(line, ref i);

                        // Find exe path:
                        process.ExePath = nextParameterToken(line, ref i);

                        // Find shell flag:
                        if (!process.parseShell(nextToken(line, ref i)))
                            throw new BadConfigException("Could not parse shell flag token", mFileName, l, (uint) i);

                        // Find start folder:
                        string startFolder = nextParameterToken(line, ref i);
                        if (startFolder != String.Empty)
                            process.StartFolder = startFolder;

                        string startExe = nextParameterToken(line, ref i);
                        if (startExe != String.Empty)
                            process.StartPath = startExe;

                        // Parse arguments:
                        parseArguments(process, line, i);
                    } catch (BadConfigException e) {
                        e.Line = l;
                        throw e;
                    }

                    newProcess(name, process);
                }

                inStream.Close();
            }