SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 26/04/2018, 06:22 PM   #1
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,883
Reputation: 1443
Default fsutil - File System Utilities for Pawn (Up-to-date FileManager Replacement)

fsutil

fsutil is a file system utility plugin for Pawn.

Provides a simple API for checking existence, creating, reading and removing directories and moving/copying files or directories.

Installation

Simply install to your project:

Code:
sampctl package install Southclaws/samp-fsutil
Include in your code and begin using the library:

Code:
#include <fsutil>
Usage

Exists, CreateDir, RemoveDir are self explanatory. Exists works on files and directories.

OpenDir opens a directory ready for iterating, each DirNext call will iterate through the directory, use it like while(DirNext(dir, type, entry) { ... where type and entry are pass by reference. When you’re done, use CloseDir to close the directory and free memory:

Code:
new
    Directory:dir = OpenDir(testDir),
    entry[256],
    ENTRY_TYPE:type;

while(DirNext(dir, type, entry)) {
    if(type == E_REGULAR) {
        printf("File: %s", entry);
    } else if(type == E_DIRECTORY) {
        printf("Directory: %s", entry);
    } else {
        printf("Something else: %s", entry);
    }
}

new ret = CloseDir(dir); // always close an open Directory
MoveFile and CopyFile do exactly what you expect.

Path Functions

There are also a handful of helper functions for working with file paths:
  • PathSep
  • PathJoin
  • PathBase
  • PathDir
  • PathExt

See the source code for documentation.

Testing

To run unit tests for Windows, first build the plugin with Visual Studio. If you use “Open CMake” mode, the .dll file will be output directly to the plugins directory of the test runtime. If you use cmake to generate a solution file, the .dll file will probably be in a directory inside plugins named Release (or Debug) so you’ll have to copy that out first with cp test/plugins/Release/fsutil.dll test/plugins/fsutil.dll.

Code:
make test-windows
Linux testing can be done on Windows if you have Docker installed. The following command just runs the same as the test-windows but with --container activated to vitualise a Linux environment.

Code:
make test-linux
__________________
Tools:

Plugins:

Links:


Last edited by [HLF]Southclaw; 28/05/2018 at 02:47 PM.
[HLF]Southclaw is online now   Reply With Quote
Old 26/04/2018, 07:22 PM   #2
Kaperstone
High-roller
 
Kaperstone's Avatar
 
Join Date: May 2011
Location: Russia
Posts: 3,352
Reputation: 822
Default Re: fsutil - File System Utilities for Pawn (Up-to-date FileManager Replacement)

What about automating this.

I give it a name, create a template on GameModeInit with operations and then when I want to call it, I'd call the template by its name.

Could be useful for calling a function once like performing save where you open a file, call 100 times the same more or less functions to save fresh data per player (auto save perhaps?), so instead of this, call a single function with the first parameter serving as the name and the rest follows by the order of the functions used in the template

Code:
template MyAwesomeTemplate {
OpenFileIn("users");
InsertInt();
InsertFloat();
InsertFloat();
InsertFloat();
InsertString();
}

callTemplate("MyAwesomeTemplate", "filename.ini", 5, 10.0000, 5.0000, 1.0000, GetPlayerName(playerid));
Just an idea I had in mind.
__________________
Find me on GitHubSEF Community (Official NEF Successor) • SA:MP ReviewsFind me on Steam
Kaperstone is offline   Reply With Quote
Old 27/04/2018, 03:48 PM   #3
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,883
Reputation: 1443
Default Re: fsutil - File System Utilities for Pawn (Up-to-date FileManager Replacement)

Quote:
Originally Posted by Kaperstone View Post
What about automating this.

I give it a name, create a template on GameModeInit with operations and then when I want to call it, I'd call the template by its name.

Could be useful for calling a function once like performing save where you open a file, call 100 times the same more or less functions to save fresh data per player (auto save perhaps?), so instead of this, call a single function with the first parameter serving as the name and the rest follows by the order of the functions used in the template

Code:
template MyAwesomeTemplate {
OpenFileIn("users");
InsertInt();
InsertFloat();
InsertFloat();
InsertFloat();
InsertString();
}

callTemplate("MyAwesomeTemplate", "filename.ini", 5, 10.0000, 5.0000, 1.0000, GetPlayerName(playerid));
Just an idea I had in mind.
That's a bit out of scope for this plugin, this is designed to be a lower level API for filesystem access. I may implement functions for manipulating directory paths and some other helpers but that's it.

Also I'm pretty sure you just described the concept of a function.
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is online now   Reply With Quote
Old 27/04/2018, 04:24 PM   #4
Zeth
Huge Clucker
 
Zeth's Avatar
 
Join Date: Feb 2017
Location: Debjit's Place | India
Posts: 464
Reputation: 77
Default Re: fsutil - File System Utilities for Pawn (Up-to-date FileManager Replacement)

Finally a C++ like filesystem for Pawn. Cheers!
__________________


Zeth is online now   Reply With Quote
Old 28/05/2018, 02:47 PM   #5
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,883
Reputation: 1443
Default Re: fsutil - File System Utilities for Pawn (Up-to-date FileManager Replacement)

fsutil is now 1.0 and declared stable after some testing and usage!

- Release page

I've also added some helper functions for working with file paths:
  • PathSep
  • PathJoin
  • PathBase
  • PathDir
  • PathExt

Ensure you have the latest version with:

Code:
sampctl package ensure
And if you want to be super safe, add a version tag to the entry in pawn.json:

Code:
{
...
  "dependencies": [
    "Southclaws/pawn-fsutil:1.x"
  ]
...
}
1.x will ensure you have the latest 1.0.0 version for all future 1.x.y releases.
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is online now   Reply With Quote
Old 12/06/2018, 01:07 PM   #6
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,740
Reputation: 793
Default Re: fsutil - File System Utilities for Pawn (Up-to-date FileManager Replacement)

There's no download link in thread.
__________________
Gammix is offline   Reply With Quote
Old 16/06/2018, 03:52 PM   #7
Zeth
Huge Clucker
 
Zeth's Avatar
 
Join Date: Feb 2017
Location: Debjit's Place | India
Posts: 464
Reputation: 77
Default Re: fsutil - File System Utilities for Pawn (Up-to-date FileManager Replacement)

Quote:
Originally Posted by Gammix View Post
There's no download link in thread.
Yes, 'cause he likes to spread sampctl and wants you to use it. ;p.

https://github.com/Southclaws/pawn-fsutil/releases
__________________


Zeth is online now   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


Similar Threads
Thread Thread Starter Forum Replies Last Post
What date type does pawn use? BenStar Scripting Help 1 11/03/2018 10:40 AM
[FilterScript] File Editor (Using FileManager plugin) Mandrakke Filterscripts 5 22/09/2012 09:24 PM
V-Admin register system replacement request! lionlev Help Archive 2 09/06/2011 02:00 PM
Writting in a file with FileManager luis_lpv_22 Help Archive 2 19/01/2011 05:20 PM
Accounts System with FileManager luis_lpv_22 Help Archive 4 18/01/2011 11:53 PM


All times are GMT. The time now is 08:23 AM.


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