From eac3074e30a36d13a5b569bed5ea38e52698b55d Mon Sep 17 00:00:00 2001 From: Fellippe Heitor Date: Sun, 7 Feb 2021 22:01:53 -0300 Subject: [PATCH] Incorporates INI-Manager to deal with the settings file. Allows for multiple IDE instances using the same config file by default. --- .gitignore | 1 + source/global/IDEsettings.bas | 1019 +++++++++++++-------------- source/ide/ide_methods.bas | 163 ++--- source/qb64.bas | 126 +--- source/utilities/ini-manager/ini.bi | 21 + source/utilities/ini-manager/ini.bm | 793 +++++++++++++++++++++ 6 files changed, 1382 insertions(+), 741 deletions(-) create mode 100644 source/utilities/ini-manager/ini.bi create mode 100644 source/utilities/ini-manager/ini.bm diff --git a/.gitignore b/.gitignore index f40a40f31..4b639cc7f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ internal/temp* *.exe *.bas internal/config*.txt +internal/config.ini internal/help internal/version.txt tempfoldersearch.bin diff --git a/source/global/IDEsettings.bas b/source/global/IDEsettings.bas index fde3641cf..b71cee193 100644 --- a/source/global/IDEsettings.bas +++ b/source/global/IDEsettings.bas @@ -6,8 +6,6 @@ DIM SHARED IDEKeywordColor AS _UNSIGNED LONG, IDENumbersColor AS _UNSIGNED LONG DIM SHARED IDE_AutoPosition AS _BYTE, IDE_TopPosition AS INTEGER, IDE_LeftPosition AS INTEGER DIM SHARED IDE_BypassAutoPosition AS _BYTE, idesortsubs AS _BYTE, IDESubsLength AS _BYTE DIM SHARED IDENormalCursorStart AS LONG, IDENormalCursorEnd AS LONG -DIM SHARED IDE_Index$ -DIM SHARED LoadedIDESettings AS INTEGER DIM SHARED MouseButtonSwapped AS _BYTE DIM SHARED PasteCursorAtEnd AS _BYTE DIM SHARED SaveExeWithSource AS _BYTE, EnableQuickNav AS _BYTE @@ -17,554 +15,481 @@ DIM SHARED IgnoreWarnings AS _BYTE, qb64versionprinted AS _BYTE DIM SHARED DisableSyntaxHighlighter AS _BYTE, ExeToSourceFolderFirstTimeMsg AS _BYTE DIM SHARED WhiteListQB64FirstTimeMsg AS _BYTE, ideautolayoutkwcapitals AS _BYTE DIM SHARED IdeAutoComplete AS _BYTE +DIM SHARED windowSettingsSection$, colorSettingsSection$, customDictionarySection$ +DIM SHARED mouseSettingsSection$, generalSettingsSection$, displaySettingsSection$ +DIM SHARED colorSchemesSection$, iniFolderIndex$, DebugInfoIniWarning$, ConfigFile$ -IF LoadedIDESettings = 0 THEN - 'We only want to load the file once when QB64 first starts - 'Other changes should occur to our settings when we change them in their appropiate routines. - 'There's no reason to open and close and open and close the same file a million times. +windowSettingsSection$ = "IDE WINDOW" +colorSettingsSection$ = "IDE COLOR SETTINGS" +colorSchemesSection$ = "IDE COLOR SCHEMES" +customDictionarySection$ = "CUSTOM DICTIONARIES" +mouseSettingsSection$ = "MOUSE SETTINGS" +generalSettingsSection$ = "GENERAL SETTINGS" +displaySettingsSection$ = "IDE DISPLAY SETTINGS" - LoadedIDESettings = -1 +ConfigFile$ = "internal/config.ini" +iniFolderIndex$ = STR$(tempfolderindex) +DebugInfoIniWarning$ = " 'Do not change manually. Use 'qb64 -s', or Options->Advanced in the IDE" - ConfigFile$ = "internal/config.txt" - ConfigBak$ = "internal/config.bak" +IniSetAddQuotes 0 +IniSetForceReload -1 +IniSetAllowBasicComments -1 +IniSetAutoCommit -1 - GOSUB CheckConfigFileExists 'make certain the config file exists and if not, create one - - result = ReadConfigSetting("AllowIndependentSettings", value$) - IF result THEN - IF value$ = "TRUE" OR ABS(VAL(value$)) = 1 THEN 'We default to false and only use one set of IDE settings, no matter how many windows we open up - IDE_Index$ = "(" + LTRIM$(RTRIM$(STR$(tempfolderindex))) + ")" - ConfigFile$ = "internal/config" + IDE_Index$ + ".txt" - ConfigBak$ = "internal/config" + IDE_Index$ + ".bak" - GOSUB CheckConfigFileExists - ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "AllowIndependentSettings", "FALSE" - IDE_Index$ = "" - END IF - ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "AllowIndependentSettings", "FALSE" - IDE_Index$ = "" - END IF - - result = ReadConfigSetting("ConfigVersion", value$) 'Not really used for anything at this point, but might be important in the future. - ConfigFileVersion = VAL(value$) 'We'll get a config file version of 0 if there isn't any in the file - - result = ReadConfigSetting("CommentColor", value$) - IF result THEN - IDECommentColor = VRGBS(value$, _RGB32(98,98,98)) - ELSE - IDECommentColor = _RGB32(98,98,98) - WriteConfigSetting "'[IDE COLOR SETTINGS]", "CommentColor", "_RGB32(98,98,98)" - END IF - - result = ReadConfigSetting("CustomKeywords$", value$) - IF result THEN - tempList$ = "" - listOfCustomKeywords$ = "@" + UCASE$(value$) + "@" - FOR i = 1 TO LEN (listOfCustomKeywords$) - checkChar = ASC(listOfCustomKeywords$, i) - IF checkChar = 64 THEN - IF RIGHT$(tempList$, 1) <> "@" THEN tempList$ = tempList$ + "@" - ELSE - tempList$ = tempList$ + CHR$(checkChar) - END IF - NEXT - listOfCustomKeywords$ = tempList$ - customKeywordsLength = LEN(listOfCustomKeywords$) - ELSE - WriteConfigSetting "'[CUSTOM DICTIONARIES]", "CustomKeywordsSyntax$", "@custom@keywords@separated@by@the@at@sign@" - WriteConfigSetting "'[CUSTOM DICTIONARIES]", "CustomKeywords$", "@" - END IF - - result = ReadConfigSetting("MetaCommandColor", value$) - IF result THEN - IDEMetaCommandColor = VRGBS(value$, _RGB32(85,206,85)) - ELSE - IDEMetaCommandColor = _RGB32(85,206,85) - WriteConfigSetting "'[IDE COLOR SETTINGS]", "MetaCommandColor", "_RGB32(85,206,85)" - END IF - - result = ReadConfigSetting("KeywordColor", value$) - IF result THEN - IDEKeywordColor = VRGBS(value$, _RGB32(69,118,147)) - ELSE - IDEKeywordColor = _RGB32(69,118,147) - WriteConfigSetting "'[IDE COLOR SETTINGS]", "KeywordColor", "_RGB32(69,118,147)" - END IF - - result = ReadConfigSetting("HighlightColor", value$) - IF result THEN - IDEBracketHighlightColor = VRGBS(value$, _RGB32(0,88,108)) - ELSE - IDEBracketHighlightColor = _RGB32(0,88,108) - WriteConfigSetting "'[IDE COLOR SETTINGS]", "HighlightColor", "_RGB32(0,88,108)" - END IF - - result = ReadConfigSetting("NumbersColor", value$) - IF result THEN - IDENumbersColor = VRGBS(value$, _RGB32(216,98,78)) - ELSE - IDENumbersColor = _RGB32(216,98,78) - WriteConfigSetting "'[IDE COLOR SETTINGS]", "NumbersColor", "_RGB32(216,98,78)" - END IF - - result = ReadConfigSetting("QuoteColor", value$) - IF result THEN - IDEQuoteColor = VRGBS(value$, _RGB32(255,167,0)) - ELSE - IDEQuoteColor = _RGB32(255,167,0) - WriteConfigSetting "'[IDE COLOR SETTINGS]", "QuoteColor", "_RGB32(255,167,0)" - END IF - - result = ReadConfigSetting("TextColor", value$) - IF result THEN - IDETextColor = VRGBS(value$, _RGB32(216,216,216)) - ELSE - IDETextColor = _RGB32(216,216,216) - WriteConfigSetting "'[IDE COLOR SETTINGS]", "TextColor", "_RGB32(216,216,216)" - END IF - - result = ReadConfigSetting("BackgroundColor", value$) - IF result THEN - IDEBackGroundColor = VRGBS(value$, _RGB32(0,0,39)) - ELSE - IDEBackGroundColor = _RGB32(0,0,39) - WriteConfigSetting "'[IDE COLOR SETTINGS]", "BackgroundColor", "_RGB32(0,0,39)" - END IF - - result = ReadConfigSetting("BackgroundColor2", value$) - IF result THEN - IDEBackGroundColor2 = VRGBS(value$, _RGB32(0,49,78)) - ELSE - IDEBackGroundColor2 = _RGB32(0,49,78) - WriteConfigSetting "'[IDE COLOR SETTINGS]", "BackgroundColor2", "_RGB32(0,49,78)" - END IF - - result = ReadConfigSetting("SwapMouseButton", value$) - if value$ = "TRUE" or val(value$) = -1 then - MouseButtonSwapped = -1 - WriteConfigSetting "'[MOUSE SETTINGS]", "SwapMouseButton", "TRUE" - else - MouseButtonSwapped = 0 - WriteConfigSetting "'[MOUSE SETTINGS]", "SwapMouseButton", "FALSE" - end if - - result = ReadConfigSetting("DisableSyntaxHighlighter", value$) - IF value$ = "TRUE" OR VAL(value$) = -1 THEN - DisableSyntaxHighlighter = -1 - WriteConfigSetting "'[GENERAL SETTINGS]", "DisableSyntaxHighlighter", "TRUE" - ELSE - DisableSyntaxHighlighter = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "DisableSyntaxHighlighter", "FALSE" - END IF - - result = ReadConfigSetting("PasteCursorAtEnd", value$) - IF result THEN - IF value$ = "TRUE" OR VAL(value$) = -1 THEN - PasteCursorAtEnd = -1 - ELSE - PasteCursorAtEnd = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "PasteCursorAtEnd", "FALSE" - END IF - ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "PasteCursorAtEnd", "TRUE" - PasteCursorAtEnd = -1 - END IF - - result = ReadConfigSetting("ExeToSourceFolderFirstTimeMsg", value$) - IF result THEN - IF value$ = "TRUE" OR VAL(value$) = -1 THEN - ExeToSourceFolderFirstTimeMsg = -1 - ELSE - ExeToSourceFolderFirstTimeMsg = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "ExeToSourceFolderFirstTimeMsg", "FALSE" - END IF - ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "ExeToSourceFolderFirstTimeMsg", "FALSE" - ExeToSourceFolderFirstTimeMsg = 0 - END IF - - result = ReadConfigSetting("WhiteListQB64FirstTimeMsg", value$) - IF result THEN - IF value$ = "TRUE" OR VAL(value$) = -1 THEN - WhiteListQB64FirstTimeMsg = -1 - ELSE - WhiteListQB64FirstTimeMsg = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "WhiteListQB64FirstTimeMsg", "FALSE" - END IF - ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "WhiteListQB64FirstTimeMsg", "FALSE" - WhiteListQB64FirstTimeMsg = 0 - END IF - - result = ReadConfigSetting("SaveExeWithSource", value$) - IF result THEN - IF value$ = "TRUE" OR VAL(value$) = -1 THEN - SaveExeWithSource = -1 - ELSE - SaveExeWithSource = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "SaveExeWithSource", "FALSE" - END IF - ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "SaveExeWithSource", "FALSE" - SaveExeWithSource = 0 - END IF - - result = ReadConfigSetting("EnableQuickNav", value$) - IF result THEN - IF value$ = "TRUE" OR VAL(value$) = -1 THEN - EnableQuickNav = -1 - ELSE - EnableQuickNav = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "EnableQuickNav", "FALSE" - END IF - ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "EnableQuickNav", "TRUE" - EnableQuickNav = -1 - END IF - - result = ReadConfigSetting("IDE_SortSUBs", value$) - IF result THEN - IF value$ = "TRUE" OR VAL(value$) = -1 THEN - idesortsubs = -1 - ELSE - idesortsubs = 0 - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_SortSUBs", "FALSE" - END IF - ELSE - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_SortSUBs", "FALSE" - idesortsubs = 0 - END IF - - result = ReadConfigSetting("IDE_KeywordCapital", value$) - IF result THEN - IF value$ = "TRUE" OR VAL(value$) = -1 THEN - ideautolayoutkwcapitals = -1 - ELSE - ideautolayoutkwcapitals = 0 - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_KeywordCapital", "FALSE" - END IF - ELSE - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_KeywordCapital", "FALSE" - ideautolayoutkwcapitals = 0 - END IF - - result = ReadConfigSetting("IDE_SUBsLength", value$) - IF result THEN - IF value$ = "TRUE" OR VAL(value$) = -1 THEN - IDESubsLength = -1 - ELSE - IDESubsLength = 0 - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_SUBsLength", "FALSE" - END IF - ELSE - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_SUBsLength", "TRUE" - IDESubsLength = -1 - END IF - - result = ReadConfigSetting("ShowErrorsImmediately", value$) - IF result THEN - IF value$ = "TRUE" OR VAL(value$) = -1 THEN - IDEShowErrorsImmediately = -1 - ELSE - IDEShowErrorsImmediately = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "ShowErrorsImmediately", "FALSE" - END IF - ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "ShowErrorsImmediately", "TRUE" - IDEShowErrorsImmediately = -1 - END IF - - result = ReadConfigSetting("ShowLineNumbers", value$) - IF result THEN - IF value$ = "TRUE" OR VAL(value$) = -1 THEN - ShowLineNumbers = -1 - ELSE - ShowLineNumbers = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "ShowLineNumbers", "FALSE" - END IF - ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "ShowLineNumbers", "TRUE" - ShowLineNumbers = -1 - END IF - - result = ReadConfigSetting("ShowLineNumbersSeparator", value$) - IF result THEN - IF value$ = "TRUE" OR VAL(value$) = -1 THEN - ShowLineNumbersSeparator = -1 - ELSE - ShowLineNumbersSeparator = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "ShowLineNumbersSeparator", "FALSE" - END IF - ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "ShowLineNumbersSeparator", "TRUE" - ShowLineNumbersSeparator = -1 - END IF - - result = ReadConfigSetting("ShowLineNumbersUseBG", value$) - IF result THEN - IF value$ = "TRUE" OR VAL(value$) = -1 THEN - ShowLineNumbersUseBG = -1 - ELSE - ShowLineNumbersUseBG = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "ShowLineNumbersUseBG", "FALSE" - END IF - ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "ShowLineNumbersUseBG", "TRUE" - ShowLineNumbersUseBG = -1 - END IF - - result = ReadConfigSetting("BracketHighlight", value$) - IF result THEN - IF value$ = "TRUE" OR VAL(value$) = -1 THEN - brackethighlight = -1 - ELSE - brackethighlight = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "BracketHighlight", "FALSE" - END IF - ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "BracketHighlight", "TRUE" - brackethighlight = -1 - END IF - - result = ReadConfigSetting("KeywordHighlight", value$) - IF result THEN - IF value$ = "TRUE" OR VAL(value$) = -1 THEN - keywordHighlight = -1 - ELSE - keywordHighlight = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "KeywordHighlight", "FALSE" - END IF - ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "KeywordHighlight", "TRUE" - keywordHighlight = -1 - END IF - - result = ReadConfigSetting("MultiHighlight", value$) - IF result THEN - IF value$ = "TRUE" OR VAL(value$) = -1 THEN - multihighlight = -1 - ELSE - multihighlight = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "MultiHighlight", "FALSE" - END IF - ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "MultiHighlight", "TRUE" - multihighlight = -1 - END IF - - result = ReadConfigSetting("IgnoreWarnings", value$) - IF result THEN - IF UCASE$(value$) = "TRUE" OR ABS(VAL(value$)) = 1 THEN - IgnoreWarnings = -1 - ELSE - IgnoreWarnings = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "IgnoreWarnings", "FALSE" - END IF - ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "IgnoreWarnings", "FALSE" - IgnoreWarnings = 0 - END IF - - result = ReadConfigSetting("IdeAutoComplete", value$) - IF result THEN - IF UCASE$(value$) = "TRUE" OR ABS(VAL(value$)) = 1 THEN - IdeAutoComplete = -1 - ELSE - IdeAutoComplete = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "IdeAutoComplete", "FALSE" - END IF - ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "IdeAutoComplete", "TRUE" - IdeAutoComplete = -1 - END IF - - IF INSTR(_OS$, "WIN") THEN - result = ReadConfigSetting("IDE_AutoPosition", value$) - IF result THEN - IF UCASE$(value$) = "TRUE" OR ABS(VAL(value$)) = 1 THEN - IDE_AutoPosition = -1 - ELSE - IDE_AutoPosition = 0 - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoPosition", "FALSE" - END IF - ELSE - IDE_AutoPosition = -1 - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoPosition", "TRUE" - END IF - - result = ReadConfigSetting("IDE_TopPosition", value$) - IF result THEN - IDE_TopPosition = VAL(value$) - ELSE - IDE_BypassAutoPosition = -1 'If there's no position saved in the file, then we certainly don't need to try and auto-position to our last setting. - IDE_TopPosition = 0 - END IF - - result = ReadConfigSetting("IDE_LeftPosition", value$) - IF result THEN - IDE_LeftPosition = VAL(value$) - ELSE - IDE_BypassAutoPosition = -1 'If there's no position saved in the file, then we certainly don't need to try and auto-position to our last setting. - IDE_LeftPosition = 0 - END IF - - 'I was going to do some basic error checking for screen position to make certain that we appeared on the monitor, - 'but I decided not to. Some people (like me) may have multiple monitors set up and may wish for QB64 to pop-up at - 'a coordinate which seems insane at first glance (-1000,0 for instance), but which may move the IDE window to the - 'second monitor instead of the primary one. - 'I'm going to trust that the user doesn't go crazy and enter values like IDE_TopPosition = 123456789 or something insane... - - ELSE 'Linux doesn't work with _SCREENY or _SCREENY, so it's impossible to move the IDE properly. - 'These settings aren't included and are always set FALSE for them. - IDE_AutoPosition = 0 - IDE_TopPosition = 0 - IDE_LeftPosition = 0 - END IF - - result = ReadConfigSetting("IDE_NormalCursorStart", value$) - IDENormalCursorStart = VAL(value$) - IF IDENormalCursorStart < 0 OR IDENormalCursorStart > 31 OR result = 0 THEN IDENormalCursorStart = 8: WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_NormalCursorStart", "8" - - result = ReadConfigSetting("IDE_NormalCursorEnd", value$) - IDENormalCursorEnd = VAL(value$) - IF IDENormalCursorEnd < 0 OR IDENormalCursorEnd > 31 OR result = 0 THEN IDENormalCursorEnd = 8: WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_NormalCursorEnd", "8" - - result = ReadConfigSetting("IDE_Width", value$) - idewx = VAL(value$) - IF idewx < 80 OR idewx > 1000 THEN idewx = 80: WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_Width", "80" - - result = ReadConfigSetting("IDE_Height", value$) - idewy = VAL(value$) - IF idewy < 25 OR idewy > 1000 THEN idewy = 25: WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_Height", "25" - - result = ReadConfigSetting("IDE_AutoFormat", value$) - ideautolayout = VAL(value$) - IF UCASE$(value$) = "TRUE" OR ideautolayout <> 0 THEN - ideautolayout = 1 - ELSE - IF UCASE$(value$) <> "FALSE" AND value$ <> "0" THEN - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoFormat", "TRUE" - ideautolayout = 1 - else - ideautolayout = 0 - end if - END IF - - result = ReadConfigSetting("IDE_AutoIndent", value$) - ideautoindent = VAL(value$) - IF UCASE$(value$) = "TRUE" OR ideautoindent <> 0 THEN - ideautoindent = 1 - ELSE - IF UCASE$(value$) <> "FALSE" AND value$ <> "0" THEN - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoIndent", "TRUE" - ideautoindent = 1 - else - ideautoindent = 0 - end if - END IF - - result = ReadConfigSetting("IDE_IndentSUBs", value$) - ideindentsubs = VAL(value$) - IF UCASE$(value$) = "TRUE" OR ideindentsubs <> 0 THEN - ideindentsubs = 1 - ELSE - IF UCASE$(value$) <> "FALSE" AND value$ <> "0" THEN - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_IndentSUBs", "TRUE" - ideindentsubs = 1 - else - ideindentsubs = 0 - end if - END IF - - result = ReadConfigSetting("IDE_IndentSize", value$) - ideautoindentsize = VAL(value$) - if ideautoindentsize < 1 OR ideautoindentsize > 64 then - ideautoindentsize = 4 - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_IndentSize", "4" - end if - - result = ReadConfigSetting("IDE_CustomFont", value$) - idecustomfont = VAL(value$) - IF UCASE$(value$) = "TRUE" OR idecustomfont <> 0 THEN - idecustomfont = 1 - ELSE - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_CustomFont", "FALSE" - idecustomfont = 0 - END IF - - result = ReadConfigSetting("IDE_UseFont8", value$) - IF UCASE$(value$) = "TRUE" THEN - IDE_UseFont8 = 1 - ELSE - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_UseFont8", "FALSE" - IDE_UseFont8 = 0 - END IF - - result = ReadConfigSetting("IDE_CustomFont$", value$) - idecustomfontfile$ = value$ - if result = 0 OR idecustomfontfile$ = "" then - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_CustomFont$", "c:\windows\fonts\lucon.ttf" - idecustomfontfile$ = "c:\windows\fonts\lucon.ttf" - end if - - result = ReadConfigSetting("IDE_CustomFontSize", value$) - idecustomfontheight = VAL(value$) - IF idecustomfontheight < 8 OR idecustomfontheight > 100 THEN idecustomfontheight = 21: WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_CustomFontSize", "21" - - result = ReadConfigSetting("IDE_CodePage", value$) - idecpindex = VAL(value$) - IF idecpindex < 0 OR idecpindex > idecpnum THEN idecpindex = 0: WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_CodePage", "0" - - result = ReadConfigSetting("BackupSize", value$) - idebackupsize = VAL(value$) - IF idebackupsize < 10 OR idebackupsize > 2000 THEN idebackupsize = 100: WriteConfigSetting "'[GENERAL SETTINGS]", "BackupSize", "100 'in MB" - - result = ReadConfigSetting("DebugInfo", value$) - idedebuginfo = VAL(value$) - IF UCASE$(LEFT$(value$, 4)) = "TRUE" THEN idedebuginfo = 1 - IF result = 0 OR idedebuginfo <> 1 THEN - WriteConfigSetting "'[GENERAL SETTINGS]", "DebugInfo", "FALSE 'INTERNAL VARIABLE USE ONLY!! DO NOT MANUALLY CHANGE!" - idedebuginfo = 0 - END IF - Include_GDB_Debugging_Info = idedebuginfo - - GOTO SkipCheckConfigFileExists - CheckConfigFileExists: - IF _FILEEXISTS(ConfigFile$) = 0 THEN - 'There's no config file in the folder. Let's make one for future use. - IF ConfigFile$ = "internal/config.txt" THEN 'It's the main file which we use for default/global settings - WriteConfigSetting "'[CONFIG VERSION]", "ConfigVersion", "1" - IF INSTR(_OS$, "WIN") THEN WriteConfigSetting "'[GENERAL SETTINGS]", "AllowIndependentSettings", "FALSE" - WriteConfigSetting "'[GENERAL SETTINGS]", "BackupSize", "100 'in MB" - WriteConfigSetting "'[GENERAL SETTINGS]", "DebugInfo", "FALSE 'INTERNAL VARIABLE USE ONLY!! DO NOT MANUALLY CHANGE!" - WriteConfigSetting "'[IDE COLOR SETTINGS]", "SchemeID", "1" - IF INSTR(_OS$, "WIN") THEN - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoPosition", "TRUE" - END IF - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_Width", "80" - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_Height", "25" - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_IndentSize", "4" - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoIndent", "TRUE" - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoFormat", "TRUE" - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_CustomFontSize", "21" - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_CustomFont$", "c:\windows\fonts\lucon.ttf" - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_CustomFont", "FALSE" - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_CodePage", "0" - WriteConfigSetting "'[MOUSE SETTINGS]", "SwapMouseButton", "FALSE" - ELSE - 'use the main config file as the default values and just copy it over to the new file - f = FREEFILE - OPEN "internal/config.txt" FOR BINARY AS #f - L = LOF(f): temp$ = SPACE$(L) - GET #f, 1, temp$ - CLOSE #f - OPEN ConfigFile$ FOR BINARY AS #f - PUT #f, 1, temp$ - CLOSE #f - END IF - END IF - RETURN - SkipCheckConfigFileExists: +'General settings ------------------------------------------------------------- +result = ReadConfigSetting(generalSettingsSection$, "DisableSyntaxHighlighter", value$) +IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + DisableSyntaxHighlighter = -1 + WriteConfigSetting generalSettingsSection$, "DisableSyntaxHighlighter", "True" +ELSE + DisableSyntaxHighlighter = 0 + WriteConfigSetting generalSettingsSection$, "DisableSyntaxHighlighter", "False" END IF +IF ReadConfigSetting(generalSettingsSection$, "PasteCursorAtEnd", value$) THEN + IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + PasteCursorAtEnd = -1 + ELSE + PasteCursorAtEnd = 0 + WriteConfigSetting generalSettingsSection$, "PasteCursorAtEnd", "False" + END IF +ELSE + PasteCursorAtEnd = -1 + WriteConfigSetting generalSettingsSection$, "PasteCursorAtEnd", "True" +END IF + +IF ReadConfigSetting(generalSettingsSection$, "ExeToSourceFolderFirstTimeMsg", value$) THEN + IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + ExeToSourceFolderFirstTimeMsg = -1 + ELSE + ExeToSourceFolderFirstTimeMsg = 0 + WriteConfigSetting generalSettingsSection$, "ExeToSourceFolderFirstTimeMsg", "False" + END IF +ELSE + ExeToSourceFolderFirstTimeMsg = 0 + WriteConfigSetting generalSettingsSection$, "ExeToSourceFolderFirstTimeMsg", "False" +END IF + +IF ReadConfigSetting(generalSettingsSection$, "WhiteListQB64FirstTimeMsg", value$) THEN + IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + WhiteListQB64FirstTimeMsg = -1 + ELSE + WhiteListQB64FirstTimeMsg = 0 + WriteConfigSetting generalSettingsSection$, "WhiteListQB64FirstTimeMsg", "False" + END IF +ELSE + WhiteListQB64FirstTimeMsg = 0 + WriteConfigSetting generalSettingsSection$, "WhiteListQB64FirstTimeMsg", "False" +END IF + +IF ReadConfigSetting(generalSettingsSection$, "SaveExeWithSource", value$) THEN + IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + SaveExeWithSource = -1 + ELSE + SaveExeWithSource = 0 + WriteConfigSetting generalSettingsSection$, "SaveExeWithSource", "False" + END IF +ELSE + SaveExeWithSource = 0 + WriteConfigSetting generalSettingsSection$, "SaveExeWithSource", "False" +END IF + +IF ReadConfigSetting(generalSettingsSection$, "EnableQuickNav", value$) THEN + IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + EnableQuickNav = -1 + ELSE + EnableQuickNav = 0 + WriteConfigSetting generalSettingsSection$, "EnableQuickNav", "False" + END IF +ELSE + EnableQuickNav = -1 + WriteConfigSetting generalSettingsSection$, "EnableQuickNav", "True" +END IF + +IF ReadConfigSetting(generalSettingsSection$, "ShowErrorsImmediately", value$) THEN + IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + IDEShowErrorsImmediately = -1 + ELSE + IDEShowErrorsImmediately = 0 + WriteConfigSetting generalSettingsSection$, "ShowErrorsImmediately", "False" + END IF +ELSE + IDEShowErrorsImmediately = -1 + WriteConfigSetting generalSettingsSection$, "ShowErrorsImmediately", "True" +END IF + +IF ReadConfigSetting(generalSettingsSection$, "ShowLineNumbers", value$) THEN + IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + ShowLineNumbers = -1 + ELSE + ShowLineNumbers = 0 + WriteConfigSetting generalSettingsSection$, "ShowLineNumbers", "False" + END IF +ELSE + ShowLineNumbers = -1 + WriteConfigSetting generalSettingsSection$, "ShowLineNumbers", "True" +END IF + +IF ReadConfigSetting(generalSettingsSection$, "ShowLineNumbersSeparator", value$) THEN + IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + ShowLineNumbersSeparator = -1 + ELSE + ShowLineNumbersSeparator = 0 + WriteConfigSetting generalSettingsSection$, "ShowLineNumbersSeparator", "False" + END IF +ELSE + ShowLineNumbersSeparator = -1 + WriteConfigSetting generalSettingsSection$, "ShowLineNumbersSeparator", "True" +END IF + +IF ReadConfigSetting(generalSettingsSection$, "ShowLineNumbersUseBG", value$) THEN + IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + ShowLineNumbersUseBG = -1 + ELSE + ShowLineNumbersUseBG = 0 + WriteConfigSetting generalSettingsSection$, "ShowLineNumbersUseBG", "False" + END IF +ELSE + ShowLineNumbersUseBG = -1 + WriteConfigSetting generalSettingsSection$, "ShowLineNumbersUseBG", "True" +END IF + +IF ReadConfigSetting(generalSettingsSection$, "BracketHighlight", value$) THEN + IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + brackethighlight = -1 + ELSE + brackethighlight = 0 + WriteConfigSetting generalSettingsSection$, "BracketHighlight", "False" + END IF +ELSE + brackethighlight = -1 + WriteConfigSetting generalSettingsSection$, "BracketHighlight", "True" +END IF + +IF ReadConfigSetting(generalSettingsSection$, "KeywordHighlight", value$) THEN + IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + keywordHighlight = -1 + ELSE + keywordHighlight = 0 + WriteConfigSetting generalSettingsSection$, "KeywordHighlight", "False" + END IF +ELSE + keywordHighlight = -1 + WriteConfigSetting generalSettingsSection$, "KeywordHighlight", "True" +END IF + +IF ReadConfigSetting(generalSettingsSection$, "MultiHighlight", value$) THEN + IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + multihighlight = -1 + ELSE + multihighlight = 0 + WriteConfigSetting generalSettingsSection$, "MultiHighlight", "False" + END IF +ELSE + multihighlight = -1 + WriteConfigSetting generalSettingsSection$, "MultiHighlight", "True" +END IF + +IF ReadConfigSetting(generalSettingsSection$, "IgnoreWarnings", value$) THEN + IF UCASE$(value$) = "TRUE" OR ABS(VAL(value$)) = 1 THEN + IgnoreWarnings = -1 + ELSE + IgnoreWarnings = 0 + WriteConfigSetting generalSettingsSection$, "IgnoreWarnings", "False" + END IF +ELSE + IgnoreWarnings = 0 + WriteConfigSetting generalSettingsSection$, "IgnoreWarnings", "False" +END IF + +IF ReadConfigSetting(generalSettingsSection$, "IdeAutoComplete", value$) THEN + IF UCASE$(value$) = "TRUE" OR ABS(VAL(value$)) = 1 THEN + IdeAutoComplete = -1 + ELSE + IdeAutoComplete = 0 + WriteConfigSetting generalSettingsSection$, "IdeAutoComplete", "False" + END IF +ELSE + IdeAutoComplete = -1 + WriteConfigSetting generalSettingsSection$, "IdeAutoComplete", "True" +END IF + +result = ReadConfigSetting(generalSettingsSection$, "BackupSize", value$) +idebackupsize = VAL(value$) +IF idebackupsize < 10 OR idebackupsize > 2000 THEN idebackupsize = 100: WriteConfigSetting generalSettingsSection$, "BackupSize", "100 'in MB" + +result = ReadConfigSetting(generalSettingsSection$, "DebugInfo", value$) +idedebuginfo = VAL(value$) +IF UCASE$(LEFT$(value$, 4)) = "TRUE" THEN idedebuginfo = 1 +IF result = 0 OR idedebuginfo <> 1 THEN + WriteConfigSetting generalSettingsSection$, "DebugInfo", "False" + DebugInfoIniWarning$ + idedebuginfo = 0 +END IF +Include_GDB_Debugging_Info = idedebuginfo + +'Mouse settings --------------------------------------------------------------- +result = ReadConfigSetting(mouseSettingsSection$, "SwapMouseButton", value$) +IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + MouseButtonSwapped = -1 + WriteConfigSetting mouseSettingsSection$, "SwapMouseButton", "True" +ELSE + MouseButtonSwapped = 0 + WriteConfigSetting mouseSettingsSection$, "SwapMouseButton", "False" +END IF + +'Display settings ------------------------------------------------------------- +IF ReadConfigSetting(displaySettingsSection$, "IDE_SortSUBs", value$) THEN + IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + idesortsubs = -1 + ELSE + idesortsubs = 0 + WriteConfigSetting displaySettingsSection$, "IDE_SortSUBs", "False" + END IF +ELSE + idesortsubs = 0 + WriteConfigSetting displaySettingsSection$, "IDE_SortSUBs", "False" +END IF + +IF ReadConfigSetting(displaySettingsSection$, "IDE_KeywordCapital", value$) THEN + IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + ideautolayoutkwcapitals = -1 + ELSE + ideautolayoutkwcapitals = 0 + WriteConfigSetting displaySettingsSection$, "IDE_KeywordCapital", "False" + END IF +ELSE + ideautolayoutkwcapitals = 0 + WriteConfigSetting displaySettingsSection$, "IDE_KeywordCapital", "False" +END IF + +IF ReadConfigSetting(displaySettingsSection$, "IDE_SUBsLength", value$) THEN + IF UCASE$(value$) = "TRUE" OR VAL(value$) = -1 THEN + IDESubsLength = -1 + ELSE + IDESubsLength = 0 + WriteConfigSetting displaySettingsSection$, "IDE_SUBsLength", "False" + END IF +ELSE + IDESubsLength = -1 + WriteConfigSetting displaySettingsSection$, "IDE_SUBsLength", "True" +END IF + +IF ReadConfigSetting(displaySettingsSection$, "IDE_AutoPosition", value$) THEN + IF UCASE$(value$) = "TRUE" OR ABS(VAL(value$)) = 1 THEN + IDE_AutoPosition = -1 + ELSE + IDE_AutoPosition = 0 + WriteConfigSetting displaySettingsSection$, "IDE_AutoPosition", "False" + END IF +ELSE + IDE_AutoPosition = -1 + WriteConfigSetting displaySettingsSection$, "IDE_AutoPosition", "True" +END IF + +result = ReadConfigSetting(displaySettingsSection$, "IDE_NormalCursorStart", value$) +IDENormalCursorStart = VAL(value$) +IF IDENormalCursorStart < 0 OR IDENormalCursorStart > 31 OR result = 0 THEN + IDENormalCursorStart = 8 + WriteConfigSetting displaySettingsSection$, "IDE_NormalCursorStart", "8" +END IF + +result = ReadConfigSetting(displaySettingsSection$, "IDE_NormalCursorEnd", value$) +IDENormalCursorEnd = VAL(value$) +IF IDENormalCursorEnd < 0 OR IDENormalCursorEnd > 31 OR result = 0 THEN + IDENormalCursorEnd = 8 + WriteConfigSetting displaySettingsSection$, "IDE_NormalCursorEnd", "8" +END IF + +result = ReadConfigSetting(displaySettingsSection$, "IDE_AutoFormat", value$) +ideautolayout = VAL(value$) +IF UCASE$(value$) = "TRUE" OR ideautolayout <> 0 THEN + ideautolayout = 1 +ELSE + IF UCASE$(value$) <> "FALSE" AND value$ <> "0" THEN + WriteConfigSetting displaySettingsSection$, "IDE_AutoFormat", "True" + ideautolayout = 1 + ELSE + ideautolayout = 0 + END IF +END IF + +result = ReadConfigSetting(displaySettingsSection$, "IDE_AutoIndent", value$) +ideautoindent = VAL(value$) +IF UCASE$(value$) = "TRUE" OR ideautoindent <> 0 THEN + ideautoindent = 1 +ELSE + IF UCASE$(value$) <> "FALSE" AND value$ <> "0" THEN + WriteConfigSetting displaySettingsSection$, "IDE_AutoIndent", "True" + ideautoindent = 1 + ELSE + ideautoindent = 0 + END IF +END IF + +result = ReadConfigSetting(displaySettingsSection$, "IDE_IndentSUBs", value$) +ideindentsubs = VAL(value$) +IF UCASE$(value$) = "TRUE" OR ideindentsubs <> 0 THEN + ideindentsubs = 1 +ELSE + IF UCASE$(value$) <> "FALSE" AND value$ <> "0" THEN + WriteConfigSetting displaySettingsSection$, "IDE_IndentSUBs", "True" + ideindentsubs = 1 + ELSE + ideindentsubs = 0 + END IF +END IF + +result = ReadConfigSetting(displaySettingsSection$, "IDE_IndentSize", value$) +ideautoindentsize = VAL(value$) +IF ideautoindentsize < 1 OR ideautoindentsize > 64 THEN + ideautoindentsize = 4 + WriteConfigSetting displaySettingsSection$, "IDE_IndentSize", "4" +END IF + +result = ReadConfigSetting(displaySettingsSection$, "IDE_CustomFont", value$) +idecustomfont = VAL(value$) +IF UCASE$(value$) = "TRUE" OR idecustomfont <> 0 THEN + idecustomfont = 1 +ELSE + WriteConfigSetting displaySettingsSection$, "IDE_CustomFont", "False" + idecustomfont = 0 +END IF + +result = ReadConfigSetting(displaySettingsSection$, "IDE_UseFont8", value$) +IF UCASE$(value$) = "TRUE" THEN + IDE_UseFont8 = 1 +ELSE + WriteConfigSetting displaySettingsSection$, "IDE_UseFont8", "False" + IDE_UseFont8 = 0 +END IF + +result = ReadConfigSetting(displaySettingsSection$, "IDE_CustomFont$", value$) +idecustomfontfile$ = value$ +IF result = 0 OR idecustomfontfile$ = "" THEN + idecustomfontfile$ = "C:\Windows\Fonts\lucon.ttf" + WriteConfigSetting displaySettingsSection$, "IDE_CustomFont$", idecustomfontfile$ +END IF + +result = ReadConfigSetting(displaySettingsSection$, "IDE_CustomFontSize", value$) +idecustomfontheight = VAL(value$) +IF idecustomfontheight < 8 OR idecustomfontheight > 100 THEN idecustomfontheight = 21: WriteConfigSetting displaySettingsSection$, "IDE_CustomFontSize", "21" + +result = ReadConfigSetting(displaySettingsSection$, "IDE_CodePage", value$) +idecpindex = VAL(value$) +IF idecpindex < 0 OR idecpindex > idecpnum THEN idecpindex = 0: WriteConfigSetting displaySettingsSection$, "IDE_CodePage", "0" + +'Color settings --------------------------------------------------------------- +'Schemes: +IniSetAddQuotes -1 +WriteConfigSetting colorSchemesSection$, "Instructions1", "Create custom color schemes in the IDE (Options->IDE Colors)." +WriteConfigSetting colorSchemesSection$, "Instructions2", "Custom color schemes will be stored in this section." +IniSetAddQuotes 0 + +'Defaults: (= Super Dark Blue scheme, as of v1.5) +IDETextColor = _RGB32(216, 216, 216) +IDEKeywordColor = _RGB32(69, 118, 147) +IDENumbersColor = _RGB32(216, 98, 78) +IDEQuoteColor = _RGB32(255, 167, 0) +IDEMetaCommandColor = _RGB32(85, 206, 85) +IDECommentColor = _RGB32(98, 98, 98) +IDEBackgroundColor = _RGB32(0, 0, 39) +IDEBackgroundColor2 = _RGB32(0, 49, 78) +IDEBracketHighlightColor = _RGB32(0, 88, 108) + +'Manual/unsaved color settings: +IF ReadConfigSetting(colorSettingsSection$, "SchemeID", value$) = 0 THEN + WriteConfigSetting colorSettingsSection$, "SchemeID", "1" +END IF + +IF ReadConfigSetting(colorSettingsSection$, "TextColor", value$) THEN + IDETextColor = VRGBS(value$, IDETextColor) +ELSE WriteConfigSetting colorSettingsSection$, "TextColor", rgbs$(IDETextColor) +END IF + +IF ReadConfigSetting(colorSettingsSection$, "KeywordColor", value$) THEN + IDEKeywordColor = VRGBS(value$, IDEKeywordColor) +ELSE WriteConfigSetting colorSettingsSection$, "KeywordColor", rgbs$(IDEKeywordColor) +END IF + +IF ReadConfigSetting(colorSettingsSection$, "NumbersColor", value$) THEN + IDENumbersColor = VRGBS(value$, IDENumbersColor) +ELSE WriteConfigSetting colorSettingsSection$, "NumbersColor", rgbs$(IDENumbersColor) +END IF + +IF ReadConfigSetting(colorSettingsSection$, "QuoteColor", value$) THEN + IDEQuoteColor = VRGBS(value$, IDEQuoteColor) +ELSE WriteConfigSetting colorSettingsSection$, "QuoteColor", rgbs$(IDEQuoteColor) +END IF + +IF ReadConfigSetting(colorSettingsSection$, "CommentColor", value$) THEN + IDECommentColor = VRGBS(value$, IDECommentColor) +ELSE WriteConfigSetting colorSettingsSection$, "CommentColor", rgbs$(IDECommentColor) +END IF + +IF ReadConfigSetting(colorSettingsSection$, "MetaCommandColor", value$) THEN + IDEMetaCommandColor = VRGBS(value$, IDEMetaCommandColor) +ELSE WriteConfigSetting colorSettingsSection$, "MetaCommandColor", rgbs$(IDEMetaCommandColor) +END IF + +IF ReadConfigSetting(colorSettingsSection$, "HighlightColor", value$) THEN + IDEBracketHighlightColor = VRGBS(value$, IDEBracketHighlightColor) +ELSE WriteConfigSetting colorSettingsSection$, "HighlightColor", rgbs$(IDEBracketHighlightColor) +END IF + +IF ReadConfigSetting(colorSettingsSection$, "BackgroundColor", value$) THEN + IDEBackgroundColor = VRGBS(value$, IDEBackgroundColor) +ELSE WriteConfigSetting colorSettingsSection$, "BackgroundColor", rgbs$(IDEBackgroundColor) +END IF + +IF ReadConfigSetting(colorSettingsSection$, "BackgroundColor2", value$) THEN + IDEBackgroundColor2 = VRGBS(value$, IDEBackgroundColor2) +ELSE WriteConfigSetting colorSettingsSection$, "BackgroundColor2", rgbs$(IDEBackgroundColor2) +END IF + +'Custom keywords -------------------------------------------------------------- +IF ReadConfigSetting(customDictionarySection$, "CustomKeywords$", value$) THEN + tempList$ = "" + listOfCustomKeywords$ = "@" + UCASE$(value$) + "@" + FOR I = 1 TO LEN(listOfCustomKeywords$) + checkChar = ASC(listOfCustomKeywords$, I) + IF checkChar = 64 THEN + IF RIGHT$(tempList$, 1) <> "@" THEN tempList$ = tempList$ + "@" + ELSE + tempList$ = tempList$ + CHR$(checkChar) + END IF + NEXT + listOfCustomKeywords$ = tempList$ + customKeywordsLength = LEN(listOfCustomKeywords$) +ELSE + IniSetAddQuotes -1 + WriteConfigSetting customDictionarySection$, "Instructions1", "Add custom keywords @separated@by@the@at@sign@ below." + WriteConfigSetting customDictionarySection$, "Instructions2", "Useful to colorize constants (eg @true@false@)." + IniSetAddQuotes 0 + WriteConfigSetting customDictionarySection$, "CustomKeywords$", "@" +END IF + +'Individual window settings (different for each running instance) ------------- +IF ReadConfigSetting(windowSettingsSection$ + iniFolderIndex$, "IDE_TopPosition", value$) THEN + IDE_TopPosition = VAL(value$) +ELSE + IDE_BypassAutoPosition = -1 'If there's no position saved in the file, then we certainly don't need to try and auto-position to our last setting. + IDE_TopPosition = 0 +END IF + +IF ReadConfigSetting(windowSettingsSection$ + iniFolderIndex$, "IDE_LeftPosition", value$) THEN + IDE_LeftPosition = VAL(value$) +ELSE + IDE_BypassAutoPosition = -1 'If there's no position saved in the file, then we certainly don't need to try and auto-position to our last setting. + IDE_LeftPosition = 0 +END IF + +result = ReadConfigSetting(windowSettingsSection$ + iniFolderIndex$, "IDE_Width", value$) +idewx = VAL(value$) +IF idewx < 80 OR idewx > 1000 THEN idewx = 80: WriteConfigSetting windowSettingsSection$ + iniFolderIndex$, "IDE_Width", "80" + +result = ReadConfigSetting(windowSettingsSection$ + iniFolderIndex$, "IDE_Height", value$) +idewy = VAL(value$) +IF idewy < 25 OR idewy > 1000 THEN idewy = 25: WriteConfigSetting windowSettingsSection$ + iniFolderIndex$, "IDE_Height", "25" + +'End of initial settings ------------------------------------------------------ + diff --git a/source/ide/ide_methods.bas b/source/ide/ide_methods.bas index b5f58219d..ca7aad538 100644 --- a/source/ide/ide_methods.bas +++ b/source/ide/ide_methods.bas @@ -246,7 +246,7 @@ FUNCTION ide2 (ignore) idecustomfonthandle = _LOADFONT(idecustomfontfile$, idecustomfontheight, "MONOSPACE") IF idecustomfonthandle = -1 THEN 'failed! - revert to default settings - idecustomfont = 0: idecustomfontfile$ = "c:\windows\fonts\lucon.ttf": idecustomfontheight = 21 + idecustomfont = 0: idecustomfontfile$ = "C:\Windows\Fonts\lucon.ttf": idecustomfontheight = 21 ELSE _FONT idecustomfonthandle END IF @@ -856,8 +856,8 @@ FUNCTION ide2 (ignore) LOOP WHILE _RESIZE IF retval = 1 THEN 'screen dimensions have changed and everything must be redrawn/reapplied - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_Width", STR$(idewx) - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_Height", STR$(idewy) + WriteConfigSetting windowSettingsSection$ + iniFolderIndex$, "IDE_Width", STR$(idewx) + WriteConfigSetting windowSettingsSection$ + iniFolderIndex$, "IDE_Height", STR$(idewy) END IF retval = 1 @@ -1041,7 +1041,7 @@ FUNCTION ide2 (ignore) PCOPY 3, 0: SCREEN , , 3, 0 IF result = 2 THEN - WriteConfigSetting "'[GENERAL SETTINGS]", "WhiteListQB64FirstTimeMsg", "TRUE" + WriteConfigSetting generalSettingsSection$, "WhiteListQB64FirstTimeMsg", "True" END IF WhiteListQB64FirstTimeMsg = -1 END IF @@ -1236,8 +1236,8 @@ FUNCTION ide2 (ignore) IF IDE_AutoPosition THEN IF IDE_TopPosition <> _SCREENY OR IDE_LeftPosition <> _SCREENX THEN IF _SCREENY >= -_HEIGHT * _FONTHEIGHT AND _SCREENX >= -_WIDTH * _FONTWIDTH THEN 'Don't record the position if it's off the screen, past the point where we can drag it back into a different position. - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_TopPosition", STR$(_SCREENY) - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_LeftPosition", STR$(_SCREENX) + WriteConfigSetting windowSettingsSection$ + iniFolderIndex$, "IDE_TopPosition", STR$(_SCREENY) + WriteConfigSetting windowSettingsSection$ + iniFolderIndex$, "IDE_LeftPosition", STR$(_SCREENX) IDE_TopPosition = _SCREENY: IDE_LeftPosition = _SCREENX END IF END IF @@ -1518,7 +1518,7 @@ FUNCTION ide2 (ignore) "Folder' in the Run menu.", "#OK;#Don't show this again;#Cancel") END IF IF result = 2 THEN - WriteConfigSetting "'[GENERAL SETTINGS]", "ExeToSourceFolderFirstTimeMsg", "TRUE" + WriteConfigSetting generalSettingsSection$, "ExeToSourceFolderFirstTimeMsg", "True" ExeToSourceFolderFirstTimeMsg = -1 ELSEIF result = 3 THEN PCOPY 3, 0: SCREEN , , 3, 0 @@ -2775,10 +2775,6 @@ FUNCTION ide2 (ignore) GET #backupIncludeFile, 1, tempInclude1$ CLOSE #backupIncludeFile - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoPosition", "FALSE" - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_Width", "80" - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_Height", "25" - SCREEN , , 3, 0 clearStatusWindow COLOR 15, 1 @@ -2795,12 +2791,6 @@ FUNCTION ide2 (ignore) END IF SHELL p$ - IF IDE_AutoPosition THEN - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoPosition", "TRUE" - END IF - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_Width", STR$(idewx) - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_Height", STR$(idewy) - OPEN f$ FOR BINARY AS #backupIncludeFile tempInclude2$ = SPACE$(LOF(backupIncludeFile)) GET #backupIncludeFile, 1, tempInclude2$ @@ -4719,10 +4709,10 @@ FUNCTION ide2 (ignore) PCOPY 2, 0 MouseButtonSwapped = NOT MouseButtonSwapped IF MouseButtonSwapped THEN - WriteConfigSetting "'[MOUSE SETTINGS]", "SwapMouseButton", "TRUE" + WriteConfigSetting mouseSettingsSection$, "SwapMouseButton", "True" menu$(OptionsMenuID, OptionsMenuSwapMouse) = CHR$(7) + "#Swap Mouse Buttons" ELSE - WriteConfigSetting "'[MOUSE SETTINGS]", "SwapMouseButton", "FALSE" + WriteConfigSetting mouseSettingsSection$, "SwapMouseButton", "False" menu$(OptionsMenuID, OptionsMenuSwapMouse) = "#Swap Mouse Buttons" END IF PCOPY 3, 0: SCREEN , , 3, 0 @@ -4733,10 +4723,10 @@ FUNCTION ide2 (ignore) PCOPY 2, 0 DisableSyntaxHighlighter = NOT DisableSyntaxHighlighter IF DisableSyntaxHighlighter THEN - WriteConfigSetting "'[GENERAL SETTINGS]", "DisableSyntaxHighlighter", "TRUE" + WriteConfigSetting generalSettingsSection$, "DisableSyntaxHighlighter", "True" menu$(OptionsMenuID, OptionsMenuDisableSyntax) = "Syntax #Highlighter" ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "DisableSyntaxHighlighter", "FALSE" + WriteConfigSetting generalSettingsSection$, "DisableSyntaxHighlighter", "False" menu$(OptionsMenuID, OptionsMenuDisableSyntax) = CHR$(7) + "Syntax #Highlighter" END IF PCOPY 3, 0: SCREEN , , 3, 0 @@ -4747,10 +4737,10 @@ FUNCTION ide2 (ignore) PCOPY 2, 0 PasteCursorAtEnd = NOT PasteCursorAtEnd IF PasteCursorAtEnd THEN - WriteConfigSetting "'[GENERAL SETTINGS]", "PasteCursorAtEnd", "TRUE" + WriteConfigSetting generalSettingsSection$, "PasteCursorAtEnd", "True" menu$(OptionsMenuID, OptionsMenuPasteCursor) = CHR$(7) + "Cursor After #Paste" ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "PasteCursorAtEnd", "FALSE" + WriteConfigSetting generalSettingsSection$, "PasteCursorAtEnd", "False" menu$(OptionsMenuID, OptionsMenuPasteCursor) = "Cursor After #Paste" END IF PCOPY 3, 0: SCREEN , , 3, 0 @@ -4761,10 +4751,10 @@ FUNCTION ide2 (ignore) PCOPY 2, 0 IDEShowErrorsImmediately = NOT IDEShowErrorsImmediately IF IDEShowErrorsImmediately THEN - WriteConfigSetting "'[GENERAL SETTINGS]", "ShowErrorsImmediately", "TRUE" + WriteConfigSetting generalSettingsSection$, "ShowErrorsImmediately", "True" menu$(OptionsMenuID, OptionsMenuShowErrorsImmediately) = CHR$(7) + "Syntax Ch#ecker" ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "ShowErrorsImmediately", "FALSE" + WriteConfigSetting generalSettingsSection$, "ShowErrorsImmediately", "False" menu$(OptionsMenuID, OptionsMenuShowErrorsImmediately) = "Syntax Ch#ecker" END IF idechangemade = 1 @@ -4776,11 +4766,11 @@ FUNCTION ide2 (ignore) PCOPY 2, 0 IF IgnoreWarnings = 0 THEN IgnoreWarnings = -1 - WriteConfigSetting "'[GENERAL SETTINGS]", "IgnoreWarnings", "TRUE" + WriteConfigSetting generalSettingsSection$, "IgnoreWarnings", "True" menu$(OptionsMenuID, OptionsMenuIgnoreWarnings) = CHR$(7) + "Ignore #Warnings" ELSE IgnoreWarnings = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "IgnoreWarnings", "FALSE" + WriteConfigSetting generalSettingsSection$, "IgnoreWarnings", "False" menu$(OptionsMenuID, OptionsMenuIgnoreWarnings) = "Ignore #Warnings" END IF idechangemade = 1 @@ -4792,11 +4782,11 @@ FUNCTION ide2 (ignore) PCOPY 2, 0 IF IdeAutoComplete = 0 THEN IdeAutoComplete = -1 - WriteConfigSetting "'[GENERAL SETTINGS]", "IdeAutoComplete", "TRUE" + WriteConfigSetting generalSettingsSection$, "IdeAutoComplete", "True" menu$(OptionsMenuID, OptionsMenuAutoComplete) = CHR$(7) + "Code Suggest#ions" ELSE IdeAutoComplete = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "IdeAutoComplete", "FALSE" + WriteConfigSetting generalSettingsSection$, "IdeAutoComplete", "False" menu$(OptionsMenuID, OptionsMenuAutoComplete) = "Code Suggest#ions" END IF idechangemade = 1 @@ -4808,10 +4798,10 @@ FUNCTION ide2 (ignore) PCOPY 2, 0 SaveExeWithSource = NOT SaveExeWithSource IF SaveExeWithSource THEN - WriteConfigSetting "'[GENERAL SETTINGS]", "SaveExeWithSource", "TRUE" + WriteConfigSetting generalSettingsSection$, "SaveExeWithSource", "True" menu$(RunMenuID, RunMenuSaveExeWithSource) = CHR$(7) + "Output EXE to Source #Folder" ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "SaveExeWithSource", "FALSE" + WriteConfigSetting generalSettingsSection$, "SaveExeWithSource", "False" menu$(RunMenuID, RunMenuSaveExeWithSource) = "Output EXE to Source #Folder" END IF PCOPY 3, 0: SCREEN , , 3, 0 @@ -4823,10 +4813,10 @@ FUNCTION ide2 (ignore) PCOPY 2, 0 EnableQuickNav = NOT EnableQuickNav IF EnableQuickNav THEN - WriteConfigSetting "'[GENERAL SETTINGS]", "EnableQuickNav", "TRUE" + WriteConfigSetting generalSettingsSection$, "EnableQuickNav", "True" menu$(SearchMenuID, SearchMenuEnableQuickNav) = CHR$(7) + "#Quick Navigation" ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "EnableQuickNav", "FALSE" + WriteConfigSetting generalSettingsSection$, "EnableQuickNav", "False" menu$(SearchMenuID, SearchMenuEnableQuickNav) = "#Quick Navigation" END IF PCOPY 3, 0: SCREEN , , 3, 0 @@ -5170,7 +5160,7 @@ FUNCTION ide2 (ignore) IF menu$(m, s) = "#Show Line Numbers" THEN PCOPY 2, 0 ShowLineNumbers = -1 - WriteConfigSetting "'[GENERAL SETTINGS]", "ShowLineNumbers", "TRUE" + WriteConfigSetting generalSettingsSection$, "ShowLineNumbers", "True" menu$(m, s) = "#Hide Line Numbers" menu$(m, ViewMenuShowBGID) = MID$(menu$(m, ViewMenuShowBGID), 2) menu$(m, ViewMenuShowSeparatorID) = MID$(menu$(m, ViewMenuShowSeparatorID), 2) @@ -5181,7 +5171,7 @@ FUNCTION ide2 (ignore) IF menu$(m, s) = "#Hide Line Numbers" THEN PCOPY 2, 0 ShowLineNumbers = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "ShowLineNumbers", "FALSE" + WriteConfigSetting generalSettingsSection$, "ShowLineNumbers", "False" menu$(m, s) = "#Show Line Numbers" menu$(m, ViewMenuShowBGID) = "~" + menu$(m, ViewMenuShowBGID) menu$(m, ViewMenuShowSeparatorID) = "~" + menu$(m, ViewMenuShowSeparatorID) @@ -5194,10 +5184,10 @@ FUNCTION ide2 (ignore) PCOPY 2, 0 ShowLineNumbersUseBG = NOT ShowLineNumbersUseBG IF ShowLineNumbersUseBG THEN - WriteConfigSetting "'[GENERAL SETTINGS]", "ShowLineNumbersUseBG", "TRUE" + WriteConfigSetting generalSettingsSection$, "ShowLineNumbersUseBG", "True" menu$(m, s) = CHR$(7) + "#Background Color" ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "ShowLineNumbersUseBG", "FALSE" + WriteConfigSetting generalSettingsSection$, "ShowLineNumbersUseBG", "False" menu$(m, s) = "#Background Color" END IF PCOPY 3, 0: SCREEN , , 3, 0 @@ -5210,10 +5200,10 @@ FUNCTION ide2 (ignore) PCOPY 2, 0 ShowLineNumbersSeparator = NOT ShowLineNumbersSeparator IF ShowLineNumbersSeparator THEN - WriteConfigSetting "'[GENERAL SETTINGS]", "ShowLineNumbersSeparator", "TRUE" + WriteConfigSetting generalSettingsSection$, "ShowLineNumbersSeparator", "True" menu$(m, s) = CHR$(7) + "Sho#w Separator" ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "ShowLineNumbersSeparator", "FALSE" + WriteConfigSetting generalSettingsSection$, "ShowLineNumbersSeparator", "False" menu$(m, s) = "Sho#w Separator" END IF PCOPY 3, 0: SCREEN , , 3, 0 @@ -8306,7 +8296,7 @@ SUB ideshowtext IF timeElapsedSince(startTime) > 1 THEN result = idemessagebox("Syntax Highlighter Disabled", "Syntax Highlighter has been disabled to avoid slowing down the IDE.\nYou can reenable the Highlighter in the 'Options' menu.", "") DisableSyntaxHighlighter = -1 - WriteConfigSetting "'[GENERAL SETTINGS]", "DisableSyntaxHighlighter", "TRUE" + WriteConfigSetting generalSettingsSection$, "DisableSyntaxHighlighter", "True" menu$(OptionsMenuID, OptionsMenuDisableSyntax) = "Syntax #Highlighter" GOTO noSyntaxHighlighting END IF @@ -9055,15 +9045,15 @@ FUNCTION idesubs$ SaveSortSettings: idesortsubs = SortedSubsFlag IF idesortsubs THEN - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_SortSUBs", "TRUE" + WriteConfigSetting displaySettingsSection$, "IDE_SortSUBs", "True" ELSE - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_SortSUBs", "FALSE" + WriteConfigSetting displaySettingsSection$, "IDE_SortSUBs", "False" END IF IF IDESubsLength THEN - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_SUBsLength", "TRUE" + WriteConfigSetting displaySettingsSection$, "IDE_SUBsLength", "True" ELSE - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_SUBsLength", "FALSE" + WriteConfigSetting displaySettingsSection$, "IDE_SUBsLength", "False" END IF RETURN @@ -9204,7 +9194,7 @@ FUNCTION idelanguagebox 'save changes v% = y: idecpindex = v% - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_CodePage", STR$(idecpindex) + WriteConfigSetting displaySettingsSection$, "IDE_CodePage", STR$(idecpindex) EXIT FUNCTION END IF @@ -10454,25 +10444,25 @@ FUNCTION idelayoutbox IF ideindentsubs <> v% THEN ideindentsubs = v%: idelayoutbox = 1 IF ideautolayout THEN - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoFormat", "TRUE" + WriteConfigSetting displaySettingsSection$, "IDE_AutoFormat", "True" ELSE - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoFormat", "FALSE" + WriteConfigSetting displaySettingsSection$, "IDE_AutoFormat", "False" END IF IF ideautolayoutkwcapitals THEN - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_KeywordCapital", "TRUE" + WriteConfigSetting displaySettingsSection$, "IDE_KeywordCapital", "True" ELSE - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_KeywordCapital", "FALSE" + WriteConfigSetting displaySettingsSection$, "IDE_KeywordCapital", "False" END IF IF ideautoindent THEN - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoIndent", "TRUE" + WriteConfigSetting displaySettingsSection$, "IDE_AutoIndent", "True" ELSE - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoIndent", "FALSE" + WriteConfigSetting displaySettingsSection$, "IDE_AutoIndent", "False" END IF - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_IndentSize", STR$(ideautoindentsize) + WriteConfigSetting displaySettingsSection$, "IDE_IndentSize", STR$(ideautoindentsize) IF ideindentsubs THEN - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_IndentSUBs", "TRUE" + WriteConfigSetting displaySettingsSection$, "IDE_IndentSUBs", "True" ELSE - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_IndentSUBs", "FALSE" + WriteConfigSetting displaySettingsSection$, "IDE_IndentSUBs", "False" END IF EXIT FUNCTION END IF @@ -10506,7 +10496,7 @@ FUNCTION idebackupbox END IF idebackupsize = v& - WriteConfigSetting "'[GENERAL SETTINGS]", "BackupSize", STR$(v&) + " 'in MB" + WriteConfigSetting generalSettingsSection$, "BackupSize", STR$(v&) + " 'in MB" idebackupbox = 1 END FUNCTION @@ -10663,9 +10653,9 @@ FUNCTION ideadvancedbox IF v% <> idedebuginfo THEN idedebuginfo = v% IF idedebuginfo THEN - WriteConfigSetting "'[GENERAL SETTINGS]", "DebugInfo", "TRUE 'INTERNAL VARIABLE USE ONLY!! DO NOT MANUALLY CHANGE!" + WriteConfigSetting generalSettingsSection$, "DebugInfo", "True" + DebugInfoIniWarning$ ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "DebugInfo", "FALSE 'INTERNAL VARIABLE USE ONLY!! DO NOT MANUALLY CHANGE!" + WriteConfigSetting generalSettingsSection$, "DebugInfo", "False" + DebugInfoIniWarning$ END IF Include_GDB_Debugging_Info = idedebuginfo IF os$ = "WIN" THEN @@ -11143,7 +11133,7 @@ FUNCTION idedisplaybox idecustomfonthandle = _LOADFONT(v$, v%, "MONOSPACE") IF idecustomfonthandle = -1 THEN 'failed! - revert to default settings - o(5).sel = 0: idetxt(o(6).txt) = "c:\windows\fonts\lucon.ttf": idetxt(o(7).txt) = "21": IF IDE_UseFont8 THEN _FONT 8 ELSE _FONT 16 + o(5).sel = 0: idetxt(o(6).txt) = "C:\Windows\Fonts\lucon.ttf": idetxt(o(7).txt) = "21": IF IDE_UseFont8 THEN _FONT 8 ELSE _FONT 16 ELSE _FONT idecustomfonthandle END IF @@ -11186,25 +11176,25 @@ FUNCTION idedisplaybox idecustomfontheight = v% - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_Width", STR$(idewx) - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_Height", STR$(idewy) + WriteConfigSetting windowSettingsSection$ + iniFolderIndex$, "IDE_Width", STR$(idewx) + WriteConfigSetting windowSettingsSection$ + iniFolderIndex$, "IDE_Height", STR$(idewy) IF idecustomfont THEN - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_CustomFont", "TRUE" + WriteConfigSetting displaySettingsSection$, "IDE_CustomFont", "True" ELSE - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_CustomFont", "FALSE" + WriteConfigSetting displaySettingsSection$, "IDE_CustomFont", "False" END IF IF IDE_UseFont8 THEN - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_UseFont8", "TRUE" + WriteConfigSetting displaySettingsSection$, "IDE_UseFont8", "True" ELSE - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_UseFont8", "FALSE" + WriteConfigSetting displaySettingsSection$, "IDE_UseFont8", "False" END IF IF IDE_AutoPosition THEN - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoPosition", "TRUE" + WriteConfigSetting displaySettingsSection$, "IDE_AutoPosition", "True" ELSE - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoPosition", "FALSE" + WriteConfigSetting displaySettingsSection$, "IDE_AutoPosition", "False" END IF - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_CustomFont$", idecustomfontfile$ - WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_CustomFontSize", STR$(idecustomfontheight) + WriteConfigSetting displaySettingsSection$, "IDE_CustomFont$", idecustomfontfile$ + WriteConfigSetting displaySettingsSection$, "IDE_CustomFontSize", STR$(idecustomfontheight) EXIT FUNCTION @@ -11327,7 +11317,7 @@ FUNCTION idechoosecolorsbox o(i).txt = idenewtxt("#OK" + sep + "Restore #defaults" + sep + "#Cancel") o(i).dft = 1 - result = ReadConfigSetting("SchemeID", value$) + result = ReadConfigSetting(colorSettingsSection$, "SchemeID", value$) SchemeID = VAL(value$) IF SchemeID > TotalColorSchemes THEN SchemeID = 0 @@ -11559,7 +11549,7 @@ FUNCTION idechoosecolorsbox i = 0 DO i = i + 1 - result = ReadConfigSetting("Scheme" + str2$(i) + "$", value$) + result = ReadConfigSetting(colorSchemesSection$, "Scheme" + str2$(i) + "$", value$) IF value$ = "" OR value$ = "0" THEN EXIT DO LOOP @@ -11585,7 +11575,7 @@ FUNCTION idechoosecolorsbox NEXT j 'Save user scheme - WriteConfigSetting "'[IDE COLOR SCHEMES]", "Scheme" + str2$(i) + "$", SchemeString$ + WriteConfigSetting colorSchemesSection$, "Scheme" + str2$(i) + "$", SchemeString$ LoadColorSchemes SchemeID = PresetColorSchemes + i ChangedScheme = -1 @@ -11623,7 +11613,7 @@ FUNCTION idechoosecolorsbox NEXT j 'Save user scheme - WriteConfigSetting "'[IDE COLOR SCHEMES]", "Scheme" + str2$(i) + "$", SchemeString$ + WriteConfigSetting colorSchemesSection$, "Scheme" + str2$(i) + "$", SchemeString$ LoadColorSchemes SchemeID = PresetColorSchemes + i ChangedScheme = -1 @@ -11639,7 +11629,7 @@ FUNCTION idechoosecolorsbox K$ = "" IF what$ = "Y" THEN i = SchemeID - PresetColorSchemes - WriteConfigSetting "'[IDE COLOR SCHEMES]", "Scheme" + str2$(i) + "$", "0" + WriteConfigSetting colorSchemesSection$, "Scheme" + str2$(i) + "$", "0" LoadColorSchemes SchemeID = SchemeID - 1 ChangedScheme = -1 @@ -11898,7 +11888,7 @@ FUNCTION idechoosecolorsbox 'save changes GOSUB enableHighlighter - WriteConfigSetting "'[IDE COLOR SETTINGS]", "SchemeID", str2$(SchemeID) + WriteConfigSetting colorSettingsSection$, "SchemeID", str2$(SchemeID) FOR i = 1 TO 9 SELECT CASE i CASE 1: CurrentColor~& = IDETextColor: colorid$ = "TextColor" @@ -11911,12 +11901,7 @@ FUNCTION idechoosecolorsbox CASE 8: CurrentColor~& = IDEBackgroundColor2: colorid$ = "BackgroundColor2" CASE 9: CurrentColor~& = IDEBracketHighlightColor: colorid$ = "HighlightColor" END SELECT - r$ = str2$(_RED32(CurrentColor~&)) - g$ = str2$(_GREEN32(CurrentColor~&)) - b$ = str2$(_BLUE32(CurrentColor~&)) - - RGBString$ = "_RGB32(" + r$ + "," + g$ + "," + b$ + ")" - WriteConfigSetting "'[IDE COLOR SETTINGS]", colorid$, RGBString$ + WriteConfigSetting colorSettingsSection$, colorid$, rgbs$(CurrentColor~&) NEXT i v% = o(5).sel @@ -11924,9 +11909,9 @@ FUNCTION idechoosecolorsbox brackethighlight = v% IF brackethighlight THEN - WriteConfigSetting "'[GENERAL SETTINGS]", "BracketHighlight", "TRUE" + WriteConfigSetting generalSettingsSection$, "BracketHighlight", "True" ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "BracketHighlight", "FALSE" + WriteConfigSetting generalSettingsSection$, "BracketHighlight", "False" END IF v% = o(6).sel @@ -11934,9 +11919,9 @@ FUNCTION idechoosecolorsbox multihighlight = v% IF multihighlight THEN - WriteConfigSetting "'[GENERAL SETTINGS]", "MultiHighlight", "TRUE" + WriteConfigSetting generalSettingsSection$, "MultiHighlight", "True" ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "MultiHighlight", "FALSE" + WriteConfigSetting generalSettingsSection$, "MultiHighlight", "False" END IF v% = o(7).sel @@ -11944,9 +11929,9 @@ FUNCTION idechoosecolorsbox keywordHighlight = v% IF keywordHighlight THEN - WriteConfigSetting "'[GENERAL SETTINGS]", "KeywordHighlight", "TRUE" + WriteConfigSetting generalSettingsSection$, "KeywordHighlight", "True" ELSE - WriteConfigSetting "'[GENERAL SETTINGS]", "KeywordHighlight", "FALSE" + WriteConfigSetting generalSettingsSection$, "KeywordHighlight", "False" END IF EXIT FUNCTION @@ -11974,7 +11959,7 @@ FUNCTION idechoosecolorsbox enableHighlighter: IF DisableSyntaxHighlighter THEN DisableSyntaxHighlighter = 0 - WriteConfigSetting "'[GENERAL SETTINGS]", "DisableSyntaxHighlighter", "FALSE" + WriteConfigSetting generalSettingsSection$, "DisableSyntaxHighlighter", "False" menu$(OptionsMenuID, OptionsMenuDisableSyntax) = CHR$(7) + "Syntax #Highlighter" END IF RETURN @@ -14449,7 +14434,7 @@ SUB LoadColorSchemes i = 0 DO i = i + 1 - result = ReadConfigSetting("Scheme" + str2$(i) + "$", value$) + result = ReadConfigSetting(colorSchemesSection$, "Scheme" + str2$(i) + "$", value$) IF result THEN TotalColorSchemes = TotalColorSchemes + 1 IF TotalColorSchemes > UBOUND(ColorSchemes$) THEN @@ -14468,7 +14453,7 @@ SUB LoadColorSchemes temp$ = temp$ + MID$(value$, FoundPipe + 1, 9) + "069147216245128177" temp$ = temp$ + MID$(value$, FoundPipe + 10) + "000147177" ColorSchemes$(TotalColorSchemes) = temp$ - WriteConfigSetting "'[IDE COLOR SCHEMES]", "Scheme" + str2$(i) + "$", temp$ + WriteConfigSetting colorSchemesSection$, "Scheme" + str2$(i) + "$", temp$ LastValidColorScheme = TotalColorSchemes ELSE GOTO DiscardInvalid diff --git a/source/qb64.bas b/source/qb64.bas index cfe1c9648..3b7241bf2 100644 --- a/source/qb64.bas +++ b/source/qb64.bas @@ -14,6 +14,7 @@ $SCREENHIDE '$INCLUDE:'global\settings.bas' '$INCLUDE:'global\constants.bas' '$INCLUDE:'subs_functions\extensions\opengl\opengl_global.bas' +'$INCLUDE:'utilities\ini-manager\ini.bi' DEFLNG A-Z @@ -12991,11 +12992,11 @@ FUNCTION ParseCMDLineArgs$ () IF SaveExeWithSource THEN PRINT "true" ELSE PRINT "false" SYSTEM CASE ":exewithsource=true" - WriteConfigSetting "'[GENERAL SETTINGS]", "SaveExeWithSource", "TRUE" + WriteConfigSetting generalSettingsSection$, "SaveExeWithSource", "True" PRINT "exewithsource = true" SaveExeWithSource = -1 CASE ":exewithsource=false" - WriteConfigSetting "'[GENERAL SETTINGS]", "SaveExeWithSource", "FALSE" + WriteConfigSetting generalSettingsSection$, "SaveExeWithSource", "False" PRINT "exewithsource = false" SaveExeWithSource = 0 CASE ":debuginfo" @@ -13004,7 +13005,7 @@ FUNCTION ParseCMDLineArgs$ () SYSTEM CASE ":debuginfo=true" PRINT "debuginfo = true" - WriteConfigSetting "'[GENERAL SETTINGS]", "DebugInfo", "TRUE 'INTERNAL VARIABLE USE ONLY!! DO NOT MANUALLY CHANGE!" + WriteConfigSetting generalSettingsSection$, "DebugInfo", "True" + DebugInfoIniWarning$ idedebuginfo = 1 Include_GDB_Debugging_Info = idedebuginfo IF os$ = "WIN" THEN @@ -13024,7 +13025,7 @@ FUNCTION ParseCMDLineArgs$ () END IF CASE ":debuginfo=false" PRINT "debuginfo = false" - WriteConfigSetting "'[GENERAL SETTINGS]", "DebugInfo", "FALSE 'INTERNAL VARIABLE USE ONLY!! DO NOT MANUALLY CHANGE!" + WriteConfigSetting generalSettingsSection$, "DebugInfo", "False" + DebugInfoIniWarning$ idedebuginfo = 0 Include_GDB_Debugging_Info = idedebuginfo IF os$ = "WIN" THEN @@ -25063,124 +25064,39 @@ SUB Give_Error (a$) Error_Message = a$ END SUB -SUB WriteConfigSetting (heading$, item$, tvalue$) - value$ = tvalue$ - SHARED ConfigFile$, ConfigBak$ - - InFile = FREEFILE: OPEN ConfigFile$ FOR BINARY AS #InFile - OutFile = FREEFILE: OPEN ConfigBak$ FOR OUTPUT AS #OutFile - placed = 0 - - 'check for quotes where needed for strings - IF RIGHT$(RTRIM$(item$), 1) = "$" THEN - IF LEFT$(value$, 1) <> CHR$(34) THEN value$ = CHR$(34) + value$ - IF RIGHT$(value$, 1) <> CHR$(34) THEN value$ = value$ + CHR$(34) - END IF - - IF LOF(InFile) THEN - DO UNTIL EOF(InFile) - LINE INPUT #InFile, junk$ - 'we really don't care about heading$ here; it's only used to make things easier for the user to locate in the config file - junk$ = LTRIM$(RTRIM$(junk$)) - l = INSTR(junk$, "=") 'compare the values to the left of the equal sign - compare$ = RTRIM$(LEFT$(junk$, l - 1)) - - IF UCASE$(compare$) = UCASE$(item$) THEN 'if it's a match, replace it - PRINT #OutFile, item$; " = "; value$ - placed = -1 - ELSE - PRINT #OutFile, junk$ 'otherwise put that line back and check the next one - END IF - LOOP - END IF - - CLOSE #InFile, #OutFile - KILL ConfigFile$ - IF NOT placed THEN 'we didn't find the proper setting already in the file somewhere. - 'Either the file was corrupted, or the user deleted this particulat setting sometime in the past. - 'Now we look to see if the heading exists in the file or not. - 'If it does, then we place the new setting under that heading. - 'If not then we write that heading to the end of the file to make it easier for the user to locate in the future - 'and then we write it below there. - OPEN ConfigBak$ FOR BINARY AS #InFile - OPEN "internal/config.tmp" FOR OUTPUT AS #OutFile - out$ = item$ + " = " + value$ - DO UNTIL EOF(InFile) OR LOF(InFile) = 0 - LINE INPUT #InFile, temp$ - PRINT #OutFile, temp$ - IF INSTR(temp$, heading$) THEN PRINT #OutFile, out$: placed = -1 'If we have the heading, we want to print the item after it - LOOP - IF NOT placed THEN 'If the heading doesn't exist already then we'll make the heading and the item - PRINT #OutFile, "" - PRINT #OutFile, heading$ - PRINT #OutFile, out$ - END IF - CLOSE #InFile, #OutFile - KILL ConfigBak$ - NAME "internal/config.tmp" AS ConfigFile$ - ELSE - NAME ConfigBak$ AS ConfigFile$ - END IF +SUB WriteConfigSetting (section$, item$, value$) + WriteSetting ConfigFile$, section$, item$, value$ END SUB -FUNCTION ReadConfigSetting (item$, value$) - SHARED ConfigFile$ - value$ = "" 'We start by blanking the value$ as a default return state - InFile = FREEFILE: OPEN ConfigFile$ FOR BINARY AS #InFile - - IF LOF(InFile) THEN - found = 0 - DO UNTIL EOF(InFile) - LINE INPUT #InFile, temp$ - temp$ = LTRIM$(RTRIM$(temp$)) - l = INSTR(temp$, "=") - compare$ = LTRIM$(RTRIM$(LEFT$(temp$, l - 1))) - IF UCASE$(compare$) = UCASE$(item$) THEN found = -1: EXIT DO - LOOP - CLOSE #InFile - IF found THEN 'we found what we're looking for - IF l THEN - value$ = MID$(temp$, l + 1) - l = INSTR(value$, CHR$(13)) 'we only want what's before a CR - IF l THEN value$ = LEFT$(value$, l) - l = INSTR(value$, CHR$(10)) 'or a LineFeed - 'These are basic text files; they shouldn't have stray CHR$(10) or CHR$(13) characters in them! - IF l THEN value$ = LEFT$(value$, l) - value$ = LTRIM$(RTRIM$(value$)) - 'check for quotes where needed for strings and remove them so our return value doesn't contain them - IF RIGHT$(RTRIM$(item$), 1) = "$" THEN - IF LEFT$(value$, 1) = CHR$(34) THEN value$ = MID$(value$, 2) - IF RIGHT$(value$, 1) = CHR$(34) THEN value$ = LEFT$(value$, LEN(value$) - 1) - END IF - ReadConfigSetting = -1 - EXIT FUNCTION - END IF - END IF - END IF - CLOSE #InFile - ReadConfigSetting = 0 'failed to find the setting +FUNCTION ReadConfigSetting (section$, item$, value$) + value$ = ReadSetting$(ConfigFile$, section$, item$) + ReadConfigSetting = (LEN(value$) > 0) END FUNCTION -FUNCTION VRGBS (text$, DefaultColor AS _UNSIGNED LONG) +FUNCTION VRGBS~& (text$, DefaultColor AS _UNSIGNED LONG) 'Value of RGB String = VRGBS without a ton of typing 'A function to get the RGB value back from a string such as _RGB32(255,255,255) 'text$ is the string that we send to check for a value 'DefaultColor is the value we send back if the string isn't in the proper format - VRGBS = DefaultColor 'A return the default value if we can't parse the string properly + VRGBS~& = DefaultColor 'A return the default value if we can't parse the string properly IF UCASE$(LEFT$(text$, 4)) = "_RGB" THEN rpos = INSTR(text$, "(") gpos = INSTR(rpos, text$, ",") bpos = INSTR(gpos + 1, text$, ",") IF rpos <> 0 AND bpos <> 0 AND gpos <> 0 THEN - red = VAL(MID$(text$, rpos + 1)) - green = VAL(MID$(text$, gpos + 1)) - blue = VAL(MID$(text$, bpos + 1)) - VRGBS = _RGB32(red, green, blue) + red = VAL(_TRIM$(MID$(text$, rpos + 1))) + green = VAL(_TRIM$(MID$(text$, gpos + 1))) + blue = VAL(_TRIM$(MID$(text$, bpos + 1))) + VRGBS~& = _RGB32(red, green, blue) END IF END IF END FUNCTION +FUNCTION rgbs$ (c AS _UNSIGNED LONG) + rgbs$ = "_RGB32(" + _TRIM$(STR$(_RED32(c))) + ", " + _TRIM$(STR$(_GREEN32(c))) + ", " + _TRIM$(STR$(_BLUE32(c))) + ")" +END FUNCTION + FUNCTION EvalPreIF (text$, err$) temp$ = text$ 'so we don't corrupt the string sent to us for evaluation err$ = "" 'null the err message to begin with @@ -25593,8 +25509,8 @@ FUNCTION SCase2$ (t$) END FUNCTION '$INCLUDE:'utilities\strings.bas' - '$INCLUDE:'subs_functions\extensions\opengl\opengl_methods.bas' +'$INCLUDE:'utilities\ini-manager\ini.bm' DEFLNG A-Z diff --git a/source/utilities/ini-manager/ini.bi b/source/utilities/ini-manager/ini.bi new file mode 100644 index 000000000..ecb096e29 --- /dev/null +++ b/source/utilities/ini-manager/ini.bi @@ -0,0 +1,21 @@ +'INI Manager +'Fellippe Heitor, 2017-2021 - fellippe@qb64.org - @fellippeheitor + +'This file isn't required to be at the top of your programs, +'unless you intend to use OPTION _EXPLICIT + +'Global variables declaration +DIM currentIniFileName$ +DIM currentIniFileLOF AS _UNSIGNED LONG +DIM IniWholeFile$ +DIM IniSectionData$ +DIM IniPosition AS _UNSIGNED LONG +DIM IniNewFile$ +DIM IniLastSection$ +DIM IniLastKey$ +DIM IniLF$ +DIM IniDisableAutoCommit +DIM IniCODE +DIM IniAllowBasicComments +DIM IniForceReload +DIM IniDisableAddQuotes diff --git a/source/utilities/ini-manager/ini.bm b/source/utilities/ini-manager/ini.bm new file mode 100644 index 000000000..02e265984 --- /dev/null +++ b/source/utilities/ini-manager/ini.bm @@ -0,0 +1,793 @@ +'INI Manager v1.01 +'Fellippe Heitor, 2017-2021 - fellippe@qb64.org - @fellippeheitor + +SUB IniSortSection (file$, __section$) + SHARED IniCODE, IniLastKey$, IniWholeFile$ + SHARED IniDisableAutoCommit + + REDIM Keys(1 TO 100) AS STRING + DIM TotalKeys, tempValue$, i AS LONG, Backup$, CommitBackup + + IF IniFormatSection$(__section$) = "[]" THEN IniCODE = 15: EXIT SUB + + DO + tempValue$ = ReadSetting(file$, __section$, "") + IF LEFT$(IniINFO$, 7) = "ERROR: " THEN EXIT SUB + IF IniCODE = 10 THEN EXIT DO + + TotalKeys = TotalKeys + 1 + IF TotalKeys > UBOUND(Keys) THEN + REDIM _PRESERVE Keys(1 TO UBOUND(Keys) + 100) AS STRING + END IF + + Keys(TotalKeys) = IniLastKey$ + "=" + tempValue$ + LOOP + + REDIM _PRESERVE Keys(1 TO TotalKeys) AS STRING + IF IniArraySort(Keys()) = 0 THEN IniCODE = 23: EXIT SUB + + CommitBackup = IniDisableAutoCommit + IniDisableAutoCommit = -1 'Prevent every minor change from being written to disk + Backup$ = IniWholeFile$ + + FOR i = 1 TO TotalKeys + IniDeleteKey file$, __section$, LEFT$(Keys(i), INSTR(Keys(i), "=") - 1) + IF LEFT$(IniINFO$, 7) = "ERROR: " THEN + IniDisableAutoCommit = CommitBackup + IniWholeFile$ = Backup$ + EXIT SUB + END IF + NEXT + + FOR i = 1 TO TotalKeys + WriteSetting file$, __section$, LEFT$(Keys(i), INSTR(Keys(i), "=") - 1), MID$(Keys(i), INSTR(Keys(i), "=") + 1) + IF LEFT$(IniINFO$, 7) = "ERROR: " THEN + IniDisableAutoCommit = CommitBackup + IniWholeFile$ = Backup$ + EXIT SUB + END IF + NEXT + + IniDisableAutoCommit = CommitBackup 'Restore writing to disk (or previously set state) and + IniCommit ' commit changes. + + IniCODE = 22 +END SUB + +SUB IniDeleteSection (file$, __section$) + SHARED IniNewFile$, IniCODE, currentIniFileName$ + SHARED IniLF$, IniWholeFile$, currentIniFileLOF AS _UNSIGNED LONG + + IniLoad file$ + IF IniCODE THEN EXIT SUB + + DIM a$ + IniCODE = 0 + a$ = IniGetSection(__section$) + IF IniCODE THEN EXIT SUB + + IniNewFile$ = LEFT$(IniWholeFile$, INSTR(IniWholeFile$, a$) - 1) + IniNewFile$ = IniNewFile$ + MID$(IniWholeFile$, INSTR(IniWholeFile$, a$) + LEN(a$ + IniLF$)) + + IniCommit + IniCODE = 13 +END SUB + +SUB IniDeleteKey (file$, __section$, __key$) + SHARED IniPosition AS _UNSIGNED LONG, IniCODE + SHARED IniLF$, IniWholeFile$, IniSectionData$ + SHARED IniLastSection$, IniLastKey$, IniNewFile$ + + DIM tempValue$ + DIM section$, key$ + DIM FoundLF AS _UNSIGNED LONG + + IniCODE = 0 + + 'prepare variables for the write operation + section$ = IniFormatSection$(__section$) + IF IniCODE THEN EXIT SUB + + key$ = LTRIM$(RTRIM$(__key$)) + IF key$ = "" THEN IniCODE = 12: EXIT SUB + IniLastKey$ = key$ + + 'Read the existing key to fill IniPosition + tempValue$ = ReadSetting$(file$, section$, key$) + IF IniCODE > 0 AND IniCODE <> 2 THEN EXIT SUB 'key not found + + 'map IniPosition (set in the section block) to the global file position + IniPosition = INSTR(IniWholeFile$, IniSectionData$) + IniPosition - 1 + + FoundLF = INSTR(IniPosition, IniWholeFile$, IniLF$) + IF FoundLF = 0 THEN FoundLF = LEN(IniWholeFile$) + + IniNewFile$ = LEFT$(IniWholeFile$, IniPosition - 1) + MID$(IniWholeFile$, FoundLF + LEN(IniLF$)) + + IniCommit + IniCODE = 19 +END SUB + +SUB IniMoveKey (file$, __section$, __key$, __newsection$) + 'A move operation is a copy operation + a delete operation + + SHARED IniCODE + + DIM tempValue$ + + tempValue$ = ReadSetting(file$, __section$, __key$) + IF IniCODE > 0 AND IniCODE <> 2 THEN EXIT SUB + + WriteSetting file$, __newsection$, __key$, tempValue$ + IF IniCODE > 0 AND IniCODE <> 2 AND IniCODE <> 7 AND IniCODE <> 9 THEN EXIT SUB + + IniDeleteKey file$, __section$, __key$ + IF IniCODE = 19 THEN IniCODE = 20 +END SUB + +SUB IniCommit + SHARED currentIniFileName$, IniWholeFile$, currentIniFileLOF AS _UNSIGNED LONG + SHARED IniNewFile$, IniDisableAutoCommit, IniCODE + + IF currentIniFileName$ = "" THEN IniCODE = 18: EXIT SUB + + IniWholeFile$ = IniNewFile$ + currentIniFileLOF = LEN(IniNewFile$) + + IF NOT IniDisableAutoCommit THEN + DIM fileNum AS INTEGER + + fileNum = FREEFILE + OPEN currentIniFileName$ FOR BINARY AS #fileNum + + IF LEN(IniWholeFile$) < LOF(fileNum) THEN + CLOSE fileNum + OPEN currentIniFileName$ FOR OUTPUT AS #fileNum: CLOSE #fileNum + OPEN currentIniFileName$ FOR BINARY AS #fileNum + END IF + + PUT #fileNum, 1, IniNewFile$ + CLOSE #fileNum 'flush + END IF +END SUB + +FUNCTION IniGetSection$ (__section$) + SHARED IniPosition AS _UNSIGNED LONG, IniCODE, currentIniFileName$ + SHARED IniLF$, IniWholeFile$, currentIniFileLOF AS _UNSIGNED LONG + + IF currentIniFileName$ = "" THEN IniCODE = 18: EXIT FUNCTION + IF currentIniFileLOF = 0 OR LEN(LTRIM$(RTRIM$(IniWholeFile$))) = 0 THEN IniCODE = 17: EXIT FUNCTION + + IniCODE = 0 + + DIM section$, foundSection AS _UNSIGNED LONG, endSection AS _UNSIGNED LONG + DIM i AS _UNSIGNED LONG, Bracket1 AS _UNSIGNED LONG, sectionStart AS _UNSIGNED LONG + DIM inQuote AS _BYTE + + section$ = IniFormatSection$(__section$) + IF IniCODE THEN EXIT FUNCTION + + IF section$ = "[]" THEN + 'fetch the "global" section, if present + sectionStart = INSTR(IniWholeFile$, "[") + IF sectionStart = 0 THEN IniGetSection$ = IniWholeFile$: EXIT FUNCTION + + FOR i = sectionStart - 1 TO 1 STEP -1 + IF ASC(IniWholeFile$, i) = 10 THEN foundSection = i + 1: EXIT FOR + IF ASC(IniWholeFile$, i) <> 32 THEN EXIT FOR + NEXT + + IF i = 0 THEN foundSection = 1 + + IniGetSection$ = LEFT$(IniWholeFile$, foundSection - 1) + ELSE + DO + sectionStart = INSTR(sectionStart + 1, LCASE$(IniWholeFile$), LCASE$(section$)) + IF sectionStart = 0 THEN IniCODE = 14: EXIT DO + + 'make sure it's a valid section header + foundSection = 0 + FOR i = sectionStart - 1 TO 1 STEP -1 + IF ASC(IniWholeFile$, i) = 10 THEN foundSection = i + 1: EXIT FOR + IF ASC(IniWholeFile$, i) <> 32 THEN EXIT FOR + NEXT + + IF i = 0 THEN foundSection = 1 + + IF foundSection > 0 THEN + 'we found it; time to identify where this section ends + '(either another [section] or the end of the file + Bracket1 = sectionStart + checkAgain: + Bracket1 = INSTR(Bracket1 + 1, IniWholeFile$, "[") + + IF Bracket1 > 0 THEN + 'found a bracket; check if it's inside quotes + inQuote = 0 + FOR i = 1 TO Bracket1 - 1 + IF ASC(IniWholeFile$, i) = 34 THEN inQuote = NOT inQuote + NEXT + IF inQuote THEN GOTO checkAgain + + FOR i = Bracket1 - 1 TO 1 STEP -1 + IF ASC(IniWholeFile$, i) = 10 THEN endSection = i + 1 - LEN(IniLF$): EXIT FOR + IF ASC(IniWholeFile$, i) = 61 THEN GOTO checkAgain 'bracket is inside a key's value + IF i <= foundSection THEN EXIT FOR + NEXT + IniGetSection$ = MID$(IniWholeFile$, foundSection, endSection - foundSection) + ELSE + IniGetSection$ = MID$(IniWholeFile$, foundSection) + END IF + EXIT FUNCTION + END IF + LOOP + END IF +END FUNCTION + +FUNCTION IniFormatSection$ (__section$) + SHARED IniCODE + + DIM section$ + + section$ = LTRIM$(RTRIM$(__section$)) + + 'sections are in the format [section name] - add brackets if not passed + IF LEFT$(section$, 1) <> "[" THEN section$ = "[" + section$ + IF RIGHT$(section$, 1) <> "]" THEN section$ = section$ + "]" + + IF INSTR(MID$(section$, 2, LEN(section$) - 3), "[") OR INSTR(MID$(section$, 2, LEN(section$) - 3), "]") THEN + IniCODE = 15 + EXIT FUNCTION + END IF + + IniFormatSection$ = section$ +END FUNCTION + +FUNCTION ReadSetting$ (file$, __section$, __key$) + SHARED IniLastSection$, IniLastKey$, IniWholeFile$, IniLF$ + SHARED IniPosition AS _UNSIGNED LONG, IniSectionData$ + SHARED IniCODE, IniAllowBasicComments + SHARED currentIniFileLOF AS _UNSIGNED LONG + + IniLoad file$ + IF IniCODE THEN EXIT FUNCTION + + IF currentIniFileLOF = 0 OR LEN(LTRIM$(RTRIM$(IniWholeFile$))) = 0 THEN IniCODE = 17: EXIT FUNCTION + + DIM Equal AS _UNSIGNED LONG, tempValue$, key$, section$ + DIM Quote AS _UNSIGNED LONG, Comment AS _UNSIGNED LONG + DIM i AS LONG, FoundLF AS _UNSIGNED LONG + + section$ = IniFormatSection(__section$) + IF IniCODE THEN EXIT FUNCTION + + 'fetch the desired section$ + IniSectionData$ = IniGetSection(section$) + IF IniCODE > 0 AND IniCODE <> 17 THEN EXIT FUNCTION + + IF LEN(IniSectionData$) = 0 AND section$ <> "[]" THEN IniCODE = 14: EXIT FUNCTION + + IniLastSection$ = section$ + + IniPosition = 0 + + key$ = LTRIM$(RTRIM$(__key$)) + IniLastKey$ = "" + IF key$ = "" THEN + IF section$ = "[]" THEN IniSectionData$ = IniWholeFile$ + key$ = IniNextKey + IF IniCODE THEN EXIT FUNCTION + IF key$ = "" THEN + IniCODE = 10 + EXIT FUNCTION + END IF + END IF + + IF LEFT$(key$, 1) = ";" OR LEFT$(key$, 1) = "'" OR INSTR(key$, "[") > 0 OR INSTR(key$, "]") > 0 OR INSTR(key$, "=") > 0 THEN + IniCODE = 12 + EXIT FUNCTION + END IF + + IniLastKey$ = key$ + + IF IniPosition > 0 THEN Equal = IniPosition: GOTO KeyFound + CheckKey: + IniPosition = INSTR(IniPosition + 1, LCASE$(IniSectionData$), LCASE$(key$)) + + IF IniPosition > 0 THEN + 'identify if this occurrence is actually a key and not part of a key name/value + FOR i = IniPosition - 1 TO 1 STEP -1 + IF ASC(IniSectionData$, i) = 10 THEN EXIT FOR + IF ASC(IniSectionData$, i) <> 10 AND ASC(IniSectionData$, i) <> 32 THEN + 'not a key + GOTO CheckKey + END IF + NEXT + + 'check if there's nothing but an equal sign ahead + FOR i = IniPosition + LEN(key$) TO LEN(IniSectionData$) + IF ASC(IniSectionData$, i) = ASC("=") THEN EXIT FOR + IF ASC(IniSectionData$, i) <> ASC("=") AND ASC(IniSectionData$, i) <> 32 THEN + 'not the key + GOTO CheckKey + END IF + NEXT + + 'so far so good; check if there is an assignment + Equal = INSTR(IniPosition, IniSectionData$, "=") + KeyFound: + FoundLF = INSTR(IniPosition, IniSectionData$, IniLF$) + + IF FoundLF > 0 THEN + IF Equal > FoundLF THEN GOTO CheckKey + ELSE + FoundLF = LEN(IniSectionData$) + 1 + IF Equal = 0 THEN GOTO CheckKey + END IF + + tempValue$ = LTRIM$(RTRIM$(MID$(IniSectionData$, Equal + 1, FoundLF - Equal - 1))) + + IF LEN(tempValue$) > 0 THEN + IF LEFT$(tempValue$, 1) = CHR$(34) THEN + tempValue$ = MID$(tempValue$, 2) + Quote = INSTR(tempValue$, CHR$(34)) + IF Quote > 0 THEN + tempValue$ = LEFT$(tempValue$, Quote - 1) + END IF + ELSE + IF IniAllowBasicComments THEN Comment = INSTR(tempValue$, "'") 'BASIC style comments accepted + IF Comment = 0 THEN Comment = INSTR(tempValue$, ";") + IF Comment > 0 THEN + tempValue$ = LTRIM$(RTRIM$(LEFT$(tempValue$, Comment - 1))) + END IF + END IF + ELSE + IniCODE = 2 + END IF + ELSE + IniCODE = 3 + EXIT FUNCTION + END IF + + ReadSetting$ = tempValue$ + IniLastSection$ = IniCurrentSection$ +END FUNCTION + +FUNCTION IniCurrentSection$ + SHARED IniPosition AS _UNSIGNED LONG, IniSectionData$, IniWholeFile$ + + DIM GlobalPosition AS _UNSIGNED LONG, i AS _UNSIGNED LONG + DIM ClosingBracket AS _UNSIGNED LONG + + GlobalPosition = INSTR(IniWholeFile$, IniSectionData$) + IniPosition - 1 + + CheckSection: + FOR i = GlobalPosition - 1 TO 1 STEP -1 + IF ASC(IniWholeFile$, i) = ASC("[") THEN + GlobalPosition = i: EXIT FOR + END IF + NEXT + + IF i = 0 THEN IniCurrentSection$ = "[]": EXIT FUNCTION + + 'identify if this occurrence is actually a section header and not something else + FOR i = GlobalPosition - 1 TO 1 STEP -1 + IF ASC(IniWholeFile$, i) = 10 THEN EXIT FOR + IF ASC(IniWholeFile$, i) <> 10 AND ASC(IniWholeFile$, i) <> 32 THEN + 'not a section header + GOTO CheckSection + END IF + NEXT + + ClosingBracket = INSTR(GlobalPosition, IniWholeFile$, "]") + IF ClosingBracket > 0 THEN + IniCurrentSection$ = MID$(IniWholeFile$, GlobalPosition, ClosingBracket - GlobalPosition + 1) + END IF +END FUNCTION + +SUB WriteSetting (file$, __section$, __key$, __value$) + SHARED IniPosition AS _UNSIGNED LONG, IniCODE, currentIniFileName$ + SHARED IniLF$, IniWholeFile$, IniSectionData$ + SHARED IniLastSection$, IniLastKey$, IniNewFile$ + SHARED IniDisableAddQuotes + + DIM tempValue$, section$, key$, value$ + + IniCODE = 0 + + 'prepare variables for the write operation + section$ = IniFormatSection$(__section$) + IF IniCODE THEN EXIT SUB + + key$ = LTRIM$(RTRIM$(__key$)) + IF key$ = "" THEN IniCODE = 12: EXIT SUB + IniLastKey$ = key$ + + value$ = LTRIM$(RTRIM$(__value$)) + IF LTRIM$(STR$(VAL(value$))) <> value$ THEN + IF NOT IniDisableAddQuotes THEN + 'if not a numeric value and value contains spaces, add quotation marks + IF INSTR(value$, CHR$(32)) THEN value$ = CHR$(34) + value$ + CHR$(34) + END IF + END IF + + 'Read the existing key to fill IniPosition + tempValue$ = ReadSetting$(file$, section$, key$) + + 'map IniPosition (set in the section block) to the global file position + IniPosition = INSTR(IniWholeFile$, IniSectionData$) + IniPosition - 1 + + IF IniCODE = 1 OR IniCODE = 17 THEN + 'file not found or empty; create a new one + IF file$ = "" THEN file$ = currentIniFileName$ + IF file$ = "" THEN IniCODE = 21: EXIT SUB + + currentIniFileName$ = file$ + + IF section$ <> "[]" THEN + IniNewFile$ = section$ + IniLF$ + END IF + + IniNewFile$ = IniNewFile$ + key$ + "=" + value$ + + IniCODE = 0 + IniCommit + IniLoad file$ + IF IniCODE = 0 THEN IniCODE = 11 + IniLastSection$ = section$ + EXIT SUB + END IF + + IF IniCODE = 0 OR IniCODE = 2 THEN 'key found and read back; write new value$ + IF LCASE$(IniLastSection$) = LCASE$(section$) THEN + IF LTRIM$(RTRIM$(__value$)) = tempValue$ AND LEN(LTRIM$(RTRIM$(__value$))) > 0 THEN + 'identical values skip the writing routine + IniCODE = 8 + EXIT SUB + END IF + + DIM nextLine AS _UNSIGNED LONG + nextLine = INSTR(IniPosition + 1, IniWholeFile$, IniLF$) + + 'create new file contents + IniNewFile$ = LEFT$(IniWholeFile$, IniPosition - 1) + IniNewFile$ = IniNewFile$ + key$ + "=" + value$ + + IF nextLine > 0 THEN + IniNewFile$ = IniNewFile$ + MID$(IniWholeFile$, nextLine) + END IF + + IniCommit + + IniCODE = 4 + END IF + ELSEIF IniCODE = 3 OR IniCODE = 14 THEN 'Key not found, Section not found + IniCODE = 0 + IF LCASE$(IniLastSection$) = LCASE$(section$) THEN + 'find this section$ in the current ini file; + DIM Bracket1 AS _UNSIGNED LONG + DIM beginSection AS _UNSIGNED LONG, endSection AS _UNSIGNED LONG + DIM i AS _UNSIGNED LONG + + beginSection = 0 + endSection = 0 + + CheckSection: + beginSection = INSTR(beginSection + 1, LCASE$(IniWholeFile$), LCASE$(section$)) + IF beginSection = 0 THEN GOTO CreateSection + + 'identify if this occurrence is actually the section header and not something else + FOR i = beginSection - 1 TO 1 STEP -1 + IF ASC(IniWholeFile$, i) = 10 THEN EXIT FOR + IF ASC(IniWholeFile$, i) <> 10 AND ASC(IniWholeFile$, i) <> 32 THEN + 'not the section header + GOTO CheckSection + END IF + NEXT + + 'we found it; time to identify where this section ends + '(either another [section], a blank line or the end of the file + Bracket1 = INSTR(beginSection + 1, IniWholeFile$, "[") + IF Bracket1 > 0 THEN + FOR i = Bracket1 - 1 TO 1 STEP -1 + IF ASC(IniWholeFile$, i) = 10 THEN endSection = i + 1 - LEN(IniLF$): EXIT FOR + IF i <= beginSection THEN EXIT FOR + NEXT + END IF + + IF endSection > 0 THEN + 'add values to the end of the specified section$ + IniNewFile$ = LEFT$(IniWholeFile$, endSection - 1) + IniNewFile$ = IniNewFile$ + key$ + "=" + value$ + IniLF$ + IF MID$(IniWholeFile$, endSection, LEN(IniLF$)) <> IniLF$ THEN IniNewFile$ = IniNewFile$ + IniLF$ + IniNewFile$ = IniNewFile$ + MID$(IniWholeFile$, endSection) + ELSE + 'add values to the end of the file + IniNewFile$ = IniWholeFile$ + IF RIGHT$(IniNewFile$, LEN(IniLF$)) = IniLF$ THEN + IniNewFile$ = IniNewFile$ + key$ + "=" + value$ + ELSE + IniNewFile$ = IniNewFile$ + IniLF$ + key$ + "=" + value$ + END IF + END IF + + IniCommit + + IF IniCODE = 0 THEN IniCODE = 7 + EXIT SUB + ELSE + CreateSection: + IniNewFile$ = IniWholeFile$ + IF section$ = "[]" THEN GOTO WriteAtTop + + IF RIGHT$(IniNewFile$, LEN(IniLF$) * 2) = IniLF$ + IniLF$ THEN + IniNewFile$ = IniNewFile$ + section$ + IniLF$ + key$ + "=" + value$ + IniLF$ + ELSEIF RIGHT$(IniNewFile$, LEN(IniLF$)) = IniLF$ THEN + IniNewFile$ = IniNewFile$ + IniLF$ + section$ + IniLF$ + key$ + "=" + value$ + IniLF$ + ELSE + IniNewFile$ = IniNewFile$ + IniLF$ + IniLF$ + section$ + IniLF$ + key$ + "=" + value$ + IniLF$ + END IF + + IniCommit + + IF IniCODE = 0 THEN IniCODE = 9 ELSE IniCODE = 16 + EXIT SUB + END IF + + 'if not found, key$=value$ is written to the beginning of the file + WriteAtTop: + IniNewFile$ = key$ + "=" + value$ + IniLF$ + IF LEFT$(LTRIM$(IniWholeFile$), 1) = "[" THEN IniNewFile$ = IniNewFile$ + IniLF$ + IniNewFile$ = IniNewFile$ + IniWholeFile$ + + IniCommit + + IniCODE = 5 + END IF +END SUB + +SUB IniSetAddQuotes (state AS _BYTE) + SHARED IniDisableAddQuotes + IF state THEN + IniDisableAddQuotes = 0 + ELSE + IniDisableAddQuotes = -1 + END IF +END SUB + +SUB IniSetForceReload (state AS _BYTE) + SHARED IniForceReload + IF state THEN + IniForceReload = -1 + ELSE + IniForceReload = 0 + END IF +END SUB + +SUB IniSetAllowBasicComments (state AS _BYTE) + SHARED IniAllowBasicComments + IF state THEN + IniAllowBasicComments = -1 + ELSE + IniAllowBasicComments = 0 + END IF +END SUB + +SUB IniSetAutoCommit (state AS _BYTE) + SHARED IniDisableAutoCommit + IF state THEN + IniDisableAutoCommit = 0 + ELSE + IniDisableAutoCommit = -1 + END IF +END SUB + +SUB IniClose + SHARED currentIniFileName$ + DIM CommitBackup + + IF currentIniFileName$ = "" THEN EXIT SUB + + CommitBackup = IniDisableAutoCommit + IniDisableAutoCommit = 0 + IniCommit + IniDisableAutoCommit = CommitBackup + + currentIniFileName$ = "" +END SUB + +SUB IniLoad (file$) + SHARED IniCODE, currentIniFileName$, IniLF$, IniWholeFile$ + SHARED currentIniFileLOF AS _UNSIGNED LONG + SHARED IniForceReload + DIM fileNum AS INTEGER + + 'Error messages are returned with IniCODE + 'Error descriptions can be fetched with function IniINFO$ + IniCODE = 0 + + IF file$ <> "" AND currentIniFileName$ <> file$ THEN currentIniFileName$ = "" + + IF IniForceReload AND LEN(currentIniFileName$) > 0 THEN + file$ = currentIniFileName$ + currentIniFileName$ = "" + END IF + + 'Passing an empty file$ is allowed if user already + 'passed a valid file in this session. + IF currentIniFileName$ = "" THEN + 'initialization + IF _FILEEXISTS(file$) THEN + currentIniFileName$ = file$ + + 'Load file into memory + fileNum = FREEFILE + OPEN currentIniFileName$ FOR BINARY AS #fileNum + currentIniFileLOF = LOF(fileNum) + IniWholeFile$ = SPACE$(currentIniFileLOF) + GET #fileNum, 1, IniWholeFile$ + CLOSE #fileNum + + 'Check if this ini file uses CRLF or LF + IF INSTR(IniWholeFile$, CHR$(13)) THEN IniLF$ = CHR$(13) + CHR$(10) ELSE IniLF$ = CHR$(10) + ELSE + IniFileNotFound: + IniCODE = 1 + + $IF WIN THEN + IniLF$ = CHR$(13) + CHR$(10) + $ELSE + IniLF$ = CHR$(10) + $END IF + EXIT SUB + END IF + ELSEIF NOT _FILEEXISTS(currentIniFileName$) THEN + currentIniFileName$ = "" + GOTO IniFileNotFound + END IF +END SUB + +FUNCTION IniNextKey$ + SHARED IniCODE, IniLF$, currentIniFileName$, IniSectionData$ + SHARED IniPosition AS _UNSIGNED LONG + STATIC lastDataBlock$, position AS _UNSIGNED LONG, tempLF$ + + IF currentIniFileName$ = "" THEN IniCODE = 18: EXIT FUNCTION + + IF IniSectionData$ <> lastDataBlock$ THEN + position = 0 + lastDataBlock$ = IniSectionData$ + + 'data blocks must end with a line feed for parsing purposes + IF RIGHT$(IniSectionData$, LEN(IniLF$)) <> IniLF$ THEN tempLF$ = IniLF$ ELSE tempLF$ = "" + END IF + + DIM Equal AS _UNSIGNED LONG, tempKey$ + + FindKey: + Equal = INSTR(position, IniSectionData$ + tempLF$, "=") + IF Equal = 0 THEN position = 0: EXIT FUNCTION + + tempKey$ = LTRIM$(RTRIM$(MID$(IniSectionData$ + tempLF$, position + 1, Equal - position - 1))) + + IF INSTR(tempKey$, CHR$(10)) > 0 THEN + position = position + INSTR(tempKey$, CHR$(10)) + 1 + tempKey$ = MID$(tempKey$, INSTR(tempKey$, CHR$(10)) + 1) + END IF + + DO WHILE LEFT$(tempKey$, LEN(IniLF$)) = IniLF$ + tempKey$ = MID$(tempKey$, LEN(IniLF$) + 1) + position = position + LEN(IniLF$) + LOOP + + position = INSTR(position + 1, IniSectionData$ + tempLF$, IniLF$) + + IF LEFT$(tempKey$, 1) = ";" OR LEFT$(tempKey$, 1) = "'" OR INSTR(tempKey$, "[") > 0 OR INSTR(tempKey$, "]") > 0 OR INSTR(tempKey$, "=") > 0 THEN + GOTO FindKey + END IF + + IniNextKey$ = tempKey$ + IniPosition = Equal +END FUNCTION + +FUNCTION IniNextSection$ (file$) + SHARED IniCODE, IniLF$, IniWholeFile$ + + STATIC sectionStart AS _UNSIGNED LONG + + IniLoad file$ + IF LEFT$(IniINFO$, 6) = "ERROR:" THEN EXIT FUNCTION + + IniCODE = 0 + + DIM foundSection AS _UNSIGNED LONG, endSection AS _UNSIGNED LONG + DIM i AS _UNSIGNED LONG, Bracket1 AS _UNSIGNED LONG, Bracket2 AS _UNSIGNED LONG + + FindNext: + sectionStart = INSTR(sectionStart + 1, IniWholeFile$, "[") + IF sectionStart = 0 THEN IniCODE = 24: EXIT FUNCTION + + 'make sure it's a valid section header + foundSection = 0 + FOR i = sectionStart - 1 TO 1 STEP -1 + IF ASC(IniWholeFile$, i) = 10 THEN foundSection = i + 1: EXIT FOR + IF ASC(IniWholeFile$, i) <> 32 THEN GOTO FindNext + NEXT + + IF i = 0 THEN foundSection = 1 + + IF foundSection > 0 THEN + 'we found it; time to identify where this section ends + '(either another [section] or the end of the file + Bracket2 = INSTR(sectionStart + 1, IniWholeFile$, "]") + IF Bracket2 = 0 THEN IniCODE = 24: EXIT FUNCTION + Bracket1 = INSTR(sectionStart + 1, IniWholeFile$, "[") + IF Bracket1 > 0 THEN + FOR i = Bracket1 - 1 TO 1 STEP -1 + IF ASC(IniWholeFile$, i) = 10 THEN endSection = i + 1 - LEN(IniLF$): EXIT FOR + IF i <= foundSection THEN EXIT FOR + NEXT + IniNextSection$ = MID$(IniWholeFile$, foundSection, Bracket2 - foundSection + 1) + ELSE + IniNextSection$ = MID$(IniWholeFile$, foundSection, Bracket2 - foundSection + 1) + IniCODE = 24 + sectionStart = 0 + END IF + ELSE + IniCODE = 24 + END IF +END FUNCTION + +FUNCTION IniINFO$ + SHARED IniCODE + SELECT CASE IniCODE + CASE 0: IniINFO$ = "Operation successful" + Case 1: IniINFO$ = "ERROR: File not found" + CASE 2: IniINFO$ = "Empty value" + CASE 3: IniINFO$ = "ERROR: Key not found" + CASE 4: IniINFO$ = "Key updated" + CASE 5: IniINFO$ = "Global key created" + CASE 7: IniINFO$ = "Key created in existing section" + CASE 8: IniINFO$ = "No changes applied (same value)" + CASE 9: IniINFO$ = "New section created; key created" + CASE 10: IniINFO$ = "No more keys" + CASE 11: IniINFO$ = "File created; new key added" + CASE 12: IniINFO$ = "ERROR: Invalid key" + CASE 13: IniINFO$ = "Section deleted" + CASE 14: IniINFO$ = "ERROR: Section not found" + CASE 15: IniINFO$ = "ERROR: Invalid section" + CASE 16: IniINFO$ = "New section created; existing key moved" + CASE 17: IniINFO$ = "ERROR: Empty file" + CASE 18: IniINFO$ = "ERROR: No file open" + CASE 19: IniINFO$ = "Key deleted" + CASE 20: IniINFO$ = "Key moved" + CASE 21: IniINFO$ = "ERROR: Invalid file name/path" + CASE 22: IniINFO$ = "Section sorted" + CASE 23: IniINFO$ = "No changes applied; section already sorted" + CASE 24: IniINFO$ = "No more sections" + CASE ELSE: IniINFO$ = "ERROR: " + END SELECT +END FUNCTION + +'Written in BASIC by Luke Ceddia for ide_methods.bas (QB64) +'After Cormen, Leiserson, Rivest & Stein "Introduction To Algoritms" via Wikipedia +'Adapted for use in .INI Manager +FUNCTION IniArraySort%% (arr() AS STRING) + DIM i&, x$, j&, moves& + + FOR i& = LBOUND(arr) + 1 TO UBOUND(arr) + x$ = arr(i&) + j& = i& - 1 + WHILE j& >= LBOUND(arr) + IF arr(j&) <= x$ THEN EXIT WHILE + moves& = moves& + 1 + arr$(j& + 1) = arr$(j&) + j& = j& - 1 + WEND + arr$(j& + 1) = x$ + NEXT i& + + 'Returns -1 (true) if any changes were made + IniArraySort%% = moves& > 0 +END FUNCTION +