Final the fileio doc

This commit is contained in:
ineed bots 2023-12-01 01:22:45 -06:00
parent 9648a38fbe
commit 56e8c485af

View File

@ -12,24 +12,24 @@ Adds custom GSC functions.
## FileIO ## FileIO
This plugin provides FileIO interface to GSC for reading and writing files, this is exact to [CoD4x's](https://github.com/callofduty4x/CoD4x_Server/blob/master/scriptdocumentation/script_functions_reference.md#file-operations) interface. This plugin provides FileIO interface to GSC for reading and writing files, this is exact to [CoD4x's](https://github.com/callofduty4x/CoD4x_Server/blob/master/scriptdocumentation/script_functions_reference.md#file-operations) interface.
However, all reads and writes will take place strictly and only in the `scriptdata` folder. However, all reads and writes will take place strictly and only in the `scriptdata` folder, no up directory traversal allowed.
All files will be closed upon GSC restart (map_restart or fast_restart or missionfailed, etc), only a maximum of 10 files may be opened at once. All files will be closed upon GSC restart (map_restart or fast_restart or missionfailed, etc), only a maximum of 10 files may be opened at once.
* `<bool> FS_TestFile(<filename string>)` Returns `true` if the file exists, `false` otherwise. * `<bool> FS_TestFile(<filename string>)` Returns `true` if the file exists, `false` otherwise.
* `<bool> FS_Remove(<filename string>)` Deletes the file, return `true` if successful, `false` otherwise.
```gsc ```gsc
if (FS_TestFile("test.txt")) // test to see if "scriptdata/test.txt" file exists
if (FS_TestFile("test.txt")) // not a typo, all file io will take place inside the "scriptdata" folder
{ {
PrintConsole("Found test.txt!"); PrintConsole("Found test.txt!");
}
```
* `<bool> FS_Remove(<filename string>)` Deletes the file, return `true` if successful. // delete it!
```gsc
if (FS_Remove("test.txt")) if (FS_Remove("test.txt"))
{ {
PrintConsole("test.txt was deleted!"); PrintConsole("test.txt was deleted!");
} }
}
``` ```
* `FS_FCloseAll()` Closes every full file. * `FS_FCloseAll()` Closes every full file.
@ -39,11 +39,11 @@ All files will be closed upon GSC restart (map_restart or fast_restart or missio
FS_FCloseAll(); // close them all FS_FCloseAll(); // close them all
``` ```
* `<int> FS_FOpen(<filename string>, <mode string>)` Tries to open the file, mode is one of `read`, `write` (clears the file), `append` (appends to the file), returns the filehandle. Will return `0` if failed to open. * `<int> FS_FOpen(<filename string>, <mode string>)` Tries to open the file, mode must be one of `read`, `write` (clears the file), `append` (appends to the file), returns the filehandle. Will return `0` if failed to open.
* `FS_FClose(<filehandle int>)` Closes the file pointed by the filehandle given, which was returned from `FS_FOpen`. * `FS_FClose(<filehandle int>)` Closes the file pointed by the filehandle given, which was returned from `FS_FOpen`.
```gsc ```gsc
// opens "scriptdata/test.txt", all io will take place inside the "scriptdata" folder // opens "scriptdata/test.txt", all io will take place inside the "scriptdata" folder
f = FS_FOpen("test.txt", "read"); // can be "read" "write" or "append" f = FS_FOpen("test.txt", "read"); // can be "read" "write", or "append"
if (!f) if (!f)
{ {
@ -76,7 +76,7 @@ All files will be closed upon GSC restart (map_restart or fast_restart or missio
// close the file // close the file
``` ```
* `<bool> FS_WriteLine(<filehandle int>, <contents string>)` Writes to the file pointed by the filehandle. Appends a newline character. Returns `true` if successful. Filehandle must be opened for writing. * `<bool> FS_WriteLine(<filehandle int>, <contents string>)` Writes to the file pointed by the filehandle. Appends a newline character. Returns `true` if successful, `false` otherwise. Filehandle must be opened for writing.
* `<bool> FS_Write(<filehandle int>, <contents string>)` Same as above, does not add a newline character. * `<bool> FS_Write(<filehandle int>, <contents string>)` Same as above, does not add a newline character.
```gsc ```gsc
// open the file for writing // open the file for writing