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
28typedef bool(*fs_list_callback)(const char* name, const char* title, const char* hash, s32 id, void* data, bool dir);
29typedef void(*fs_done_callback)(void* data);
30typedef void(*fs_isdir_callback)(bool dir, void* data);
31typedef void(*fs_load_callback)(const u8* buffer, s32 size, void* data);
32
33typedef struct tic_fs tic_fs;
34struct tic_net;
35
36tic_fs* tic_fs_create (const char* path, struct tic_net* net);
37const char* tic_fs_path (tic_fs* fs, const char* name);
38const char* tic_fs_pathroot (tic_fs* fs, const char* name);
39
40void tic_fs_enum (tic_fs* fs, fs_list_callback onItem, fs_done_callback onDone, void* data);
41void tic_fs_isdir_async (tic_fs* fs, const char* name, fs_isdir_callback callback, void* data);
42void tic_fs_hashload (tic_fs* fs, const char* name, const char* hash, fs_load_callback callback, void* data);
43bool tic_fs_delfile (tic_fs* fs, const char* name);
44bool tic_fs_deldir (tic_fs* fs, const char* name);
45bool tic_fs_save (tic_fs* fs, const char* name, const void* data, s32 size, bool overwrite);
46bool tic_fs_saveroot (tic_fs* fs, const char* name, const void* data, s32 size, bool overwrite);
47void* tic_fs_load (tic_fs* fs, const char* name, s32* size);
48void* tic_fs_loadroot (tic_fs* fs, const char* name, s32* size);
49bool tic_fs_makedir (tic_fs* fs, const char* name);
50bool tic_fs_exists (tic_fs* fs, const char* name);
51void tic_fs_openfolder (tic_fs* fs);
52bool tic_fs_isdir (tic_fs* fs, const char* dir);
53bool tic_fs_ispubdir (tic_fs* fs);
54void tic_fs_changedir (tic_fs* fs, const char* dir);
55void tic_fs_dir (tic_fs* fs, char* out);
56void tic_fs_dirback (tic_fs* fs);
57void tic_fs_homedir (tic_fs* fs);
58
59u64 fs_date (const char* name);
60bool fs_exists (const char* name);
61void* fs_read (const char* path, s32* size);
62bool fs_write (const char* path, const void* data, s32 size);
63