| 126 | } |
| 127 | |
| 128 | void FileCache::Open(QIFStream& stream, const char* name) |
| 129 | { |
| 130 | if (!name || !*name) |
| 131 | { |
| 132 | // Opening an empty/null name is a benign "no resource" request — e.g. a |
| 133 | // profile with no custom squad logo / voice sample set. The stream is left |
| 134 | // in its failed state for the caller to handle; this is not an asset error, |
| 135 | // so it must not be logged at ERROR (which would abort the app under --strict |
| 136 | // on a perfectly normal profile open). |
| 137 | LOG_DEBUG(Core, "FileCache::Open: empty name — no resource requested (no-op)"); |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | if (GEnableCaching) |
| 142 | { |
| 143 | // note: multiple threads may open file same time |
| 144 | // make sure file is in cache |
| 145 | int index = Load(name); |
| 146 | if (index >= 0) |
| 147 | { |
| 148 | // it must be the first file |
| 149 | PoseidonAssert(index == 0); |
| 150 | PoseidonAssert(!strcmp(name, _cache[index]->_name)); |
| 151 | // share cached data |
| 152 | stream = _cache[index]->_data; |
| 153 | } |
| 154 | else |
| 155 | { |
| 156 | // Load already logged a "file not found" warning with the same name; |
| 157 | // include it here too so the error line carries enough context on its own. |
| 158 | LOG_ERROR(Core, "FileCache: Cache failure loading '{}' (file not found or stream fail)", name); |
| 159 | } |
| 160 | } |
| 161 | else |
| 162 | { |
| 163 | QIFStreamB temp; |
| 164 | temp.AutoOpen(name); |
| 165 | stream = temp; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | void FileCache::Store(QIFStreamB& stream, const char* name) |
| 170 | { |
no test coverage detected