Skip to content

Commit

Permalink
Changed ICAO Airlines file loading logic to cover GNG usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
pierr3 committed Oct 28, 2020
1 parent c85ea40 commit 2813b3f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
4 changes: 3 additions & 1 deletion vSMR/CallsignLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
// CCallsignLookup Class by Even Rognlien, used with permission
//

CCallsignLookup::CCallsignLookup(std::string fileName) {
CCallsignLookup::CCallsignLookup() {}

void CCallsignLookup::readFile(string fileName)
{

ifstream myfile;

Expand Down
3 changes: 2 additions & 1 deletion vSMR/CallsignLookup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class CCallsignLookup

public:

CCallsignLookup(string fileName);
CCallsignLookup();
void readFile(string fileName);
string getCallsign(string airlineCode);

~CCallsignLookup();
Expand Down
36 changes: 21 additions & 15 deletions vSMR/SMRRadar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,29 @@ CSMRRadar::CSMRRadar()
ConfigPath = DllPath + "\\vSMR_Profiles.json";

Logger::info("Loading callsigns");
// Loading up the callsigns for the bottom line
// Search for ICAO airlines file if it already exists (usually given by the VACC)
string AirlinesPath = DllPath;
for (int i = 0; i < 3; ++i) {
AirlinesPath = AirlinesPath.substr(0, AirlinesPath.find_last_of("/\\"));
}
AirlinesPath += "\\ICAO\\ICAO_Airlines.txt";

ifstream f(AirlinesPath.c_str());
// Creating the RIMCAS instance
if (Callsigns == nullptr)
Callsigns = new CCallsignLookup();

// We can look in three places for this file:
// 1. Within the plugin directory
// 2. In the ICAO folder of a GNG package
// 3. In the working directory of EuroScope
fs::path possible_paths[3];
possible_paths[0] = fs::path(DllPath) / fs::path("ICAO_Airlines.txt");
possible_paths[1] = fs::path(DllPath).parent_path().parent_path() / fs::path("ICAO") / fs::path("ICAO_Airlines.txt");
possible_paths[2] = fs::path(DllPath).parent_path().parent_path().parent_path() / fs::path("ICAO") / fs::path("ICAO_Airlines.txt");

for (auto p : possible_paths) {
Logger::info("Trying to read callsigns from: " + p.string());
if (fs::exists(p)) {
Logger::info("Found callsign file!");
Callsigns->readFile(p.string());

if (f.good()) {
Callsigns = new CCallsignLookup(AirlinesPath);
}
else {
Callsigns = new CCallsignLookup(DllPath + "\\ICAO_Airlines.txt");
}
f.close();
break;
}
};

Logger::info("Loading RIMCAS & Config");
// Creating the RIMCAS instance
Expand Down
6 changes: 4 additions & 2 deletions vSMR/SMRRadar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
#include <thread>
#include "ColorManager.h"
#include "Logger.h"
#include <filesystem>
#include <iostream>

using namespace std;
using namespace Gdiplus;
using namespace EuroScopePlugIn;

namespace fs = std::filesystem;

namespace SMRSharedData
{
Expand Down Expand Up @@ -79,7 +81,7 @@ class CSMRRadar :
char DllPathFile[_MAX_PATH];
string DllPath;
string ConfigPath;
CCallsignLookup * Callsigns;
CCallsignLookup * Callsigns = nullptr;
CColorManager * ColorManager;

map<string, bool> ShowLists;
Expand Down
5 changes: 4 additions & 1 deletion vSMR/vSMR.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ProjectGuid>{6DE02EC4-F0B1-4BA2-AED5-D261FEC4D758}</ProjectGuid>
<RootNamespace>vSMR</RootNamespace>
<Keyword>MFCDLLProj</Keyword>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down Expand Up @@ -67,6 +68,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down Expand Up @@ -99,6 +101,7 @@
<AdditionalIncludeDirectories>..\lib\include</AdditionalIncludeDirectories>
<TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down Expand Up @@ -187,4 +190,4 @@
<UserProperties RESOURCE_FILE="vSMR.rc" />
</VisualStudio>
</ProjectExtensions>
</Project>
</Project>

0 comments on commit 2813b3f

Please sign in to comment.