INI File Functions by Genesis Rage21st Oct 2003 21:15
|
---|
Summary Easily read and write .ini files, with no external .dll to download! Description Got this code from someone in the forums, changed some stuff around and added help files! Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com `Title: INI file functions `Version: 2.0 `Developer: Unknown (re-coded by Genesis Rage) `Date: 10-22-2003 ` `Email: ceo@genesisrage.com `Web: http://genesisrage.com ` `History: ` 2.0 code completely re-done, got from forums actually, just spreading the wealth! ` and this also comes complete with help files... if you download the file! ` 1.3 fixed bug that would not return default value if key was not found ` 1.2 Optimized INI_ReadValue ` 1.1 Fixed bug, no longer searches after value has been found ` 1.0 Initial release (only read capabilities) ` `Example Usage: ` Return String = INI_ReadString("config","Section","Key","Default Value") ` Return Integer or Float = INI_ReadInteger("config","Section","Key",1458) ` INI_WriteSring("config","Section","Key","Value") ` INI_WriteInteger("config","Section","Key",500) ` `Info: ` the file path is generated from you current directory 'get dir$()' so change directory if file ` is located elsewhere. Do NOT change the FileName arguments in this code, Win 2k and Win XP must ` have FULL PATH NAME to read or write the file. ` ` You MUST load the DLL, either manually or by using 'InitialiseKernel32DLL()' function. The default ` number in THIS code is '203' if you change it, make sure to update the rest of the code. function InitialiseKernel32DLL() load dll "kernel32.dll", 203 endfunction function ShutdownKernel32DLL() delete dll 203 endfunction function INI_ReadInteger(FileName as string, Section as string, KeyName as string, Default as integer) r as integer r=val(INI_ReadString(FileName, Section, KeyName, str$(Default))) endfunction r function INI_WriteInteger(FileName as string, Section as string, KeyName as string, Value as integer) INI_WriteString(FileName, Section, KeyName, str$(Value)) endfunction function INI_ReadString(FileName as string, Section as string, KeyName as string, Default as string) r as string r=space$(1024) FileName = get dir$() + "" + FileName + ".ini" call dll 203, "GetPrivateProfileStringA", Section, KeyName, Default, r, len(r), FileName endfunction r function INI_WriteString(FileName as string, Section as string, KeyName as string, Value as string) FileName = get dir$() + "" + FileName + ".ini" call dll 203, "WritePrivateProfileStringA", Section, KeyName, Value, FileName endfunction |