Skip to content

Commit

Permalink
Merge pull request Revolutionary-Games#290 from Revolutionary-Games/2…
Browse files Browse the repository at this point in the history
…54-microbe-save-crash-fix

Game now creates the necessary folders for saving creations
  • Loading branch information
jjonj committed Feb 16, 2015
2 parents a0cc2d3 + e83a3f6 commit 7952d69
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions src/engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,25 +732,33 @@ Engine::saveCreation(
) const {
namespace fs = boost::filesystem;
StorageContainer creation = entityManager.storeEntity(entityId);
creation.set("thriveversion", this->thriveVersion());
std::ofstream stream(
(fs::path("creations") / fs::path(type) / fs::path(name + "." + type)).string<std::string>(),
std::ofstream::trunc | std::ofstream::binary
);
stream.exceptions(std::ofstream::failbit | std::ofstream::badbit);
if (stream) {
try {
stream << creation;
stream.flush();
stream.close();
}
catch (const std::ofstream::failure& e) {
std::cerr << "Error saving file: " << e.what() << std::endl;
throw;
}
fs::path pth = (fs::path("creations") / fs::path(type));
boost::system::error_code returnedError;
boost::filesystem::create_directories( pth, returnedError );
if (returnedError) {
std::perror("Could not create necessary directories for saving.");
}
else {
std::perror("Could not open file for saving");
creation.set("thriveversion", this->thriveVersion());
std::ofstream stream(
(pth / fs::path(name + "." + type)).string<std::string>(),
std::ofstream::trunc | std::ofstream::binary
);
stream.exceptions(std::ofstream::failbit | std::ofstream::badbit);
if (stream) {
try {
stream << creation;
stream.flush();
stream.close();
}
catch (const std::ofstream::failure& e) {
std::cerr << "Error saving file: " << e.what() << std::endl;
throw;
}
}
else {
std::perror("Could not open file for saving");
}
}
}

Expand Down

0 comments on commit 7952d69

Please sign in to comment.