109 lines
3.5 KiB
C++
109 lines
3.5 KiB
C++
#include "logbook/logbook.h"
|
|
|
|
namespace germanairlinesva
|
|
{
|
|
namespace file
|
|
{
|
|
namespace logbook
|
|
{
|
|
Logbook::Logbook()
|
|
{
|
|
if (germanairlinesva::util::fileExists(XPLANE_PLUGIN_DIRECTORY LOGBOOK)) {
|
|
this->fromFile();
|
|
}
|
|
}
|
|
|
|
void Logbook::fromFile()
|
|
{
|
|
std::ifstream in(XPLANE_PLUGIN_DIRECTORY LOGBOOK, std::ifstream::binary);
|
|
|
|
// File Header
|
|
std::string ident = readString(in, 5);
|
|
if (ident.compare("VGAL") != 0) {
|
|
throw std::invalid_argument("Wrong file");
|
|
}
|
|
std::uint8_t version = read<std::uint8_t>(in);
|
|
|
|
if (version == 1) {
|
|
while (in.peek() != EOF) {
|
|
this->readVersion1(in);
|
|
}
|
|
}
|
|
}
|
|
|
|
void Logbook::readVersion1(std::ifstream &in)
|
|
{
|
|
std::string date = readString(in, 10);
|
|
std::string flightNumber = readString(in, 4);
|
|
std::string aircraftType = readString(in, 4);
|
|
std::string aircraftRegistration = readString(in, 6);
|
|
std::string departureAirport = readString(in);
|
|
std::string departureGate = readString(in);
|
|
std::string departureRunway = readString(in);
|
|
std::string arrivalAirport = readString(in);
|
|
std::string arrivalGate = readString(in);
|
|
std::string arrivalRunway = readString(in);
|
|
std::string offBlockTime = readString(in, 5);
|
|
std::string outTime = readString(in, 5);
|
|
std::string inTime = readString(in, 5);
|
|
std::string onBlockTime = readString(in, 5);
|
|
float totalFlightTime = read<float>(in);
|
|
float taxiOutFuel = read<float>(in);
|
|
float inFlightFuel = read<float>(in);
|
|
float taxiInFuel = read<float>(in);
|
|
float totalFuel = read<float>(in);
|
|
float taxiOutDistance = read<float>(in);
|
|
float inFlightDistance = read<float>(in);
|
|
float taxiInDistance = read<float>(in);
|
|
float totalDistance = read<float>(in);
|
|
float maxLandingRate = read<float>(in);
|
|
std::uint8_t touchdowns = read<std::uint8_t>(in);
|
|
float maxLandingGees = read<float>(in);
|
|
std::string recordingFilename = readString(in);
|
|
float points = read<float>(in);
|
|
std::uint8_t flags = read<std::uint8_t>(in);
|
|
|
|
this->addEntry(date,
|
|
flightNumber,
|
|
aircraftType,
|
|
aircraftRegistration,
|
|
departureAirport,
|
|
departureGate,
|
|
departureRunway,
|
|
arrivalAirport,
|
|
arrivalGate,
|
|
arrivalRunway,
|
|
offBlockTime,
|
|
outTime,
|
|
inTime,
|
|
onBlockTime,
|
|
totalFlightTime,
|
|
taxiOutFuel,
|
|
inFlightFuel,
|
|
taxiInFuel,
|
|
totalFuel,
|
|
taxiOutDistance,
|
|
inFlightDistance,
|
|
taxiInDistance,
|
|
totalDistance,
|
|
maxLandingRate,
|
|
touchdowns,
|
|
maxLandingGees,
|
|
recordingFilename,
|
|
points,
|
|
flags);
|
|
}
|
|
|
|
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) {
|
|
entry.toFile(out);
|
|
}
|
|
out.close();
|
|
}
|
|
} // namespace logbook
|
|
} // namespace file
|
|
} // namespace germanairlinesva
|