Adjust Header to be non Nul Terminated
This commit is contained in:
parent
6e27fc27fb
commit
a50d89f4aa
@ -99,9 +99,8 @@ namespace file
|
|||||||
{
|
{
|
||||||
std::ifstream in(BASE_DIRECTORY LOGBOOK, std::ifstream::binary);
|
std::ifstream in(BASE_DIRECTORY LOGBOOK, std::ifstream::binary);
|
||||||
|
|
||||||
// File Header
|
|
||||||
std::string ident = readString(in, 5);
|
std::string ident = readString(in, 5);
|
||||||
if (ident.compare("VGAL") != 0) {
|
if (ident.compare(LOGBOOK_HEADER) != 0) {
|
||||||
throw std::invalid_argument("Wrong file");
|
throw std::invalid_argument("Wrong file");
|
||||||
}
|
}
|
||||||
std::uint8_t version = read<std::uint8_t>(in);
|
std::uint8_t version = read<std::uint8_t>(in);
|
||||||
@ -129,8 +128,8 @@ namespace file
|
|||||||
inline void toFile() const
|
inline void toFile() const
|
||||||
{
|
{
|
||||||
std::ofstream out(BASE_DIRECTORY LOGBOOK, std::fstream::binary);
|
std::ofstream out(BASE_DIRECTORY LOGBOOK, std::fstream::binary);
|
||||||
char header[] = {'V', 'G', 'A', 'L', '\0', 1};
|
out.write(LOGBOOK_HEADER, 4);
|
||||||
out.write(header, 6);
|
out.write("\1", 1);
|
||||||
for (const LogbookEntry &entry : this->entries) {
|
for (const LogbookEntry &entry : this->entries) {
|
||||||
entry.toFile(out);
|
entry.toFile(out);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,8 +41,8 @@ namespace file
|
|||||||
{
|
{
|
||||||
std::ofstream out(BASE_DIRECTORY RECORDING_DIRECTORY + fileName,
|
std::ofstream out(BASE_DIRECTORY RECORDING_DIRECTORY + fileName,
|
||||||
std::fstream::binary);
|
std::fstream::binary);
|
||||||
char header[] = {'V', 'G', 'A', 'R', '\0', 1};
|
out.write(RECORDING_HEADER, 4);
|
||||||
out.write(header, 6);
|
out.write("\1", 1);
|
||||||
for (const RecordingEntry &entry : this->entries) {
|
for (const RecordingEntry &entry : this->entries) {
|
||||||
entry.toFile(out);
|
entry.toFile(out);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -88,9 +88,8 @@ namespace file
|
|||||||
{
|
{
|
||||||
std::ifstream in(BASE_DIRECTORY SIMDATABASE, std::ifstream::binary);
|
std::ifstream in(BASE_DIRECTORY SIMDATABASE, std::ifstream::binary);
|
||||||
|
|
||||||
// File Header
|
|
||||||
std::string ident = readString(in, 5);
|
std::string ident = readString(in, 5);
|
||||||
if (ident.compare("VGAS") != 0) {
|
if (ident.compare(SIMDATABASE_HEADER) != 0) {
|
||||||
throw std::invalid_argument("Wrong file");
|
throw std::invalid_argument("Wrong file");
|
||||||
}
|
}
|
||||||
std::uint8_t version = read<std::uint8_t>(in);
|
std::uint8_t version = read<std::uint8_t>(in);
|
||||||
@ -133,9 +132,9 @@ namespace file
|
|||||||
{
|
{
|
||||||
std::ofstream out(BASE_DIRECTORY SIMDATABASE, std::fstream::binary);
|
std::ofstream out(BASE_DIRECTORY SIMDATABASE, std::fstream::binary);
|
||||||
|
|
||||||
// File Header, Last member is version
|
// File Header
|
||||||
std::uint8_t header[] = {'V', 'G', 'A', 'S', '\0', 1};
|
out.write(SIMDATABASE_HEADER, 4);
|
||||||
out.write(reinterpret_cast<const char *>(header), 6);
|
out.write("\1", 1);
|
||||||
// Num Airports
|
// Num Airports
|
||||||
write<std::uint16_t>(out, airports.size());
|
write<std::uint16_t>(out, airports.size());
|
||||||
// Airport
|
// Airport
|
||||||
|
|||||||
@ -5,7 +5,7 @@ namespace germanairlinesva_recording;
|
|||||||
class Recording
|
class Recording
|
||||||
{
|
{
|
||||||
private const ident = "VGAR";
|
private const ident = "VGAR";
|
||||||
private const header_unpack = "Z5ident/Cversion";
|
private const header_unpack = "a4ident/Cversion";
|
||||||
private const segment_unpack = "Vtime/Saltitude/Sgroundspeed/elatitude/elongitude";
|
private const segment_unpack = "Vtime/Saltitude/Sgroundspeed/elatitude/elongitude";
|
||||||
|
|
||||||
private string $file_name;
|
private string $file_name;
|
||||||
@ -122,7 +122,7 @@ class Recording
|
|||||||
throw new \InvalidArgumentException(sprintf('Argument must be a valid resource type. %s given.', gettype($file)));
|
throw new \InvalidArgumentException(sprintf('Argument must be a valid resource type. %s given.', gettype($file)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$header = unpack(Recording::header_unpack, fread($file, 6));
|
$header = unpack(Recording::header_unpack, fread($file, 5));
|
||||||
|
|
||||||
if ($header["ident"] !== Recording::ident) {
|
if ($header["ident"] !== Recording::ident) {
|
||||||
throw
|
throw
|
||||||
|
|||||||
@ -19,4 +19,8 @@
|
|||||||
#define SIMDATABASE "sim.bin"
|
#define SIMDATABASE "sim.bin"
|
||||||
#define LOGBOOK "logbook.bin"
|
#define LOGBOOK "logbook.bin"
|
||||||
|
|
||||||
|
#define LOGBOOK_HEADER "VGAL"
|
||||||
|
#define RECORDING_HEADER "VGAR"
|
||||||
|
#define SIMDATABASE_HEADER "VGAS"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Loading…
x
Reference in New Issue
Block a user