From 4fb918ea7de6e835f8017fb5189c0bb8e1d57a79 Mon Sep 17 00:00:00 2001 From: Kristian Zarebski Date: Wed, 5 Jan 2022 17:52:53 +0000 Subject: [PATCH 1/9] Try 11Zip --- .gitmodules | 6 +++--- CMakeLists.txt | 21 +++------------------ external/11Zip | 1 + external/AbZip | 1 - include/ros_packager.hxx | 2 +- include/ros_system.hxx | 2 +- src/ros_packager.cxx | 6 +----- src/ros_system.cxx | 17 +++++++---------- 8 files changed, 17 insertions(+), 39 deletions(-) create mode 160000 external/11Zip delete mode 160000 external/AbZip diff --git a/.gitmodules b/.gitmodules index cc36669..a0e4aac 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "external/AbZip"] - path = external/AbZip - url = https://github.com/artemis-beta/AbZip.git +[submodule "external/11Zip"] + path = external/11Zip + url = https://github.com/artemis-beta/11Zip.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f34b3a..b78d94f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,21 +14,6 @@ find_package( Qt${QT_VERSION_MAJOR} COMPONENTS Widgets LinguistTools Core Gui RE set( MAIN_SRC ${CMAKE_SOURCE_DIR}/application.cxx ) set( EXTERNAL_SOURCES ${CMAKE_SOURCE_DIR}/external ) -# ------------------------- AbZip ---------------------------- # -file( GLOB_RECURSE ABZIP_SRCS ${EXTERNAL_SOURCES}/AbZip/*.cpp ) -file( GLOB_RECURSE ABZIP_HEADERS ${EXTERNAL_SOURCES}/AbZip/*.h ) -find_package( ZLIB REQUIRED ) -set( ABZIP abzip ) -set( ABZIP_INCLUDE_DIR ${EXTERNAL_SOURCES}/AbZip ) -add_library( ${ABZIP} ${ABZIP_SRCS} ${ABZIP_HEADERS} ) -target_include_directories( ${ABZIP} PRIVATE ${ABZIP_INCLUDE_DIR} ) -target_include_directories( ${ABZIP} PRIVATE ${ABZIP_INCLUDE_DIR}/Compressors ) -target_include_directories( ${ABZIP} PRIVATE ${ABZIP_INCLUDE_DIR}/Encryption ) -target_link_libraries( ${ABZIP} PRIVATE ${ZLIB_LIBRARIES} ) -target_link_libraries( ${ABZIP} PUBLIC Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui ) - -# ------------------------------------------------------------ # - file( GLOB SRC_FILES ${CMAKE_SOURCE_DIR}/src/*.cxx ) file( GLOB TS_FILES ${CMAKE_SOURCE_DIR}/lang/*.ts ) @@ -36,11 +21,12 @@ file( GLOB TS_FILES ${CMAKE_SOURCE_DIR}/lang/*.ts ) file( GLOB HEADERS ${CMAKE_SOURCE_DIR}/include/*.hxx ) set( DIGESTPP digestpp ) - +set( 11ZIP elzip ) set( ROSTOOLS rostools ) find_package( ${ROSTOOLS} 0.4.0 REQUIRED ) add_library( ${LIBRARY_NAME} STATIC ${SRC_FILES} ${HEADERS} ) +add_subdirectory( ${CMAKE_SOURCE_DIR}/external/11Zip ) include(FetchContent) FetchContent_Declare( @@ -50,10 +36,9 @@ FetchContent_Declare( ) FetchContent_MakeAvailable( ${DIGESTPP} ) -target_link_libraries( ${LIBRARY_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui ${ABZIP} ${ROSTOOLS_LIBRARIES} ) +target_link_libraries( ${LIBRARY_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui ${ROSTOOLS_LIBRARIES} ${11ZIP} ) target_include_directories( ${LIBRARY_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include ) target_include_directories( ${LIBRARY_NAME} PUBLIC ${tomlplusplus_SOURCE_DIR} ) -target_include_directories( ${LIBRARY_NAME} PUBLIC ${EXTERNAL_SOURCES} ) target_link_libraries( ${LIBRARY_NAME} PUBLIC ${ROSTOOLS} ) target_include_directories( ${LIBRARY_NAME} PUBLIC ${digestpp_SOURCE_DIR} ) diff --git a/external/11Zip b/external/11Zip new file mode 160000 index 0000000..5b9e014 --- /dev/null +++ b/external/11Zip @@ -0,0 +1 @@ +Subproject commit 5b9e014dc04e4a3e8b992d0af10dac95c2c10698 diff --git a/external/AbZip b/external/AbZip deleted file mode 160000 index 0d2eed2..0000000 --- a/external/AbZip +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0d2eed2e4261e604e74e12da917a3829dda79032 diff --git a/include/ros_packager.hxx b/include/ros_packager.hxx index 8d2d799..b30e59d 100644 --- a/include/ros_packager.hxx +++ b/include/ros_packager.hxx @@ -12,7 +12,7 @@ #include #include -#include "AbZip/AbZip.h" +#include "elzip.hpp" namespace ROSPkg { class Packager { diff --git a/include/ros_system.hxx b/include/ros_system.hxx index c7d73a7..bd1eef3 100644 --- a/include/ros_system.hxx +++ b/include/ros_system.hxx @@ -22,7 +22,7 @@ #include "rostools/metadata.hxx" #include "digestpp.hpp" -#include "AbZip/AbZip.h" +#include "elzip.hpp" #include "ros_packager.hxx" diff --git a/src/ros_packager.cxx b/src/ros_packager.cxx index f0aa067..4d8c207 100644 --- a/src/ros_packager.cxx +++ b/src/ros_packager.cxx @@ -110,11 +110,7 @@ QString ROSPkg::Packager::createPackage() { ); } - AbZip zip(build_dir_ + QDir::separator() + package_file_name_+".zip"); - - zip.addDirectory(build_dir_ + QDir::separator() + package_file_name_, AbZip::Recursive); - - zip.close(); + elz::zipFolder((build_dir_ + QDir::separator() + package_file_name_).toStdString()); QDir(build_dir_ + QDir::separator() + package_file_name_).removeRecursively(); diff --git a/src/ros_system.cxx b/src/ros_system.cxx index 1c2a954..25781e7 100644 --- a/src/ros_system.cxx +++ b/src/ros_system.cxx @@ -98,11 +98,8 @@ QList> ROSPkg::System::getTableInfo() const { void ROSPkg::System::unzipFile(const QString& file_name) const { QString info_text_ = ""; - AbZip zip_(file_name); QTemporaryDir temp_dir_; - if(!zip_.extractAll(temp_dir_.path())) { - qDebug() << zip_.errorCount() << "errors occurred:" << zip_.errorString(); - } + elz::extractFile(file_name.toStdString(), temp_dir_.path().toStdString()); // File path filters QList filter_ssn_{"*.ssn", "*.SSN"}; @@ -152,7 +149,7 @@ void ROSPkg::System::unzipFile(const QString& file_name) const { QMessageBox::tr("Package definition ambiguous"), QMessageBox::tr("Expected single RLY file from archive.") ); - zip_.close(); + return; } if(files_ttb_.empty()) { @@ -161,7 +158,7 @@ void ROSPkg::System::unzipFile(const QString& file_name) const { QMessageBox::tr("Missing timetables"), QMessageBox::tr("Expected one or more TTB files within archive.") ); - zip_.close(); + return; } for(const QString& ttb_file : files_ttb_) packager_.addTTBFile(ttb_file); @@ -179,7 +176,7 @@ void ROSPkg::System::unzipFile(const QString& file_name) const { QMessageBox::tr("TOML creation failure"), QMessageBox::tr("TOML creation for non-project archive failed.") ); - zip_.close(); + return; } files_toml_.push_back(new_toml_); @@ -190,7 +187,7 @@ void ROSPkg::System::unzipFile(const QString& file_name) const { QMessageBox::tr("Package Definition Ambiguous"), QMessageBox::tr("Expected single metadata (TOML) file in package, but multiple candidates found.") ); - zip_.close(); + return; } @@ -236,7 +233,7 @@ void ROSPkg::System::unzipFile(const QString& file_name) const { QMessageBox::tr("Missing Package Metadata"), QMessageBox::tr("Cannot install selected package, missing package metadata.") ); - zip_.close(); + return; } if(!files_docs_.empty()) { @@ -252,7 +249,7 @@ void ROSPkg::System::unzipFile(const QString& file_name) const { info_text_ += "\n\nAdded " + new_path_; QFile(doc_file).copy(new_path_); } - zip_.close(); + QMessageBox::information(parent_, QMessageBox::tr("Add-on installed successfully"), QMessageBox::tr(info_text_.toStdString().c_str())); } From 09ee45066df3e912a826535813a65cc1c2fa36db Mon Sep 17 00:00:00 2001 From: Kristian Zarebski Date: Wed, 5 Jan 2022 18:09:53 +0000 Subject: [PATCH 2/9] Use Qt6 in build and update windows building --- .github/workflows/build_packager.yaml | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build_packager.yaml b/.github/workflows/build_packager.yaml index aa4ca88..f36773d 100644 --- a/.github/workflows/build_packager.yaml +++ b/.github/workflows/build_packager.yaml @@ -33,8 +33,8 @@ jobs: working-directory: rostools/cpp - name: Install Qt uses: jurplel/install-qt-action@v2 - with: - version: '5.15.2' + with: + version: '6.2.2' setup-python: false - name: Build ROSPackageManager env: @@ -62,28 +62,21 @@ jobs: path: rostools - name: Install ZLIB run: powershell -Command "(Invoke-WebRequest -Uri https://git.io/JnHTY -OutFile install_zlib.bat)"; ./install_zlib.bat; del install_zlib.bat - - name: Set up Cygwin - uses: egor-tensin/setup-cygwin@v3 + - name: Install Qt + uses: jurplel/install-qt-action@v2 with: - platform: x64 - packages: cmake gcc-g++ - - name: Set up MinGW - uses: egor-tensin/setup-mingw@v2 + version: '6.2.2' + setup-python: false + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@v1.9 with: - platform: x64 - cygwin: 1 - cc: 1 + cmake-version: '3.20.x' - name: Install ROSTools run: | mkdir install cmake -Bbuild cmake --build build/ --target install working-directory: rostools/cpp - - name: Install Qt - uses: jurplel/install-qt-action@v2 - with: - version: '5.15.2' - setup-python: false - name: Build ROSPackageManager run: | cmake -Bbuild From b5c74c5919f9abf3b8ccf674146f6234624fe703 Mon Sep 17 00:00:00 2001 From: Kristian Zarebski Date: Wed, 5 Jan 2022 18:13:08 +0000 Subject: [PATCH 3/9] Add macOS CI --- .github/workflows/build_packager.yaml | 48 ++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_packager.yaml b/.github/workflows/build_packager.yaml index f36773d..a22ab21 100644 --- a/.github/workflows/build_packager.yaml +++ b/.github/workflows/build_packager.yaml @@ -46,7 +46,53 @@ jobs: working-directory: rospkgmanager - uses: actions/upload-artifact@v1 with: - name: unix_rospkg + name: ubuntu_rospkg + path: rospkgmanager/build/ROSPkgManager + build-test-macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + path: rospkgmanager + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@v1.9 + with: + cmake-version: '3.20.x' + - uses: actions/checkout@v2 + with: + repository: Railway-Op-Sim/rostools + ref: v0.4.0 + path: rostools + - name: Set up GCC + uses: egor-tensin/setup-gcc@v1 + with: + version: 11 + platform: x64 + - name: Install ROSTools + env: + CC: gcc-11 + CXX: g++-11 + run: | + cmake -Bbuild + sudo cmake --build build/ --target install + working-directory: rostools/cpp + - name: Install Qt + uses: jurplel/install-qt-action@v2 + with: + version: '6.2.2' + setup-python: false + - name: Build ROSPackageManager + env: + CC: gcc-11 + CXX: g++-11 + run: | + cmake -Bbuild + cmake --build build + working-directory: rospkgmanager + - uses: actions/upload-artifact@v1 + with: + name: darwin_rospkg path: rospkgmanager/build/ROSPkgManager build-test-windows: runs-on: windows-latest From 92a341b88858044412463160c6ae90db186f7311 Mon Sep 17 00:00:00 2001 From: Kristian Zarebski Date: Wed, 5 Jan 2022 18:17:45 +0000 Subject: [PATCH 4/9] Remove ambiguity of QStandardPaths to string --- src/ros_pkgmanager.cxx | 2 +- src/ros_system.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ros_pkgmanager.cxx b/src/ros_pkgmanager.cxx index 6955493..23c6ea1 100644 --- a/src/ros_pkgmanager.cxx +++ b/src/ros_pkgmanager.cxx @@ -302,7 +302,7 @@ void ROSPkg::Manager::on_InstallButtonClicked() { const QString zip_file_ = QFileDialog::getOpenFileName( this, QFileDialog::tr("Open Zip Archive"), - QString(QStandardPaths::HomeLocation), QFileDialog::tr("Add-ons (*.zip)") + QString(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)), QFileDialog::tr("Add-ons (*.zip)") ); if(zip_file_.isEmpty() || zip_file_.isNull()) return; system_->unzipFile(zip_file_); diff --git a/src/ros_system.cxx b/src/ros_system.cxx index 25781e7..a8e8af1 100644 --- a/src/ros_system.cxx +++ b/src/ros_system.cxx @@ -8,7 +8,7 @@ void ROSPkg::System::createCache_() { ros_loc_ = QFileDialog::getOpenFileName( parent_, QFileDialog::tr("Locate") + QString(" Railway Operation Simulator"), - QString(QStandardPaths::HomeLocation), QFileDialog::tr("ROS Exe (railway.exe)") + QString(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)), QFileDialog::tr("ROS Exe (railway.exe)") ); if(ros_loc_.isEmpty() || ros_loc_.isNull()) return; QFile file_(cache_file_); From 51268ca29d0f35c48c62e62be3ca69f80fe1a2b5 Mon Sep 17 00:00:00 2001 From: Kristian Zarebski Date: Wed, 5 Jan 2022 18:19:21 +0000 Subject: [PATCH 5/9] Fix no GCC action for mac --- .github/workflows/build_packager.yaml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/workflows/build_packager.yaml b/.github/workflows/build_packager.yaml index a22ab21..2dc722b 100644 --- a/.github/workflows/build_packager.yaml +++ b/.github/workflows/build_packager.yaml @@ -64,15 +64,7 @@ jobs: repository: Railway-Op-Sim/rostools ref: v0.4.0 path: rostools - - name: Set up GCC - uses: egor-tensin/setup-gcc@v1 - with: - version: 11 - platform: x64 - name: Install ROSTools - env: - CC: gcc-11 - CXX: g++-11 run: | cmake -Bbuild sudo cmake --build build/ --target install @@ -83,9 +75,6 @@ jobs: version: '6.2.2' setup-python: false - name: Build ROSPackageManager - env: - CC: gcc-11 - CXX: g++-11 run: | cmake -Bbuild cmake --build build From 2d1785ad62c3c4b2e247e8f55990e795c3b4f118 Mon Sep 17 00:00:00 2001 From: Kristian Zarebski Date: Wed, 5 Jan 2022 18:26:11 +0000 Subject: [PATCH 6/9] Ensure release build and use .app for mac artifact --- .github/workflows/build_packager.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_packager.yaml b/.github/workflows/build_packager.yaml index 2dc722b..6157db1 100644 --- a/.github/workflows/build_packager.yaml +++ b/.github/workflows/build_packager.yaml @@ -28,7 +28,7 @@ jobs: CC: gcc-11 CXX: g++-11 run: | - cmake -Bbuild + cmake -Bbuild -DCMAKE_BUILD_TYPE=Release sudo cmake --build build/ --target install working-directory: rostools/cpp - name: Install Qt @@ -76,13 +76,13 @@ jobs: setup-python: false - name: Build ROSPackageManager run: | - cmake -Bbuild + cmake -Bbuild -DCMAKE_BUILD_TYPE=Release cmake --build build working-directory: rospkgmanager - uses: actions/upload-artifact@v1 with: name: darwin_rospkg - path: rospkgmanager/build/ROSPkgManager + path: rospkgmanager/build/ROSPkgManager.app build-test-windows: runs-on: windows-latest steps: @@ -109,7 +109,7 @@ jobs: - name: Install ROSTools run: | mkdir install - cmake -Bbuild + cmake -Bbuild -DCMAKE_BUILD_TYPE=Release cmake --build build/ --target install working-directory: rostools/cpp - name: Build ROSPackageManager From 9df38e364ba4766c923800fd75d3d364fd41e7e4 Mon Sep 17 00:00:00 2001 From: Kristian Zarebski Date: Wed, 5 Jan 2022 18:44:17 +0000 Subject: [PATCH 7/9] Fixed wrong archive function --- src/ros_packager.cxx | 39 ++++++++++++++++++++++++--------------- src/ros_system.cxx | 3 ++- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/ros_packager.cxx b/src/ros_packager.cxx index 4d8c207..6d98a4c 100644 --- a/src/ros_packager.cxx +++ b/src/ros_packager.cxx @@ -71,48 +71,57 @@ QString ROSPkg::Packager::createPackage() { package_file_name_ += version_; package_file_name_.replace(" ", "_"); - QDir().mkdir(build_dir_ + QDir::separator() + package_file_name_); - QDir().mkdir(build_dir_ + QDir::separator() + package_file_name_ + QDir::separator() + "Railway"); - QDir().mkdir(build_dir_ + QDir::separator() + package_file_name_ + QDir::separator() + "Program_Timetables"); - QDir().mkdir(build_dir_ + QDir::separator() + package_file_name_ + QDir::separator() + "Sessions"); - QDir().mkdir(build_dir_ + QDir::separator() + package_file_name_ + QDir::separator() + "Documentation"); - QDir().mkdir(build_dir_ + QDir::separator() + package_file_name_ + QDir::separator() + "Images"); - QDir().mkdir(build_dir_ + QDir::separator() + package_file_name_ + QDir::separator() + "Metadata"); + const QString out_dir_ = build_dir_ + QDir::separator() + package_file_name_; + + QDir().mkdir(out_dir_); + QDir().mkdir(out_dir_+ QDir::separator() + "Railway"); + QDir().mkdir(out_dir_+ QDir::separator() + "Program_Timetables"); + QDir().mkdir(out_dir_+ QDir::separator() + "Sessions"); + QDir().mkdir(out_dir_+ QDir::separator() + "Documentation"); + QDir().mkdir(out_dir_+ QDir::separator() + "Images"); + QDir().mkdir(out_dir_+ QDir::separator() + "Metadata"); QFile(rly_file_).copy( - build_dir_ + QDir::separator() + package_file_name_ + + out_dir_+ QDir::separator() + "Railway" + QDir::separator() + QFileInfo(rly_file_).fileName() ); QFile(toml_file_).copy( - build_dir_ + QDir::separator() + package_file_name_ + + out_dir_+ QDir::separator() + "Metadata" + QDir::separator() + QFileInfo(toml_file_).fileName() ); for(const QString& ttb_file : ttb_files_) { QFile(ttb_file).copy( - build_dir_ + QDir::separator() + package_file_name_ + + out_dir_+ QDir::separator() + "Program_Timetables" + QDir::separator() + QFileInfo(ttb_file).fileName() ); } for(const QString& ssn_file : ssn_files_) { QFile(ssn_file).copy( - build_dir_ + QDir::separator() + package_file_name_ + + out_dir_+ QDir::separator() + "Sessions" + QDir::separator() + QFileInfo(ssn_file).fileName() ); } for(const QString& doc_file : doc_files_) { QFile(doc_file).copy( - build_dir_ + QDir::separator() + package_file_name_ + + out_dir_+ QDir::separator() + "Documentation" + QDir::separator() + QFileInfo(doc_file).fileName() ); } - elz::zipFolder((build_dir_ + QDir::separator() + package_file_name_).toStdString()); + const QString zip_file_ = out_dir_ + ".zip"; + + elz::zipFolder(out_dir_.toStdString(), zip_file_.toStdString()); + + if(!QFile::exists(zip_file_)) { + QMessageBox::critical(parent_, QMessageBox::tr("Archive creation failure"), QMessageBox::tr("Failed to create package archive")); + throw std::runtime_error(""); + } - QDir(build_dir_ + QDir::separator() + package_file_name_).removeRecursively(); + QDir(out_dir_).removeRecursively(); - return build_dir_ + QDir::separator() + package_file_name_+".zip"; + return zip_file_; } diff --git a/src/ros_system.cxx b/src/ros_system.cxx index a8e8af1..f49f7ab 100644 --- a/src/ros_system.cxx +++ b/src/ros_system.cxx @@ -99,7 +99,8 @@ QList> ROSPkg::System::getTableInfo() const { void ROSPkg::System::unzipFile(const QString& file_name) const { QString info_text_ = ""; QTemporaryDir temp_dir_; - elz::extractFile(file_name.toStdString(), temp_dir_.path().toStdString()); + QDir().mkdir(temp_dir_.path()); + elz::extractZip(file_name.toStdString(), temp_dir_.path().toStdString()); // File path filters QList filter_ssn_{"*.ssn", "*.SSN"}; From 08b5979b866a3e2f67ded620932b974598f3ed01 Mon Sep 17 00:00:00 2001 From: Kristian Zarebski Date: Wed, 5 Jan 2022 19:33:06 +0000 Subject: [PATCH 8/9] Started docstrings --- include/ros_packager.hxx | 198 ++++++++++++++++++++++++++++++------- include/ros_pkgmanager.hxx | 178 ++++++++++++++++++++++++--------- include/ros_system.hxx | 105 +++++++++++++++----- 3 files changed, 371 insertions(+), 110 deletions(-) diff --git a/include/ros_packager.hxx b/include/ros_packager.hxx index b30e59d..1e63d47 100644 --- a/include/ros_packager.hxx +++ b/include/ros_packager.hxx @@ -1,3 +1,23 @@ +/*! ************************************************************************** + * @file ros_packager.hxx + * @author K. Zarebski + * @date 2022-01-05 + * @brief File containing method related to ROS package creation + * + * This file contains the Packager class used for handling and creating + * packages for Railway Operation Simulator. A package is defined as a single + * route simulation consisting of: + * + * - A single railway definition (.rly) file + * - One or more program timetable files (.ttb) + * - Optionally, session files (.ssn) + * - Documentation files (.pdf, .md) + * - A metadata definition file (.toml) + * + * A metadata file following the standard is created and used as a package + * definition file. + * + ****************************************************************************/ #ifndef __ROSPACKAGER_HXX__ #define __ROSPACKAGER_HXX__ @@ -6,6 +26,7 @@ #include #include #include + #include #include #include @@ -15,43 +36,146 @@ #include "elzip.hpp" namespace ROSPkg { - class Packager { - private: - QWidget* parent_ = nullptr; - const QDir output_dir_{QStandardPaths::writableLocation(QStandardPaths::CacheLocation)}; - const QString package_name_ = ""; - const QString ros_loc_ = ""; - QString display_name_ = ""; - QString author_ = "Unknown"; - QList contributors_ = {}; - QString version_ = ""; - QString description_ = ""; - int year_ = -1; - QString factual_ = "false"; - QString country_code_ = "UN"; - QString rly_file_ = ""; - QList ssn_files_; - QList doc_files_; - QList ttb_files_; - QString toml_file_ = ""; - public: - Packager(QWidget* parent, const QString& ros_loc, const QString& package_name) : - parent_(parent), ros_loc_(ros_loc), package_name_(package_name) {} - void setRLYFile(const QString& rly_path) {rly_file_ = rly_path;} - void addTTBFile(const QString& ttb_path) {ttb_files_.push_back(ttb_path);} - void addSSNFile(const QString& ssn_path) {ssn_files_.push_back(ssn_path);} - void addDocFile(const QString& doc_path) {doc_files_.push_back(doc_path);} - void addContributor(const QString& contributor) {contributors_.push_back(contributor);} - void setAuthor(const QString& author) {author_ = author;} - void setDescription(const QString& description) {description_ = description;} - void setFactual(bool is_true) {factual_ = (is_true) ? "true" : "false";} - void setYear(int year) {year_ = year;} - void setVersion(const QString& version) {version_ = version;} - void setCountryCode(const QString& country_code) {country_code_ = country_code;} - void setDisplayName(const QString& display_name) {display_name_ = display_name;} - QString buildTOML(); - void packageFailure(); - QString createPackage(); +/*! ********************************************************************** + * @class Packager + * @brief Performs assembly of files into a single package directory + * + * Files are assembled into a single directory and metadata obtained. + * A metadata TOML file is automatically generated for the given file + * set and information provided by the user. + * **********************************************************************/ +class Packager { + private: + QWidget* parent_ = nullptr; + const QDir output_dir_{QStandardPaths::writableLocation(QStandardPaths::CacheLocation)}; + const QString package_name_ = ""; + const QString ros_loc_ = ""; + QString display_name_ = ""; + QString author_ = "Unknown"; + QList contributors_ = {}; + QString version_ = ""; + QString description_ = ""; + int year_ = -1; + QString factual_ = "false"; + QString country_code_ = "UN"; + QString rly_file_ = ""; + QList ssn_files_; + QList doc_files_; + QList ttb_files_; + QString toml_file_ = ""; + public: +/*! ************************************************************************** + * @brief Initialise a new packager for a given parent widget + * + * @param parent pointer of parent widget for application + * @param ros_loc full path to directory containing railway.exe + * @param package_name name to give final package + * **************************************************************************/ + Packager(QWidget* parent, const QString& ros_loc, const QString& package_name) : + parent_(parent), ros_loc_(ros_loc), package_name_(package_name) {} + +/*! ************************************************************************* + * @brief set main railway definition (.rly) file for package + * + * @param rly_path full path to the RLY file + * *************************************************************************/ + void setRLYFile(const QString& rly_path) {rly_file_ = rly_path;} + +/*! ************************************************************************* + * @brief append a program timetable file (.ttb) to the package + * + * @param ttb_path full path to the TTB file + * *************************************************************************/ + void addTTBFile(const QString& ttb_path) {ttb_files_.push_back(ttb_path);} + +/*! ************************************************************************* + * @brief append a session file (.ssn) to the package + * + * @param ssn_path full path to the SSN file + * *************************************************************************/ + void addSSNFile(const QString& ssn_path) {ssn_files_.push_back(ssn_path);} + +/*! ************************************************************************* + * @brief append a documentation file (.pdf, .md) to the package + * + * @param doc_path full path to the documentation file + * *************************************************************************/ + void addDocFile(const QString& doc_path) {doc_files_.push_back(doc_path);} + +/*! ************************************************************************* + * @brief add a contributor to the package, this is an additional author. + * + * @param contributor name of contributor + * *************************************************************************/ + void addContributor(const QString& contributor) {contributors_.push_back(contributor);} + +/*! ************************************************************************* + * @brief set name of package author + * + * @param author name of package author + * *************************************************************************/ + void setAuthor(const QString& author) {author_ = author;} + +/*! ************************************************************************* + * @brief set package description + * + * @param description package description + * *************************************************************************/ + void setDescription(const QString& description) {description_ = description;} + +/*! ************************************************************************* + * @brief set whether package contains a factual or fictional simulation + * + * @param is_true if simulation is factual + * *************************************************************************/ + void setFactual(bool is_true) {factual_ = (is_true) ? "true" : "false";} + +/*! ************************************************************************* + * @brief set the year the simulation in the package is set + * + * @param year year of simulation (if fictional this can be any positive int) + * *************************************************************************/ + void setYear(int year) {year_ = year;} + +/*! ************************************************************************* + * @brief set semantic version for package in the form MAJOR.MINOR.PATCH + * + * @param version semantic version + * *************************************************************************/ + void setVersion(const QString& version) {version_ = version;} + +/*! ************************************************************************* + * @brief set the two letter ISO country code for the represented region + * + * @param country_code ISO code + * *************************************************************************/ + void setCountryCode(const QString& country_code) {country_code_ = country_code;} + +/*! ************************************************************************* + * @brief set package display name + * + * @param author name of package as to be displayed + * *************************************************************************/ + void setDisplayName(const QString& display_name) {display_name_ = display_name;} + +/*! ************************************************************************* + * @brief construct a TOML metadata file for the package + * + * @return full path of created TOML file + * *************************************************************************/ + QString buildTOML(); + +/*! ************************************************************************* + * @brief display package assembly failure dialog + * *************************************************************************/ + void packageFailure(); + +/*! ************************************************************************* + * @brief create the directory for the package and then an archive + * + * @return the full path of the created ZIP file + * *************************************************************************/ + QString createPackage(); }; }; diff --git a/include/ros_pkgmanager.hxx b/include/ros_pkgmanager.hxx index 69e6a58..0b99c46 100644 --- a/include/ros_pkgmanager.hxx +++ b/include/ros_pkgmanager.hxx @@ -1,3 +1,14 @@ +/*! ************************************************************************** + * @file ros_packager.hxx + * @author K. Zarebski + * @date 2022-01-05 + * @brief Main application definition file + * + * This file contains code for the construction of the main GUI application + * which forms the central interface for the install/uninstall and creation + * of padckages for Railway Operation Simulator + * + ****************************************************************************/ #ifndef __ROSPKGMANAGER_HXX__ #define __ROSPKGMANAGER_HXX__ @@ -19,54 +30,127 @@ #include "ros_system.hxx" #include "rostools/country_codes.hxx" +/*! ********************************************************************** + * @namespace ROSPkg + * @brief Contains all methods and classes relating to the ROSPkgManager + ************************************************************************/ namespace ROSPkg { - class Manager : public QWidget - { - Q_OBJECT - - private: - const int WINDOW_WIDTH = 600; - const int WINDOW_HEIGHT = 480; - const int TABLE_WIDTH = 510; - const int TABLE_HEIGHT = 330; - const int TABLE_NCOLS = 4; - const int BUTTON_WIDTH = 150; - const int BUTTON_HEIGHT = 30; - QString cache_str_ = ""; - System* system_ = new System(this); - QWidget* subwindow_ = new QWidget(this, Qt::Tool); - QSpinBox* year_box_; - QCheckBox* factual_box_; - QLabel* factual_box_label_; - QComboBox* country_code_; - QLabel* year_box_label_; - QLabel* country_code_label_; - QMap package_form_entry_; - QMap package_form_labels_; - QMap buttons_ = { - {"install", new QPushButton(QPushButton::tr("Install Package"), this)}, - {"create", new QPushButton(QPushButton::tr("Create Package"), this)}, - {"uninstall", new QPushButton(QPushButton::tr("Uninstall Package"), this)}, - }; - QLabel* info_str_ = new QLabel(this); - QTableWidget* installed_ = new QTableWidget(this); - void populateTable_(); - void buildPackageForm_(); - void clearPackageForm_(); - QMap checkPackageForm_(); - private slots: - void on_InstallButtonClicked(); - void on_UninstallButtonClicked(); - void on_CreateButtonClicked(); - void on_CreateConfirmClicked(); - void on_CreateCancelClicked(); - void on_BrowseRlyFilesClicked(); - void on_BrowseTTBFilesClicked(); - void on_BrowseSSNFilesClicked(); - void on_BrowseDocFilesClicked(); - public: - Manager(); - ~Manager(); +/*! ********************************************************************** + * @class Manager + * @brief Constructs the main GUI interface for the package manager + * + * Creates the windows and widgets with which the user interacts acting + * as the central interface for the install/uninstall and creation of + * packages. GUI is built using Qt widgets consisting of Buttons, + * Text Entry objects and windows + * **********************************************************************/ +class Manager : public QWidget +{ + Q_OBJECT + +private: + const int WINDOW_WIDTH = 600; + const int WINDOW_HEIGHT = 480; + const int TABLE_WIDTH = 510; + const int TABLE_HEIGHT = 330; + const int TABLE_NCOLS = 4; + const int BUTTON_WIDTH = 150; + const int BUTTON_HEIGHT = 30; + QString cache_str_ = ""; + System* system_ = new System(this); + QWidget* subwindow_ = new QWidget(this, Qt::Tool); + QSpinBox* year_box_; + QCheckBox* factual_box_; + QLabel* factual_box_label_; + QComboBox* country_code_; + QLabel* year_box_label_; + QLabel* country_code_label_; + QMap package_form_entry_; + QMap package_form_labels_; + QMap buttons_ = { + {"install", new QPushButton(QPushButton::tr("Install Package"), this)}, + {"create", new QPushButton(QPushButton::tr("Create Package"), this)}, + {"uninstall", new QPushButton(QPushButton::tr("Uninstall Package"), this)}, }; + QLabel* info_str_ = new QLabel(this); + QTableWidget* installed_ = new QTableWidget(this); + +/*! ************************************************************************** + * @brief Populate the table display with all installed packages + * **************************************************************************/ + void populateTable_(); + +/*! ************************************************************************** + * @brief Construct the package creation form for metadata entry + * **************************************************************************/ + void buildPackageForm_(); + +/*! ************************************************************************** + * @brief Wipe all inputs from the package creation form + * **************************************************************************/ + void clearPackageForm_(); + +/*! ************************************************************************** + * @brief Validate information provided in the package creation form + * + * @return A mapping of the recorded form information + * **************************************************************************/ + QMap checkPackageForm_(); +private slots: +/*! ************************************************************************** + * @brief Action associated with the "Install Package" button + * **************************************************************************/ + void on_InstallButtonClicked(); + +/*! ************************************************************************** + * @brief Action associated with the "Uninstall Package" button + * **************************************************************************/ + void on_UninstallButtonClicked(); + +/*! ************************************************************************** + * @brief Action associated with the "Create Package" button + * **************************************************************************/ + void on_CreateButtonClicked(); + +/*! ************************************************************************** + * @brief Action associated with the "Create Package/Confirm" button + * **************************************************************************/ + void on_CreateConfirmClicked(); + +/*! ************************************************************************** + * @brief Action associated with the "Create Package/Cancel" button + * **************************************************************************/ + void on_CreateCancelClicked(); + +/*! ************************************************************************** + * @brief Action associated with the "Create Package/RLY Browse" button + * **************************************************************************/ + void on_BrowseRlyFilesClicked(); + +/*! ************************************************************************** + * @brief Action associated with the "Create Package/TTB Browse" button + * **************************************************************************/ + void on_BrowseTTBFilesClicked(); + +/*! ************************************************************************** + * @brief Action associated with the "Create Package/SSN Browse" button + * **************************************************************************/ + void on_BrowseSSNFilesClicked(); + +/*! ************************************************************************** + * @brief Action associated with the "Create Package/Docs Browse" button + * **************************************************************************/ + void on_BrowseDocFilesClicked(); +public: +/*! ************************************************************************** + * @brief Initialise an instance of the application GUI definition + * **************************************************************************/ + Manager(); + +/*! ************************************************************************** + * @brief Destructor for application GUI definition + * **************************************************************************/ + ~Manager(); +}; }; #endif // ROSPKGMANAGER_HXX diff --git a/include/ros_system.hxx b/include/ros_system.hxx index bd1eef3..555d045 100644 --- a/include/ros_system.hxx +++ b/include/ros_system.hxx @@ -27,32 +27,85 @@ #include "ros_packager.hxx" namespace ROSPkg { - class System { - private: - QWidget* parent_ = nullptr; - QMap installed_; - QString ros_loc_ = ""; - const QString cache_file_ = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)).filePath("ros_cfg"); - void createCache_(); - void parseMetaFile_(const QString& file_name); - public: - System(QWidget* parent); - QList> getTableInfo() const; - - /*! - * @brief Extract contents from add-on archive - * - * Although all contents is extracted, only files stated in the relevant - * metadata file will be kept. - * - * @param file_name path of archive to be extracted. - * - */ - void unzipFile(const QString& file_name) const; - void populateInstalled(); - void uninstall(const QString& sha); - QString getROSLocation() const {return ros_loc_;} - }; +/*! ********************************************************************** + * @class System + * @brief Procedures relating to the files on the file system + * + * Handles the creation/removal of files on the file system including + * the building of packages and metadata files. Also determines which + * packages are installed. Packages are stored under an SHA256 hash + * calculated from the relevant metadata file. + * **********************************************************************/ +class System { +private: + QWidget* parent_ = nullptr; + QMap installed_; + QString ros_loc_ = ""; + const QString cache_file_ = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)).filePath("ros_cfg"); + +/*! ************************************************************************** +* @brief Locate the ROS installation on the local system and cache it +* +* Opens a user dialog requesting the location of railway.exe on the system +* and stores the location for future use. +* **************************************************************************/ + void createCache_(); + +/*! ************************************************************************** + * @brief Parse an existing metadata file for information on a package + * + * If a package contains a metadata TOML file this is read and information + * extracted to be displayed on the installed packages listing + * **************************************************************************/ + void parseMetaFile_(const QString& file_name); +public: +/*! ************************************************************************** + * @brief Initialise a new instance of the System class + * + * @param parent pointer to the parent widget + * **************************************************************************/ + System(QWidget* parent); + +/*! ************************************************************************** + * @brief Retrieve the listing of installed add-ons for display + * + * Converts the data of the installed packages into table objects to be + * displayed on the main application interface. + * + * @return a 2D array of information for display on the table widget + * **************************************************************************/ + QList> getTableInfo() const; + +/*! ************************************************************************** +* @brief Extract contents from add-on archive +* +* Although all contents is extracted, only files stated in the relevant +* metadata file will be kept. +* +* @param file_name path of archive to be extracted. +* ***************************************************************************/ + void unzipFile(const QString& file_name) const; + +/*! ************************************************************************** + * @brief Find the list of packages installed on the local system + * **************************************************************************/ + void populateInstalled(); + +/*! ************************************************************************** + * @brief Uninstall a package given its SHA256 ID + * + * Packages are stored under an SHA256 ID calculated from their metadata TOML + * file contents. + * + * @param sha the SHA256 hash of the package to remove + * **************************************************************************/ + void uninstall(const QString& sha); + +/*! ************************************************************************** + * @brief Retrieve the location of railway.exe on the file system + * **************************************************************************/ + QString getROSLocation() const {return ros_loc_;} +}; }; #endif \ No newline at end of file From fc5e75f0faaf10140bcaab5419d8ccf1042a84a7 Mon Sep 17 00:00:00 2001 From: Kristian Zarebski Date: Wed, 5 Jan 2022 19:35:27 +0000 Subject: [PATCH 9/9] Use config release for windows --- .github/workflows/build_packager.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_packager.yaml b/.github/workflows/build_packager.yaml index 6157db1..6a07068 100644 --- a/.github/workflows/build_packager.yaml +++ b/.github/workflows/build_packager.yaml @@ -28,7 +28,7 @@ jobs: CC: gcc-11 CXX: g++-11 run: | - cmake -Bbuild -DCMAKE_BUILD_TYPE=Release + cmake -Bbuildout_dir_ sudo cmake --build build/ --target install working-directory: rostools/cpp - name: Install Qt @@ -76,7 +76,7 @@ jobs: setup-python: false - name: Build ROSPackageManager run: | - cmake -Bbuild -DCMAKE_BUILD_TYPE=Release + cmake -Bbuildout_dir_ cmake --build build working-directory: rospkgmanager - uses: actions/upload-artifact@v1 @@ -109,13 +109,13 @@ jobs: - name: Install ROSTools run: | mkdir install - cmake -Bbuild -DCMAKE_BUILD_TYPE=Release + cmake -Bbuildout_dir_ cmake --build build/ --target install working-directory: rostools/cpp - name: Build ROSPackageManager run: | cmake -Bbuild - cmake --build build + cmake --build build --config Release working-directory: rospkgmanager - uses: actions/upload-artifact@v1 with: