Raised This Month: $51 Target: $400
 12% 

[INC] SINI v1.4 - Advanced File Reading/Writing - UPDATED!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Startukk
Junior Member
Join Date: Jul 2013
Old 07-06-2013 , 11:37   [INC] SINI v1.4 - Advanced File Reading/Writing - UPDATED!
Reply With Quote #1

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], variable2Floatvariable3// 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"variable135); // 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!
Attached Files
File Type: sma Get Plugin or Get Source (SINI Money Saving Example.sma - 516 views - 2.3 KB)
File Type: inc SINI.inc (6.5 KB, 513 views)

Last edited by Startukk; 07-13-2013 at 15:01. Reason: v1.4 version.
Startukk is offline
lebox
Junior Member
Join Date: Aug 2011
Old 07-06-2013 , 11:42   Re: [INC] SINI - Startukk INI
Reply With Quote #2

nice inc, easy to get the point
lebox is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-06-2013 , 12:29   Re: [INC] SINI - Startukk INI
Reply With Quote #3

Your code is absolutely horrible, in the meaning inefficient.

Just for the example : SINI_OPen()
  • You check an empty string with a native when you can check just [0] != EOS
  • You check if file exists when you can know with fopen()
  • You create variables before knowing if file can be opened
  • The most horrible part: you read line by line using file_size + read_file, while the latter already use fopen (!). You could just use fgets...
  • Calling these replace_all seems unnecessary, just parse with the '=' and document to not use space in params.

The others function is the same OMG reaction.

It's welcomed to see useful stocks, but proposing something worse than original way...
__________________

Last edited by Arkshine; 07-06-2013 at 12:30.
Arkshine is offline
Startukk
Junior Member
Join Date: Jul 2013
Old 07-06-2013 , 12:41   Re: [INC] SINI - Startukk INI
Reply With Quote #4

Quote:
Originally Posted by Arkshine View Post
Your code is absolutely horrible, in the meaning inefficient.

Just for the example : SINI_OPen()
  • You check an empty string with a native when you can check just [0] != EOS
  • You check if file exists when you can know with fopen()
  • You create variables before knowing if file can be opened
  • The most horrible part: you read line by line using file_size + read_file, while the latter already use fopen (!). You could just use fgets...
  • Calling these replace_all seems unnecessary, just parse with the '=' and document to not use space in params.

The others function is the same OMG reaction.

It's welcomed to see useful stocks, but proposing something worse than original way...
Thank you, Im working on a fix right now.
.INC will be updated soon.


EDIT: Include is now updated to version 1.1
Thanks to Arkshine for letting me know my mistakes!
If you people find any other bug feel free to report about it here and I'll fix it ASAP.
If you people have any suggestions feel free to post them here and I'll see what I can do about it.

EDIT 2: Found some client_print parts that were for testing purposes, It is removed now.
Also added new functions, check changelog!

Last edited by Startukk; 07-06-2013 at 18:41.
Startukk is offline
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 07-07-2013 , 03:29   Re: [INC] SINI v1.2 - Advanced File Reading/Writing - UPDATED!
Reply With Quote #5

This is almost as the Cell Trie, expect the cell trie doesn't have a count function.

Anyway, nice job.
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
pokemonmaster is offline
Startukk
Junior Member
Join Date: Jul 2013
Old 07-07-2013 , 03:45   Re: [INC] SINI v1.2 - Advanced File Reading/Writing - UPDATED!
Reply With Quote #6

Quote:
Originally Posted by pokemonmaster View Post
This is almost as the Cell Trie, expect the cell trie doesn't have a count function.

Anyway, nice job.
Thank you!
Startukk is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-07-2013 , 04:35   Re: [INC] SINI v1.2 - Advanced File Reading/Writing - UPDATED!
Reply With Quote #7

It's still poorly coded, and even if it was really well-coded, it doesn't offer really useful and it doesn't seem you know really what you're doing.

In SINI_Open() : I told you to use the EXISTING fopen() to know if a file exists or not, why did you ADD another fopen/close before ? It doesn't make sense...

Still using replace_all everywhere is just wrong.

This should be used Trie, as you associate a param to its value, to remove hardcoded limit, and to check/get/set more efficiently with one line.

At the end, when doing that, since code will be simplified, it will appear all you're doing is to make wrappers to use same function name SINI_something() without offering something useful.
__________________
Arkshine is offline
Startukk
Junior Member
Join Date: Jul 2013
Old 07-07-2013 , 04:55   Re: [INC] SINI v1.2 - Advanced File Reading/Writing - UPDATED!
Reply With Quote #8

Quote:
Originally Posted by Arkshine View Post
It's still poorly coded, and even if it was really well-coded, it doesn't offer really useful and it doesn't seem you know really what you're doing.

In SINI_Open() : I told you to use the EXISTING fopen() to know if a file exists or not, why did you ADD another fopen/close before ? It doesn't make sense...

Still using replace_all everywhere is just wrong.

This should be used Trie, as you associate a param to its value, to remove hardcoded limit, and to check/get/set more efficiently with one line.

At the end, when doing that, since code will be simplified, it will appear all you're doing is to make wrappers to use same function name SINI_something() without offering something useful.
SINI_Open will be fixed again shortly.
I dont know any other way than replace_all, if there was split() or explode() that'd be great.
All I want to offer is simple and easy file creating/saving/writing/reading.
I want the user to have the option to write variables with spaces.


EDIT: Fixed SINI_Open, found a replacement for replace_all on SINI_Open.
Version is now 1.3, check changelog.

Last edited by Startukk; 07-07-2013 at 05:41.
Startukk is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 07-07-2013 , 07:48   Re: [INC] SINI v1.3 - Advanced File Reading/Writing - UPDATED!
Reply With Quote #9

Thanks, this will come for sure handy sometime.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Startukk
Junior Member
Join Date: Jul 2013
Old 07-07-2013 , 07:53   Re: [INC] SINI v1.3 - Advanced File Reading/Writing - UPDATED!
Reply With Quote #10

Quote:
Originally Posted by bibu View Post
Thanks, this will come for sure handy sometime.
Thank you, I appreciate that
Startukk is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:48.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode