mirror of
https://github.com/QB64Official/qb64.git
synced 2024-07-05 01:50:25 +00:00
Moved config related functions to the new config.bas file.
This commit is contained in:
parent
0b1c3fd7a7
commit
391b6178b8
|
@ -25752,15 +25752,6 @@ SUB Give_Error (a$)
|
||||||
Error_Message = a$
|
Error_Message = a$
|
||||||
END SUB
|
END SUB
|
||||||
|
|
||||||
SUB WriteConfigSetting (section$, item$, value$)
|
|
||||||
WriteSetting ConfigFile$, section$, item$, value$
|
|
||||||
END SUB
|
|
||||||
|
|
||||||
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
|
'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)
|
'A function to get the RGB value back from a string such as _RGB32(255,255,255)
|
||||||
|
@ -26309,7 +26300,13 @@ SUB increaseUDTArrays
|
||||||
REDIM _PRESERVE udtenext(x + 1000) AS LONG
|
REDIM _PRESERVE udtenext(x + 1000) AS LONG
|
||||||
END SUB
|
END SUB
|
||||||
|
|
||||||
|
' Generic method (can be used outside of QB64) includes:
|
||||||
|
|
||||||
'$INCLUDE:'utilities\strings.bas'
|
'$INCLUDE:'utilities\strings.bas'
|
||||||
|
|
||||||
|
' Custom method (designed specifically for QB64) includes:
|
||||||
|
|
||||||
|
'$INCLUDE:'utilities\config.bas'
|
||||||
'$INCLUDE:'utilities\file.bas'
|
'$INCLUDE:'utilities\file.bas'
|
||||||
'$INCLUDE:'subs_functions\extensions\opengl\opengl_methods.bas'
|
'$INCLUDE:'subs_functions\extensions\opengl\opengl_methods.bas'
|
||||||
'$INCLUDE:'utilities\ini-manager\ini.bm'
|
'$INCLUDE:'utilities\ini-manager\ini.bm'
|
||||||
|
|
84
source/utilities/config.bas
Normal file
84
source/utilities/config.bas
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
SUB WriteConfigSetting (section$, item$, value$)
|
||||||
|
WriteSetting ConfigFile$, section$, item$, value$
|
||||||
|
END SUB
|
||||||
|
|
||||||
|
FUNCTION ReadConfigSetting (section$, item$, value$)
|
||||||
|
value$ = ReadSetting$(ConfigFile$, section$, item$)
|
||||||
|
ReadConfigSetting = (LEN(value$) > 0)
|
||||||
|
END FUNCTION
|
||||||
|
|
||||||
|
' Convert a boolean value to 'True' or 'False'.
|
||||||
|
FUNCTION BoolToTFString$ (b AS LONG)
|
||||||
|
IF b THEN BoolToTFString$ = "True" ELSE BoolToTFString$ = "False"
|
||||||
|
END FUNCTION
|
||||||
|
|
||||||
|
' Convert 'True' or 'False' to a boolean value.
|
||||||
|
' Any string not 'True' or 'False' is returned as -2.
|
||||||
|
FUNCTION TFStringToBool% (s AS STRING)
|
||||||
|
SELECT CASE _TRIM$(UCASE$(s))
|
||||||
|
CASE "TRUE": TFStringToBool% = -1
|
||||||
|
CASE "FALSE": TFStringToBool% = 0
|
||||||
|
CASE ELSE: TFStringToBool% = -2
|
||||||
|
END SELECT
|
||||||
|
END FUNCTION
|
||||||
|
|
||||||
|
' Reads the bool setting at section:setting.
|
||||||
|
' If it is not there or invalid, writes the default value to it.
|
||||||
|
FUNCTION ReadWriteBooleanSettingValue% (section AS STRING, setting AS STRING, default AS INTEGER)
|
||||||
|
|
||||||
|
DIM checkResult AS INTEGER
|
||||||
|
DIM value AS STRING
|
||||||
|
DIM result AS INTEGER
|
||||||
|
|
||||||
|
result = ReadConfigSetting(section, setting, value)
|
||||||
|
|
||||||
|
checkResult = TFStringToBool%(value)
|
||||||
|
|
||||||
|
IF checkResult = -2 THEN
|
||||||
|
WriteConfigSetting section, setting, BoolToTFString$(default)
|
||||||
|
ReadWriteBooleanSettingValue% = default
|
||||||
|
ELSE
|
||||||
|
ReadWriteBooleanSettingValue% = checkResult
|
||||||
|
END IF
|
||||||
|
|
||||||
|
END FUNCTION
|
||||||
|
|
||||||
|
' Reads the string setting at section:setting.
|
||||||
|
' If it is not there or invalid, writes the default value to it.
|
||||||
|
FUNCTION ReadWriteStringSettingValue$ (section AS STRING, setting AS STRING, default AS STRING)
|
||||||
|
|
||||||
|
DIM value AS STRING
|
||||||
|
DIM result AS INTEGER
|
||||||
|
|
||||||
|
result = ReadConfigSetting(section, setting, value)
|
||||||
|
|
||||||
|
IF result = 0 THEN
|
||||||
|
WriteConfigSetting section, setting, default
|
||||||
|
ReadWriteStringSettingValue$ = default
|
||||||
|
ELSE
|
||||||
|
ReadWriteStringSettingValue$ = value
|
||||||
|
END IF
|
||||||
|
|
||||||
|
END FUNCTION
|
||||||
|
|
||||||
|
' Reads the integer setting at section:setting.
|
||||||
|
' If it is not there or invalid, writes the default value to it.
|
||||||
|
' Verifies the value is positive and non-zero.
|
||||||
|
FUNCTION ReadWriteLongSettingValue& (section AS STRING, setting AS STRING, default AS LONG)
|
||||||
|
|
||||||
|
DIM value AS STRING
|
||||||
|
DIM result AS INTEGER
|
||||||
|
DIM checkResult AS LONG
|
||||||
|
|
||||||
|
result = ReadConfigSetting(section, setting, value)
|
||||||
|
|
||||||
|
checkResult = VAL(value)
|
||||||
|
|
||||||
|
IF result = 0 OR checkResult <= 0 THEN
|
||||||
|
WriteConfigSetting section, setting, str2$(default)
|
||||||
|
ReadWriteLongSettingValue& = default
|
||||||
|
ELSE
|
||||||
|
ReadWriteLongSettingValue& = checkResult
|
||||||
|
END IF
|
||||||
|
|
||||||
|
END FUNCTION
|
|
@ -1,5 +1,11 @@
|
||||||
''' String manipulation functions
|
' String Extensions
|
||||||
FUNCTION StrRemove$ (myString$, whatToRemove$) ' noncase sensitive
|
|
||||||
|
' Please reserve this module for only string methods that can be
|
||||||
|
' utilized outside of QB64. Meaning, anyone could add this to their
|
||||||
|
' personal project and leverage the same functionality.
|
||||||
|
|
||||||
|
' Removes a string pattern from an existing string (case-insensitive).
|
||||||
|
FUNCTION StrRemove$ (myString$, whatToRemove$)
|
||||||
DIM a$, b$
|
DIM a$, b$
|
||||||
DIM AS LONG i
|
DIM AS LONG i
|
||||||
a$ = myString$
|
a$ = myString$
|
||||||
|
@ -12,7 +18,8 @@ FUNCTION StrRemove$ (myString$, whatToRemove$) ' noncase sensitive
|
||||||
StrRemove$ = a$
|
StrRemove$ = a$
|
||||||
END FUNCTION
|
END FUNCTION
|
||||||
|
|
||||||
FUNCTION StrReplace$ (myString$, find$, replaceWith$) ' noncase sensitive
|
' Replaces a string pattern within an existing string (case-insensitive).
|
||||||
|
FUNCTION StrReplace$ (myString$, find$, replaceWith$)
|
||||||
DIM a$, b$
|
DIM a$, b$
|
||||||
DIM AS LONG basei, i
|
DIM AS LONG basei, i
|
||||||
IF LEN(myString$) = 0 THEN EXIT FUNCTION
|
IF LEN(myString$) = 0 THEN EXIT FUNCTION
|
||||||
|
@ -28,90 +35,7 @@ FUNCTION StrReplace$ (myString$, find$, replaceWith$) ' noncase sensitive
|
||||||
StrReplace$ = a$
|
StrReplace$ = a$
|
||||||
END FUNCTION
|
END FUNCTION
|
||||||
|
|
||||||
|
' Adds quotation (ASCII 034) marks around a string.
|
||||||
FUNCTION AddQuotes$ (s$)
|
FUNCTION AddQuotes$ (s$)
|
||||||
AddQuotes$ = CHR$(34) + s$ + CHR$(34)
|
AddQuotes$ = CHR$(34) + s$ + CHR$(34)
|
||||||
END FUNCTION
|
END FUNCTION
|
||||||
|
|
||||||
' Convert a boolean value to 'True' or 'False'.
|
|
||||||
FUNCTION BoolToTFString$ (b AS LONG)
|
|
||||||
IF b THEN
|
|
||||||
BoolToTFString$ = "True"
|
|
||||||
ELSE
|
|
||||||
BoolToTFString$ = "False"
|
|
||||||
END IF
|
|
||||||
END FUNCTION
|
|
||||||
|
|
||||||
' Convert 'True' or 'False' to a boolean value.
|
|
||||||
' Any string not 'True' or 'False' is returned as -2.
|
|
||||||
FUNCTION TFStringToBool% (s AS STRING)
|
|
||||||
DIM s2 AS STRING
|
|
||||||
s2 = _TRIM$(UCASE$(s))
|
|
||||||
IF s2 = "TRUE" THEN
|
|
||||||
TFStringToBool% = -1
|
|
||||||
ELSEIF s2 = "FALSE" THEN
|
|
||||||
TFStringToBool% = 0
|
|
||||||
ELSE
|
|
||||||
TFStringToBool% = -2
|
|
||||||
END IF
|
|
||||||
END FUNCTION
|
|
||||||
|
|
||||||
''' Reads the bool setting at section:setting.
|
|
||||||
''' If it is not there or invalid, writes the default value to it.
|
|
||||||
FUNCTION ReadWriteBooleanSettingValue% (section AS STRING, setting AS STRING, default AS INTEGER)
|
|
||||||
|
|
||||||
DIM checkResult AS INTEGER
|
|
||||||
DIM value AS STRING
|
|
||||||
DIM result AS INTEGER
|
|
||||||
|
|
||||||
result = ReadConfigSetting(section, setting, value)
|
|
||||||
|
|
||||||
checkResult = TFStringToBool%(value)
|
|
||||||
|
|
||||||
IF checkResult = -2 THEN
|
|
||||||
WriteConfigSetting section, setting, BoolToTFString$(default)
|
|
||||||
ReadWriteBooleanSettingValue% = default
|
|
||||||
ELSE
|
|
||||||
ReadWriteBooleanSettingValue% = checkResult
|
|
||||||
END IF
|
|
||||||
|
|
||||||
END FUNCTION
|
|
||||||
|
|
||||||
''' Reads the string setting at section:setting.
|
|
||||||
''' If it is not there or invalid, writes the default value to it.
|
|
||||||
FUNCTION ReadWriteStringSettingValue$ (section AS STRING, setting AS STRING, default AS STRING)
|
|
||||||
|
|
||||||
DIM value AS STRING
|
|
||||||
DIM result AS INTEGER
|
|
||||||
|
|
||||||
result = ReadConfigSetting(section, setting, value)
|
|
||||||
|
|
||||||
IF result = 0 THEN
|
|
||||||
WriteConfigSetting section, setting, default
|
|
||||||
ReadWriteStringSettingValue$ = default
|
|
||||||
ELSE
|
|
||||||
ReadWriteStringSettingValue$ = value
|
|
||||||
END IF
|
|
||||||
|
|
||||||
END FUNCTION
|
|
||||||
|
|
||||||
''' Reads the integer setting at section:setting.
|
|
||||||
''' If it is not there or invalid, writes the default value to it.
|
|
||||||
''' Verifies the value is positive and non-zero.
|
|
||||||
FUNCTION ReadWriteLongSettingValue& (section AS STRING, setting AS STRING, default AS LONG)
|
|
||||||
|
|
||||||
DIM value AS STRING
|
|
||||||
DIM result AS INTEGER
|
|
||||||
DIM checkResult AS LONG
|
|
||||||
|
|
||||||
result = ReadConfigSetting(section, setting, value)
|
|
||||||
|
|
||||||
checkResult = VAL(value)
|
|
||||||
|
|
||||||
IF result = 0 OR checkResult <= 0 THEN
|
|
||||||
WriteConfigSetting section, setting, str2$(default)
|
|
||||||
ReadWriteLongSettingValue& = default
|
|
||||||
ELSE
|
|
||||||
ReadWriteLongSettingValue& = checkResult
|
|
||||||
END IF
|
|
||||||
|
|
||||||
END FUNCTION
|
|
||||||
|
|
Loading…
Reference in a new issue