| 1 | #ifndef SEAD_FILEDEVICEMGR_H_ |
| 2 | #define SEAD_FILEDEVICEMGR_H_ |
| 3 | |
| 4 | #ifdef cafe |
| 5 | #include <cafe.h> |
| 6 | #endif // cafe |
| 7 | |
| 8 | #include <basis/seadTypes.h> |
| 9 | #include <container/seadTList.h> |
| 10 | #include <filedevice/seadFileDevice.h> |
| 11 | #include <filedevice/seadMainFileDevice.h> |
| 12 | #include <heap/seadDisposer.h> |
| 13 | #include <prim/seadSafeString.h> |
| 14 | |
| 15 | namespace sead |
| 16 | { |
| 17 | class FileDeviceMgr |
| 18 | { |
| 19 | SEAD_SINGLETON_DISPOSER(FileDeviceMgr) |
| 20 | FileDeviceMgr(); |
| 21 | ~FileDeviceMgr(); |
| 22 | |
| 23 | public: |
| 24 | void traceFilePath(const SafeString& path) const; |
| 25 | void traceDirectoryPath(const SafeString& path) const; |
| 26 | void resolveFilePath(BufferedSafeString* out, const SafeString& path) const; |
| 27 | void resolveDirectoryPath(BufferedSafeString* out, const SafeString& path) const; |
| 28 | |
| 29 | void mount(FileDevice* device, const SafeString& name = SafeString::cEmptyString); |
| 30 | void unmount(FileDevice* device); |
| 31 | void unmount(const SafeString& name); |
| 32 | FileDevice* findDeviceFromPath(const SafeString& path, BufferedSafeString* pathNoDrive) const; |
| 33 | FileDevice* findDevice(const SafeString& name) const; |
| 34 | |
| 35 | FileDevice* tryOpen(FileHandle* handle, const SafeString& path, FileDevice::FileOpenFlag flag, |
| 36 | u32 divSize); |
| 37 | FileDevice* tryOpenDirectory(DirectoryHandle* handle, const SafeString& path); |
| 38 | |
| 39 | u8* tryLoad(FileDevice::LoadArg& arg); |
| 40 | void unload(u8* data); |
| 41 | bool trySave(FileDevice::SaveArg& arg); |
| 42 | |
| 43 | void mountSaveDataForDebug(Heap* heap); |
| 44 | void unmountSaveDataForDebug(); |
| 45 | |
| 46 | FileDevice* getMainFileDevice() const { return mMainFileDevice; } |
| 47 | FileDevice* getDefaultFileDevice() const { return mDefaultFileDevice; } |
| 48 | void setDefaultFileDevice(FileDevice* device) { mDefaultFileDevice = device; } |
| 49 | |
| 50 | #ifdef NNSDK |
| 51 | bool hasMountedHost() const { return mMountedHost; } |
| 52 | bool hasMountedSd() const { return mMountedSd; } |
| 53 | #endif |
| 54 | |
| 55 | private: |
| 56 | typedef TList<FileDevice*> DeviceList; |
| 57 | |
| 58 | void mount_(Heap* heap); |
| 59 | void unmount_(); |
| 60 | |
| 61 | DeviceList mDeviceList{}; |
| 62 | FileDevice* mDefaultFileDevice = nullptr; |
| 63 | MainFileDevice* mMainFileDevice = nullptr; |
| 64 | |
| 65 | #ifdef cafe |
| 66 | static void stateChangeCallback_(FSClient* client, FSVolumeState state, void* context); |
| 67 | |
| 68 | FSClient client; |
| 69 | u8 _1724[128]; |
| 70 | u8 _17A4[128]; |
| 71 | u32 _1824; |
| 72 | #elif defined(NNSDK) |
| 73 | u8* mRomCache = nullptr; |
| 74 | bool mMountedHost = false; |
| 75 | bool mMountedSd = false; |
| 76 | #endif |
| 77 | }; |
| 78 | |
| 79 | } // namespace sead |
| 80 | |
| 81 | #endif // SEAD_FILEDEVICEMGR_H_ |
| 82 | |