libER 0.1.4.2
ELDEN RING API library
Loading...
Searching...
No Matches
fileio.hpp
Go to the documentation of this file.
1
9#pragma once
10
12#include <dantelion2/text.hpp>
13#include <detail/preprocessor.hpp>
14#include <detail/windows.inl>
16#include <fd4/time.hpp>
19
20#include <filesystem>
21
22// TODO
24
25namespace from {
26// Forward declaration
27namespace DLIOD {
28namespace msvc90_windows {
29class MicrosoftDiskFileDevice;
30}
31} // namespace DLIOD
32// Dantelion input/output
33namespace DLIO {
34// Forward declaration
35class DLFileOperator;
36class DLFileEnumeratorSPI;
37
38namespace DLFileConstants {
39enum file_openmode : int {
40 READ = 1,
41 WRITE = 2,
42 READWRITE = READ | WRITE,
43 APPEND = 4,
44 ASYNC = 16,
45 EXCLUSIVE = 64
46};
47
48enum file_result : int {
49 DIR_NOT_EMPTY = -17,
50 OUT_OF_MEMORY = -13,
51 DISK_FULL = -12,
52 NOT_STREAMED = -9,
53 ALREADY_OPEN = -6,
54 IS_NOT_OPEN = -5,
55 NOT_FOUND = -4,
56 ACCESS_DENIED = -3,
57 OPERATION_UNSUPPORTED = -2,
58 INVALID = -1,
59 SUCCESS = 0,
60 NO_MORE_FILES = 1
61};
62} // namespace DLFileConstants
63
64class DLFileDevice {
65public:
66 LIBER_CLASS(DLFileDevice);
67
68 virtual ~DLFileDevice() = default;
69
70 virtual from::unique_ptr<DLFileOperator> load_file(
71 DLTX::DLString* path_dlstr, const wchar_t* path_lpcwstr,
72 void* liber_unknown, from::allocator<void> allocator,
73 bool liber_unknown) = 0;
74
75 virtual from::unique_ptr<DLFileEnumeratorSPI> get_file_enumerator() = 0;
76
77 // Default = 2, CD-ROM = 1, unknown = 0
78 virtual int drive_type(const wchar_t* path) {
79 return 2;
80 }
81
82private:
83 // Always false?
84 virtual bool liber_unknown() {
85 return false;
86 }
87
88 bool liber_unknown;
89 mutable DLKR::DLPlainLightMutex mutex;
90};
91
92class DLFileEnumeratorSPI {};
93
94class DLFileDeviceImageSPI {
95public:
96 virtual ~DLFileDeviceImageSPI() = default;
97};
98
99class DLFileOperator {
100public:
101 LIBER_CLASS(DLFileOperator);
102
103 using filesys_time = std::pair<FILETIME, FD4::FD4PackedSystemTime>;
104 using read_size_type = uint32_t;
105 using file_size_type = uint64_t;
106 using file_difference_type = int64_t;
107
108 virtual ~DLFileOperator() = default;
109 virtual bool copy_base(DLFileOperator* other) = 0;
110 virtual bool set_path(DLTX::DLString* new_path, bool iostate_0x2) = 0;
111
112private:
113 // set_path duplicates, potentially for other string types
114 virtual bool liber_unknown(DLTX::DLString* new_path, bool iostate_0x2) = 0;
115 virtual bool liber_unknown(DLTX::DLString* new_path, bool iostate_0x2) = 0;
116 virtual bool liber_unknown(DLTX::DLString* new_path, bool iostate_0x2) = 0;
117
118public:
119 virtual bool close_file() = 0;
120 virtual from::unique_ptr<DLFileOperator> get_virtual_disk_operator() = 0;
121 virtual DLFileDeviceImageSPI* bind_device_image(DLFileDeviceImageSPI*) = 0;
122 virtual bool populate_dir_info() = 0;
123 virtual bool populate_file_info() = 0;
124 virtual filesys_time get_last_access_time() = 0;
125 virtual filesys_time get_last_write_time() = 0;
126 virtual file_size_type get_file_size() = 0;
127 virtual file_difference_type get_remaining_size() = 0;
128 virtual int max_non_streamed_size() = 0;
129 virtual void truncate_file() = 0;
130 virtual bool has_file_control_0x4() = 0;
131 virtual bool is_directory() = 0;
132 virtual bool is_open() = 0;
133 virtual bool open_file(int dlfile_openmode) = 0;
134 virtual bool try_close_file() = 0;
135 virtual bool set_control_unk(bool unk) = 0;
136 virtual bool seek(bool is_stream, file_difference_type pos,
137 int move_method) = 0;
138 virtual file_size_type get_cursor_pos() = 0;
139 virtual read_size_type read_file(void* out, read_size_type cb) = 0;
140 virtual read_size_type write_file(void* in, read_size_type cb) = 0;
141 virtual read_size_type get_sector_size() = 0;
142 virtual read_size_type get_virtual_sector_size() = 0;
143 virtual read_size_type stream_read_file(void* out, read_size_type cb) = 0;
144 virtual read_size_type stream_write_file(void* in, read_size_type cb) = 0;
145 virtual bool stream_complete_operation(HANDLE* event_handle_out,
146 read_size_type* cb_out) = 0;
147 virtual int get_file_creation_flags() = 0;
148 virtual bool delete_file() = 0;
149 virtual bool liber_unknown() = 0;
150 virtual bool populate_file_info_again() = 0;
151 virtual bool liber_unknown() = 0;
152 virtual bool move_file_w(const wchar_t* new_path) = 0;
153 virtual bool move_file(const char* new_path) = 0;
154 virtual bool create_directory() = 0;
155
156private:
157 from::allocator<void> allocator;
158 DLFileConstants::file_result result;
159 void* liber_unknown;
160 // 0x1 might be "open"
161 int iostate;
162 DLFileDevice* owner;
163 DLTX::DLString file;
164};
165
166class DLBinder4FileDeviceImageSPI : public DLFileDeviceImageSPI {
167public:
168 virtual ~DLBinder4FileDeviceImageSPI() = default;
169
170private:
171 DLTX::DLString path;
172 DLFileOperator* file_operator;
173};
174
175class DLFileDeviceManager {
176public:
177 FD4_SINGLETON_CLASS(DLFileDeviceManager);
178
179 LIBERAPI bool is_virtual_path(const std::filesystem::path& path);
180
181private:
182 struct bnd_file_entry {
183 DLTX::DLString name;
184 DLFileDevice* device;
185 size_t filesize;
186 };
187
189 from::vector<DLFileDeviceImageSPI*> service_providers;
190 DLIOD::msvc90_windows::MicrosoftDiskFileDevice* msvc_file_device;
191 from::vector<DLTX::DLString> virtual_directories;
194 DLFileDeviceImageSPI* bnd3_service_provider;
195 DLBinder4FileDeviceImageSPI* bnd4_service_provider;
196 mutable DLKR::DLPlainLightMutex mutex;
197};
198
199LIBER_ASSERTS_BEGIN(DLFileDevice);
200LIBER_ASSERT_SIZE(0x40);
201LIBER_ASSERTS_END;
202
203LIBER_ASSERTS_BEGIN(DLFileOperator);
204LIBER_ASSERT_SIZE(0x60);
205LIBER_ASSERTS_END;
206
207LIBER_ASSERTS_BEGIN(DLFileDeviceManager);
208LIBER_ASSERT_SIZE(0xE8);
209LIBER_ASSERT_OFFS(0xB8, mutex);
210LIBER_ASSERTS_END;
211
212} // namespace DLIO
213// Dantelion input/output devices (older namespace, has D postfix)
214namespace DLIOD {
215namespace msvc90_windows {
216
217class MicrosoftDiskFileDevice : public DLIO::DLFileDevice {};
218
219class MicrosoftDiskFileOperator : public DLIO::DLFileOperator {
220public:
221 LIBER_CLASS(MicrosoftDiskFileOperator);
222
223 virtual ~MicrosoftDiskFileOperator() = default;
224
225private:
226 HANDLE file_handle;
227 // | 0x1 | 0x2 | 0x4 | 0x8 | 0x10 |
228 // | unk | has_info | EOF? | is_async | is_streamed |
229 char file_control;
230 BY_HANDLE_FILE_INFORMATION file_info;
231 file_size_type cursor_pos;
232 OVERLAPPED overlapped;
233 void* liber_unknown;
234 int liber_unknown;
235};
236
237LIBER_ASSERTS_BEGIN(MicrosoftDiskFileOperator);
238LIBER_ASSERT_SIZE(0xD8);
239LIBER_ASSERT_OFFS(0x6C, file_info);
240LIBER_ASSERT_OFFS(0xA0, cursor_pos);
241LIBER_ASSERTS_END;
242} // namespace msvc90_windows
243} // namespace DLIOD
244} // namespace from
The main libER stand-in for ER allocator proxies.
Definition from_allocator.hpp:310
from::unique_ptr based on std::unique_ptr
std::unique_ptr< T, from::delay_delete< T, AllocatorTag > > unique_ptr
std::unique_ptr with from::allocator and from::delay_delete.
Definition from_unique_ptr.hpp:22
from::vector based on std::vector
std::vector< T, from::allocator< T, AllocatorTag > > vector
std::vector with from::allocator.
Definition from_vector.hpp:23
Dantelion2 kernel object management and synchronization.
FD4_SINGLETON_CLASS implementation.
Dantelion2 strings.
Namespace FD4 FD4Time.