| 192 | } |
| 193 | |
| 194 | bool Close(bool clear_tables = true) |
| 195 | { |
| 196 | if (!stream.IsOpen()) |
| 197 | return true; |
| 198 | #ifdef _DEBUG |
| 199 | SDL_Log("Closing %s", name.c_str()); |
| 200 | #endif |
| 201 | |
| 202 | bool result = true; |
| 203 | if (modified && !(stream.seekp(0, std::ios::beg) && WriteHeaderAndTables())) |
| 204 | result = false; |
| 205 | stream.Close(); |
| 206 | if (modified && result && size != 0) { |
| 207 | #ifdef _DEBUG |
| 208 | SDL_Log("ResizeFile(\"%s\", %" PRIuMAX ")", name.c_str(), size); |
| 209 | #endif |
| 210 | result = ResizeFile(name.c_str(), size); |
| 211 | } |
| 212 | name.clear(); |
| 213 | if (clear_tables) { |
| 214 | delete[] sgpHashTbl; |
| 215 | sgpHashTbl = nullptr; |
| 216 | delete[] sgpBlockTbl; |
| 217 | sgpBlockTbl = nullptr; |
| 218 | } |
| 219 | return result; |
| 220 | } |
| 221 | |
| 222 | bool WriteHeaderAndTables() { |
| 223 | return WriteHeader() && WriteBlockTable() && WriteHashTable(); |
no test coverage detected