예제 #1
0
        private void scriptLoad()
        {
            if (File.Exists(this.scriptFile))
            {
                String[] qs_lines = System.IO.File.ReadAllLines(this.scriptFile);
                int      line     = 0;

                // Go to the line of [Configuration]
                while (line < qs_lines.Length)
                {
                    if (qs_lines[line].IndexOf("[Configuration]") != -1)
                    {
                        line++;
                        break;
                    }
                    else
                    {
                        line++;
                    }
                }
                // Read configurations
                this.configList = new List <conftype>();
                while (line < qs_lines.Length && qs_lines[line].IndexOf("[Events and Actions]") == -1)
                {
                    conftype conf = parseConfigLine(qs_lines[line]);
                    if (conf != null)
                    {
                        this.configList.Add(conf);
                    }
                    else if (qs_lines[line].Length > 0)
                    {
                        Console.WriteLine("Unrecognized config line: " + qs_lines[line]);
                    }

                    line++;
                }
                // TODO: Need to add back!
                //this.configComboBox.SelectedIndex = -1;

                // Read actions
                line++;
                this.actions = new List <actionlinetype>();
                while (line < qs_lines.Length)
                {
                    actionlinetype action = parseActionLine(qs_lines[line]);
                    if (action != null)
                    {
                        this.actions.Add(action);
                    }
                    else
                    {
                        Console.WriteLine("Unrecognized action in line " + (line + 1).ToString() + ", which will be removed if you save the current scripts!");
                    }
                    line++;
                }

                checkQScript(this.configList, this.actions);
                //flashListBoxActions();
                //if (this.actions.Count > 0)
                //    listBoxActionsSelect(0);
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public static actionlinetype parseActionLine(string line)
        {
            if (line == null)
            {
                return(null);
            }

            List <string> tokens = new List <string>();
            int           length = 0, pos = 0;
            int           i, j;

            // get label and timestamp
            for (i = 0; i < line.Length && line[i] != '\n' && line[i] != ':'; i++)
            {
                char c = line[i];
                if (c == ' ' || c == '\t')
                {
                    if (length > 0)
                    {
                        tokens.Add(line.Substring(pos, length));
                        length = 0;
                    }
                    pos = i + 1;
                }
                else
                {
                    length++;
                }
            }

            if (length > 0)
            {
                tokens.Add(line.Substring(pos, length));
            }

            if (tokens.Count != 2)
            {
                return(null);
            }

            length = 0;
            pos    = i + 1;
            j      = pos;
            string opcode = null;

            // get opcode
            for (j = i + 1; j < line.Length && line[j] != '\n'; j++)
            {
                char c = line[j];
                if (c == ' ' || c == '\t')
                {
                    if (length > 0)
                    {
                        break;
                    }
                    pos = j + 1;
                }
                else
                {
                    length++;
                }
            }
            if (length > 0)
            {
                opcode = line.Substring(pos, length);
                tokens.Add(opcode);
            }
            // No opcode
            if (opcode == null)
            {
                return(null);
            }

            length = 0;
            pos    = j + 1;
            // get the parameters
            if (opcode.Equals("OPCODE_ERROR") || opcode.Equals("OPCODE_MESSAGE"))
            {
                if (pos < line.Length)
                {
                    tokens.Add(line.Substring(pos));
                }
            }
            else
            {
                for (j = pos; j < line.Length && line[j] != '\n'; j++)
                {
                    char c = line[j];
                    if (c == ' ' || c == '\t')
                    {
                        if (length > 0)
                        {
                            tokens.Add(line.Substring(pos, length));
                            length = 0;
                        }
                        pos = j + 1;
                    }
                    else
                    {
                        length++;
                    }
                }

                if (length > 0)
                {
                    tokens.Add(line.Substring(pos, length));
                }
            }
            if (tokens.Count <= 2)
            {
                return(null);
            }
            actionlinetype action = new actionlinetype();

            if (!int.TryParse(tokens[0], out action.label))
            {
                return(null);
            }
            if (!double.TryParse(tokens[1], out action.time))
            {
                return(null);
            }
            action.name = tokens[2];
            if (tokens.Count > 3)
            {
                action.parameters = new string[tokens.Count - 3];
                for (int k = 0; k < tokens.Count - 3; k++)
                {
                    action.parameters[k] = tokens[k + 3];
                }
            }

            return(action);
        }