From 569ae471f6a519b1b9e41daff2c86534dd831693 Mon Sep 17 00:00:00 2001 From: Adrian Del Grosso <10929341+ad3154@users.noreply.github.com> Date: Wed, 24 Apr 2024 17:41:18 -0500 Subject: [PATCH] Moved ISO Data to a location where it's more likely that we'll have write access Moved ISO data to the user's app data directory, since that is often easier to get write permissions for. Fixed compilation issue in ASCIILogFile when using updated AgIsoStack. --- include/ASCIILogFile.hpp | 4 ++-- src/ServerMainComponent.cpp | 41 +++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/include/ASCIILogFile.hpp b/include/ASCIILogFile.hpp index aea76d1..8f0eda1 100644 --- a/include/ASCIILogFile.hpp +++ b/include/ASCIILogFile.hpp @@ -23,8 +23,8 @@ class ASCIILogFile private: File logFile; - std::shared_ptr canFrameReceivedListener; - std::shared_ptr canFrameSentListener; + isobus::EventCallbackHandle canFrameReceivedListener; + isobus::EventCallbackHandle canFrameSentListener; Time initialTimestamp; }; diff --git a/src/ServerMainComponent.cpp b/src/ServerMainComponent.cpp index 49d468a..f238d00 100644 --- a/src/ServerMainComponent.cpp +++ b/src/ServerMainComponent.cpp @@ -180,7 +180,7 @@ std::vector> ServerMainComponent::get_versions(isobu std::ostringstream nameString; std::vector> retVal; nameString << std::hex << std::setfill('0') << std::setw(16) << clientNAME.get_full_name(); - File isoDirectory(std::filesystem::current_path().string() + File::getSeparatorString() + ISO_DATA_PATH + File::getSeparatorString() + nameString.str()); + File isoDirectory(File::getSpecialLocation(File::userApplicationDataDirectory).getFullPathName().toStdString() + File::getSeparatorString() + ISO_DATA_PATH + File::getSeparatorString() + nameString.str()); if (isoDirectory.exists() && isoDirectory.isDirectory()) { @@ -232,13 +232,14 @@ std::vector ServerMainComponent::load_version(const std::vector loadedIOPData; std::vector loadedVersionLabel(7); + auto path = (File::getSpecialLocation(File::userApplicationDataDirectory).getFullPathName().toStdString() + ISO_DATA_PATH + File::getSeparatorString()).toStdString(); nameString << std::hex << std::setfill('0') << std::setw(16) << clientNAME.get_full_name(); - if ((std::filesystem::is_directory(ISO_DATA_PATH + "/" + nameString.str()) || - std::filesystem::exists(ISO_DATA_PATH + "/" + nameString.str())) && + if ((std::filesystem::is_directory(path + nameString.str()) || + std::filesystem::exists(path + nameString.str())) && (7 == versionLabel.size())) { - for (const auto &entry : std::filesystem::directory_iterator(ISO_DATA_PATH + "/" + nameString.str())) + for (const auto &entry : std::filesystem::directory_iterator(path + nameString.str())) { if (entry.path().has_extension() && entry.path().extension() == ".iopx") { @@ -277,24 +278,26 @@ std::vector ServerMainComponent::load_version(const std::vector &objectPool, const std::vector &versionLabel, isobus::NAME clientNAME) { bool retVal = false; + auto userAppData = File::getSpecialLocation(File::userApplicationDataDirectory); + std::string path = (userAppData.getFullPathName() + File::getSeparatorString() + String(ISO_DATA_PATH)).toStdString(); // Main saved data folder - if (!std::filesystem::is_directory(ISO_DATA_PATH) || !std::filesystem::exists(ISO_DATA_PATH)) - { // Check if src folder exists - std::filesystem::create_directory(ISO_DATA_PATH); // create src folder + if (!std::filesystem::is_directory(path) || !std::filesystem::exists(path)) + { + std::filesystem::create_directory(path); } // NAME specific folder std::ostringstream nameString; nameString << std::hex << std::setfill('0') << std::setw(16) << clientNAME.get_full_name(); - if (!std::filesystem::is_directory(ISO_DATA_PATH + "/" + nameString.str()) || !std::filesystem::exists(ISO_DATA_PATH + "/" + nameString.str())) + if (!std::filesystem::is_directory(path + "/" + nameString.str()) || !std::filesystem::exists(path + "/" + nameString.str())) { // Check if src folder exists - std::filesystem::create_directory(ISO_DATA_PATH + "/" + nameString.str()); // create src folder + std::filesystem::create_directory(path + "/" + nameString.str()); // create src folder } - std::ofstream iopxFile(ISO_DATA_PATH + "/" + nameString.str() + "/object_pool_with_label_" + std::to_string(number_of_iop_files_in_directory(ISO_DATA_PATH + "/" + nameString.str())) + ".iopx", std::ios::trunc | std::ios::binary); - std::ofstream iopFile(ISO_DATA_PATH + "/" + nameString.str() + "/object_pool_" + std::to_string(number_of_iop_files_in_directory(ISO_DATA_PATH + "/" + nameString.str())) + ".iop", std::ios::trunc | std::ios::binary); + std::ofstream iopxFile(path + "/" + nameString.str() + "/object_pool_with_label_" + std::to_string(number_of_iop_files_in_directory(path + "/" + nameString.str())) + ".iopx", std::ios::trunc | std::ios::binary); + std::ofstream iopFile(path + "/" + nameString.str() + "/object_pool_" + std::to_string(number_of_iop_files_in_directory(path + "/" + nameString.str())) + ".iop", std::ios::trunc | std::ios::binary); if (iopxFile.is_open()) { @@ -317,13 +320,14 @@ bool ServerMainComponent::delete_version(const std::vector &versio std::ostringstream nameString; std::vector loadedVersionLabel(7); std::vector filesToRemove; + auto path = (File::getSpecialLocation(File::userApplicationDataDirectory).getFullPathName().toStdString() + ISO_DATA_PATH + File::getSeparatorString()).toStdString(); nameString << std::hex << std::setfill('0') << std::setw(16) << clientNAME.get_full_name(); - if ((std::filesystem::is_directory(ISO_DATA_PATH + "/" + nameString.str()) || - std::filesystem::exists(ISO_DATA_PATH + "/" + nameString.str())) && + if ((std::filesystem::is_directory(path + nameString.str()) || + std::filesystem::exists(path + nameString.str())) && (7 == versionLabel.size())) { - for (const auto &entry : std::filesystem::directory_iterator(ISO_DATA_PATH + "/" + nameString.str())) + for (const auto &entry : std::filesystem::directory_iterator(path + nameString.str())) { if (entry.path().has_extension() && entry.path().extension() == ".iopx") { @@ -371,12 +375,13 @@ bool ServerMainComponent::delete_all_versions(isobus::NAME clientNAME) std::ostringstream nameString; std::vector loadedVersionLabel(7); std::vector filesToRemove; + auto path = (File::getSpecialLocation(File::userApplicationDataDirectory).getFullPathName().toStdString() + ISO_DATA_PATH + File::getSeparatorString()).toStdString(); nameString << std::hex << std::setfill('0') << std::setw(16) << clientNAME.get_full_name(); - if ((std::filesystem::is_directory(ISO_DATA_PATH + "/" + nameString.str()) || - std::filesystem::exists(ISO_DATA_PATH + "/" + nameString.str()))) + if ((std::filesystem::is_directory(path + nameString.str()) || + std::filesystem::exists(path + nameString.str()))) { - for (const auto &entry : std::filesystem::directory_iterator(ISO_DATA_PATH + "/" + nameString.str())) + for (const auto &entry : std::filesystem::directory_iterator(path + nameString.str())) { if (entry.path().has_extension() && entry.path().extension() == ".iopx") { @@ -1488,7 +1493,7 @@ void ServerMainComponent::remove_working_set(std::shared_ptr