MCPcopy Create free account
hub / github.com/diasurgical/devilution / Close

Method Close

Source/mpqapi.cpp:194–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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();

Callers 3

OpenMethod · 0.45
OpenMPQFunction · 0.45
mpqapi_flush_and_closeFunction · 0.45

Calls 5

SDL_LogFunction · 0.85
ResizeFileFunction · 0.85
IsOpenMethod · 0.80
seekpMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected