Battle_Script_Pro.Form1.LoadCustomCommands C# (CSharp) Method

LoadCustomCommands() private method

private LoadCustomCommands ( ) : void
return void
        private void LoadCustomCommands()
        {
            string filePath = System.Windows.Forms.Application.StartupPath + @"\Data\commands.bsh";
            if (File.Exists(filePath))
            {
                string[] file = File.ReadAllLines(filePath);
                foreach (string line in file)
                {
                    if (line.StartsWith("#command"))
                    {
                        string[] theLine = line.Split(' ');
                        List<string> paramNames = new List<string>();
                        List<byte> paramLengths = new List<byte>();
                        byte numberOfParams = 0;
                        ushort commandId = 0;
                        byte paramLength = 0;
                        string commandName = "";
                        string paramName = "";
                        bool getString = false;
                        bool getParamLength = false;
                        for (int i = 1; i < theLine.Length; i++)
                        {
                            if (i == 1)
                            {
                                commandName = theLine[i];
                                continue;
                            }
                            if (i == 2)
                            {
                                bool success = UInt16.TryParse(theLine[i], out commandId);
                                if (!success)
                                {
                                    success = UInt16.TryParse(ToDecimal(theLine[i]), out commandId);
                                    if (!success)
                                    {
                                        MessageBox.Show("The command ID was not formatted correctly. A number is required");
                                    }
                                }
                                continue;
                            }
                            if (i == 3)
                            {
                                bool success = Byte.TryParse(theLine[i], out numberOfParams);
                                if (!success)
                                {
                                    success = Byte.TryParse(ToDecimal(theLine[i]), out numberOfParams);
                                    if (!success)
                                    {
                                        MessageBox.Show("The number of parameters was not formatted correctly. A number is required");
                                    }
                                }
                                continue;
                            }
                            if (theLine[i].StartsWith("\""))
                            {
                                if (!theLine[i].EndsWith("\""))
                                {
                                    getString = true;
                                }
                                else
                                {
                                    getParamLength = true;
                                    paramName = theLine[i].Substring(1, theLine[i].Length - 2);
                                    continue;
                                }
                                paramName += theLine[i].Substring(1);
                                continue;
                            }
                            if (getString)
                            {
                                if (theLine[i].EndsWith("\""))
                                {
                                    getString = false;
                                    getParamLength = true;
                                    paramName += " " + theLine[i].Substring(0, theLine[i].Length - 1);
                                    continue;
                                }
                                paramName += " " + theLine[i];
                            }
                            if (getParamLength)
                            {
                                getParamLength = false;
                                bool success = Byte.TryParse(theLine[i], out paramLength);
                                if (!success)
                                {
                                    success = Byte.TryParse(ToDecimal(theLine[i]), out paramLength);
                                    if (!success)
                                    {
                                        MessageBox.Show("The parameter length was not formatted correctly. A number is required");
                                    }
                                }
                                paramNames.Add(paramName);
                                paramLengths.Add(paramLength);
                                paramName = "";
                                paramLength = 0;
                                continue;
                            }
                        }
                        commands.Add(commandName.ToUpper(), new Command(commandId, numberOfParams, paramNames.ToArray(), paramLengths.ToArray()));
                    }
                }
            }
        }
Form1