MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / SaveTable

Method SaveTable

editor/TableManage.cpp:211–307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209}
210
211bool GenericPageList::SaveTable(char *table_filename) {
212 CFILE *infile, *outfile;
213 uint8_t pagetype, replaced = 0;
214 int done = 0;
215 uint32_t page_id;
216 GenericPageNode *new_generic_page;
217 mngs_generic_page genericpage;
218
219 CWaitCursor wc;
220
221 // If no table is loaded, get outta here
222 if (!m_TableLoaded)
223 return FALSE;
224
225 // First make sure we can open the table file and the temp table file
226 infile = cfopen(m_TableFilename.GetBuffer(0), "rb");
227 if (!infile) {
228 mprintf(0, "Couldn't open table file to replace generic!\n");
229 return FALSE;
230 }
231
232 outfile = cfopen(TEMP_TABLE_FILENAME, "wb");
233 if (!outfile) {
234 mprintf(0, "Couldn't open temp table file to replace generic!\n");
235 cfclose(infile);
236 return FALSE;
237 }
238
239 // Clear out the generic page
240 memset(&genericpage, 0, sizeof(mngs_generic_page));
241
242 // Read through the entire pagefile and replace the page we want replaced
243 // If we can't find the one we want, we simply append it to the end of the file
244 page_id = 0;
245 while (!done) {
246 if (cfeof(infile)) {
247 done = 1;
248 continue;
249 }
250 pagetype = cf_ReadByte(infile);
251
252 // If not a generic page, just read it in and write it right back out
253 if (pagetype != PAGETYPE_GENERIC) {
254 mng_ReadWriteDummyPage(infile, outfile, pagetype);
255 page_id++;
256 continue;
257 }
258
259 mng_ReadNewGenericPage(infile, &genericpage);
260
261 // Look for the generic page with the current page position in list
262 new_generic_page = FindNode(page_id);
263 if (new_generic_page == NULL) {
264 // There is a page incompatibility!!!!
265 // so, just write out the one that was read instead
266 mng_WriteNewGenericPage(outfile, &genericpage);
267 OutrageMessageBox("File incompatibility Error!", "Error!");
268 } else {

Callers 2

OnTableEditFileSaveMethod · 0.80
OnTableEditFileSaveAsMethod · 0.80

Calls 10

cfopenFunction · 0.85
cfcloseFunction · 0.85
cfeofFunction · 0.85
cf_ReadByteFunction · 0.85
mng_ReadWriteDummyPageFunction · 0.85
mng_ReadNewGenericPageFunction · 0.85
mng_WriteNewGenericPageFunction · 0.85
OutrageMessageBoxFunction · 0.85
SwitcherooFilesFunction · 0.85
GetBufferMethod · 0.80

Tested by

no test coverage detected