Project Alice
Loading...
Searching...
No Matches
simple_fs.hpp
Go to the documentation of this file.
1#pragma once
2
3#ifdef _WIN64
4// WINDOWS typedefs go here
6
7#else
8// LINUX typedefs go here
10#endif
11
12#include <stdint.h>
13#include <vector>
14#include <optional>
15#include <map>
16
17namespace simple_fs {
18class file;
19class directory;
20class unopened_file;
21class file_system;
22
24 char const* data = nullptr;
26};
27} // namespace simple_fs
28
29#ifdef _WIN64
30// WINDOWS typedefs go here
32
33#else
34// LINUX typedefs go here
36#endif
37
38namespace simple_fs {
39// general file system functions
40// root paths should include the trailing separator
41void reset(file_system& fs);
42void add_root(file_system& fs, native_string_view root_path);
43// will be added relative to the location that the executable file exists in (but it is stored as an absolute path)
44void add_relative_root(file_system& fs, native_string_view root_path);
45directory get_root(file_system const& fs);
46
47// functions for saving and restoring its state
48native_string extract_state(file_system const& fs);
49void restore_state(file_system& fs, native_string_view data);
50
51// directory functions
52std::vector<unopened_file> list_files(directory const& dir, native_char const* extension);
53std::vector<directory> list_subdirectories(directory const& dir);
54std::optional<file> open_file(directory const& dir, native_string_view file_name);
55std::optional<unopened_file> peek_file(directory const& dir, native_string_view file_name);
56void add_ignore_path(file_system& fs, native_string_view replaced_path);
57std::vector<native_string> list_roots(file_system const& fs);
58bool is_ignored_path(file_system const& fs, native_string_view path);
59
60directory open_directory(directory const& dir, native_string_view directory_name);
61native_string get_full_name(directory const& f);
62
63// write_file will clear an existing file, if it exists, will create a new file if it does not
64void write_file(directory const& dir, native_string_view file_name, char const* file_data, uint32_t file_size);
65
66// unopened file functions
67std::optional<file> open_file(unopened_file const& f);
68native_string get_full_name(unopened_file const& f);
69native_string get_file_name(unopened_file const& f);
70
71// opened file functions
72file_contents view_contents(file const& f);
73native_string get_full_name(file const& f);
74
75// functions that operate outside of a filesystem object
83
84// necessary for reading paths out of data from inside older paradox files:
85// even on linux, this must do something, because win1250 isn't ascii or utf8
86native_string win1250_to_native(std::string_view data_in);
87
88// necessary for reading paths out of data from inside files we may create:
89// on linux, this just has to call the string constructor
90native_string utf8_to_native(std::string_view data_in);
91std::string native_to_utf8(native_string_view data_in);
92
93std::string remove_double_backslashes(std::string_view data_in); // unfortunately, paradox decided to escape their paths ...
95} // namespace simple_fs
std::vector< unopened_file > list_files(directory const &dir, native_char const *extension)
void add_root(file_system &fs, native_string_view root_path)
void reset(file_system &fs)
native_string win1250_to_native(std::string_view data_in)
void add_relative_root(file_system &fs, native_string_view root_path)
std::vector< directory > list_subdirectories(directory const &dir)
directory open_directory(directory const &dir, native_string_view directory_name)
void add_ignore_path(file_system &fs, native_string_view replaced_path)
native_string utf8_to_native(std::string_view data_in)
native_string extract_state(file_system const &fs)
directory get_root(file_system const &fs)
void restore_state(file_system &fs, native_string_view data)
void write_file(directory const &dir, native_string_view file_name, char const *file_data, uint32_t file_size)
directory get_or_create_oos_directory()
std::vector< native_string > list_roots(file_system const &fs)
directory get_or_create_templates_directory()
std::string remove_double_backslashes(std::string_view data_in)
directory get_or_create_settings_directory()
native_string get_full_name(directory const &f)
native_string correct_slashes(native_string_view path)
directory get_or_create_save_game_directory()
std::optional< file > open_file(directory const &dir, native_string_view file_name)
directory get_or_create_root_documents()
directory get_or_create_data_dumps_directory()
bool is_ignored_path(file_system const &fs, native_string_view path)
std::optional< unopened_file > peek_file(directory const &dir, native_string_view file_name)
std::string native_to_utf8(native_string_view data_in)
file_contents view_contents(file const &f)
native_string get_file_name(unopened_file const &f)
directory get_or_create_scenario_directory()
char native_char
std::string_view native_string_view
std::string native_string
uint uint32_t