26.07.2012, 21:31
(
Последний раз редактировалось Maxips2; 26.07.2012 в 22:36.
)
Introduction:
Recently I was struggling with different file systems, some were slow or some weren't convinient at all.
I decided to write my own system, and I've been working on it for a while.
This is the first system I am releasing, so please be gentle with your comments!
How To Use:
Simply download the file, and put it in your includes folder.
At the top of your filterscript/gamemode write this line:
after this line:
should look like this:
Settings:
I have declared a few defines in the include itself, I advice to keep it as it is, but if you insist you may change it.
Version:
• mFiles v1.0 - Initial Release
Bugs:
• None found yet, however if you find a bug please post here or PM me on forums with the details.
Download:
Mediafire: http://www.mediafire.com/?u4xcoh45wkrbqh5
Please do not make any mirrors without my permission.
Examples:
Writing:
Writing is done in a very simple way:
Open a file, write the data and close the file.
Reading:
Reading is done pretty much the same way, open a file, read the data and close it.
Functions:
Natives:
• File_Create(filename[])
(accuracy idea was originally by ****** as you can see in y_ini)
Running this code: http://pastebin.com/J5X7n9Xz
Writing:
Writing 100 strings into a blank file:
Writing (replacing) 100 strings in a file:
Reading:
Reading 100 strings from a file:
Recently I was struggling with different file systems, some were slow or some weren't convinient at all.
I decided to write my own system, and I've been working on it for a while.
This is the first system I am releasing, so please be gentle with your comments!
How To Use:
Simply download the file, and put it in your includes folder.
At the top of your filterscript/gamemode write this line:
pawn Код:
#include <mfiles>
pawn Код:
#include <a_samp>
pawn Код:
#include <a_samp>
#include <mfiles>
// Other includes ...
I have declared a few defines in the include itself, I advice to keep it as it is, but if you insist you may change it.
pawn Код:
#define MAX_FILE_READ_STRING 255
// The number of cells which will be used in the reading/writing array.
#define MAX_KEY_LEN 32
// Maximum length of a key
#define MAX_VAL_LEN 128
// Maximum length of a value.
#define KEY_IGNORECASE false
// Ignorecase:
// When set to false: when reading/writing to a file it will be case-sensetive.
// That means that VALUE and value won't be the same key.
// If set to true it does the opposite action.
• mFiles v1.0 - Initial Release
Bugs:
• None found yet, however if you find a bug please post here or PM me on forums with the details.
Download:
Mediafire: http://www.mediafire.com/?u4xcoh45wkrbqh5
Please do not make any mirrors without my permission.
Examples:
Writing:
Writing is done in a very simple way:
Open a file, write the data and close the file.
pawn Код:
new file[] = "settings.ini";
// Check if a file exists, if not: create it.
if(!File_Exists(file)) File_Create(file);
// Begin writing into a file.
File_Write(file);
// Writing the data...
File_WriteString("hostname", "gamemode_0");
File_WriteInt("maxplayers", 50);
File_WriteFloat("gravity", 0.08);
File_WriteBool("allow_connect", true);
File_WriteHex("spawn_color", 0xFFFFFF);
File_WriteBin("binary_info", 0b1110110);
// Finish writing, save and close.
File_WriteFinish(file);
Reading is done pretty much the same way, open a file, read the data and close it.
pawn Код:
new hostname[11], maxplayers, Float:gravity, bool:allow_connect, file[] = "settings.ini";
// Check if file exists
if(File_Exists(file)) {
// Open the file
File_Open(file);
// Read the data from it...
File_GetStringEx("hostname", hostname);
maxplayers = File_GetInt("maxplayers");
gravity = File_GetFloat("gravity");
allow_connect = File_GetBool("allow_connect");
// Close the file
File_Close();
}
Natives:
pawn Код:
native File_Create(filename[]);
native File_Rename(filename[], newfile[]);
native File_Copy(filename[], copyname[], bool:remove_original = false, bool:content_only = false);
native File_Exists(filename[]);
native File_Write(filename[]);
native File_WriteInt(key[], value);
native File_WriteFloat(key[], Float:value, accuracy = 6);
native File_WriteString(key[], value[]);
native File_WriteHex(key[], value);
native File_WriteBool(key[], bool:value);
native File_WriteBin(key[], value);
native File_WriteFinish(filename[]);
native File_Open(filename[]);
native File_GetInt(key[]);
native File_GetFloat(key[]);
native File_GetString(key[]);
native File_GetStringEx(key[], dest[], size = sizeof(dest), bool:pack = false);
native File_GetHex(key[]);
native File_GetBool(key[]);
native File_GetBin(key[]);
native File_Close();
Description: Create a new file.• File_Rename(filename[], newfile[])
Returns: 1 if succeded, 0 if failed (or file already exists).
Parameters:- filename[] - The name of the file you want to create.
Description: Rename a file.• File_Copy(filename[], copyname[], bool:remove_original = false, bool:content_only = false)
Returns: 1 if succeded, 0 if failed (or original doesn't exist/new name already exist).
Parameters:- filename[] - The name of the file you want to rename.
- newfile[] - The new name of the file.
Description: Copy a file.• File_Exists(filename[])
Returns: 1 if succeded, 0 if failed
Parameters:- filename[] - The name of the file you want to copy.
- copyname[] - The name of the copy file.
- bool:remove_original - Remove original file (set to false by default).
- bool:content_only - Copy content only (set to false by default).
Description: Check if a file exists.• File_Write(filename[])
Returns: 1 if exists, 0 if not.
Parameters:- filename[] - Name of the file you want to check if exists.
Description: Begin writing into a file.• File_WriteString(key[], value[])
Returns: 1 if succeded, 0 if failed.
Parameters:- filename[] - The name of the file you want to write into.
Description: Write a string into a file.• File_WriteInt(key[], value)
Returns: 1 if succeded, 0 if failed.
Parameters:- key[] - The name of the file you want to write into.
- value[] - The string value you want to write.
Description: Write an integer into a file.• File_WriteFloat(key[], Float:value, accuracy = 6)
Returns: 1 if succeded, 0 if failed.
Parameters:- key[] - The name of the file you want to write into.
- value - The integer value you want to write.
(accuracy idea was originally by ****** as you can see in y_ini)
Description: Write a float into a file.• File_WriteBool(key[], bool:value)
Returns: 1 if succeded, 0 if failed.
Parameters:- key[] - The name of the file you want to write into.
- Float:value - The float value you want to write.
- accuracy - The number of digits after the dot.
Description: Write a boolean into a file.• File_WriteHex(key[], value)
Returns: 1 if succeded, 0 if failed.
Parameters:- key[] - The name of the file you want to write into.
- bool:value - The boolean value you want to write.
Description: Write an hexadecimal into a file.• File_WriteBin(key[], value)
Returns: 1 if succeded, 0 if failed.
Parameters:- key[] - The name of the file you want to write into.
- value - The hexadecimal value you want to write.
Description: Write a binary into a file.• File_WriteFinish(filename[])
Returns: 1 if succeded, 0 if failed.
Parameters:- key[] - The name of the file you want to write into.
- value - The binary value you want to write.
Description: Write the data into the originally file and close it (must be used when finishing writing).• File_Open(filename[])
Returns: None.
Parameters:- filename[] - The name of the file you finish writing to.
Description: Open a file to begin reading from it.• File_GetString(key[])
Returns: 1 if succeded, 0 if failed (or file doesn't exist).
Parameters:- filename[] - The name of the file you want to read from.
Description: Read a string value from a file.• File_GetStringEx(key[], dest[], size = sizeof(dest), bool: pack = false)
Returns: The string it read from a file.
Parameters:- key[] - The key you want to read from.
Description: Read a string value from a file (with extra parameters).• File_GetInt(key[])
Returns: Nothing if failed.
Parameters:- key[] - The key you want to read from.
- dest[] - The array you want to save the string to.
- size - Size of the array.
- bool: pack - Pack the string or not (set to false by default).
Description: Read an integer value from a file.• Float: File_GetFloat(key[])
Returns: The integer it read from a file.
Parameters:- key[] - The key you want to read from.
Description: Read a float value from a file.• bool: File_GetBool(key[])
Returns: The float it read from a file.
Parameters:- key[] - The key you want to read from.
Description: Read a boolean value from a file.• File_GetHex(key[])
Returns: The boolean value it read from a file.
Parameters:- key[] - The key you want to read from.
Description: Read an hexadecimal value from a file.• File_GetBin(key[])
Returns: The hexadecimal value it read from a file.
Parameters:- key[] - The key you want to read from.
Description: Read a binary value from a file.• File_Close()
Returns: The binary value it read from a file.
Parameters:- key[] - The key you want to read from.
Description: Finish reading from a file and close it.Timings:
Returns: None.
Running this code: http://pastebin.com/J5X7n9Xz
Writing:
Writing 100 strings into a blank file:
Код:
4 (ms)
Код:
50-60 (ms)
Reading 100 strings from a file:
Код:
20-40 (ms)