44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
#include "logbook.h"
|
|
|
|
namespace germanairlinesva_logbook
|
|
{
|
|
Logbook::Logbook()
|
|
{
|
|
if (germanairlinesva_util::fileExists(XPLANE_PLUGIN_DIRECTORY LOGBOOK)) {
|
|
this->fromFile(XPLANE_PLUGIN_DIRECTORY LOGBOOK);
|
|
}
|
|
}
|
|
|
|
void Logbook::fromFile(const std::string &file)
|
|
{
|
|
std::ifstream in(file, std::ifstream::binary);
|
|
|
|
// File Header
|
|
char ident[5];
|
|
in.read(ident, 5);
|
|
if (strcmp(ident, "VGAL") != 0) {
|
|
throw std::invalid_argument("Wrong file");
|
|
}
|
|
std::uint8_t version;
|
|
in.read(reinterpret_cast<char *>(&version), 1);
|
|
|
|
if (version == 1) {
|
|
return this->readVersion1(in);
|
|
}
|
|
}
|
|
|
|
void Logbook::readVersion1(std::ifstream &in) {}
|
|
|
|
|
|
void Logbook::toFile() const
|
|
{
|
|
std::ofstream out(XPLANE_PLUGIN_DIRECTORY LOGBOOK, std::fstream::binary);
|
|
char header[] = {'V', 'G', 'A', 'L', '\0', 1};
|
|
out.write(header, 6);
|
|
for (const LogbookEntry &entry : this->entries) {
|
|
out.write(reinterpret_cast<const char *>(entry.getBinaryData()),
|
|
entry.getBinaryLength());
|
|
}
|
|
out.close();
|
|
}
|
|
} // namespace germanairlinesva_logbook
|