| 1 | #include "Library/File/FileUtil.h" |
| 2 | |
| 3 | #include <filedevice/seadPath.h> |
| 4 | |
| 5 | #include "Library/Base/StringUtil.h" |
| 6 | #include "Library/Memory/HeapUtil.h" |
| 7 | #include "Library/Message/MessageHolder.h" |
| 8 | #include "Library/Resource/Resource.h" |
| 9 | #include "Library/System/SystemKit.h" |
| 10 | #include "Library/Yaml/ByamlIter.h" |
| 11 | #include "Project/File/FileLoader.h" |
| 12 | |
| 13 | #include "System/ProjectInterface.h" |
| 14 | |
| 15 | namespace al { |
| 16 | inline FileLoader* getFileLoader() { |
| 17 | return alProjectInterface::getSystemKit()->getFileLoader(); |
| 18 | } |
| 19 | |
| 20 | bool isExistFile(const sead::SafeString& fileName) { |
| 21 | return getFileLoader()->isExistFile(path: fileName, device: nullptr); |
| 22 | } |
| 23 | |
| 24 | bool isExistDirectory(const sead::SafeString& fileName) { |
| 25 | return getFileLoader()->isExistDirectory(path: fileName, device: nullptr); |
| 26 | } |
| 27 | |
| 28 | bool isExistArchive(const sead::SafeString& fileName) { |
| 29 | return getFileLoader()->isExistArchive(path: StringTmp<256>("%s.szs" , fileName.cstr()), device: nullptr); |
| 30 | } |
| 31 | |
| 32 | bool isExistArchive(const sead::SafeString& fileName, const char* ext) { |
| 33 | return getFileLoader()->isExistArchive(path: StringTmp<256>("%s.%s" , fileName.cstr(), ext), device: nullptr); |
| 34 | } |
| 35 | |
| 36 | u32 getFileSize(const sead::SafeString& fileName) { |
| 37 | return getFileLoader()->getFileSize(path: fileName, device: nullptr); |
| 38 | } |
| 39 | |
| 40 | u32 calcFileAlignment(const sead::SafeString& fileName) { |
| 41 | StringTmp<32> ext("" ); |
| 42 | sead::Path::getExt(ext: &ext, path: fileName); |
| 43 | |
| 44 | return isEqualString(str1: "aras" , str2: ext.cstr()) ? 0x1000 : 0; |
| 45 | } |
| 46 | |
| 47 | u32 calcBufferSizeAlignment(const sead::SafeString& fileName) { |
| 48 | StringTmp<32> ext("" ); |
| 49 | sead::Path::getExt(ext: &ext, path: fileName); |
| 50 | |
| 51 | return isEqualString(str1: "aras" , str2: ext.cstr()) ? 0x1000 : 0; |
| 52 | } |
| 53 | |
| 54 | u8* loadFile(const sead::SafeString& fileName, s32 size) { |
| 55 | return getFileLoader()->loadFile(fileName, size, nullptr); |
| 56 | } |
| 57 | |
| 58 | bool tryLoadFileToBuffer(const sead::SafeString& fileName, u8* buffer, u32 bufferSize, s32 size) { |
| 59 | return getFileLoader()->tryLoadFileToBuffer(path: fileName, buffer, bufferSize, alignment: size, device: nullptr); |
| 60 | } |
| 61 | |
| 62 | sead::ArchiveRes* loadArchive(const sead::SafeString& fileName) { |
| 63 | return getFileLoader()->loadArchive(path: StringTmp<256>("%s.szs" , fileName.cstr()), device: nullptr); |
| 64 | } |
| 65 | |
| 66 | sead::ArchiveRes* loadArchiveWithExt(const sead::SafeString& fileName, const char* ext) { |
| 67 | return getFileLoader()->loadArchiveWithExt(path: StringTmp<256>("%s.%s" , fileName.cstr(), ext), suffix: ext, |
| 68 | device: nullptr); |
| 69 | } |
| 70 | |
| 71 | bool tryRequestLoadArchive(const sead::SafeString& fileName, sead::Heap* heap) { |
| 72 | return getFileLoader()->tryRequestLoadArchive(path: StringTmp<256>("%s.szs" , fileName.cstr()), heap, |
| 73 | device: nullptr); |
| 74 | } |
| 75 | |
| 76 | void loadSoundItem(u32 soundEntryId, u32 unknown, IAudioResourceLoader* resLoader) { |
| 77 | getFileLoader()->loadSoundItem(itemId: soundEntryId, unknown, loader: resLoader); |
| 78 | } |
| 79 | |
| 80 | bool tryRequestLoadSoundItem(u32 soundEntryId) { |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | bool tryRequestPreLoadFile(const Resource* res, s32 id, sead::Heap* heap, |
| 85 | IAudioResourceLoader* resLoader) { |
| 86 | return tryRequestPreLoadFile(res, fileName: StringTmp<256>("PreLoadFileList%d" , id), heap, resLoader); |
| 87 | } |
| 88 | |
| 89 | bool tryRequestPreLoadFile(const Resource* res, const sead::SafeString& fileName, sead::Heap* heap, |
| 90 | IAudioResourceLoader* resLoader) { |
| 91 | if (!res->isExistFile(filePath: StringTmp<256>("%s.byml" , fileName.cstr()))) |
| 92 | return false; |
| 93 | |
| 94 | ByamlIter byml = res->getByml(filePath: fileName); |
| 95 | FileLoader* fileLoader = getFileLoader(); |
| 96 | if (!heap) |
| 97 | heap = getSceneResourceHeap(); |
| 98 | |
| 99 | fileLoader->requestPreLoadFile(preLoadList: byml, heap, loader: resLoader); |
| 100 | return true; |
| 101 | } |
| 102 | |
| 103 | void waitLoadDoneAllFile() { |
| 104 | getFileLoader()->waitLoadDoneAllFile(); |
| 105 | } |
| 106 | |
| 107 | void clearFileLoaderEntry() { |
| 108 | getFileLoader()->clearAllEntry(); |
| 109 | } |
| 110 | |
| 111 | void makeLocalizedArchivePath(sead::BufferedSafeString* outPath, const sead::SafeString& fileName) { |
| 112 | outPath->format(formatStr: "LocalizedData/%s/%s" , getLanguage(), fileName.cstr()); |
| 113 | } |
| 114 | |
| 115 | void makeLocalizedArchivePathByCountryCode(sead::BufferedSafeString* outPath, |
| 116 | const sead::SafeString& fileName) { |
| 117 | outPath->format(formatStr: "LocalizedData/%s/%s" , "EuEnglish" , fileName.cstr()); |
| 118 | } |
| 119 | |
| 120 | void setFileLoaderThreadPriority(s32 priority) { |
| 121 | getFileLoader()->setThreadPriority(priority); |
| 122 | } |
| 123 | } // namespace al |
| 124 | |