public static void LoadCurrentTheme()
        {
            StreamReader TextFile = new StreamReader(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\ThemeConfig.txt");
            string       CurrentLine;
            int          IndexOfColour;

            while ((CurrentLine = TextFile.ReadLine()) != null)
            {
                IndexOfColour = CurrentLine.IndexOf("#");

                if (CurrentLine.Contains("TitleBarColor: "))
                {
                    ThemeMethods.SetTopBarThemeManual(ColorTranslator.FromHtml(CurrentLine.Substring(IndexOfColour)));
                }
                else if (CurrentLine.Contains("SideBarColor: "))
                {
                    ThemeMethods.SetSideBarThemeManual(ColorTranslator.FromHtml(CurrentLine.Substring(IndexOfColour)));
                }
                else if (CurrentLine.Contains("AccentColor: "))
                {
                    ThemeMethods.SetThemeAccentManual(ColorTranslator.FromHtml(CurrentLine.Substring(IndexOfColour)));
                }
            }

            TextFile.Dispose();
        }
Exemple #2
0
        /// <summary>
        /// Analize, but don't read, a line of type: Begin ObjectType ObjectName
        /// </summary>
        /// <returns>Returns the ObjectName part</returns>
        /// <exception cref="WrongFileFormatException">if ObjectName is not found</exception>
        public string PeekObjectName()
        {
            int pos = CurrentLine.IndexOf(' ', Math.Min(CurrentLine.Length, theBegin.Length + 1));

            if (pos == -1)
            {
                throw new WrongFileFormatException(String.Format(Properties.ImportRes.ObjectNameNotFound, LineNumber),
                                                   (sr.BaseStream as FileStream).Name,
                                                   LineNumber);
            }
            return(CurrentLine.Substring(pos + 1));
        }
Exemple #3
0
        private string FindVersionNumber(string StringToFind, string[] AllLines)
        {
            string FoundVersion = "Unknown";

            foreach (string CurrentLine in AllLines)
            {
                int Index = CurrentLine.IndexOf(StringToFind);
                if (Index != -1)
                {
                    FoundVersion = CurrentLine.Substring(Index + StringToFind.Length);
                    break;
                }
            }
            return(FoundVersion.Trim());
        }
Exemple #4
0
        /// <summary>
        /// To be used by mod loader mods. Loads the current theme properties for the mod loader configurator.
        /// </summary>
        public static (Color, Color, Color) Load_Theme_Configurator()
        {
            // Colours;
            Color SidebarColor = new Color();
            Color TopBarColor  = new Color();
            Color AccentColor  = new Color();

            try
            {
                // Load Configurator Theme
                string       Save_Seting_Path = File.ReadAllText(Environment.CurrentDirectory + "\\Mod_Loader_Config.txt") + @"\Mod-Loader-Config\\ThemeConfig.txt";
                StreamReader TextFile         = new StreamReader(Save_Seting_Path);

                string CurrentLine;
                int    IndexOfColour;

                while ((CurrentLine = TextFile.ReadLine()) != null)
                {
                    IndexOfColour = CurrentLine.IndexOf("#");

                    if (CurrentLine.Contains("TitleBarColor: "))
                    {
                        SidebarColor = ColorTranslator.FromHtml(CurrentLine.Substring(IndexOfColour));
                    }
                    else if (CurrentLine.Contains("SideBarColor: "))
                    {
                        TopBarColor = ColorTranslator.FromHtml(CurrentLine.Substring(IndexOfColour));
                    }
                    else if (CurrentLine.Contains("AccentColor: "))
                    {
                        AccentColor = ColorTranslator.FromHtml(CurrentLine.Substring(IndexOfColour));
                    }
                }

                TextFile.Dispose();
                return(SidebarColor, TopBarColor, AccentColor);
            }
            catch
            {
                SidebarColor = ColorTranslator.FromHtml("#283540");
                TopBarColor  = ColorTranslator.FromHtml("#22292E");
                AccentColor  = ColorTranslator.FromHtml("#3F51B5");
                return(SidebarColor, TopBarColor, AccentColor);
            }
        }
Exemple #5
0
        /// <summary>
        /// Parse a raw callstack into a pattern
        /// </summary>
        /// <param name="CurrentCrash">The crash with a raw callstack to parse.</param>
        private void ParseCallStack(Crash CurrentCrash)
        {
            // Everything is disabled by default
            bDisplayUnformattedCallStack = false;
            bDisplayModuleNames          = false;
            bDisplayFunctionNames        = false;
            bDisplayFileNames            = false;
            bDisplayFilePathNames        = false;

            bool   bSkipping      = false;
            string LineToSkipUpto = "";

            switch (CurrentCrash.CrashType)
            {
            case 2:
                bSkipping      = true;
                LineToSkipUpto = "FDebug::AssertFailed()";
                break;

            case 3:
                bSkipping      = true;
                LineToSkipUpto = "FDebug::EnsureFailed()";
                break;
            }

            if (string.IsNullOrEmpty(CurrentCrash.RawCallStack))
            {
                return;
            }

            CallStackEntries.Clear();

            // Store off a pre split array of call stack lines
            string[] RawCallStackLines = CurrentCrash.RawCallStack.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

            // Support older callstacks uploaded before UE4 upgrade
            if (!NewCallstackFormat.Match(RawCallStackLines[0]).Success)
            {
                foreach (string CurrentLine in RawCallStackLines)
                {
                    // Exit if we've hit the max number of lines we want
                    if (CallStackEntries.Count >= MaxLinesToParse)
                    {
                        break;
                    }

                    ParseUE3FormatCallstackLine(CurrentLine);
                }
                return;
            }

            foreach (string CurrentLine in RawCallStackLines)
            {
                // Exit if we've hit the max number of lines we want
                if (CallStackEntries.Count >= MaxLinesToParse)
                {
                    break;
                }

                if (bSkipping)
                {
                    if (CurrentLine.Contains(LineToSkipUpto))
                    {
                        bSkipping = false;
                    }
                }

                if (bSkipping)
                {
                    continue;
                }

                string ModuleName = "<Unknown>";
                string FuncName   = "<Unknown>";
                string FilePath   = "";
                int    LineNumber = 0;

                // Sample line "UE4_Engine!UEngine::Exec() + 21105 bytes [d:\depot\ue4\engine\source\runtime\engine\private\unrealengine.cpp:2777]"

                int PlingOffset        = CurrentLine.IndexOf('!');
                int PlusOffset         = CurrentLine.IndexOf(" + ");
                int BytesOffset        = CurrentLine.IndexOf(" bytes");
                int OpenBracketOffset  = CurrentLine.IndexOf('[');
                int CloseBracketOffset = CurrentLine.LastIndexOf(']');

                // Parse out the juicy info from the line of the callstack
                if (PlingOffset > 0)
                {
                    ModuleName = CurrentLine.Substring(0, PlingOffset).Trim();
                    if (BytesOffset > PlingOffset)
                    {
                        // Grab the function name if it exists
                        FuncName = CurrentLine.Substring(PlingOffset + 1, BytesOffset - PlingOffset + " bytes".Length - 1).Trim();

                        // Grab the source file
                        if (OpenBracketOffset > BytesOffset && CloseBracketOffset > BytesOffset && CloseBracketOffset > OpenBracketOffset)
                        {
                            string FileLinePath = CurrentLine.Substring(OpenBracketOffset + 1, CloseBracketOffset - OpenBracketOffset - 1).Trim();

                            FilePath = FileLinePath.TrimEnd("0123456789:".ToCharArray());
                            int SourceLine = 0;
                            Debug.Assert(FilePath.Length < FileLinePath.Length, "WRONG SIZE");
                            if (int.TryParse(FileLinePath.Substring(FilePath.Length + 1), out SourceLine))
                            {
                                LineNumber = SourceLine;
                            }
                        }
                    }
                }
                else if (BytesOffset > 0)
                {
                    // Grab the module name if there is no function name
                    ModuleName = CurrentLine.Substring(0, PlusOffset).Trim();
                }

                CallStackEntries.Add(new CallStackEntry(CurrentLine, ModuleName, FilePath, FuncName, LineNumber));
            }
        }
Exemple #6
0
        //.*?\(.*?\).*?\[.*?\]

        /// <summary>
        /// Parse a raw callstack into a pattern
        /// </summary>
        /// <param name="CurrentCrash">The crash with a raw callstack to parse.</param>
        private void ParseCallStack(Crash CurrentCrash)
        {
            // Everything is disabled by default
            bDisplayUnformattedCallStack = false;
            bDisplayModuleNames          = false;
            bDisplayFunctionNames        = false;
            bDisplayFileNames            = false;
            bDisplayFilePathNames        = false;

            bool   bSkipping      = false;
            string LineToSkipUpto = "";

            switch (CurrentCrash.CrashType)
            {
            case 2:
                bSkipping      = true;
                LineToSkipUpto = "FDebug::AssertFailed";
                break;

            case 3:
                bSkipping      = true;
                LineToSkipUpto = "FDebug::";
                break;
            }

            if (string.IsNullOrEmpty(CurrentCrash.RawCallStack))
            {
                return;
            }

            CallStackEntries.Clear();

            // Store off a pre split array of call stack lines
            string[] RawCallStackLines = CurrentCrash.RawCallStack.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

            int Middle = RawCallStackLines.Length / 2;

            // Support older callstacks uploaded before UE4 upgrade
            if (!NewCallstackFormat.Match(RawCallStackLines[Middle]).Success)
            {
                foreach (string CurrentLine in RawCallStackLines)
                {
                    // Exit if we've hit the max number of lines we want
                    if (CallStackEntries.Count >= MaxLinesToParse)
                    {
                        break;
                    }

                    ParseUE3FormatCallstackLine(CurrentLine);
                }
                return;
            }

            foreach (string CurrentLine in RawCallStackLines)
            {
                // Exit if we've hit the max number of lines we want
                if (CallStackEntries.Count >= MaxLinesToParse)
                {
                    break;
                }

                if (bSkipping)
                {
                    if (CurrentLine.Contains(LineToSkipUpto))
                    {
                        bSkipping = false;
                    }
                }

                if (bSkipping)
                {
                    continue;
                }

                string ModuleName = "<Unknown>";
                string FuncName   = "<Unknown>";
                string FilePath   = "";
                int    LineNumber = 0;

                //
                // Generic sample line "UE4_Engine!UEngine::Exec() {+ 21105 bytes} [d:\depot\ue4\engine\source\runtime\engine\private\unrealengine.cpp:2777]"
                //
                // Mac
                // thread_start()  Address = 0x7fff87ae141d (filename not found) [in libsystem_pthread.dylib]
                //
                // Linux
                // Unknown!AFortPlayerController::execServerSaveLoadoutData(FFrame&, void*) + some bytes

                int ModuleSeparator    = CurrentLine.IndexOf('!');
                int PlusOffset         = CurrentLine.IndexOf(" + ");
                int OpenFuncSymbol     = CurrentLine.IndexOf('(');
                int CloseFuncSymbol    = CurrentLine.IndexOf(')');
                int OpenBracketOffset  = CurrentLine.IndexOf('[');
                int CloseBracketOffset = CurrentLine.LastIndexOf(']');

                int MacModuleStart = CurrentLine.IndexOf("[in ");
                int MacModuleEnd   = MacModuleStart > 0 ? CurrentLine.IndexOf("]", MacModuleStart) : 0;

                bool bLinux   = CurrentCrash.PlatformName.Contains("Linux");
                bool bMac     = CurrentCrash.PlatformName.Contains("Mac");
                bool bWindows = CurrentCrash.PlatformName.Contains("Windows");


                // Parse out the juicy info from the line of the callstack
                if (ModuleSeparator > 0)
                {
                    ModuleName = CurrentLine.Substring(0, ModuleSeparator).Trim();
                    if (OpenFuncSymbol > ModuleSeparator && CloseFuncSymbol > OpenFuncSymbol)
                    {
                        // Grab the function name if it exists
                        FuncName  = CurrentLine.Substring(ModuleSeparator + 1, OpenFuncSymbol - ModuleSeparator - 1).Trim();
                        FuncName += "()";

                        // Grab the source file
                        if (OpenBracketOffset > CloseFuncSymbol && CloseBracketOffset > OpenBracketOffset && (bWindows || bLinux))
                        {
                            string FileLinePath = CurrentLine.Substring(OpenBracketOffset + 1, CloseBracketOffset - OpenBracketOffset - 1).Trim();

                            FilePath = FileLinePath.TrimEnd("0123456789:".ToCharArray());

                            if (FileLinePath.Length > FilePath.Length + 1)
                            {
                                int SourceLine = 0;
                                if (int.TryParse(FileLinePath.Substring(FilePath.Length + 1), out SourceLine))
                                {
                                    LineNumber = SourceLine;
                                }
                            }
                        }
                    }
                }
                else if (bWindows)
                {
                    // Grab the module name if there is no function name
                    int WhiteSpacePos = CurrentLine.IndexOf(' ');
                    ModuleName = WhiteSpacePos > 0 ? CurrentLine.Substring(0, WhiteSpacePos) : CurrentLine;
                }

                if (bMac && MacModuleStart > 0 && MacModuleEnd > 0)
                {
                    int AddressOffset     = CurrentLine.IndexOf("Address =");
                    int OpenFuncSymbolMac = AddressOffset > 0 ? CurrentLine.Substring(0, AddressOffset).LastIndexOf('(') : 0;
                    if (OpenFuncSymbolMac > 0)
                    {
                        FuncName  = CurrentLine.Substring(0, OpenFuncSymbolMac).Trim();
                        FuncName += "()";
                    }

                    ModuleName = CurrentLine.Substring(MacModuleStart + 3, MacModuleEnd - MacModuleStart - 3).Trim();
                }

                // Remove callstack entries that match any of these functions.
                var FuncsToRemove = new HashSet <string>(new string[]
                {
                    "RaiseException",
                    "FDebug::",
                    "Error::Serialize",
                    "FOutputDevice::Logf",
                    "FMsg::Logf",
                    "ReportCrash",
                    "NewReportEnsure",
                    "EngineCrashHandler",
                    "FLinuxPlatformStackWalk::CaptureStackBackTrac",
                    "FGenericPlatformStackWalk::StackWalkAndDump",
                    "FLinuxCrashContext::CaptureStackTrace",
                    "CommonLinuxCrashHandler",
                    // Generic crash handler for all platforms
                });

                bool Contains = FuncsToRemove.Contains(FuncName, new CustomFuncComparer());
                if (!Contains)
                {
                    CallStackEntries.Add(new CallStackEntry(CurrentLine, ModuleName, FilePath, FuncName, LineNumber));
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Loads the Sonic Heroes Configuration File, returns under the custom struct defined in the same file.
        /// </summary>
        public static Sonic_Heroes_Configuration_File Load_Configuration_File()
        {
            Sonic_Heroes_Configuration_File ConfigFile = new Sonic_Heroes_Configuration_File();
            string ConfigFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\SEGA\SONICHEROES\sonic_h.ini";

            try
            {
                string CurrentLine;
                System.IO.StreamReader INIConfigFile = new System.IO.StreamReader(ConfigFilePath);

                // Initialize size of struct arrays;
                ConfigFile.ControllerOne = new byte[8];
                ConfigFile.ControllerTwo = new byte[8];
                ConfigFile.MouseControls = new byte[8];

                while ((CurrentLine = INIConfigFile.ReadLine()) != null)
                {
                    if (CurrentLine.StartsWith("Frame_Rate"))
                    {
                        ConfigFile.FrameRate = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                    }
                    else if (CurrentLine.StartsWith("Free_Camera"))
                    {
                        ConfigFile.FreeCamera = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                    }
                    else if (CurrentLine.StartsWith("Fog"))
                    {
                        ConfigFile.FogEmulation = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                    }
                    else if (CurrentLine.StartsWith("Clip_Range"))
                    {
                        ConfigFile.ClipRange = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                    }
                    else if (CurrentLine.StartsWith("Anisotoropic"))
                    {
                        ConfigFile.AnisotropicFiltering = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                    }
                    else if (CurrentLine.StartsWith("Pad_Assign1"))
                    {
                        ReadStringByteArray(CurrentLine.Substring(CurrentLine.IndexOf(" ") + 1), ConfigFile.ControllerOne);
                    }
                    else if (CurrentLine.StartsWith("Pad_Assign2"))
                    {
                        ReadStringByteArray(CurrentLine.Substring(CurrentLine.IndexOf(" ") + 1), ConfigFile.ControllerTwo);
                    }
                    else if (CurrentLine.StartsWith("Mouse_Assign"))
                    {
                        ReadStringByteArray(CurrentLine.Substring(CurrentLine.IndexOf(" ") + 1), ConfigFile.MouseControls);
                    }
                    else if (CurrentLine.StartsWith("Screen_Size_Selection"))
                    {
                        ConfigFile.Screensize = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                    }
                    else if (CurrentLine.StartsWith("Screen_Full"))
                    {
                        ConfigFile.FullScreen = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                    }
                    else if (CurrentLine.StartsWith("Language"))
                    {
                        ConfigFile.Language = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                    }
                    else if (CurrentLine.StartsWith("3D_Sound"))
                    {
                        ConfigFile.SurroundSound = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                    }
                    else if (CurrentLine.StartsWith("SE_Volume"))
                    {
                        ConfigFile.SFXVolume = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                    }
                    else if (CurrentLine.StartsWith("SE_On"))
                    {
                        ConfigFile.SFXToggle = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                    }
                    else if (CurrentLine.StartsWith("BGM_Volume"))
                    {
                        ConfigFile.BGMVolume = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                    }
                    else if (CurrentLine.StartsWith("BGM_On"))
                    {
                        ConfigFile.BGMToggle = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                    }
                    else if (CurrentLine.StartsWith("Cheap_Shadow"))
                    {
                        ConfigFile.SoftShadows = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                    }
                    else if (CurrentLine.StartsWith("Mouse_Control_Type"))
                    {
                        ConfigFile.MouseControlType = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                    }
                }

                INIConfigFile.Dispose();
                return(ConfigFile);
            }
            catch (Exception)
            {
                // If the game is not Sonic Heroes or a config file is missing, set a default file into memory undefined defaults.
                MessageBox.Show("Could not find the Sonic Heroes configuration ini. The settings in the mod loader have been replaced with the defaults.");
                return(ConfigFile);
            }
        }
        private void LoadHeroesConfig()
        {
            string ConfigFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\SEGA\SONICHEROES\sonic_h.ini";
            string CurrentLine;

            System.IO.StreamReader INIConfigFile = new System.IO.StreamReader(ConfigFilePath);

            // Initialize size of struct arrays;
            ConfigFile.ControllerOne = new byte[8];
            ConfigFile.ControllerTwo = new byte[8];
            ConfigFile.MouseControls = new byte[8];

            while ((CurrentLine = INIConfigFile.ReadLine()) != null)
            {
                if (CurrentLine.StartsWith("Frame_Rate"))
                {
                    ConfigFile.FrameRate = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                }
                else if (CurrentLine.StartsWith("Free_Camera"))
                {
                    ConfigFile.FreeCamera = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                }
                else if (CurrentLine.StartsWith("Fog"))
                {
                    ConfigFile.FogEmulation = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                }
                else if (CurrentLine.StartsWith("Clip_Range"))
                {
                    ConfigFile.ClipRange = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                }
                else if (CurrentLine.StartsWith("Anisotoropic"))
                {
                    ConfigFile.AnisotropicFiltering = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                }
                else if (CurrentLine.StartsWith("Pad_Assign1"))
                {
                    ReadStringByteArray(CurrentLine.Substring(CurrentLine.IndexOf(" ") + 1), ConfigFile.ControllerOne);
                }
                else if (CurrentLine.StartsWith("Pad_Assign2"))
                {
                    ReadStringByteArray(CurrentLine.Substring(CurrentLine.IndexOf(" ") + 1), ConfigFile.ControllerTwo);
                }
                else if (CurrentLine.StartsWith("Mouse_Assign"))
                {
                    ReadStringByteArray(CurrentLine.Substring(CurrentLine.IndexOf(" ") + 1), ConfigFile.MouseControls);
                }
                else if (CurrentLine.StartsWith("Screen_Size_Selection"))
                {
                    ConfigFile.Screensize = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                }
                else if (CurrentLine.StartsWith("Screen_Full"))
                {
                    ConfigFile.FullScreen = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                }
                else if (CurrentLine.StartsWith("Language"))
                {
                    ConfigFile.Language = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                }
                else if (CurrentLine.StartsWith("3D_Sound"))
                {
                    ConfigFile.SurroundSound = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                }
                else if (CurrentLine.StartsWith("SE_Volume"))
                {
                    ConfigFile.SFXVolume = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                }
                else if (CurrentLine.StartsWith("SE_On"))
                {
                    ConfigFile.SFXToggle = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                }
                else if (CurrentLine.StartsWith("BGM_Volume"))
                {
                    ConfigFile.BGMVolume = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                }
                else if (CurrentLine.StartsWith("BGM_On"))
                {
                    ConfigFile.BGMToggle = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                }
                else if (CurrentLine.StartsWith("Cheap_Shadow"))
                {
                    ConfigFile.SoftShadows = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                }
                else if (CurrentLine.StartsWith("Mouse_Control_Type"))
                {
                    ConfigFile.MouseControlType = byte.Parse(CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1));
                }
            }

            INIConfigFile.Dispose();
        }
        public ScriptError ParseScriptFile()
        {
            #region Initialization
            string CurrentLine, CurrentLineLessComments;
            char[] charsToTrim = { '\t', ' ' };
            int    commentIndex;

            hasSecSerialPort   = false;
            hasSecInit         = false;
            hasSecMeasure      = false;
            hasSecStop         = false;
            currentSection     = ScriptSections.NoSectionFound;
            secInitCommands    = new List <string>();
            secMeasureCommands = new List <string>();
            secStopCommands    = new List <string>();

            lineCount = 0;
            #endregion

            try
            {
                StreamReader InputFile = new StreamReader(scriptFileName);
                while ((CurrentLine = InputFile.ReadLine()) != null)
                {
                    lineCount++;

                    #region Empty_Line_Processing
                    if (CurrentLine.Length <= 0)
                    {
                        continue;
                    }
                    #endregion

                    #region Comment_Processing
                    columnCount  = 1;
                    commentIndex = CurrentLine.IndexOf(commentString);
                    if (commentIndex == 0)
                    {
                        continue;
                    }
                    else if (commentIndex > 0)
                    {
                        CurrentLineLessComments = CurrentLine.Substring(0, commentIndex);
                    }
                    else
                    {
                        CurrentLineLessComments = CurrentLine;
                    }

                    CurrentLineLessComments = CurrentLineLessComments.TrimEnd(charsToTrim);
                    #endregion

                    #region Section_Processing
                    if (CurrentLineLessComments.Contains(sectionString))
                    {
                        if (CurrentLine.IndexOf(sectionString) != 0)
                        {
                            columnCount = CurrentLineLessComments.IndexOf(sectionString);
                            InputFile.Close();
                            return(ScriptError.SecBegOfLineErr);
                        }

                        int sectionStringIndex = CurrentLineLessComments.IndexOf(sectionString);
                        CurrentLineLessComments = CurrentLineLessComments.Remove(sectionStringIndex, sectionString.Length);
                        ScriptSections identifiedSection = ScriptSections.NoSectionFound;
                        foreach (ScriptSections currentScriptSection in Enum.GetValues(typeof(ScriptSections)))
                        {
                            if (CurrentLineLessComments.Contains(currentScriptSection.ToString()))
                            {
                                int sectionNameIndex = CurrentLineLessComments.IndexOf(currentScriptSection.ToString());
                                if (sectionNameIndex != 0)
                                {
                                    columnCount = sectionString.Length;
                                    InputFile.Close();
                                    return(ScriptError.UnknownSecErr);
                                }

                                if (CurrentLineLessComments.Length > currentScriptSection.ToString().Length)
                                {
                                    if (CurrentLineLessComments[currentScriptSection.ToString().Length] != ' ' &&
                                        CurrentLineLessComments[currentScriptSection.ToString().Length] != '\t')
                                    {
                                        columnCount = sectionString.Length;
                                        InputFile.Close();
                                        return(ScriptError.UnknownSecErr);
                                    }
                                }

                                identifiedSection = currentScriptSection;
                                break;
                            }
                        }
                        if (identifiedSection == ScriptSections.NoSectionFound)
                        {
                            InputFile.Close();
                            return(ScriptError.UnknownSecErr);
                        }
                        if (identifiedSection == ScriptSections.SerialPort)
                        {
                            if (hasSecSerialPort == false)
                            {
                                hasSecSerialPort = true;
                            }
                            else
                            {
                                InputFile.Close();
                                columnCount = sectionString.Length;
                                return(ScriptError.SecRepeatErr);
                            }
                        }
                        else if (identifiedSection == ScriptSections.Init)
                        {
                            if (hasSecInit == false)
                            {
                                hasSecInit = true;
                            }
                            else
                            {
                                InputFile.Close();
                                columnCount = sectionString.Length;
                                return(ScriptError.SecRepeatErr);
                            }
                        }
                        else if (identifiedSection == ScriptSections.Measure)
                        {
                            if (hasSecMeasure == false)
                            {
                                hasSecMeasure = true;
                            }
                            else
                            {
                                InputFile.Close();
                                columnCount = sectionString.Length;
                                return(ScriptError.SecRepeatErr);
                            }
                        }
                        else if (identifiedSection == ScriptSections.Stop)
                        {
                            if (hasSecStop == false)
                            {
                                hasSecStop = true;
                            }
                            else
                            {
                                InputFile.Close();
                                columnCount = sectionString.Length;
                                return(ScriptError.SecRepeatErr);
                            }
                        }

                        currentSection = identifiedSection;
                        continue;
                    }
                    #endregion

                    #region Section_Statement_Processing
                    CurrentLineLessComments = CurrentLineLessComments.Trim(charsToTrim);

                    #region Section_Serial_Port
                    if (currentSection == ScriptSections.SerialPort)
                    {
                        if (Regex.IsMatch(CurrentLineLessComments, @"\s*PortName\s*=\s*"))
                        {
                            serialPortName = Regex.Replace(CurrentLineLessComments, @"\s*PortName\s*=\s*", "", RegexOptions.None);
                        }
                        else if (Regex.IsMatch(CurrentLineLessComments, @"\s*BaudRate\s*=\s*"))
                        {
                            CurrentLineLessComments = Regex.Replace(CurrentLineLessComments, @"\s*BaudRate\s*=\s*", "", RegexOptions.None);
                            if (Int32.TryParse(CurrentLineLessComments, out spBaudRate) == false)
                            {
                                columnCount = CurrentLine.IndexOf(CurrentLineLessComments);
                                InputFile.Close();
                                return(ScriptError.BaudRateResolutionErr);
                            }
                        }
                        else if (Regex.IsMatch(CurrentLineLessComments, @"\s*Parity\s*=\s*"))
                        {
                            CurrentLineLessComments = Regex.Replace(CurrentLineLessComments, @"\s*Parity\s*=\s*", "", RegexOptions.None);
                            try
                            {
                                spParity = (Parity)Enum.Parse(typeof(Parity), CurrentLineLessComments, true);
                            }
                            catch (Exception ex)
                            {
                                if ((ex is ArgumentException) || (ex is OverflowException))
                                {
                                    columnCount = CurrentLine.IndexOf(CurrentLineLessComments);
                                }
                                InputFile.Close();
                                return(ScriptError.ParityResolutionErr);
                            }
                        }
                        else if (Regex.IsMatch(CurrentLineLessComments, @"\s*DataBits\s*=\s*"))
                        {
                            CurrentLineLessComments = Regex.Replace(CurrentLineLessComments, @"\s*DataBits\s*=\s*", "", RegexOptions.None);
                            if (Int32.TryParse(CurrentLineLessComments, out spDataBits) == false)
                            {
                                columnCount = CurrentLine.IndexOf(CurrentLineLessComments);
                                InputFile.Close();
                                return(ScriptError.DataBitsResolutionErr);
                            }

                            if ((spDataBits > 8) || (spDataBits < 5))
                            {
                                columnCount = CurrentLine.IndexOf(CurrentLineLessComments);
                                InputFile.Close();
                                return(ScriptError.DataBitsResolutionErr);
                            }
                        }
                        else if (Regex.IsMatch(CurrentLineLessComments, @"\s*StopBits\s*=\s*"))
                        {
                            CurrentLineLessComments = Regex.Replace(CurrentLineLessComments, @"\s*StopBits\s*=\s*", "", RegexOptions.None);
                            try
                            {
                                spStopBits = (StopBits)Enum.Parse(typeof(StopBits), CurrentLineLessComments, true);
                            }
                            catch (Exception ex)
                            {
                                if ((ex is ArgumentException) || (ex is OverflowException))
                                {
                                    columnCount = CurrentLine.IndexOf(CurrentLineLessComments);
                                }
                                InputFile.Close();
                                return(ScriptError.StopBitsResolutionErr);
                            }
                        }
                        else if (Regex.IsMatch(CurrentLineLessComments, @"\s*Handshake\s*=\s*"))
                        {
                            CurrentLineLessComments = Regex.Replace(CurrentLineLessComments, @"\s*Handshake\s*=\s*", "", RegexOptions.None);
                            try
                            {
                                spHandshake = (Handshake)Enum.Parse(typeof(Handshake), CurrentLineLessComments, true);
                            }
                            catch (Exception ex)
                            {
                                if ((ex is ArgumentException) || (ex is OverflowException))
                                {
                                    columnCount = CurrentLine.IndexOf(CurrentLineLessComments);
                                }
                                InputFile.Close();
                                return(ScriptError.HandShakeResolutionErr);
                            }
                        }
                        else if (Regex.IsMatch(CurrentLineLessComments, @"\s*DtrEnable\s*=\s*"))
                        {
                            CurrentLineLessComments = Regex.Replace(CurrentLineLessComments, @"\s*DtrEnable\s*=\s*", "", RegexOptions.None);
                            try
                            {
                                spDtrEnable = Boolean.Parse(CurrentLineLessComments);
                            }
                            catch
                            {
                                columnCount = CurrentLine.IndexOf(CurrentLineLessComments);
                                InputFile.Close();
                                return(ScriptError.HandShakeResolutionErr);
                            }
                        }
                        else
                        {
                            InputFile.Close();
                            return(ScriptError.UnknownSerialPortSetting);
                        }
                    }
                    #endregion
                    #region Section_Others
                    else
                    {
                        if (CurrentLineLessComments.Contains("SendString"))
                        {
                            //string processedString;
                            if (Regex.IsMatch(CurrentLineLessComments, @"\s*SendString\s*\(\s*"".*""\s*\)\s*") == false)
                            {
                                InputFile.Close();
                                return(ScriptError.SyntaxErr);
                            }

                            //processedString = Regex.Replace(CurrentLineLessComments, @"\s*SendString\s*\(\s*""", "");
                            //processedString = Regex.Replace(processedString, @"""\s*\)\s*", "");

                            if (currentSection == ScriptSections.Init)
                            {
                                secInitCommands.Add(CurrentLineLessComments);
                            }
                            else if (currentSection == ScriptSections.Measure)
                            {
                                secMeasureCommands.Add(CurrentLineLessComments);
                            }
                            else if (currentSection == ScriptSections.Stop)
                            {
                                secStopCommands.Add(CurrentLineLessComments);
                            }
                        }
                        else if (CurrentLineLessComments.Contains("DelayMS"))
                        {
                            //string processedString;
                            if (Regex.IsMatch(CurrentLineLessComments, @"\s*DelayMS\s*\(\s*\d+\s*\)\s*") == false)
                            {
                                InputFile.Close();
                                return(ScriptError.SyntaxErr);
                            }

                            //processedString = Regex.Replace(CurrentLineLessComments, @"\s*SendString\s*\(\s*""", "");
                            //processedString = Regex.Replace(processedString, @"""\s*\)\s*", "");

                            if (currentSection == ScriptSections.Init)
                            {
                                secInitCommands.Add(CurrentLineLessComments);
                            }
                            else if (currentSection == ScriptSections.Measure)
                            {
                                secMeasureCommands.Add(CurrentLineLessComments);
                            }
                            else if (currentSection == ScriptSections.Stop)
                            {
                                secStopCommands.Add(CurrentLineLessComments);
                            }
                        }
                        else if (CurrentLineLessComments.Contains("ReceiveString"))
                        {
                            //string processedString;
                            if (Regex.IsMatch(CurrentLineLessComments, @"\s*ReceiveString\s*\(\s*"",*%[dlfxsc],*""\s*\)\s*") == false)
                            {
                                InputFile.Close();
                                return(ScriptError.SyntaxErr);
                            }

                            //processedString = Regex.Replace(CurrentLineLessComments, @"\s*SendString\s*\(\s*""", "");
                            //processedString = Regex.Replace(processedString, @"""\s*\)\s*", "");

                            if (currentSection == ScriptSections.Init)
                            {
                                secInitCommands.Add(CurrentLineLessComments);
                            }
                            else if (currentSection == ScriptSections.Measure)
                            {
                                secMeasureCommands.Add(CurrentLineLessComments);
                            }
                            else if (currentSection == ScriptSections.Stop)
                            {
                                secStopCommands.Add(CurrentLineLessComments);
                            }
                        }

                        else
                        {
                            InputFile.Close();
                            return(ScriptError.UnknownCmdErr);
                        }
                    }
                    #endregion
                    #endregion
                }

                InputFile.Close();

                if (lineCount == 0)
                {
                    return(ScriptError.FileEmpty);
                }
            }
            catch (Exception ex)
            {
                if (ex is ArgumentException)
                {
                    return(ScriptError.CannotOpenFile);
                }
                else if (ex is ArgumentNullException)
                {
                    return(ScriptError.FileDoesNotExist);
                }
            }

            scriptParsed = true;

            return(ScriptError.NoError);
        }
Exemple #10
0
        public static void MainParser(mcPage aPage, string CommandString)
        {
            System.Reflection.MethodInfo m;
            Type   t;
            string CurrentLine;

            string[] Lines;
            string   MyCmd;
            string   Parameters;
            int      i;
            int      a;

            CommandString = CommandString.Replace('\r', '\n');
            Lines         = CommandString.Split('\n');

            for (i = 0; i < Lines.Length; i++)
            {
                CurrentLine = Lines[i];
                if (CurrentLine.Length < 1)
                {
                    continue;
                }
                if (CurrentLine[0] == '/')
                {
                    a = CurrentLine.IndexOf(" ");
                    if (a == -1)
                    {
                        //one-word command, no params
                        MyCmd      = CurrentLine.Substring(1);
                        Parameters = null;
                    }
                    else
                    {
                        //more complex :/
                        MyCmd      = CurrentLine.Substring(1, a - 1);
                        Parameters = CurrentLine.Substring(a);
                    }
                    /* Try and invoke it now. */
                    mcCommands MyScript = new mcCommands();
                    t = MyScript.GetType();
                    m = t.GetMethod("cmd" + MyCmd, BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.IgnoreCase | BindingFlags.Public);
                    if (m == null)
                    {
                        /* no command, send it raw. */
                        aPage.Server.IRCSend(MyCmd + " " + Parameters);
                    }
                    else
                    {
                        try
                        {
                            object[] anObj = new object[] { aPage, Parameters };
                            m.Invoke(null, anObj);
                            anObj = null;
                        }
                        catch (TargetInvocationException ex)
                        {
                            aPage.MessageInfo("Scripting error, error dump follows:");
                            aPage.MessageInfo(ex.ToString());
                        }
                    }
                }
                else
                {
                    cmdSay(aPage, CurrentLine);
                }
            }
        }