-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfilesystem.mbt
More file actions
211 lines (177 loc) · 5.8 KB
/
filesystem.mbt
File metadata and controls
211 lines (177 loc) · 5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
///|
struct FilePathList(@ffi.FilePathList)
// Re-export passthrough functions from internal FFI layer
///|
pub using @ffi {is_file_dropped}
///|
/// Load dropped filepaths.
#as_free_fn(load_dropped_files)
pub fn FilePathList::load_dropped() -> FilePathList {
@ffi.load_dropped_files()
}
///|
/// Get the number of filepaths in the list.
#as_free_fn(file_path_list_count)
pub fn FilePathList::count(self : FilePathList) -> Int {
@ffi.file_path_list_count(self.0)
}
///|
/// Unload dropped filepaths.
pub fn unload_dropped_files(files : FilePathList) -> Unit {
@ffi.unload_dropped_files(files.0)
}
///|
/// Unload filepaths loaded with `load_directory_files`.
pub fn unload_directory_files(files : FilePathList) -> Unit {
@ffi.unload_directory_files(files.0)
}
// ============================================================================
// File system: Queries (wrappers)
// ============================================================================
///|
/// Check if file exists.
pub fn file_exists(file_name : String) -> Bool {
@ffi.file_exists(@utf8.encode(file_name))
}
///|
/// Check if a directory path exists.
pub fn directory_exists(dir_path : String) -> Bool {
@ffi.directory_exists(@utf8.encode(dir_path))
}
///|
/// Check file extension (including point: .png, .wav).
pub fn is_file_extension(file_name : String, ext : String) -> Bool {
@ffi.is_file_extension(@utf8.encode(file_name), @utf8.encode(ext))
}
///|
/// Get file length in bytes.
pub fn get_file_length(file_name : String) -> Int {
@ffi.get_file_length(@utf8.encode(file_name))
}
///|
/// Get pointer to extension for a filename string (includes dot: '.png').
pub fn get_file_extension(file_name : String) -> String {
@utf8.decode_lossy(@ffi.get_file_extension(@utf8.encode(file_name)))
}
///|
/// Get filename for a path string.
pub fn get_file_name(file_path : String) -> String {
@utf8.decode_lossy(@ffi.get_file_name(@utf8.encode(file_path)))
}
///|
/// Get filename string without extension.
pub fn get_file_name_without_ext(file_path : String) -> String {
@utf8.decode_lossy(@ffi.get_file_name_without_ext(@utf8.encode(file_path)))
}
///|
/// Get full path for a given fileName with path.
pub fn get_directory_path(file_path : String) -> String {
@utf8.decode_lossy(@ffi.get_directory_path(@utf8.encode(file_path)))
}
///|
/// Get previous directory path for a given path.
pub fn get_prev_directory_path(dir_path : String) -> String {
@utf8.decode_lossy(@ffi.get_prev_directory_path(@utf8.encode(dir_path)))
}
///|
/// Get current working directory.
pub fn get_working_directory() -> String {
@utf8.decode_lossy(@ffi.get_working_directory())
}
///|
/// Get the directory of the running application.
pub fn get_application_directory() -> String {
@utf8.decode_lossy(@ffi.get_application_directory())
}
///|
/// Create directories (including full path requested), returns 0 on success.
pub fn make_directory(dir_path : String) -> Int {
@ffi.make_directory(@utf8.encode(dir_path))
}
///|
/// Change working directory, return true on success.
pub fn change_directory(dir : String) -> Bool {
@ffi.change_directory(@utf8.encode(dir))
}
///|
/// Check if a given path is a file or a directory.
pub fn is_path_file(path : String) -> Bool {
@ffi.is_path_file(@utf8.encode(path))
}
///|
/// Check if fileName is valid for the platform/OS.
pub fn is_file_name_valid(file_name : String) -> Bool {
@ffi.is_file_name_valid(@utf8.encode(file_name))
}
// ============================================================================
// File system: Data load/save (wrappers)
// ============================================================================
///|
/// Load file data as byte array (read).
pub fn load_file_data(file_name : String) -> Bytes {
@ffi.load_file_data(@utf8.encode(file_name))
}
///|
/// Save data to file from byte array (write), returns true on success.
pub fn save_file_data(
file_name : String,
data : Bytes,
data_size : Int,
) -> Bool {
@ffi.save_file_data(@utf8.encode(file_name), data, data_size)
}
///|
/// Load text data from file (read).
pub fn load_file_text(file_name : String) -> String {
@utf8.decode_lossy(@ffi.load_file_text(@utf8.encode(file_name)))
}
///|
/// Save text data to file (write), returns true on success.
pub fn save_file_text(file_name : String, text : String) -> Bool {
@ffi.save_file_text(@utf8.encode(file_name), @utf8.encode(text))
}
///|
/// Export data to code (.h), returns true on success.
pub fn export_data_as_code(
data : Bytes,
data_size : Int,
file_name : String,
) -> Bool {
@ffi.export_data_as_code(data, data_size, @utf8.encode(file_name))
}
// ============================================================================
// File system: Directory listing (wrappers)
// ============================================================================
///|
/// Load directory filepaths.
pub fn load_directory_files(dir_path : String) -> FilePathList {
FilePathList(@ffi.load_directory_files(@utf8.encode(dir_path)))
}
///|
/// Load directory filepaths with extension filtering and recursive directory scan.
pub fn load_directory_files_ex(
base_path : String,
filter : String,
scan_subdirs : Bool,
) -> FilePathList {
FilePathList(
@ffi.load_directory_files_ex(
@utf8.encode(base_path),
@utf8.encode(filter),
scan_subdirs,
),
)
}
///|
/// Get a filepath from the list by index.
pub fn file_path_list_get(files : FilePathList, index : Int) -> String {
@utf8.decode_lossy(@ffi.file_path_list_get(files.0, index))
}
// ============================================================================
// File system: File mod time (wrapper)
// ============================================================================
///|
/// Get file modification time (last write time).
pub fn get_file_mod_time(file_name : String) -> Int {
@ffi.get_file_mod_time(@utf8.encode(file_name))
}