SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 03/05/2011, 05:49 PM   #1
RyDeR`
High-roller
 
RyDeR`'s Avatar
 
Join Date: Feb 2009
Location: Belgium
Posts: 2,929
Reputation: 700
Default FileFunctions v0.1b

FileFunctions v0.1b

This plugin allows you to manage files. There are some interresting features:
  • Lots of functions
  • More filemodes available
  • Slightly faster than SA-MP I/O
  • Allows you to manage files not only limited in 'scriptfiles' but over your whole server directory (starting from the root)
  • Usage is very similar and working is exact the same like SA:MP I/O
  • Using a 'File' tag for file index.
  • ...

Natives
  • File: fileOpen(const fileName[], io_FileMode: fileMode);
    • Opens a file.
    • If the file has been succesfully opened the function will return a pointer to a file object that is used to identify the handle on all further operations involving it. Otherwise, a null pointer is returned.
  • File: fileReOpen(File: handle, const fileName[], io_FileMode: fileMode);
    • Reopens a file.
    • If the file was succesfully reopened, the function returns a pointer to an object identifying the handle. Otherwise, a null pointer is returned.
  • fileClose(File: handle);
    • Closes a file.
    • If the handle is successfully closed, a zero value is returned. On failure, EOF (-1) is returned.
  • fileRemove(const fileName[]);
    • Removes a file.
    • If the file is successfully removed, a true value is returned. On failure, a null pointer is returned.
  • fileExists(const fileName[]);
    • Checks if a files exists.
    • If the file exists, a true value is returned. On failure, a null pointer is returned.
  • fileMove(const currentFilePath[], const newFilePath[]);
    • Moves a file. It can be used to rename a file too.
    • If the file is succesfully moved, a true value is returned. On failure, a null pointer is returned.
  • fileRewind(File: handle);
    • Sets the position indicator associated with handle to the beginning of the file.
    • If the file that has to be rewind exists, a true value is returned. On failure, a null pointer is returned.
  • fileWrite(File: handle, const string[]);
    • Writes the string to the current position of the handle.
    • The total number of elements successfully written is returned.
  • fileRead(File: handle, buffer[], const size = sizeof(buffer));
    • Reads the file starting from the current position of the handle and stores the data in the buffer. Reads line by line.
    • If reading is succesful, a true value will be returned. On failure, a null pointer is returned.
  • filePutChar(File: handle, value);
    • Writes a character to the handle and advances the position indicator.
    • If there are no errors, the same character that has been written is returned. On failure, EOF (-1) is returned.
  • fileGetChar(File: handle);
    • Returns the character currently pointed by the internal file position indicator of the specified handle.
    • If there are no errors, the character read is returned as an integer value. On failure, EOF (-1) is returned.
  • fileSeek(File: handle, position, seek_Origin: origin);
    • Sets the position indicator associated with the stream to a new position defined by adding offset to a reference position specified by origin.
    • If there are no errors, a true value is returned. Otherwise, a null pointer is returned.
  • fileLength(File: handle);
    • On success, the current value of the position indicator is returned.
    • If there are no errors, the size of the file will return in bytes. On failure, EOF (-1) is returned.

Changelog

0.1b:
- Initial release.

Download

Download (Source + Include + .dll) (Windows)
Download (Source + .so) (Linux)

Note(s)

- You must have Microsoft .NET Framework 4 installed to run this.
- This is a beta version and may contain bugs. Please report if you find one.
- Credits go to this site where I got many useful information from.
__________________

Sup?

Last edited by RyDeR`; 06/08/2011 at 06:35 PM.
RyDeR` is offline   Reply With Quote
Old 03/05/2011, 05:54 PM   #2
CJ101
High-roller
 
CJ101's Avatar
 
Join Date: Jan 2008
Location: RevolutionX
Posts: 1,759
Reputation: 162
Default Re: FileFunctions v0.1b

Cool, but would be nice to be able to remove specific lines from files too.

Update:
You would be the sexiest person in SA-MP if you integrated a INI system into this too.
__________________
I have left SA-MP. Thanks for a great ten years.

Last edited by CJ101; 03/05/2011 at 09:17 PM.
CJ101 is offline   Reply With Quote
Old 03/05/2011, 06:49 PM   #3
Zh3r0
High-roller
 
Join Date: Mar 2008
Posts: 4,513
Reputation: 398
Default Re: FileFunctions v0.1b

Nice job RyDeR.

How about some functions to check folders, for example?
__________________
Zh3r0 is offline   Reply With Quote
Old 03/05/2011, 07:00 PM   #4
fissekarl
Big Clucker
 
Join Date: Apr 2011
Posts: 142
Reputation: 0
Default Re: FileFunctions v0.1b

Nice

Last edited by fissekarl; 07/06/2011 at 04:48 PM.
fissekarl is offline   Reply With Quote
Old 03/05/2011, 07:06 PM   #5
1337connor
Huge Clucker
 
Join Date: Nov 2008
Posts: 228
Reputation: 14
Default Re: FileFunctions v0.1b

Suggestion:
FileRename(const currentName[], const newName[]);

Would be useful for /setname
1337connor is offline   Reply With Quote
Old 03/05/2011, 07:08 PM   #6
RyDeR`
High-roller
 
RyDeR`'s Avatar
 
Join Date: Feb 2009
Location: Belgium
Posts: 2,929
Reputation: 700
Default Re: FileFunctions v0.1b

@cj101:
Great idea, I'll add that ASAP!

@Zh3r0:
Thanks Zh3r0! Oh, a function like "directoryExists" or something?

@fissekarl:
Sure, you will be able to do that when I add the proposal from cj101. Check the topic for updates.

@1337connor:
"fileMove(const currentFilePath[], const newFilePath[]);" does the thing that you want
__________________

Sup?
RyDeR` is offline   Reply With Quote
Old 03/05/2011, 07:15 PM   #7
GaGlets(R)
Gangsta
 
GaGlets(R)'s Avatar
 
Join Date: Oct 2009
Posts: 791
Reputation: 3
Default Re: FileFunctions v0.1b

Thank you! You made my minute x]
GaGlets(R) is offline   Reply With Quote
Old 03/05/2011, 07:32 PM   #8
Ricop522
High-roller
 
Ricop522's Avatar
 
Join Date: Feb 2010
Location: ES
Posts: 2,640
Reputation: 159
Default Re: FileFunctions v0.1b

I love that
__________________
"Any fool can write code that a
computer can understand. Good
programmers write code that
humans can understand."

AJUDA! Programação
Github
Ricop522 is offline   Reply With Quote
Old 03/05/2011, 07:40 PM   #9
=WoR=Varth
High-roller
 
=WoR=Varth's Avatar
 
Join Date: Apr 2011
Location: Indonesia
Posts: 1,988
Reputation: 133
Default Re: FileFunctions v0.1b

Good work
__________________
(RETIRED)
=WoR=Varth is offline   Reply With Quote
Old 03/05/2011, 07:57 PM   #10
Calgon
Banned
 
Join Date: Jan 2009
Posts: 6,136
Reputation: 1127
Default Re: FileFunctions v0.1b

You should create a function for fileRename() for people who won't be able to understand how fileMove() works.
Calgon is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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



All times are GMT. The time now is 05:27 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.