Skip to content

Commit

Permalink
Fixes for Windows version
Browse files Browse the repository at this point in the history
  • Loading branch information
artemis-beta committed Jan 22, 2022
1 parent c12698b commit 84ab5fc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 28 deletions.
32 changes: 19 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
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 )

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 )

Expand All @@ -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 )
Expand All @@ -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
Expand Down
28 changes: 19 additions & 9 deletions src/ros_packager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -74,14 +82,16 @@ QString ROSPkg::Packager::buildTOML() {
stream_ << "country_code = \"" << country_code_ << "\"" << Qt::endl;
}

file_.close();

return toml_file_;
}

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_;
Expand All @@ -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_+
Expand Down
17 changes: 11 additions & 6 deletions src/ros_system.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -273,7 +278,7 @@ void ROSPkg::System::unpackZip_(const QMap<QString, QList<QString>>& 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";
Expand Down Expand Up @@ -307,7 +312,7 @@ void ROSPkg::System::unpackZip_(const QMap<QString, QList<QString>>& 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"] ) {
Expand All @@ -322,7 +327,7 @@ void ROSPkg::System::unpackZip_(const QMap<QString, QList<QString>>& 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<QString, QList<QString>> files_list_ = getZipFileListing_(temp_dir_.path());

Expand Down Expand Up @@ -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<QString> gh_path_ = repository_path.split("/");

QString zip_file_name_ = "download";
Expand Down

0 comments on commit 84ab5fc

Please sign in to comment.