Startukk INI
UPDATED! Version 1.4
.: Description :.
This include allows you to easily and freely read/write from/to INI/txt files.
It is fast and easy to learn and understand.
.: Features :.
Code:
Features:
* SINI_Create(filename[]); - Create a specific file.
* SINI_Delete(filename[]); - Deletes a specific file.
* SINI_Open(filename[]); - Opens a specific file. <!> MUST BE USED WHEN READING/WRITING FILE!
* SINI_Exists(filename[]); - Checks if a specific file exists.
* SINI_Save(); - Saves the current opened file. <!> MUST BE USED WHEN WRITING TO FILE!
* SINI_Close(); - Closes the current opened file. <!> MUST BE USED WHEN FILE IS OPENED!
* SINI_WriteString(varname[], string[]); - Writes a String to a file. <!> FILE MUST BE OPENED TO USE THIS FUNCTION!
* SINI_WriteInt(varname[], number); - Writes a Integer to a file. <!> FILE MUST BE OPENED TO USE THIS FUNCTION!
* SINI_ReadString(varname[], data[], len); - Reads a String from a file. <!> FILE MUST BE OPENED TO USE THIS FUNCTION!
* SINI_ReadInt(varname[], integer); - Reads an Integer from a file. <!> FILE MUST BE OPENED TO USE THIS FUNCTION!
* SINI_RemoveVariable(varname[]); - Removes a variable from a file. <!> FILE MUST BE OPENED TO USE THIS FUNCTION!
* SINI_CountLines(); - Returns the number of lines in file. <!> FILE MUST BE OPENED TO USE THIS FUNCTION!
* SINI_VariableExists(varname[]); - Checks if given variable exists in file. <!> FILE MUST BE OPENED TO USE THIS FUNCTION!
* SINI_WriteFloat(varname[], Float: floatvar); - Writes a Float to a file. <!> FILE MUST BE OPENED TO USE THIS FUNCTION!
* SINI_ReadFloat(varname[], Float: floatvar); - Reads a Float from a file. <!> FILE MUST BE OPENED TO USE THIS FUNCTION!
.: Writing Usage :.
PHP Code:
SINI_Create("addons/amxmodx/data/SINI_Test.ini"); // Creating a .INI file named SINI_Test that will be located at addons/amxmodx/data/.
SINI_Open("addons/amxmodx/data/SINI_Test.ini"); // Opening the .INI file we created above.
SINI_WriteString("Variable1", "Hello World"); // Writing the variable "Variable1" with the string value "Hello World" assigned to it, this will end up as 'Variable1=Hello World' in the file.
SINI_WriteInt("Variable2", 555); // Writing the variable "Variable2" with the integer value "555" assinged to it, this will end up as 'Variable2=555' in the file.
SINI_WriteFloat("Variable3", 1337.1337); // Writing the variable "Variable3" with the float value "1337.1337" assinged to it, this will end up as 'Variable3=1337.1337' in the file.
SINI_Save(); // Saving the file as we wrote variables to it.
SINI_Close(); // Closing the file as we are done using it.
.: Reading Usage :.
PHP Code:
new variable1[35], variable2, Float: variable3; // Creating variables that will store our file reading.
SINI_Open("addons/amxmodx/data/SINI_Test.ini"); // Opening the .INI file SINI_Test which is located at addons/amxmodx/data/.
SINI_ReadString("Variable1", variable1, 35); // Reading the variable "Variable1" and storing its string value at variable1.
SINI_ReadInt("Variable2", variable2); // Reading the variable "Variable2" and storing its integer value at variable2.
SINI_ReadFloat("Variable3", variable3); // Reading the variable "Variable3" and storing its float value at variable3.
SINI_Close(); // Closing the file as we are done using it.
.: Other usages :.
PHP Code:
new lines = 0; // Creating a variable with will store our lines count in the file we'll open.
SINI_Open("addons/amxmodx/data/SINI_Test.ini"); // Opening a .INI file named SINI_Test which is located at addons/amxmodx/data/.
SINI_RemoveVariable("Variable3"); // Removing the variable "Variable3" from the file.
lines = SINI_CountLines(); // Getting the number of lines in the file and storing it in the variable lines.
SINI_Save(); // Saving the file as we removed a variable from it.
SINI_Close(); // Closing the file since we're done using it.
.: Defines :.
Code:
MAX_FILE_NAME_LEGNTH - Defines the max file name length. (DEFAULT: 80)
MAX_VARS_PER_FILE - Defines the max variables in file. (DEFAULT: 40)
MAX_VAR_NAME_LENGTH - Defines the max variable name. (DEFAULT: 60)
.: Changelog :.
Code:
v1.0: Initial release
v1.1: Improved opening/saving/reading/creating/deleting abilities. (Thanks to Arkshine)
v1.1: Added new function SINI_VariableExists, check function list above.
v1.2: Added new functions: SINI_WriteFloat, SINI_ReadFloat, check function list above.
v1.2: Removed client_print parts that were for testing purposes.
v1.3: Include is now not using replace_all functions, all those functions are now replaced with copyc().
v1.3: Removed file existing check in SINI_Open as I was able to check is file exists with the current fopen() in the function.
v1.4: SINI_ReadFloat(), SINI_ReadString(), SINI_ReadInt() syntax changed, check function list and examples.
v1.4: Include is no longer using format() to store strings, we now have copy() instead.
v1.4: Money saving script has been updated also due to new reading functions syntax.
.: Other information :.
There is also a small money saving script.
You can learn from it, Its located in the attachments.
.: Credits :.- Startukk, for creating this include.
- b1NNNNNN, for testing purposes and helping on some scripting parts.
.: Bugs & Suggestions :.
If you find any bugs or have a suggestion, you are more then welcome to post about it in here!