| 1 | // MIT License |
| 2 | |
| 3 | // Copyright (c) 2017 Vadim Grigoruk @nesbox // grigoruk@gmail.com |
| 4 | |
| 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | // of this software and associated documentation files (the "Software"), to deal |
| 7 | // in the Software without restriction, including without limitation the rights |
| 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | // copies of the Software, and to permit persons to whom the Software is |
| 10 | // furnished to do so, subject to the following conditions: |
| 11 | |
| 12 | // The above copyright notice and this permission notice shall be included in all |
| 13 | // copies or substantial portions of the Software. |
| 14 | |
| 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | // SOFTWARE. |
| 22 | |
| 23 | #pragma once |
| 24 | |
| 25 | #include <tic80_types.h> |
| 26 | #include <string.h> |
| 27 | |
| 28 | typedef bool(*fs_list_callback)(const char* name, const char* title, const char* hash, s32 id, void* data, bool dir); |
| 29 | typedef void(*fs_done_callback)(void* data); |
| 30 | typedef void(*fs_isdir_callback)(bool dir, void* data); |
| 31 | typedef void(*fs_load_callback)(const u8* buffer, s32 size, void* data); |
| 32 | |
| 33 | typedef struct tic_fs tic_fs; |
| 34 | struct tic_net; |
| 35 | |
| 36 | tic_fs* tic_fs_create (const char* path, struct tic_net* net); |
| 37 | const char* tic_fs_path (tic_fs* fs, const char* name); |
| 38 | const char* tic_fs_pathroot (tic_fs* fs, const char* name); |
| 39 | |
| 40 | void tic_fs_enum (tic_fs* fs, fs_list_callback onItem, fs_done_callback onDone, void* data); |
| 41 | void tic_fs_isdir_async (tic_fs* fs, const char* name, fs_isdir_callback callback, void* data); |
| 42 | void tic_fs_hashload (tic_fs* fs, const char* name, const char* hash, fs_load_callback callback, void* data); |
| 43 | bool tic_fs_delfile (tic_fs* fs, const char* name); |
| 44 | bool tic_fs_deldir (tic_fs* fs, const char* name); |
| 45 | bool tic_fs_save (tic_fs* fs, const char* name, const void* data, s32 size, bool overwrite); |
| 46 | bool tic_fs_saveroot (tic_fs* fs, const char* name, const void* data, s32 size, bool overwrite); |
| 47 | void* tic_fs_load (tic_fs* fs, const char* name, s32* size); |
| 48 | void* tic_fs_loadroot (tic_fs* fs, const char* name, s32* size); |
| 49 | bool tic_fs_makedir (tic_fs* fs, const char* name); |
| 50 | bool tic_fs_exists (tic_fs* fs, const char* name); |
| 51 | void tic_fs_openfolder (tic_fs* fs); |
| 52 | bool tic_fs_isdir (tic_fs* fs, const char* dir); |
| 53 | bool tic_fs_ispubdir (tic_fs* fs); |
| 54 | void tic_fs_changedir (tic_fs* fs, const char* dir); |
| 55 | void tic_fs_dir (tic_fs* fs, char* out); |
| 56 | void tic_fs_dirback (tic_fs* fs); |
| 57 | void tic_fs_homedir (tic_fs* fs); |
| 58 | |
| 59 | u64 fs_date (const char* name); |
| 60 | bool fs_exists (const char* name); |
| 61 | void* fs_read (const char* path, s32* size); |
| 62 | bool fs_write (const char* path, const void* data, s32 size); |
| 63 | |