MCPcopy Create free account
hub / github.com/SimHacker/micropolis / saveCityAs

Method saveCityAs

MicropolisCore/src/MicropolisEngine/src/fileio.cpp:615–642  ·  view source on GitHub ↗

* Save the city under a new name (?) * @param filename Name of the file to use for storing the game. * @todo String normalization code is duplicated in Micropolis::loadCity(). * Extract to a sub-function. * @bug Function fails if \c lastDot<lastSlash (ie with \c "x.y/bla" ) */

Source from the content-addressed store, hash-verified

613 * @bug Function fails if \c lastDot<lastSlash (ie with \c "x.y/bla" )
614 */
615void Micropolis::saveCityAs(const char *filename)
616{
617 cityFileName = filename;
618
619 if (saveFile(cityFileName.c_str())) {
620
621 unsigned int lastDot = cityFileName.find_last_of('.');
622 unsigned int lastSlash = cityFileName.find_last_of('/');
623
624 unsigned int pos =
625 (lastSlash == std::string::npos) ? 0 : lastSlash + 1;
626 unsigned int last =
627 (lastDot == std::string::npos) ? cityFileName.length() : lastDot;
628 unsigned int len =
629 last - pos;
630 std::string newCityName =
631 cityFileName.substr(pos, len);
632
633 setCityName(newCityName);
634
635 didSaveCity();
636
637 } else {
638
639 didntSaveCity(cityFileName.c_str());
640
641 }
642}
643
644
645////////////////////////////////////////////////////////////////////////

Callers 2

getSaveFileDataMethod · 0.80
saveMetaCityMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected