| 2109 | } |
| 2110 | |
| 2111 | std::FILE* FileAccessHelper::ReOpen(const std::string_view folderName, MemoryCardFileMetadataReference* fileRef, bool writeMetadata /* = false */) |
| 2112 | { |
| 2113 | std::string internalPath; |
| 2114 | fileRef->GetInternalPath(&internalPath); |
| 2115 | auto it = m_files.find(internalPath); |
| 2116 | if (it != m_files.end()) |
| 2117 | { |
| 2118 | // we already have a handle to this file |
| 2119 | |
| 2120 | // if the caller wants to write metadata and we haven't done this recently, do so and remember that we did |
| 2121 | if (writeMetadata) |
| 2122 | { |
| 2123 | if (m_lastWrittenFileRef != fileRef) |
| 2124 | { |
| 2125 | WriteMetadata(folderName, fileRef); |
| 2126 | m_lastWrittenFileRef = fileRef; |
| 2127 | } |
| 2128 | } |
| 2129 | else |
| 2130 | { |
| 2131 | if (m_lastWrittenFileRef != nullptr) |
| 2132 | { |
| 2133 | m_lastWrittenFileRef = nullptr; |
| 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | // update the fileRef in the map since it might have been modified or deleted |
| 2138 | it->second.fileRef = fileRef; |
| 2139 | |
| 2140 | return it->second.fileHandle; |
| 2141 | } |
| 2142 | else |
| 2143 | { |
| 2144 | return this->Open(folderName, fileRef, writeMetadata); |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | void FileAccessHelper::CloseFileHandle(std::FILE*& file, const MemoryCardFileEntry* entry /* = nullptr */) |
| 2149 | { |
no test coverage detected