Files
The plugin’s own files, whole at a time, like its saves and cache. Each call runs on a worker, so it never stalls a game thread, and the game’s I/O watchers don’t see it. Any thread.
A path is relative to a root, or absolute. Its own folders (game_data, data, cache) are free to
read and write, and its own files and the game’s folder free to read. So is whatever the player picks
in pickFile or pickFolder. Anything else needs “files”: true in “permissions” in its wraith.json.
Get it with Api.files().
resolve(root: Wraith.Files.Root | Wraith.Files.RootName, path: string): stringread(root: Wraith.Files.Root | Wraith.Files.RootName, path: string, max_bytes: number | bigint): Promise<Uint8Array | null>write(root: Wraith.Files.Root | Wraith.Files.RootName, path: string, bytes: Array<number>): Promise<void>append(root: Wraith.Files.Root | Wraith.Files.RootName, path: string, bytes: Array<number>): Promise<void>list(root: Wraith.Files.Root | Wraith.Files.RootName, path: string): Promise<Array<Wraith.Files.Info>>stat(root: Wraith.Files.Root | Wraith.Files.RootName, path: string): Promise<Wraith.Files.Info>remove(root: Wraith.Files.Root | Wraith.Files.RootName, path: string): Promise<void>move(from_root: Wraith.Files.Root | Wraith.Files.RootName, from: string, to_root: Wraith.Files.Root | Wraith.Files.RootName, to: string): Promise<void>makeDir(root: Wraith.Files.Root | Wraith.Files.RootName, path: string): Promise<void>pickFile(options: import("salamander").Given<Wraith.Files.FileDialog>): Promise<string | null>pickFolder(options: import("salamander").Given<Wraith.Files.FolderDialog>): Promise<string | null>resolve(root: Wraith.Files.Root|Wraith.Files.RootName, path: string): stringread(root: Wraith.Files.Root|Wraith.Files.RootName, path: string, max_bytes: integer): salamander.Promisewrite(root: Wraith.Files.Root|Wraith.Files.RootName, path: string, bytes: (integer)[]): salamander.Promiseappend(root: Wraith.Files.Root|Wraith.Files.RootName, path: string, bytes: (integer)[]): salamander.Promiselist(root: Wraith.Files.Root|Wraith.Files.RootName, path: string): salamander.Promisestat(root: Wraith.Files.Root|Wraith.Files.RootName, path: string): salamander.Promiseremove(root: Wraith.Files.Root|Wraith.Files.RootName, path: string): salamander.Promisemove(from_root: Wraith.Files.Root|Wraith.Files.RootName, from: string, to_root: Wraith.Files.Root|Wraith.Files.RootName, to: string): salamander.PromisemakeDir(root: Wraith.Files.Root|Wraith.Files.RootName, path: string): salamander.PromisepickFile(options: Wraith.Files.FileDialog): salamander.PromisepickFolder(options: Wraith.Files.FolderDialog): salamander.Promisestring Resolve(Wraith.Files.Root root, string path)System.Threading.Tasks.Task<Salamander.Blob?> ReadAsync(Wraith.Files.Root root, string path, ulong max_bytes, System.Threading.CancellationToken cancel = default)System.Threading.Tasks.Task WriteAsync(Wraith.Files.Root root, string path, byte[] bytes, System.Threading.CancellationToken cancel = default)System.Threading.Tasks.Task AppendAsync(Wraith.Files.Root root, string path, byte[] bytes, System.Threading.CancellationToken cancel = default)System.Threading.Tasks.Task<Wraith.Files.Info[]> ListAsync(Wraith.Files.Root root, string path, System.Threading.CancellationToken cancel = default)System.Threading.Tasks.Task<Wraith.Files.Info> StatAsync(Wraith.Files.Root root, string path, System.Threading.CancellationToken cancel = default)System.Threading.Tasks.Task RemoveAsync(Wraith.Files.Root root, string path, System.Threading.CancellationToken cancel = default)System.Threading.Tasks.Task MoveAsync(Wraith.Files.Root from_root, string from, Wraith.Files.Root to_root, string to, System.Threading.CancellationToken cancel = default)System.Threading.Tasks.Task MakeDirAsync(Wraith.Files.Root root, string path, System.Threading.CancellationToken cancel = default)System.Threading.Tasks.Task<string?> PickFileAsync(Wraith.Files.FileDialog options, System.Threading.CancellationToken cancel = default)System.Threading.Tasks.Task<string?> PickFolderAsync(Wraith.Files.FolderDialog options, System.Threading.CancellationToken cancel = default)sal::Result<std::string_view, Wraith::FileError> resolve(Wraith::Files_Root root, std::string_view path) constsal::Future<sal::Blob, Wraith::FileError> read(Wraith::Files_Root root, std::string_view path, uint64_t max_bytes) constsal::Future<void, Wraith::FileError> write(Wraith::Files_Root root, std::string_view path, std::span<const uint8_t> bytes) constsal::Future<void, Wraith::FileError> append(Wraith::Files_Root root, std::string_view path, std::span<const uint8_t> bytes) constsal::Future<sal::Slice<Wraith::Files_Info>, Wraith::FileError> list(Wraith::Files_Root root, std::string_view path) constsal::Future<Wraith::Files_Info, Wraith::FileError> stat(Wraith::Files_Root root, std::string_view path) constsal::Future<void, Wraith::FileError> remove(Wraith::Files_Root root, std::string_view path) constsal::Future<void, Wraith::FileError> move(Wraith::Files_Root from_root, std::string_view from, Wraith::Files_Root to_root, std::string_view to) constsal::Future<void, Wraith::FileError> makeDir(Wraith::Files_Root root, std::string_view path) constsal::Future<sal::Opt<sal::String>, Wraith::FileError> pickFile(Wraith::Files_FileDialog options) constsal::Future<sal::Opt<sal::String>, Wraith::FileError> pickFolder(Wraith::Files_FolderDialog options) constpub fn resolve(&self, root: wraith::FilesRoot, path: &str) -> Result<&str, wraith::FileError>pub fn read(&self, root: wraith::FilesRoot, path: &str, max_bytes: u64) -> salamander::Future<salamander::Blob, wraith::FileError>pub fn write(&self, root: wraith::FilesRoot, path: &str, bytes: &[u8]) -> salamander::Future<(), wraith::FileError>pub fn append(&self, root: wraith::FilesRoot, path: &str, bytes: &[u8]) -> salamander::Future<(), wraith::FileError>pub fn list(&self, root: wraith::FilesRoot, path: &str) -> salamander::Future<salamander::Slice<wraith::FilesInfo>, wraith::FileError>pub fn stat(&self, root: wraith::FilesRoot, path: &str) -> salamander::Future<wraith::FilesInfo, wraith::FileError>pub fn remove(&self, root: wraith::FilesRoot, path: &str) -> salamander::Future<(), wraith::FileError>pub fn r#move(&self, from_root: wraith::FilesRoot, from: &str, to_root: wraith::FilesRoot, to: &str) -> salamander::Future<(), wraith::FileError>pub fn make_dir(&self, root: wraith::FilesRoot, path: &str) -> salamander::Future<(), wraith::FileError>pub fn pick_file(&self, options: wraith::FilesFileDialog) -> salamander::Future<salamander::Opt<salamander::Str>, wraith::FileError>pub fn pick_folder(&self, options: wraith::FilesFolderDialog) -> salamander::Future<salamander::Opt<salamander::Str>, wraith::FileError>fn resolve(self: Wraith.Files, root: Wraith.Files.Root, path: []const u8) (Wraith.FileError || rt.Failure)![]const u8fn read(self: Wraith.Files, root: Wraith.Files.Root, path: []const u8, max_bytes: u64) rt.Promise((Wraith.FileError || rt.Failure)!rt.Blob, Wraith.FileErrorCode)fn write(self: Wraith.Files, root: Wraith.Files.Root, path: []const u8, bytes: []const u8) rt.Promise((Wraith.FileError || rt.Failure)!void, Wraith.FileErrorCode)fn append(self: Wraith.Files, root: Wraith.Files.Root, path: []const u8, bytes: []const u8) rt.Promise((Wraith.FileError || rt.Failure)!void, Wraith.FileErrorCode)fn list(self: Wraith.Files, root: Wraith.Files.Root, path: []const u8) rt.Promise((Wraith.FileError || rt.Failure)![]const raw.Wraith_Files_Info, Wraith.FileErrorCode)fn stat(self: Wraith.Files, root: Wraith.Files.Root, path: []const u8) rt.Promise((Wraith.FileError || rt.Failure)!raw.Wraith_Files_Info, Wraith.FileErrorCode)fn remove(self: Wraith.Files, root: Wraith.Files.Root, path: []const u8) rt.Promise((Wraith.FileError || rt.Failure)!void, Wraith.FileErrorCode)fn move(self: Wraith.Files, from_root: Wraith.Files.Root, from: []const u8, to_root: Wraith.Files.Root, to: []const u8) rt.Promise((Wraith.FileError || rt.Failure)!void, Wraith.FileErrorCode)fn makeDir(self: Wraith.Files, root: Wraith.Files.Root, path: []const u8) rt.Promise((Wraith.FileError || rt.Failure)!void, Wraith.FileErrorCode)fn pickFile(self: Wraith.Files, options: raw.Wraith_Files_FileDialog) rt.Promise((Wraith.FileError || rt.Failure)!?[]const u8, Wraith.FileErrorCode)fn pickFolder(self: Wraith.Files, options: raw.Wraith_Files_FolderDialog) rt.Promise((Wraith.FileError || rt.Failure)!?[]const u8, Wraith.FileErrorCode)uint32_t Wraith_Files_resolve(Wraith_Files self, Wraith_Files_Root root, sal_string path, sal_string *out)sal_Promise Wraith_Files_read(Wraith_Files self, Wraith_Files_Root root, sal_string path, uint64_t max_bytes)sal_Promise Wraith_Files_write(Wraith_Files self, Wraith_Files_Root root, sal_string path, Slice_u8 bytes)sal_Promise Wraith_Files_append(Wraith_Files self, Wraith_Files_Root root, sal_string path, Slice_u8 bytes)sal_Promise Wraith_Files_list(Wraith_Files self, Wraith_Files_Root root, sal_string path)sal_Promise Wraith_Files_stat(Wraith_Files self, Wraith_Files_Root root, sal_string path)sal_Promise Wraith_Files_remove(Wraith_Files self, Wraith_Files_Root root, sal_string path)sal_Promise Wraith_Files_move(Wraith_Files self, Wraith_Files_Root from_root, sal_string from, Wraith_Files_Root to_root, sal_string to)sal_Promise Wraith_Files_makeDir(Wraith_Files self, Wraith_Files_Root root, sal_string path)sal_Promise Wraith_Files_pickFile(Wraith_Files self, Wraith_Files_FileDialog options)sal_Promise Wraith_Files_pickFolder(Wraith_Files self, Wraith_Files_FolderDialog options)resolve
Section titled “resolve”The full path, or path itself when it’s absolute. For showing the player, not for opening yourself.
Fails with FileError. Uses Files.Root.
Its whole contents, up to max_bytes, or 64 MiB when 0.
Async. Fails with FileError. Uses Files.Root.
Replaces it whole, through a temporary file so it’s never left half written. Makes its folders.
Async. Fails with FileError. Uses Files.Root.
append
Section titled “append”Onto the end, making it if it isn’t there.
Async. Fails with FileError. Uses Files.Root.
What’s in a folder, not in any order.
Async. Fails with FileError. Uses Files.Root, Files.Info.
Async. Fails with FileError. Uses Files.Root, Files.Info.
remove
Section titled “remove”A file, or an empty folder.
Async. Fails with FileError. Uses Files.Root.
A file or folder, within one drive. Makes to’s folders.
Async. Fails with FileError. Uses Files.Root.
makeDir
Section titled “makeDir”And the folders it’s in. Fine if it’s there already.
Async. Fails with FileError. Uses Files.Root.
pickFile
Section titled “pickFile”Windows’ own dialogs. The full path, or null if cancelled. Till the plugin unloads it may read what the player picked to open, read and write what they picked to save, and use anything in a folder they picked, whatever its “permissions” say.
Async. Fails with FileError. Uses Files.FileDialog.
pickFolder
Section titled “pickFolder”Async. Fails with FileError. Uses Files.FolderDialog.
FileError
Section titled “FileError”What can go wrong, besides Cancelled, Unsupported and Gone.
| Code | Error | |
|---|---|---|
| 1 | NotFound |
|
| 2 | Exists |
Something’s already where move would put it |
| 3 | Denied |
The system refused, like a read-only file or one another program has open |
| 4 | NotDeclared |
Outside its own folders, and its wraith.json doesn’t list “files” in “permissions” |
| 5 | WrongKind |
A folder where a file should be, or the other way around |
| 6 | NotEmpty |
A folder with something in it, for remove |
| 7 | TooBig |
Bigger than read was allowed |
| 8 | InvalidPath |
Empty, or a relative path that leaves its root |
| 9 | Failed |
Files.Root
Section titled “Files.Root”An enum of u8.
| Value | Name | |
|---|---|---|
| 0 | game_data |
Its data for this game, kept across updates |
| 1 | data |
Its data for every game, like its settings |
| 2 | cache |
Safe to delete, like downloads |
| 3 | plugin |
Its own files, as installed. Read only |
| 4 | game |
The game’s folder. Read only without “files” |
Files.FileDialog
Section titled “Files.FileDialog”A struct, 0x58 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | save |
bool |
Where to write one, else one to open |
| 0x8 | title |
string |
|
| 0x18 | folder |
string |
Where it starts. Empty is the system’s pick |
| 0x28 | file_name |
string |
Filled in to start with, for saving |
| 0x38 | kind |
string |
Like “Pose” |
| 0x48 | extension |
string |
Like “.pose”, added when a name’s typed without it |
save: booleantitle: stringfolder: stringfile_name: stringkind: stringextension: stringsave: booleantitle: stringfolder: stringfile_name: stringkind: stringextension: stringbool Savestring Titlestring Folderstring FileNamestring Kindstring Extensionbool savesal::String titlesal::String foldersal::String file_namesal::String kindsal::String extensionpub save: boolpub title: salamander::Strpub folder: salamander::Strpub file_name: salamander::Strpub kind: salamander::Strpub extension: salamander::Strsave: booltitle: []const u8folder: []const u8file_name: []const u8kind: []const u8extension: []const u8bool savesal_string titlesal_string foldersal_string file_namesal_string kindsal_string extensionFiles.FolderDialog
Section titled “Files.FolderDialog”A struct, 0x20 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | title |
string |
|
| 0x10 | folder |
string |
title: stringfolder: stringtitle: stringfolder: stringstring Titlestring Foldersal::String titlesal::String folderpub title: salamander::Strpub folder: salamander::Strtitle: []const u8folder: []const u8sal_string titlesal_string folderFiles.Info
Section titled “Files.Info”A struct, 0x28 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | name |
string |
|
| 0x10 | directory |
bool |
|
| 0x18 | size |
u64 |
|
| 0x20 | modified_ms |
i64 |
Milliseconds since 1970 |
name: stringdirectory: booleansize: bigintmodified_ms: bigintname: stringdirectory: booleansize: integermodified_ms: integerstring Namebool Directoryulong Sizelong ModifiedMssal::String namebool directoryuint64_t sizeint64_t modified_mspub name: salamander::Strpub directory: boolpub size: u64pub modified_ms: i64name: []const u8directory: boolsize: u64modified_ms: i64sal_string namebool directoryuint64_t sizeint64_t modified_mswraith.io · Mods on the Hub · Get Wraith
Made with ♥ by Asgard
