LeviLamina
Loading...
Searching...
No Matches
FileStorageArea.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5// auto generated inclusion list
6#include "mc/deps/core/file/FileAccessType.h"
7#include "mc/deps/core/file/FileStats.h"
8#include "mc/deps/core/file/PathBuffer.h"
9#include "mc/deps/core/file/StorageAreaState.h"
10#include "mc/deps/core/file/WriteOperation.h"
11#include "mc/deps/core/file/file_system/TransactionFlags.h"
12#include "mc/deps/core/threading/BasicLockbox.h"
13#include "mc/deps/core/utility/NonOwnerPointer.h"
14#include "mc/deps/core/utility/SingleThreadedLock.h"
15#include "mc/deps/core/utility/Subject.h"
16
17// auto generated forward declare list
18// clang-format off
19namespace Bedrock::Threading { class Mutex; }
20namespace Core { class FileIndexLru; }
21namespace Core { class FileSystemImpl; }
22namespace Core { class FlatFileManifestTracker; }
23namespace Core { class PathView; }
24namespace Core { class Result; }
25namespace Core { class StorageAreasTree; }
26namespace Core { class FileStorageAreaObserver; }
27// clang-format on
28
29namespace Core {
30
31class FileStorageArea : public ::std::enable_shared_from_this<::Core::FileStorageArea> {
32public:
33 // FileStorageArea inner types declare
34 // clang-format off
36 // clang-format on
37
38 // FileStorageArea inner types define
39 enum class FlushableLevelDbEnvType : int {
40 None = 0,
41 InMemory = 1,
42 StorageArea = 2,
43 };
44
45 struct StorageAreaSpaceInfo {
46 public:
47 // member variables
48 // NOLINTBEGIN
53 // NOLINTEND
54
55 public:
56 // prevent constructor by default
57 StorageAreaSpaceInfo& operator=(StorageAreaSpaceInfo const&);
58 StorageAreaSpaceInfo(StorageAreaSpaceInfo const&);
59 StorageAreaSpaceInfo();
60 };
61
62public:
63 // member variables
64 // NOLINTBEGIN
65 ::ll::TypedStorage<8, 80, ::std::recursive_mutex> mLock;
66 ::ll::TypedStorage<8, 24, ::std::vector<::Core::FileSystemImpl*>> mAllTransactions;
67 ::ll::TypedStorage<1, 1, bool> mCanAttemptExtendSave;
68 ::ll::TypedStorage<1, 1, bool> mCachedFileUsageSize;
69 ::ll::TypedStorage<8, 64, ::Core::FileStats> mTransactionStats;
70 ::ll::TypedStorage<8, 64, ::Core::FileStats> mTotalStats;
71 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::Core::FileStorageArea>> mParent;
72 ::ll::TypedStorage<4, 4, ::Core::FileAccessType> mAccessType;
73 ::ll::TypedStorage<8, 32, ::Core::PathBuffer<::std::string>> mRootPath;
74 ::ll::TypedStorage<8, 24, ::std::vector<::Core::FileSystemImpl*>> mWriteTransactions;
75 ::ll::TypedStorage<8, 32, ::Core::Subject<::Core::FileStorageAreaObserver, ::Core::SingleThreadedLock>> mSubject;
76 ::ll::TypedStorage<8, 144, ::Core::StorageAreaState> mState;
77 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mFileIOSuspended;
78 ::ll::TypedStorage<8, 88, ::std::condition_variable_any> mResumeSignal;
79 ::ll::TypedStorage<1, 1, bool> mLoggingEnabled;
80 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::Core::FlatFileManifestTracker>> mManifestTracker;
81 ::ll::TypedStorage<1, 1, bool> mIsAccessedDirectly;
82 // NOLINTEND
83
84public:
85 // prevent constructor by default
86 FileStorageArea();
87
88public:
89 // virtual functions
90 // NOLINTBEGIN
91 virtual ~FileStorageArea();
92
93 virtual ::std::unique_ptr<::Core::FileSystemImpl> createTransaction(::Core::FileAccessType accessType) = 0;
94
95 virtual ::std::unique_ptr<::Core::FileSystemImpl>
96 createTransaction(::Core::FileAccessType fileAccessType, ::Core::TransactionFlags);
97
98 virtual bool supportsSizeQuery() const = 0;
99
100 virtual uint64 getTotalSize() const = 0;
101
102 virtual ::Core::Result getUsedSize(uint64& outUsedSize) = 0;
103
104 virtual void setUsedSizeOverride(uint64 fileSize);
105
106 virtual void clearUsedSizeOverride();
107
108 virtual void notifyChangeInFileSize(int64 changeInSize, int64 changeInAllocatedSize);
109
110 virtual bool handlesPendingWrites() const;
111
112 virtual void informPendingWriteSize(uint64, bool const);
113
114 virtual uint64 estimatePendingWriteDiskSize(uint64 rawFileSize) const;
115
116 virtual void informStorageAreaCopy(uint64);
117
118 virtual bool supportsExtendSize() const;
119
120 virtual bool canExtendSize() const;
121
122 virtual void resetCanAttemptExtendSize();
123
124 virtual ::Core::Result getExtendSizeThreshold(uint64& outExtendSizeThreshold) const;
125
126 virtual void attemptExtendSize(int64 const& currentFreeSpace, ::std::function<void()> onCompleteCallback);
127
128 virtual void preemptiveExtendSize(
129 uint64 const expectedContentSize,
130 ::std::function<void()> successCallback,
131 ::std::function<void()> failureCallback
132 );
133
134 virtual uint64 getAvailableUserStorageSize();
135
136 virtual void unloadFlatFileManifests(bool shouldClearManifests);
137
138 virtual void tick();
139
140 virtual void flushImmediately();
141
142 virtual void enableFlushToDisk(bool);
143
144 virtual void enableSequentialWrites(bool);
145
146 virtual bool checkCorrupt(bool);
147
148 virtual ::Bedrock::NonOwnerPointer<::Core::FileIndexLru> getFileIndexLru();
149
150 virtual ::Core::FileStorageArea::FlushableLevelDbEnvType getFlushableLevelDbEnvType() const;
151
152 virtual uint64 getTransactionWriteSizeLimit() const;
153
154 virtual ::Core::Result setSaveDataIcon(::Core::PathView);
155
156 virtual bool shouldAllowCommit() const;
157
158 virtual void trackBytesWritten(::Core::PathView targetPath, uint64 amount, ::Core::WriteOperation);
159
160 virtual void trackWriteOperation(::Core::PathView targetPath, ::Core::WriteOperation);
161
162 virtual ::Core::FileStorageArea::StorageAreaSpaceInfo getStorageAreaSpaceInfo();
163
164 virtual bool shouldRecordFileError(::Core::PathView path, ::std::error_code error) const;
165
166 virtual ::Core::Result _commit();
167
168 virtual ::Core::Result _onTransactionsEmpty(bool);
169
170 virtual void _onTeardown();
171 // NOLINTEND
172
173public:
174 // member functions
175 // NOLINTBEGIN
176 MCAPI FileStorageArea(
177 ::Core::FileAccessType type,
178 ::Core::PathView rootPath,
179 bool usesFlatFiles,
180 bool isAccessedDirectly,
181 ::std::shared_ptr<::Core::FileStorageArea> parent
182 );
183
184 MCAPI void _addReadOperation(bool succeeded, uint64 numBytesRead);
185
186 MCAPI void _addWriteOperation(bool succeeded, uint64 numBytesWritten);
187
188 MCAPI void _beginTransaction(::Core::FileSystemImpl* pTransaction, bool);
189
190 MCAPI ::Core::Result _endTransaction(::Core::FileSystemImpl* pTransaction, bool fromChild);
191
192 MCAPI void _onDeleteFile(::Core::PathView filePath);
193
194 MCAPI void _onWriteFile(::Core::PathView filePath);
195
196#ifdef LL_PLAT_C
197 MCAPI void addObserver(::Core::FileStorageAreaObserver& observer);
198#endif
199
200 MCAPI void checkUserStorage();
201
202#ifdef LL_PLAT_C
203 MCAPI uint64 getRestrictedMaximumFileSize() const;
204#endif
205
206 MCFOLD ::Core::PathBuffer<::std::string> const& getRootPath() const;
207
208#ifdef LL_PLAT_C
209 MCAPI void setLoggingEnabled(bool enabled);
210
211 MCAPI bool supportsFlatFiles() const;
212#endif
213 // NOLINTEND
214
215public:
216 // static functions
217 // NOLINTBEGIN
218 MCAPI static ::Core::Result
219 _getStorageAreaForPathImpl(::std::shared_ptr<::Core::FileStorageArea>& fileStorageArea, ::Core::PathView path);
220
221 MCAPI static ::Core::Result
222 getStorageAreaForPath(::std::shared_ptr<::Core::FileStorageArea>& fileStorageArea, ::Core::PathView path);
223
224#ifdef LL_PLAT_C
225 MCAPI static void getTotalBytesWrittenAndReadFromAllStorageAreas(uint64& outBytesWritten, uint64& outBytesRead);
226#endif
227
228 MCAPI static void teardown();
229
230#ifdef LL_PLAT_C
231 MCAPI static void tickStorageAreas();
232
233 MCAPI static ::Core::Result unloadAllStorageAreaFlatFileManifests(bool isInGame);
234#endif
235 // NOLINTEND
236
237public:
238 // static variables
239 // NOLINTBEGIN
240 MCAPI static ::Bedrock::Threading::BasicLockbox<::std::vector<::Core::FileStats*>, ::Bedrock::Threading::Mutex>&
241 sStorageAreaFileStats();
242
243 MCAPI static ::Core::StorageAreasTree& sStorageAreas();
244 // NOLINTEND
245
246public:
247 // constructor thunks
248 // NOLINTBEGIN
249 MCAPI void* $ctor(
250 ::Core::FileAccessType type,
251 ::Core::PathView rootPath,
252 bool usesFlatFiles,
253 bool isAccessedDirectly,
254 ::std::shared_ptr<::Core::FileStorageArea> parent
255 );
256 // NOLINTEND
257
258public:
259 // destructor thunk
260 // NOLINTBEGIN
261 MCAPI void $dtor();
262 // NOLINTEND
263
264public:
265 // virtual function thunks
266 // NOLINTBEGIN
267 MCFOLD ::std::unique_ptr<::Core::FileSystemImpl>
268 $createTransaction(::Core::FileAccessType fileAccessType, ::Core::TransactionFlags);
269
270 MCFOLD void $setUsedSizeOverride(uint64 fileSize);
271
272 MCFOLD void $clearUsedSizeOverride();
273
274 MCAPI void $notifyChangeInFileSize(int64 changeInSize, int64 changeInAllocatedSize);
275
276 MCFOLD bool $handlesPendingWrites() const;
277
278 MCFOLD void $informPendingWriteSize(uint64, bool const);
279
280 MCFOLD uint64 $estimatePendingWriteDiskSize(uint64 rawFileSize) const;
281
282 MCFOLD void $informStorageAreaCopy(uint64);
283
284 MCFOLD bool $supportsExtendSize() const;
285
286 MCFOLD bool $canExtendSize() const;
287
288 MCAPI void $resetCanAttemptExtendSize();
289
290 MCAPI ::Core::Result $getExtendSizeThreshold(uint64& outExtendSizeThreshold) const;
291
292 MCAPI void $attemptExtendSize(int64 const& currentFreeSpace, ::std::function<void()> onCompleteCallback);
293
294 MCAPI void $preemptiveExtendSize(
295 uint64 const expectedContentSize,
296 ::std::function<void()> successCallback,
297 ::std::function<void()> failureCallback
298 );
299
300 MCAPI uint64 $getAvailableUserStorageSize();
301
302 MCAPI void $unloadFlatFileManifests(bool shouldClearManifests);
303
304 MCFOLD void $tick();
305
306 MCFOLD void $flushImmediately();
307
308 MCFOLD void $enableFlushToDisk(bool);
309
310 MCFOLD void $enableSequentialWrites(bool);
311
312 MCFOLD bool $checkCorrupt(bool);
313
314 MCFOLD ::Bedrock::NonOwnerPointer<::Core::FileIndexLru> $getFileIndexLru();
315
316 MCFOLD ::Core::FileStorageArea::FlushableLevelDbEnvType $getFlushableLevelDbEnvType() const;
317
318 MCFOLD uint64 $getTransactionWriteSizeLimit() const;
319
320 MCAPI ::Core::Result $setSaveDataIcon(::Core::PathView);
321
322 MCAPI bool $shouldAllowCommit() const;
323
324 MCAPI void $trackBytesWritten(::Core::PathView targetPath, uint64 amount, ::Core::WriteOperation);
325
326 MCAPI void $trackWriteOperation(::Core::PathView targetPath, ::Core::WriteOperation);
327
328 MCAPI ::Core::FileStorageArea::StorageAreaSpaceInfo $getStorageAreaSpaceInfo();
329
330 MCAPI bool $shouldRecordFileError(::Core::PathView path, ::std::error_code error) const;
331
332 MCFOLD ::Core::Result $_commit();
333
334 MCFOLD ::Core::Result $_onTransactionsEmpty(bool);
335
336 MCFOLD void $_onTeardown();
337
338
339 // NOLINTEND
340
341public:
342 // vftables
343 // NOLINTBEGIN
344 MCNAPI static void** $vftable();
345 // NOLINTEND
346};
347
348} // namespace Core
Definition Mutex.h:10
Definition FileIndexLru.h:13
Definition FileStorageAreaObserver.h:7
static MCAPI void ** $vftable()
Definition FileSystemImpl.h:30
Definition FlatFileManifestTracker.h:13
Definition PathView.h:19
Definition Result.h:11
Definition StorageAreasTree.h:17
Definition FileStorageArea.h:45
Definition Alias.h:14