2019-05-28 00:40:09 +01:00
|
|
|
#ifndef FILE_UTILS_H
|
|
|
|
#define FILE_UTILS_H
|
|
|
|
|
2021-02-17 20:34:35 +00:00
|
|
|
#include "../util/math/vector3i.h"
|
2021-12-13 21:38:10 +00:00
|
|
|
#include <core/io/dir_access.h>
|
|
|
|
#include <core/io/file_access.h>
|
2019-05-28 00:40:09 +01:00
|
|
|
|
2022-01-09 02:21:49 +00:00
|
|
|
namespace zylann {
|
|
|
|
|
2019-05-28 00:40:09 +01:00
|
|
|
inline Vector3i get_vec3u8(FileAccess *f) {
|
|
|
|
Vector3i v;
|
|
|
|
v.x = f->get_8();
|
|
|
|
v.y = f->get_8();
|
|
|
|
v.z = f->get_8();
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void store_vec3u8(FileAccess *f, const Vector3i v) {
|
|
|
|
f->store_8(v.x);
|
|
|
|
f->store_8(v.y);
|
|
|
|
f->store_8(v.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Vector3i get_vec3u32(FileAccess *f) {
|
|
|
|
Vector3i v;
|
|
|
|
v.x = f->get_32();
|
|
|
|
v.y = f->get_32();
|
|
|
|
v.z = f->get_32();
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void store_vec3u32(FileAccess *f, const Vector3i v) {
|
|
|
|
f->store_32(v.x);
|
|
|
|
f->store_32(v.y);
|
|
|
|
f->store_32(v.z);
|
|
|
|
}
|
|
|
|
|
2022-01-09 02:21:49 +00:00
|
|
|
enum FileResult {
|
|
|
|
FILE_OK = 0,
|
|
|
|
FILE_CANT_OPEN,
|
|
|
|
FILE_DOES_NOT_EXIST,
|
|
|
|
FILE_UNEXPECTED_EOF,
|
|
|
|
FILE_INVALID_MAGIC,
|
|
|
|
FILE_INVALID_VERSION,
|
|
|
|
FILE_INVALID_DATA
|
2020-02-09 17:07:53 +00:00
|
|
|
};
|
|
|
|
|
2022-01-09 02:21:49 +00:00
|
|
|
const char *to_string(FileResult res);
|
|
|
|
FileResult check_magic_and_version(
|
2022-01-03 01:58:35 +00:00
|
|
|
FileAccess *f, uint8_t expected_version, const char *expected_magic, uint8_t &out_version);
|
2020-02-09 17:07:53 +00:00
|
|
|
Error check_directory_created(const String &directory_path);
|
2019-05-28 00:40:09 +01:00
|
|
|
|
2020-09-19 21:50:23 +01:00
|
|
|
void insert_bytes(FileAccess *f, size_t count, size_t temp_chunk_size = 512);
|
|
|
|
|
2022-01-03 01:58:35 +00:00
|
|
|
} // namespace zylann
|
2020-09-19 21:50:23 +01:00
|
|
|
|
2019-05-28 00:40:09 +01:00
|
|
|
#endif // FILE_UTILS_H
|