SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Plugin Development (https://forum.sa-mp.com/forumdisplay.php?f=18)
-   -   [Plugin] fsutil - File System Utilities for Pawn (Up-to-date FileManager Replacement) (https://forum.sa-mp.com/showthread.php?t=653119)

[HLF]Southclaw 26/04/2018 07:22 PM

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

Kaperstone 26/04/2018 08:22 PM

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.

[HLF]Southclaw 27/04/2018 04:48 PM

Re: fsutil - File System Utilities for Pawn (Up-to-date FileManager Replacement)
 
Quote:

Originally Posted by Kaperstone (Post 4015423)
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.

Zeth 27/04/2018 05:24 PM

Re: fsutil - File System Utilities for Pawn (Up-to-date FileManager Replacement)
 
Finally a C++ like filesystem for Pawn. Cheers!

[HLF]Southclaw 28/05/2018 03:47 PM

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.

Gammix 12/06/2018 02:07 PM

Re: fsutil - File System Utilities for Pawn (Up-to-date FileManager Replacement)
 
There's no download link in thread.

Zeth 16/06/2018 04:52 PM

Re: fsutil - File System Utilities for Pawn (Up-to-date FileManager Replacement)
 
Quote:

Originally Posted by Gammix (Post 4027969)
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


All times are GMT. The time now is 04:24 PM.

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