| 2014 | } |
| 2015 | |
| 2016 | void FileAccessHelper::WriteMetadata(const std::string_view folderName, const MemoryCardFileMetadataReference* fileRef) |
| 2017 | { |
| 2018 | std::string fileName(folderName); |
| 2019 | const bool cleanedFilename = fileRef->GetPath(&fileName); |
| 2020 | std::string metaFileName(Path::AppendDirectory(fileName, "_pcsx2_meta")); |
| 2021 | std::string metaDirName(Path::GetDirectory(metaFileName)); |
| 2022 | |
| 2023 | const auto* entry = &fileRef->entry->entry; |
| 2024 | const bool metadataIsNonstandard = cleanedFilename || entry->data.mode != MemoryCardFileEntry::DefaultFileMode || entry->data.attr != 0; |
| 2025 | |
| 2026 | if (metadataIsNonstandard) |
| 2027 | { |
| 2028 | // write metadata of file if it's nonstandard |
| 2029 | if (!FileSystem::DirectoryExists(metaDirName.c_str())) |
| 2030 | { |
| 2031 | FileSystem::CreateDirectoryPath(metaDirName.c_str(), false); |
| 2032 | } |
| 2033 | |
| 2034 | auto metaFile = FileSystem::OpenManagedCFile(metaFileName.c_str(), "wb"); |
| 2035 | if (metaFile) |
| 2036 | std::fwrite(entry->raw, sizeof(entry->raw), 1, metaFile.get()); |
| 2037 | } |
| 2038 | else |
| 2039 | { |
| 2040 | // if metadata is standard remove metadata file if it exists |
| 2041 | if (FileSystem::DirectoryExists(metaDirName.c_str())) |
| 2042 | { |
| 2043 | FileSystem::DeleteFilePath(metaFileName.c_str()); |
| 2044 | |
| 2045 | // and remove the metadata dir if it's now empty |
| 2046 | if (FileSystem::DirectoryIsEmpty(metaDirName.c_str())) |
| 2047 | FileSystem::DeleteDirectory(metaDirName.c_str()); |
| 2048 | } |
| 2049 | } |
| 2050 | } |
| 2051 | |
| 2052 | void FileAccessHelper::WriteIndex(const std::string& baseFolderName, MemoryCardFileEntry* const entry, MemoryCardFileMetadataReference* const parent) |
| 2053 | { |