From 55a4231cae8cb9beb6d858b44d0d5eca1e255507 Mon Sep 17 00:00:00 2001 From: Kirollos Date: Thu, 11 Apr 2024 02:40:45 +0200 Subject: [PATCH] ESE file parser to extract [POSITIONS] --- DiscordEuroscope/ESEHandler.cpp | 68 +++++++++++++++++++++++++++++++++ DiscordEuroscope/ESEHandler.h | 40 +++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 DiscordEuroscope/ESEHandler.cpp create mode 100644 DiscordEuroscope/ESEHandler.h diff --git a/DiscordEuroscope/ESEHandler.cpp b/DiscordEuroscope/ESEHandler.cpp new file mode 100644 index 0000000..751ae1d --- /dev/null +++ b/DiscordEuroscope/ESEHandler.cpp @@ -0,0 +1,68 @@ +#include "stdafx.h" +#include "ESEHandler.h" +#include +#include + +std::vector ESEHandler::path_to_ese; +std::vector ESEHandler::positions; + +bool ESEHandler::LocateESEFile(std::string relative_path_to_ese) +{ + path_to_ese.clear(); + for (auto& file : std::filesystem::directory_iterator(relative_path_to_ese)) + { + if (file.is_regular_file() && stricmp(file.path().filename().extension().string().c_str(), ".ese") == 0) + { + path_to_ese.push_back(file.path().string()); + } + } + return path_to_ese.size() > 0; +} + +int ESEHandler::ParsePositions(void) +{ + if (path_to_ese.size() > 0) + { + for (auto& file : path_to_ese) + { + bool start_pos = false; + std::ifstream fs(file); + std::string line; + while (std::getline(fs, line)) + { + if (line == "[POSITIONS]") + { + start_pos = true; + continue; + } + if (!start_pos) continue; + + if (!(line[0] >= 'A' && line[0] <= 'Z')) + { + if (line[0] == '[') break; + continue; + } + + ESEPositionItem pos; + int idx1 = line.find_first_of(':'); + pos.callsign = line.substr(0, idx1); + int idx2 = line.find_first_of(':', idx1 + 1); + pos.radio_callsign = line.substr(idx1 + 1, idx2 - idx1 - 1); + idx1 = line.find_first_of(':', idx2 + 1); + pos.frequency = line.substr(idx2 + 1, idx1 - idx2 - 1); + positions.push_back(pos); + } + fs.close(); + } + } + return positions.size(); +} + +void ESEHandler::GetRadioCallsigns(std::map& rcs) +{ + rcs.clear(); + for (auto& pos : positions) + { + rcs.insert(std::pair(pos.callsign, pos.radio_callsign)); + } +} diff --git a/DiscordEuroscope/ESEHandler.h b/DiscordEuroscope/ESEHandler.h new file mode 100644 index 0000000..7dfbdbd --- /dev/null +++ b/DiscordEuroscope/ESEHandler.h @@ -0,0 +1,40 @@ +/* + Copyright(C) 2023-2024 Kirollos Nashaat + + This program is free software : you can redistribute it and /or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program.If not, see < https://www.gnu.org/licenses/>. +*/ + +#pragma once +#include +#include +#include + + +struct ESEPositionItem +{ + std::string callsign; + std::string radio_callsign; + std::string frequency; +}; + +class ESEHandler +{ +private: + static std::vector path_to_ese; + static std::vector positions; +public: + static bool LocateESEFile(std::string relative_path_to_ese); + static int ParsePositions(void); + static void GetRadioCallsigns(std::map& rcs); +};