Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/lcf/ldb/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,32 @@ namespace LDB_Reader {
/**
* Loads Database.
*/
std::unique_ptr<lcf::rpg::Database> Load(const std::string& filename, const std::string& encoding);
std::unique_ptr<lcf::rpg::Database> Load(StringView filename, StringView encoding = "");

/**
* Saves Database.
*/
bool Save(const std::string& filename, const lcf::rpg::Database& db, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
bool Save(StringView filename, const lcf::rpg::Database& db, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);

/**
* Saves Database as XML.
*/
bool SaveXml(const std::string& filename, const lcf::rpg::Database& db);
bool SaveXml(StringView filename, const lcf::rpg::Database& db);

/**
* Load Database as XML.
*/
std::unique_ptr<lcf::rpg::Database> LoadXml(const std::string& filename);
std::unique_ptr<lcf::rpg::Database> LoadXml(StringView filename);

/**
* Loads Database.
*/
std::unique_ptr<lcf::rpg::Database> Load(std::istream& filestream, const std::string& encoding);
std::unique_ptr<lcf::rpg::Database> Load(std::istream& filestream, StringView encoding = "");

/**
* Saves Database.
*/
bool Save(std::ostream& filestream, const lcf::rpg::Database& db, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
bool Save(std::ostream& filestream, const lcf::rpg::Database& db, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);

/**
* Saves Database as XML.
Expand Down
12 changes: 6 additions & 6 deletions src/lcf/lmt/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,32 @@ namespace LMT_Reader {
/**
* Loads Map Tree.
*/
std::unique_ptr<lcf::rpg::TreeMap> Load(const std::string& filename, const std::string &encoding);
std::unique_ptr<lcf::rpg::TreeMap> Load(StringView filename, StringView encoding = "");

/**
* Saves Map Tree.
*/
bool Save(const std::string& filename, const lcf::rpg::TreeMap& tmap, EngineVersion engine, const std::string &encoding, SaveOpt opt = SaveOpt::eNone);
bool Save(StringView filename, const lcf::rpg::TreeMap& tmap, EngineVersion engine, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);

/**
* Saves Map Tree as XML.
*/
bool SaveXml(const std::string& filename, const lcf::rpg::TreeMap& tmap, EngineVersion engine);
bool SaveXml(StringView filename, const lcf::rpg::TreeMap& tmap, EngineVersion engine);

/**
* Loads Map Tree as XML.
*/
std::unique_ptr<lcf::rpg::TreeMap> LoadXml(const std::string& filename);
std::unique_ptr<lcf::rpg::TreeMap> LoadXml(StringView filename);

/**
* Loads Map Tree.
*/
std::unique_ptr<lcf::rpg::TreeMap> Load(std::istream& filestream, const std::string &encoding);
std::unique_ptr<lcf::rpg::TreeMap> Load(std::istream& filestream, StringView encoding = "");

/**
* Saves Map Tree.
*/
bool Save(std::ostream& filestream, const lcf::rpg::TreeMap& tmap, EngineVersion engine, const std::string &encoding, SaveOpt opt = SaveOpt::eNone);
bool Save(std::ostream& filestream, const lcf::rpg::TreeMap& tmap, EngineVersion engine, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);

/**
* Saves Map Tree as XML.
Expand Down
12 changes: 6 additions & 6 deletions src/lcf/lmu/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,32 @@ namespace LMU_Reader {
/**
* Loads map.
*/
std::unique_ptr<rpg::Map> Load(const std::string& filename, const std::string& encoding);
std::unique_ptr<rpg::Map> Load(StringView filename, StringView encoding = "");

/**
* Saves map.
*/
bool Save(const std::string& filename, const rpg::Map& map, EngineVersion engine, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
bool Save(StringView filename, const rpg::Map& map, EngineVersion engine, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);

/**
* Saves map as XML.
*/
bool SaveXml(const std::string& filename, const rpg::Map& map, EngineVersion engine);
bool SaveXml(StringView filename, const rpg::Map& map, EngineVersion engine);

/**
* Loads map as XML.
*/
std::unique_ptr<rpg::Map> LoadXml(const std::string& filename);
std::unique_ptr<rpg::Map> LoadXml(StringView filename);

/**
* Loads map.
*/
std::unique_ptr<rpg::Map> Load(std::istream& filestream, const std::string& encoding);
std::unique_ptr<rpg::Map> Load(std::istream& filestream, StringView encoding = "");

/**
* Saves map.
*/
bool Save(std::ostream& filestream, const rpg::Map& map, EngineVersion engine, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
bool Save(std::ostream& filestream, const rpg::Map& map, EngineVersion engine, StringView encoding = "", SaveOpt opt = SaveOpt::eNone);

/**
* Saves map as XML.
Expand Down
18 changes: 9 additions & 9 deletions src/lcf/lsd/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ namespace LSD_Reader {
/**
* Converts from UNIX timestamp to Delphi's TDateTime format.
*/
double ToTDateTime(std::time_t const t);
double ToTDateTime(std::time_t t);

/**
* Converts from Delphi's TDateTime format to UNIX timestamp.
*/
std::time_t ToUnixTimestamp(double const ms);
std::time_t ToUnixTimestamp(double ms);

/**
* Returns current system time encoded in Delphi's TDateTime format.
*/
double GenerateTimestamp(std::time_t const t = std::time(NULL));
double GenerateTimestamp(std::time_t t = std::time(nullptr));

/**
* Increment the save save_count and update the timestamp.
Expand All @@ -47,32 +47,32 @@ namespace LSD_Reader {
/**
* Loads Savegame.
*/
std::unique_ptr<rpg::Save> Load(const std::string& filename, const std::string &encoding);
std::unique_ptr<rpg::Save> Load(StringView filename, StringView encoding = "");

/**
* Saves Savegame.
*/
bool Save(const std::string& filename, const rpg::Save& save, EngineVersion engine, const std::string &encoding);
bool Save(StringView filename, const rpg::Save& save, EngineVersion engine, StringView encoding = "");

/*
* Saves Savegame as XML.
*/
bool SaveXml(const std::string& filename, const rpg::Save& save, EngineVersion engine);
bool SaveXml(StringView filename, const rpg::Save& save, EngineVersion engine);

/**
* Loads Savegame as XML.
*/
std::unique_ptr<rpg::Save> LoadXml(const std::string& filename);
std::unique_ptr<rpg::Save> LoadXml(StringView filename);

/**
* Loads Savegame.
*/
std::unique_ptr<rpg::Save> Load(std::istream& filestream, const std::string &encoding);
std::unique_ptr<rpg::Save> Load(std::istream& filestream, StringView encoding = "");

/**
* Saves Savegame.
*/
bool Save(std::ostream& filestream, const rpg::Save& save, EngineVersion engine, const std::string &encoding);
bool Save(std::ostream& filestream, const rpg::Save& save, EngineVersion engine, StringView encoding = "");

/*
* Saves Savegame as XML.
Expand Down
7 changes: 1 addition & 6 deletions src/lcf/reader_lcf.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ class LcfReader {
* @param filestream already opened filestream.
* @param encoding name of the encoding.
*/
LcfReader(std::istream& filestream, std::string encoding = "");

/**
* Destructor. Closes the opened file.
*/
~LcfReader();
explicit LcfReader(std::istream& filestream, std::string encoding = "");

/**
* Returns the last set error.
Expand Down
35 changes: 19 additions & 16 deletions src/lcf/reader_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include "lcf/string_view.h"

namespace lcf {
namespace rpg {
class Database;
}

/**
* ReaderUtil namespace.
Expand All @@ -29,42 +32,42 @@ namespace ReaderUtil {
std::string CodepageToEncoding(int codepage);

/**
* Detects the encoding based on text analysis.
* Detects the encoding of the database based on text analysis.
*
* @param filestream stream containing the database file
* @param db Database to process
*
* @return encoding or empty string if not detected.
*/
std::string DetectEncoding(std::istream& filestream);
std::string DetectEncoding(lcf::rpg::Database& db);

/**
* Detects the encoding based on text analysis.
* Detects the encoding of the database based on text analysis.
* Returns a vector of possible candidates, highest candidate being at the beginning.
*
* @param filestream stream containing the database file
* @param db Database to process
*
* @return encoding or empty string if not detected.
* @return list of encodings or empty if not detected
*/
std::string DetectEncoding(StringView data);
std::vector<std::string> DetectEncodings(lcf::rpg::Database& db);

/**
* Detects the encoding based on text analysis and returns a vector with
* possible candidates, highest candidate being at the beginning.
* Detects the encoding of a string based on text analysis.
*
* @param filestream stream containing the database file
* @param string encoded data of a few hundred bytes
*
* @return list of encodings or empty if not detected
* @return encoding or empty string if not detected.
*/
std::vector<std::string> DetectEncodings(std::istream& filestream);
std::string DetectEncoding(StringView data);

/**
* Detects the encoding based on text analysis and returns a vector with
* possible candidates, highest candidate being at the beginning.
* Detects the encoding of a string based on text analysis.
* Returns a vector of possible candidates, highest candidate being at the beginning.
*
* @param string encoded data of a few hundred bytes
*
* @return list of encodings or empty if not detected
*/
std::vector<std::string> DetectEncodings(StringView data);
std::vector<std::string> DetectEncodings(StringView string);

/**
* Returns the encoding set in the ini file.
Expand All @@ -73,7 +76,7 @@ namespace ReaderUtil {
*
* @return encoding or empty string if not found.
*/
std::string GetEncoding(const std::string& ini_file);
std::string GetEncoding(StringView ini_file);

/**
* Returns the encoding set in the ini file.
Expand Down
5 changes: 0 additions & 5 deletions src/lcf/writer_lcf.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ class LcfWriter {
*/
LcfWriter(std::ostream& filestream, EngineVersion engine, std::string encoding = "");

/**
* Destructor. Closes the opened file.
*/
~LcfWriter();

/**
* Writes raw data to the stream (fwrite() wrapper).
*
Expand Down
32 changes: 16 additions & 16 deletions src/ldb_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,44 @@ void LDB_Reader::PrepareSave(rpg::Database& db) {
++db.system.save_count;
}

std::unique_ptr<lcf::rpg::Database> LDB_Reader::Load(const std::string& filename, const std::string& encoding) {
std::ifstream stream(filename.c_str(), std::ios::binary);
std::unique_ptr<lcf::rpg::Database> LDB_Reader::Load(StringView filename, StringView encoding) {
std::ifstream stream(ToString(filename), std::ios::binary);
if (!stream.is_open()) {
fprintf(stderr, "Failed to open LDB file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
fprintf(stderr, "Failed to open LDB file `%s' for reading : %s\n", ToString(filename).c_str(), strerror(errno));
return nullptr;
}
return LDB_Reader::Load(stream, encoding);
}

bool LDB_Reader::Save(const std::string& filename, const lcf::rpg::Database& db, const std::string& encoding, SaveOpt opt) {
std::ofstream stream(filename.c_str(), std::ios::binary);
bool LDB_Reader::Save(StringView filename, const lcf::rpg::Database& db, StringView encoding, SaveOpt opt) {
std::ofstream stream(ToString(filename), std::ios::binary);
if (!stream.is_open()) {
fprintf(stderr, "Failed to open LDB file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
fprintf(stderr, "Failed to open LDB file `%s' for writing : %s\n", ToString(filename).c_str(), strerror(errno));
return false;
}
return LDB_Reader::Save(stream, db, encoding, opt);
}

bool LDB_Reader::SaveXml(const std::string& filename, const lcf::rpg::Database& db) {
std::ofstream stream(filename.c_str(), std::ios::binary);
bool LDB_Reader::SaveXml(StringView filename, const lcf::rpg::Database& db) {
std::ofstream stream(ToString(filename), 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));
fprintf(stderr, "Failed to open LDB XML file `%s' for writing : %s\n", ToString(filename).c_str(), strerror(errno));
return false;
}
return LDB_Reader::SaveXml(stream, db);
}

std::unique_ptr<lcf::rpg::Database> LDB_Reader::LoadXml(const std::string& filename) {
std::ifstream stream(filename.c_str(), std::ios::binary);
std::unique_ptr<lcf::rpg::Database> LDB_Reader::LoadXml(StringView filename) {
std::ifstream stream(ToString(filename), 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));
fprintf(stderr, "Failed to open LDB XML file `%s' for reading : %s\n", ToString(filename).c_str(), strerror(errno));
return nullptr;
}
return LDB_Reader::LoadXml(stream);
}

std::unique_ptr<lcf::rpg::Database> LDB_Reader::Load(std::istream& filestream, const std::string& encoding) {
LcfReader reader(filestream, encoding);
std::unique_ptr<lcf::rpg::Database> LDB_Reader::Load(std::istream& filestream, StringView encoding) {
LcfReader reader(filestream, ToString(encoding));
if (!reader.IsOk()) {
LcfReader::SetError("Couldn't parse database file.\n");
return nullptr;
Expand Down Expand Up @@ -87,9 +87,9 @@ std::unique_ptr<lcf::rpg::Database> LDB_Reader::Load(std::istream& filestream, c
return db;
}

bool LDB_Reader::Save(std::ostream& filestream, const lcf::rpg::Database& db, const std::string& encoding, SaveOpt opt) {
bool LDB_Reader::Save(std::ostream& filestream, const lcf::rpg::Database& db, StringView encoding, SaveOpt opt) {
const auto engine = GetEngineVersion(db);
LcfWriter writer(filestream, engine, encoding);
LcfWriter writer(filestream, engine, ToString(encoding));
if (!writer.IsOk()) {
LcfReader::SetError("Couldn't parse database file.\n");
return false;
Expand Down
Loading