Move MakeRwys to own lib

This commit is contained in:
2022-09-04 01:19:50 +02:00
parent a820f7456a
commit 3b2f146679
11 changed files with 119 additions and 3 deletions
+5 -1
View File
@@ -4,11 +4,11 @@ file(GLOB file CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/file/*.cpp)
add_library(germanairlinesva_xplugin SHARED
${socket}
${file}
makeRwysXP.cpp
main.cpp
)
target_include_directories(germanairlinesva_xplugin PRIVATE
${CMAKE_SOURCE_DIR}/makerwysxp/include
${CMAKE_SOURCE_DIR}/socket/include
${CMAKE_SOURCE_DIR}/XPSDK/CHeaders
${CMAKE_SOURCE_DIR}/nlohmann
@@ -133,3 +133,7 @@ elseif(WIN32)
xPluginWin.cpp
)
endif()
target_link_libraries(germanairlinesva_xplugin PRIVATE
makerwysxp
)
-30
View File
@@ -1,30 +0,0 @@
#ifndef GERMANAIRLINESVA_GACONNECTOR_XPLUGIN_MAKERWYSXP_H
#define GERMANAIRLINESVA_GACONNECTOR_XPLUGIN_MAKERWYSXP_H
#include <fstream>
#include <iostream>
#include <map>
#include <string>
#include "gate.hpp"
#include "runway.hpp"
#include "stringExtensions.hpp"
#include "util.hpp"
int scan(const char *defaultFile,
const char *sceneryPack,
const char *logFile,
std::map<std::string,
std::pair<std::vector<Gate>, std::vector<Runway>>> &airports);
void makeAirport(
const std::string &kind,
std::ifstream *infile,
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
*airports,
std::ofstream *logfile);
void makeGate15(std::vector<Gate> *gates, std::vector<std::string> fields);
void makeRunway(std::vector<Runway> *runways, std::vector<std::string> fields);
void makeGate1300(std::vector<Gate> *gates, std::vector<std::string> fields);
#endif
-174
View File
@@ -1,174 +0,0 @@
#include "include/makeRwysXP.h"
int scan(const char *defaultFile,
const char *sceneryPack,
const char *logFile,
std::map<std::string,
std::pair<std::vector<Gate>, std::vector<Runway>>> &airports)
{
std::ifstream base(defaultFile);
if (!base.good()) {
return 1;
}
std::ifstream custom(sceneryPack);
if (!custom.good()) {
base.close();
return 2;
}
std::ofstream logfile(logFile, std::ios::out | std::ios::trunc);
if (!logfile.good()) {
base.close();
custom.close();
return 3;
}
// Default
logfile << "<FILE> " << defaultFile << std::endl;
makeAirport("DEFAULT", &base, &airports, &logfile);
base.close();
std::string line;
size_t pos;
std::vector<std::string> packs;
while (std::getline(custom, line)) {
if ((pos = line.find("SCENERY_PACK")) != std::string::npos) {
std::string path =
rtrim_copy(line.substr(pos + 13)) + "Earth nav data/apt.dat";
packs.push_back(path);
}
}
std::reverse(packs.begin(), packs.end());
for (std::string const &path : packs) {
std::ifstream pack(path);
if (pack.good()) {
logfile << "<FILE> " << path << std::endl;
makeAirport("CUSTOM", &pack, &airports, &logfile);
pack.close();
} else {
pack.close();
logfile << "<STATUS>"
<< "Could not find " << path << std::endl;
}
}
logfile << std::endl
<< "<STATUS> Total airports: " << airports.size() << std::endl;
custom.close();
logfile.close();
return 0;
}
void makeAirport(
const std::string &kind,
std::ifstream *infile,
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
*airports,
std::ofstream *logfile)
{
std::string line;
std::string *currentIcao = nullptr;
std::vector<Gate> tmpGates;
std::vector<Runway> tmpRunways;
int apCount = 0;
int validCount = 0;
while (std::getline(*infile, line)) {
std::vector<std::string> fields = split(line, ' ');
fields = util::select_T<std::string>(fields, [](const std::string &s) {
return s.length() > 0;
});
if (fields.empty())
continue;
if (fields[0] == "1") {
// Write to file if ICAO is valid, and we have gates and runways
if (currentIcao != nullptr && !tmpRunways.empty() && !tmpGates.empty()) {
(*airports)[*currentIcao] = {tmpGates, tmpRunways};
validCount += 1;
*logfile << "\t<STATUS> " << *currentIcao << " committed" << std::endl;
} else if (currentIcao != nullptr) {
*logfile << "\t<STATUS> " << *currentIcao << " had no gates or runways"
<< std::endl;
}
tmpGates = std::vector<Gate>();
tmpRunways = std::vector<Runway>();
currentIcao = new std::string(fields[4]);
apCount += 1;
*logfile << "\t<" << kind << "> " << line << std::endl;
} else if (currentIcao != nullptr && fields[0] == "15") {
makeGate15(&tmpGates, fields);
*logfile << "\t\t<GATE OLD> " << line << std::endl;
} else if (fields[0] == "16" || fields[0] == "17") {
// Write to file if ICAO is valid, and we have gates and runways
if (currentIcao != nullptr && !tmpRunways.empty() && !tmpGates.empty()) {
(*airports)[*currentIcao] = {tmpGates, tmpRunways};
validCount += 1;
*logfile << "\t<STATUS> " << *currentIcao << " committed" << std::endl;
} else if (currentIcao != nullptr) {
*logfile << "\t<STATUS> " << *currentIcao << " had no gates or runways"
<< std::endl;
}
tmpGates = std::vector<Gate>();
tmpRunways = std::vector<Runway>();
currentIcao = nullptr;
*logfile << "\t<" << kind << " SKIPPED> " << line << std::endl;
} else if (currentIcao != nullptr && fields[0] == "100") {
makeRunway(&tmpRunways, fields);
*logfile << "\t\t<RUNWAY> " << line << std::endl;
} else if (currentIcao != nullptr && fields[0] == "1300") {
makeGate1300(&tmpGates, fields);
*logfile << "\t\t<GATE> " << line << std::endl;
}
}
if (currentIcao != nullptr && !tmpRunways.empty() && !tmpGates.empty()) {
(*airports)[*currentIcao] = {tmpGates, tmpRunways};
validCount += 1;
*logfile << "\t<STATUS> " << *currentIcao << " committed" << std::endl;
}
*logfile << "<STATUS> " << apCount << " airports found, of which "
<< validCount << " are valid" << std::endl;
}
void makeGate15(std::vector<Gate> *gates, std::vector<std::string> fields)
{
std::string gateName;
for (size_t j = 4; j < fields.size() - 1; j++) {
gateName += fields[j] + " ";
}
gateName += fields.back();
gateName = std::regex_replace(gateName, std::regex{","}, "0");
gates->push_back(Gate{gateName, std::stod(fields[1]), std::stod(fields[2])});
}
void makeRunway(std::vector<Runway> *runways, std::vector<std::string> fields)
{
runways->push_back(Runway{fields[8],
std::stod(fields[9]),
std::stod(fields[10]),
std::stod(fields[18]),
std::stod(fields[19]),
std::stod(fields[1])});
runways->push_back(Runway{fields[17],
std::stod(fields[18]),
std::stod(fields[19]),
std::stod(fields[9]),
std::stod(fields[10]),
std::stod(fields[1])});
}
void makeGate1300(std::vector<Gate> *gates, std::vector<std::string> fields)
{
std::string gateName;
for (size_t j = 6; j < fields.size() - 1; j++) {
gateName += fields[j] + " ";
}
gateName += fields.back();
gateName = std::regex_replace(gateName, std::regex{","}, "0");
gates->push_back(Gate{gateName, std::stod(fields[1]), std::stod(fields[2])});
}
+4
View File
@@ -1,6 +1,8 @@
#include <cstdio>
#include <windows.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
BOOL APIENTRY DllMain(HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
@@ -15,3 +17,5 @@ BOOL APIENTRY DllMain(HANDLE hModule,
}
return TRUE;
}
#pragma clang diagnostic pop