Saves it without any conventional INI formatting characters, however it only uses string streams
| 443 | |
| 444 | //Saves it without any conventional INI formatting characters, however it only uses string streams |
| 445 | bool saveBinary(const std::string filename = "") |
| 446 | { |
| 447 | if (!hasFileAssociation(filename)) |
| 448 | return false; |
| 449 | |
| 450 | fini_ofstream_t file(((filename == "") ? this->filename : filename).c_str(), std::ios::trunc | std::ios::binary); |
| 451 | if (!file.is_open()) |
| 452 | return false; |
| 453 | |
| 454 | size_t sectionCount = sections.size(); |
| 455 | size_t keyCount; |
| 456 | |
| 457 | file.write((fini_char_t*)§ionCount, sizeof(sectionCount)); |
| 458 | |
| 459 | //Loop through sections |
| 460 | for (typename INI::sectionsit_t i = sections.begin(); i != sections.end(); i++) |
| 461 | { |
| 462 | keyCount = i->second->size(); |
| 463 | file.write((fini_char_t*)&keyCount, sizeof(keyCount)); |
| 464 | |
| 465 | file << i->first << std::endl; |
| 466 | |
| 467 | for (typename INI::keysit_t j = i->second->begin(); j != i->second->end(); j++) |
| 468 | { |
| 469 | file << j->first << std::endl; |
| 470 | file << j->second << std::endl; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | file.close(); |
| 475 | |
| 476 | return true; |
| 477 | } |
| 478 | |
| 479 | //Saves it as a true binary file, intended to replace the existing one. Don't bother using it with all strings. |
| 480 | bool saveBinaryExperimental(std::string filename = "") |