| 209 | } |
| 210 | |
| 211 | bool 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 { |
no test coverage detected