diff --git a/CMakeLists.txt b/CMakeLists.txt index ced8aa1..3c6ddd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,10 @@ cmake_minimum_required( VERSION 3.20 ) -project( ROSPkgManager VERSION 0.5.0 LANGUAGES CXX ) +project( ROSPkgManager VERSION 0.5.1 LANGUAGES CXX ) set( CMAKE_CXX_STANDARD 17 ) set( CMAKE_CXX_STANDARD_REQUIRED ON ) -set( LIBRARY_NAME rospkg ) +set( ROSPKGMANAGER_LIBRARY rospkg ) find_package( QT NAMES Qt6 Qt5 ) find_package( Qt${QT_VERSION_MAJOR} COMPONENTS Widgets LinguistTools Core Gui REQUIRED ) @@ -12,6 +12,8 @@ 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 ) +option( BUILD_ROSPKGMANAGER_TESTS "Build the available ROSPkgManager tests" OFF ) + file( GLOB SRC_FILES ${CMAKE_SOURCE_DIR}/src/*.cxx ) file( GLOB TS_FILES ${CMAKE_SOURCE_DIR}/lang/*.ts ) @@ -22,8 +24,8 @@ set( DIGESTPP digestpp ) set( 11ZIP elzip ) set( ROSTOOLS rostools ) -add_library( ${LIBRARY_NAME} STATIC ${SRC_FILES} ${HEADERS} ) -set_target_properties( ${LIBRARY_NAME} PROPERTIES AUTOMOC ON ) +add_library( ${ROSPKGMANAGER_LIBRARY} STATIC ${SRC_FILES} ${HEADERS} ) +set_target_properties( ${ROSPKGMANAGER_LIBRARY} PROPERTIES AUTOMOC ON ) add_subdirectory( ${CMAKE_SOURCE_DIR}/external/11Zip ) find_package( CURL ) @@ -48,20 +50,24 @@ FetchContent_Declare( ) FetchContent_MakeAvailable( ${DIGESTPP} ) -target_link_libraries( ${LIBRARY_NAME} PUBLIC ${11ZIP} ) -target_link_libraries( ${LIBRARY_NAME} PUBLIC ${CURL_LIBRARIES} ) -target_link_libraries( ${LIBRARY_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui ) -target_link_libraries( ${LIBRARY_NAME} PUBLIC ${ROSTOOLS} ) -target_include_directories( ${LIBRARY_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include ) -target_include_directories( ${LIBRARY_NAME} PUBLIC ${CURL_INCLUDE_DIR} ) -target_include_directories( ${LIBRARY_NAME} PUBLIC ${tomlplusplus_SOURCE_DIR} ) -target_include_directories( ${LIBRARY_NAME} PUBLIC ${digestpp_SOURCE_DIR} ) +target_link_libraries( ${ROSPKGMANAGER_LIBRARY} PUBLIC ${11ZIP} ) +target_link_libraries( ${ROSPKGMANAGER_LIBRARY} PUBLIC ${CURL_LIBRARIES} ) +target_link_libraries( ${ROSPKGMANAGER_LIBRARY} PUBLIC Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui ) +target_link_libraries( ${ROSPKGMANAGER_LIBRARY} PUBLIC ${ROSTOOLS} ) +target_include_directories( ${ROSPKGMANAGER_LIBRARY} PRIVATE ${CMAKE_SOURCE_DIR}/include ) +target_include_directories( ${ROSPKGMANAGER_LIBRARY} PUBLIC ${CURL_INCLUDE_DIR} ) +target_include_directories( ${ROSPKGMANAGER_LIBRARY} PUBLIC ${tomlplusplus_SOURCE_DIR} ) +target_include_directories( ${ROSPKGMANAGER_LIBRARY} PUBLIC ${digestpp_SOURCE_DIR} ) add_executable( ${PROJECT_NAME} ${MAIN_SRC} ) set_target_properties( ${PROJECT_NAME} PROPERTIES AUTOMOC ON ) -target_link_libraries( ${PROJECT_NAME} PRIVATE ${LIBRARY_NAME} ) +target_link_libraries( ${PROJECT_NAME} PRIVATE ${ROSPKGMANAGER_LIBRARY} ) target_include_directories( ${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include ) +if( BUILD_ROSPKGMANAGER_TESTS ) + add_subdirectory( ${CMAKE_CURRENT_SOURCE_DIR}/tests ) +endif() + set_target_properties( ${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE diff --git a/src/ros_packager.cxx b/src/ros_packager.cxx index cfa567b..0489624 100644 --- a/src/ros_packager.cxx +++ b/src/ros_packager.cxx @@ -7,7 +7,14 @@ void ROSPkg::Packager::packageFailure() { QString ROSPkg::Packager::buildTOML() { QString file_name_ = QString(package_name_); file_name_.replace(" ", "_"); - toml_file_ = ros_loc_ + QDir::separator() + "Metadata" + QDir::separator() + file_name_ + ".toml"; + + QString metadata_dir_ = ros_loc_ + QDir::separator() + "Metadata"; + + if(!QDir(metadata_dir_).exists()) { + QDir().mkpath(metadata_dir_); + } + + toml_file_ = metadata_dir_ + QDir::separator() + file_name_ + ".toml"; if(version_.isEmpty()) { const QDate now_ = QDate::currentDate(); @@ -20,6 +27,7 @@ QString ROSPkg::Packager::buildTOML() { // Builds a TOML file manually using strings QFile file_(toml_file_); + qDebug() << toml_file_ << Qt::endl; if(file_.open(QIODevice::WriteOnly)) { QTextStream stream_(&file_); stream_ << "name = \"" << package_name_ << "\"" << Qt::endl; @@ -74,6 +82,8 @@ QString ROSPkg::Packager::buildTOML() { stream_ << "country_code = \"" << country_code_ << "\"" << Qt::endl; } + file_.close(); + return toml_file_; } @@ -81,7 +91,7 @@ QString ROSPkg::Packager::createPackage() { buildTOML(); const QString build_dir_ = ros_loc_ + QDir::separator() + "Packages"; if(!QDir(build_dir_).exists()) { - QDir().mkdir(build_dir_); + QDir().mkpath(build_dir_); } QString package_file_name_ = package_name_; QString package_name_version_ = version_; @@ -91,13 +101,13 @@ QString ROSPkg::Packager::createPackage() { 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"); + QDir().mkpath(out_dir_); + QDir().mkpath(out_dir_+ QDir::separator() + "Railway"); + QDir().mkpath(out_dir_+ QDir::separator() + "Program_Timetables"); + QDir().mkpath(out_dir_+ QDir::separator() + "Sessions"); + QDir().mkpath(out_dir_+ QDir::separator() + "Documentation"); + QDir().mkpath(out_dir_+ QDir::separator() + "Images"); + QDir().mkpath(out_dir_+ QDir::separator() + "Metadata"); QFile(rly_file_).copy( out_dir_+ diff --git a/src/ros_system.cxx b/src/ros_system.cxx index f36e33d..57ef1d7 100644 --- a/src/ros_system.cxx +++ b/src/ros_system.cxx @@ -7,13 +7,18 @@ size_t ROSPkg::download_write_file_(void *ptr, size_t size, size_t nmemb, FILE * void ROSPkg::System::createCache_() { const QString cache_dir_ = QFileInfo(cache_file_).absolutePath(); if(!QDir(cache_dir_).exists()) { - QDir().mkdir(cache_dir_); + QDir().mkpath(cache_dir_); } - ros_loc_ = QFileDialog::getOpenFileName( + const QString ros_exe_ = QFileDialog::getOpenFileName( parent_, QFileDialog::tr("Locate") + QString(" Railway Operation Simulator"), QString(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)), QFileDialog::tr("ROS Exe (railway.exe)") ); + + const QDir ros_dir_ = QFileInfo(ros_exe_).dir(); + + ros_loc_ = QFileInfo(ros_dir_.path()).absolutePath(); + if(ros_loc_.isEmpty() || ros_loc_.isNull()) return; QFile file_(cache_file_); if(file_.open(QIODevice::WriteOnly)) { @@ -273,7 +278,7 @@ void ROSPkg::System::unpackZip_(const QMap>& files_list) // If the Documentation directory does not yet exist create it if(!QDir(ros_loc_ + QDir::separator() + "Documentation").exists()) { - QDir().mkdir(ros_loc_ + QDir::separator() + "Documentation"); + QDir().mkpath(ros_loc_ + QDir::separator() + "Documentation"); } QString doc_dir_ = ros_loc_ + QDir::separator() + "Documentation"; @@ -307,7 +312,7 @@ void ROSPkg::System::unpackZip_(const QMap>& files_list) if(!files_list["docs"].empty()) { // Create directory for add-on docs doc_dir_ += QDir::separator() + QString::fromStdString(package_data_.display_name()).replace(" ", "_"); - QDir().mkdir(doc_dir_); + QDir().mkpath(doc_dir_); } for(const QString& doc_file : files_list["docs"] ) { @@ -322,7 +327,7 @@ void ROSPkg::System::unpackZip_(const QMap>& files_list) void ROSPkg::System::unzipFile(const QString& file_name, const QString& author, const QString& pkg_name, const QString& country_code) const { QTemporaryDir temp_dir_; - QDir().mkdir(temp_dir_.path()); + QDir().mkpath(temp_dir_.path()); elz::extractZip(file_name.toStdString(), temp_dir_.path().toStdString()); QMap> files_list_ = getZipFileListing_(temp_dir_.path()); @@ -466,7 +471,7 @@ void ROSPkg::System::uninstall(const QString& sha) { void ROSPkg::System::fetchGitHub(const QString& repository_path, const QString& branch) const { const QString GitHub_URL_ = "https://github.com/" + repository_path + "/archive/refs/heads/" + branch + ".zip"; QTemporaryDir temp_dir_; - QDir().mkdir(temp_dir_.path()); + QDir().mkpath(temp_dir_.path()); const QList gh_path_ = repository_path.split("/"); QString zip_file_name_ = "download";