ReXGlue SDK
Loading...
Searching...
No Matches
file.h
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <filesystem>
14#include <iosfwd>
15#include <span>
16#include <string>
17#include <string_view>
18#include <system_error>
19#include <vector>
20
21#include <rex/platform.h>
22#include <rex/result.h>
23#include <rex/types.h>
24
25namespace rex::platform {
26
30REX_API std::filesystem::path GetExecutablePath();
31
35REX_API std::filesystem::path GetExecutableFolder();
36
44REX_API std::filesystem::path GetLibraryFolder();
45
49REX_API std::filesystem::path GetUserFolder();
50
56[[nodiscard]] REX_API bool IsPackagedApp();
57
65[[nodiscard]] REX_API std::filesystem::path GetUserConfigFolder(std::string_view app_name);
66
74[[nodiscard]] REX_API std::filesystem::path GetAppRoot(std::string_view app_name);
75
81[[nodiscard]] REX_API bool IsDirectoryWritable(const std::filesystem::path& dir);
82
91[[nodiscard]] REX_API std::string SanitizeFolderName(std::string_view name,
92 std::string_view fallback = "default");
93
101[[nodiscard]] REX_API Result<std::vector<u8>> ReadHostFile(const std::filesystem::path& path,
102 u64 offset = 0, u64 length = 0);
103
110[[nodiscard]] REX_API Result<void> WriteHostFile(const std::filesystem::path& path,
111 std::span<const u8> data);
112
114[[nodiscard]] REX_API Result<void> WriteHostFile(const std::filesystem::path& path,
115 std::string_view text);
116
123[[nodiscard]] REX_API std::filesystem::path ResolveEntryCase(const std::filesystem::path& parent,
124 std::string_view name);
125
127REX_API bool OpenStorageFile(std::fstream& file, const std::filesystem::path& path);
128
132inline u64 GetStorageFileSize(const std::filesystem::path& path) {
133 std::error_code error;
134 const auto size = std::filesystem::file_size(path, error);
135 return error ? 0 : static_cast<u64>(size);
136}
137
143REX_API size_t ReadStorageFile(std::fstream& file, void* data, size_t size);
144
145REX_API void AppendStorageFile(std::fstream& file, const void* data, size_t size);
146
152REX_API void ResetStorageFile(std::fstream& file, const std::filesystem::path& path, u64 length);
153
154} // namespace rex::platform
Definition platform.h:345
std::filesystem::path GetExecutableFolder()
std::string SanitizeFolderName(std::string_view name, std::string_view fallback="default")
Result< void > WriteHostFile(const std::filesystem::path &path, std::span< const u8 > data)
bool OpenStorageFile(std::fstream &file, const std::filesystem::path &path)
bool IsPackagedApp()
std::filesystem::path GetLibraryFolder()
std::filesystem::path GetUserFolder()
size_t ReadStorageFile(std::fstream &file, void *data, size_t size)
Result< std::vector< u8 > > ReadHostFile(const std::filesystem::path &path, u64 offset=0, u64 length=0)
void ResetStorageFile(std::fstream &file, const std::filesystem::path &path, u64 length)
bool IsDirectoryWritable(const std::filesystem::path &dir)
std::filesystem::path GetAppRoot(std::string_view app_name)
std::filesystem::path GetExecutablePath()
std::filesystem::path GetUserConfigFolder(std::string_view app_name)
std::filesystem::path ResolveEntryCase(const std::filesystem::path &parent, std::string_view name)
u64 GetStorageFileSize(const std::filesystem::path &path)
Definition file.h:132
std::expected< T, Error > Result
Definition result.h:98
Platform flags, packing macros and export markers.
#define REX_API
Definition platform.h:177
Integer types, byte order wrappers and size literals.