Check for failure to open file
MODIFY
src/ldb_reader.cpp
src/ldb_reader.cpp
*/
#include <fstream>
+#include <cerrno>
+#include <cstring>
#include "ldb_reader.h"
#include "ldb_chunks.h"
bool LDB_Reader::Load(const std::string& filename, const std::string& encoding) {
std::ifstream stream(filename.c_str(), std::ios::binary);
+ if (!stream.is_open()) {
+ fprintf(stderr, "Failed to open LDB file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
+ return false;
+ }
return LDB_Reader::Load(stream, encoding);
}
bool LDB_Reader::Save(const std::string& filename, const std::string& encoding, SaveOpt opt) {
std::ofstream stream(filename.c_str(), std::ios::binary);
+ if (!stream.is_open()) {
+ fprintf(stderr, "Failed to open LDB file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
+ return false;
+ }
return LDB_Reader::Save(stream, encoding, opt);
}
bool LDB_Reader::SaveXml(const std::string& filename) {
std::ofstream stream(filename.c_str(), std::ios::binary);
+ if (!stream.is_open()) {
+ fprintf(stderr, "Failed to open LDB XML file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
+ return false;
+ }
return LDB_Reader::SaveXml(stream);
}
bool LDB_Reader::LoadXml(const std::string& filename) {
std::ifstream stream(filename.c_str(), std::ios::binary);
+ if (!stream.is_open()) {
+ fprintf(stderr, "Failed to open LDB XML file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
+ return false;
+ }
return LDB_Reader::LoadXml(stream);
}

MODIFY
src/lmt_reader.cpp
src/lmt_reader.cpp
*/
#include <fstream>
+#include <cerrno>
+#include <cstring>
#include "lmt_reader.h"
#include "lmt_chunks.h"
bool LMT_Reader::Load(const std::string& filename, const std::string& encoding) {
std::ifstream stream(filename.c_str(), std::ios::binary);
+ if (!stream.is_open()) {
+ fprintf(stderr, "Failed to open LMT file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
+ return false;
+ }
return LMT_Reader::Load(stream, encoding);
}
bool LMT_Reader::Save(const std::string& filename, const std::string& encoding) {
std::ofstream stream(filename.c_str(), std::ios::binary);
+ if (!stream.is_open()) {
+ fprintf(stderr, "Failed to open LMT file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
+ return false;
+ }
return LMT_Reader::Save(stream, encoding);
}
bool LMT_Reader::SaveXml(const std::string& filename) {
std::ofstream stream(filename.c_str(), std::ios::binary);
+ if (!stream.is_open()) {
+ fprintf(stderr, "Failed to open LMT XML file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
+ return false;
+ }
return LMT_Reader::SaveXml(stream);
}
bool LMT_Reader::LoadXml(const std::string& filename) {
std::ifstream stream(filename.c_str(), std::ios::binary);
+ if (!stream.is_open()) {
+ fprintf(stderr, "Failed to open LMT XML file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
+ return false;
+ }
return LMT_Reader::LoadXml(stream);
}

MODIFY
src/lmu_reader.cpp
src/lmu_reader.cpp
*/
#include <fstream>
+#include <cerrno>
+#include <cstring>
#include "lmu_reader.h"
#include "lmu_chunks.h"
std::unique_ptr<RPG::Map> LMU_Reader::Load(const std::string& filename, const std::string& encoding) {
std::ifstream stream(filename.c_str(), std::ios::binary);
+ if (!stream.is_open()) {
+ fprintf(stderr, "Failed to open LMU file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
+ return nullptr;
+ }
return LMU_Reader::Load(stream, encoding);
}
bool LMU_Reader::Save(const std::string& filename, const RPG::Map& save, const std::string& encoding) {
std::ofstream stream(filename.c_str(), std::ios::binary);
+ if (!stream.is_open()) {
+ fprintf(stderr, "Failed to open LMU file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
+ return false;
+ }
return LMU_Reader::Save(stream, save, encoding);
}
bool LMU_Reader::SaveXml(const std::string& filename, const RPG::Map& save) {
std::ofstream stream(filename.c_str(), std::ios::binary);
+ if (!stream.is_open()) {
+ fprintf(stderr, "Failed to open LMU XML file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
+ return false;
+ }
return LMU_Reader::SaveXml(stream, save);
}
std::unique_ptr<RPG::Map> LMU_Reader::LoadXml(const std::string& filename) {
std::ifstream stream(filename.c_str(), std::ios::binary);
+ if (!stream.is_open()) {
+ fprintf(stderr, "Failed to open LMU XML file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
+ return nullptr;
+ }
return LMU_Reader::LoadXml(stream);
}

MODIFY
src/lsd_reader.cpp
src/lsd_reader.cpp
#include <cmath>
#include <fstream>
+#include <cerrno>
+#include <cstring>
+
#include "lsd_reader.h"
#include "lsd_chunks.h"
#include "ldb_reader.h"
@@ -32,21 +35,37 @@ double LSD_Reader::GenerateTimestamp(std::time_t const t) {
std::unique_ptr<RPG::Save> LSD_Reader::Load(const std::string& filename, const std::string& encoding) {
std::ifstream stream(filename.c_str(), std::ios::binary);
+ if (!stream.is_open()) {
+ fprintf(stderr, "Failed to open LSD file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
+ return nullptr;
+ }
return LSD_Reader::Load(stream, encoding);
}
bool LSD_Reader::Save(const std::string& filename, const RPG::Save& save, const std::string& encoding) {
std::ofstream stream(filename.c_str(), std::ios::binary);
+ if (!stream.is_open()) {
+ fprintf(stderr, "Failed to open LSD file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
+ return false;
+ }
return LSD_Reader::Save(stream, save, encoding);
}
bool LSD_Reader::SaveXml(const std::string& filename, const RPG::Save& save) {
std::ofstream stream(filename.c_str(), std::ios::binary);
+ if (!stream.is_open()) {
+ fprintf(stderr, "Failed to open LSD XML file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
+ return false;
+ }
return LSD_Reader::SaveXml(stream, save);
}
std::unique_ptr<RPG::Save> LSD_Reader::LoadXml(const std::string& filename) {
std::ifstream stream(filename.c_str(), std::ios::binary);
+ if (!stream.is_open()) {
+ fprintf(stderr, "Failed to open LSD XML file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
+ return nullptr;
+ }
return LSD_Reader::LoadXml(stream);
}

Check for failure to open file