From a2cba0b94fc73305b461041e9121a5edec1a5dd2 Mon Sep 17 00:00:00 2001 From: Andreas Stallinger Date: Thu, 14 Apr 2016 13:39:48 +0200 Subject: [PATCH] logic: enviroment variable handling * expanding env vars for existsens check * expand source paths in filemanager --- cmake/pre_install_linux.cmake | 2 ++ script/setup.sh | 22 +++++++------- src/lib/settings/ProjectSettings.cpp | 1 + src/lib/utility/file/FileManager.cpp | 10 +++++-- src/lib/utility/file/FilePath.cpp | 29 ++++++++++++++++++- src/lib/utility/file/FilePath.h | 2 ++ src/lib_gui/qt/element/QtDirectoryListBox.cpp | 10 +++---- src/lib_gui/qt/window/QtStartScreen.cpp | 1 - .../QtProjectWizzardContentPaths.cpp | 20 +++++++++++++ 9 files changed, 78 insertions(+), 19 deletions(-) diff --git a/cmake/pre_install_linux.cmake b/cmake/pre_install_linux.cmake index 6196ca33..5d1c1217 100644 --- a/cmake/pre_install_linux.cmake +++ b/cmake/pre_install_linux.cmake @@ -3,11 +3,13 @@ set(upxPath ${CMAKE_CURRENT_LIST_DIR}/../bin/app/Release) message(STATUS "upx the app") execute_process( + COMMAND rm ${upxPath}/Coati_upx COMMAND upx --brute ${upxPath}/Coati -o ${upxPath}/Coati_upx ) message(STATUS "upx the trial") execute_process( + COMMAND rm ${upxPath}/Coati_trial_upx COMMAND upx --brute ${upxPath}/Coati_trial -o ${upxPath}/Coati_trial_upx ) diff --git a/script/setup.sh b/script/setup.sh index 74d1060c..ae4c55c5 100755 --- a/script/setup.sh +++ b/script/setup.sh @@ -15,8 +15,10 @@ elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then fi # Enter masterproject directory +SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" +ROOT_DIR=$SCRIPT_DIR/.. MY_PATH=`dirname "$0"` -cd $MY_PATH/.. +cd $ROOT_DIR # git settings echo -e $INFO "install git settings" @@ -49,17 +51,17 @@ if [ $PLATFORM == "Windows" ]; then echo -e $INFO "creating program icon" sh script/create_windows_icon.sh - cmd //c 'mklink /d /j '.$MY_PATH.'\..\bin\app\Debug\data '.$MY_PATH.'\..\bin\app\data' & - cmd //c 'mklink /d /j '.$MY_PATH.'\..\bin\app\Debug\user '.$MY_PATH.'\..\bin\app\user' & - cmd //c 'mklink /d /j '.$MY_PATH.'\..\bin\app\Release\data '.$MY_PATH.'\..\bin\app\data' & - cmd //c 'mklink /d /j '.$MY_PATH.'\..\bin\app\Release\user '.$MY_PATH.'\..\bin\app\user' & + cmd //c 'mklink /d /j '.$ROOT_DIR.'\bin\app\Debug\data '.$ROOT_DIR.'\bin\app\data' & + cmd //c 'mklink /d /j '.$ROOT_DIR.'\bin\app\Debug\user '.$ROOT_DIR.'\bin\app\user' & + cmd //c 'mklink /d /j '.$ROOT_DIR.'\bin\app\Release\data '.$ROOT_DIR.'\bin\app\data' & + cmd //c 'mklink /d /j '.$ROOT_DIR.'\bin\app\Release\user '.$ROOT_DIR.'\bin\app\user' & elif [ $PLATFORM == "Linux" ]; then echo -e $INFO "create symbolic links for data" - cd bin/app/Release - ln -s ../data data - cd ../Debug - ln -s ../data data - cd ../../.. + cd $ROOT_DIR/bin/app/Release + ln -s ../data + cd $ROOT_DIR/bin/app/Debug + ln -s ../data + cd $ROOT_DIR fi # Setup both Debug and Release configuration diff --git a/src/lib/settings/ProjectSettings.cpp b/src/lib/settings/ProjectSettings.cpp index 92029b3c..ca5c0644 100644 --- a/src/lib/settings/ProjectSettings.cpp +++ b/src/lib/settings/ProjectSettings.cpp @@ -242,6 +242,7 @@ void ProjectSettings::makePathsAbsolute(std::vector& paths) const FilePath basePath = getFilePath().parentDirectory(); for (size_t i = 0; i < paths.size(); i++) { + paths[i] = paths[i].expandEnvironmentVariables(); if (!paths[i].isAbsolute()) { paths[i] = basePath.concat(paths[i]).canonical(); diff --git a/src/lib/utility/file/FileManager.cpp b/src/lib/utility/file/FileManager.cpp index eb2f613d..562d9b17 100644 --- a/src/lib/utility/file/FileManager.cpp +++ b/src/lib/utility/file/FileManager.cpp @@ -26,8 +26,14 @@ void FileManager::setPaths( std::vector sourceExtensions, std::vector includeExtensions ){ - m_sourcePaths = sourcePaths; - m_headerPaths = headerPaths; + for ( FilePath path : sourcePaths ) + { + m_sourcePaths.push_back(path.expandEnvironmentVariables()); + } + for ( FilePath path : headerPaths ) + { + m_headerPaths.push_back(path.expandEnvironmentVariables()); + } m_sourceExtensions = sourceExtensions; m_includeExtensions = includeExtensions; } diff --git a/src/lib/utility/file/FilePath.cpp b/src/lib/utility/file/FilePath.cpp index 9e4ba345..bc6da114 100644 --- a/src/lib/utility/file/FilePath.cpp +++ b/src/lib/utility/file/FilePath.cpp @@ -1,5 +1,8 @@ #include "utility/file/FilePath.h" +#include +#include "utility/logging/logging.h" + FilePath::FilePath() : m_exists(false) { @@ -98,6 +101,29 @@ FilePath FilePath::canonical() const return result; } +FilePath FilePath::expandEnvironmentVariables() const +{ + return FilePath(expandEnvironmentVariables(str())); +} + +std::string FilePath::expandEnvironmentVariables(const std::string& path) const +{ + std::string text = path; + + static std::regex env( "\\$\\{([^}]+)\\}|%([0-9A-Za-z\\/]*)%" ); + std::smatch match; + while ( std::regex_search( text, match, env ) ) { + const char * s = getenv( match[1].str().c_str() ); + if (s == nullptr) + { + LOG_ERROR(match[1].str() + " is no a environment variable"); + return path; + } + text.replace( match[0].first, match[0].second, s); + } + return text; +} + FilePath FilePath::relativeTo(const FilePath& other) const { boost::filesystem::path a = m_path; @@ -202,7 +228,8 @@ bool FilePath::operator<(const FilePath& other) const void FilePath::init() { - if (boost::filesystem::exists(m_path)) + boost::filesystem::path p(expandEnvironmentVariables(m_path.generic_string())); + if (boost::filesystem::exists(p)) { m_exists = true; } diff --git a/src/lib/utility/file/FilePath.h b/src/lib/utility/file/FilePath.h index c44985b0..b0381a4c 100644 --- a/src/lib/utility/file/FilePath.h +++ b/src/lib/utility/file/FilePath.h @@ -26,6 +26,8 @@ public: FilePath canonical() const; FilePath relativeTo(const FilePath& other) const; FilePath concat(const FilePath& other) const; + FilePath expandEnvironmentVariables() const; + std::string expandEnvironmentVariables(const std::string & path) const; std::string str() const; std::string fileName() const; diff --git a/src/lib_gui/qt/element/QtDirectoryListBox.cpp b/src/lib_gui/qt/element/QtDirectoryListBox.cpp index 60d33aad..58b063aa 100644 --- a/src/lib_gui/qt/element/QtDirectoryListBox.cpp +++ b/src/lib_gui/qt/element/QtDirectoryListBox.cpp @@ -76,13 +76,13 @@ void QtListItemWidget::handleButtonPress() QListView *l = dialog.findChild("listView"); if (l) - { - l->setSelectionMode(QAbstractItemView::SingleSelection); - } - QTreeView *t = dialog.findChild(); + { + l->setSelectionMode(QAbstractItemView::SingleSelection); + } + QTreeView *t = dialog.findChild(); if (t) { - t->setSelectionMode(QAbstractItemView::SingleSelection); + t->setSelectionMode(QAbstractItemView::SingleSelection); } if (dialog.exec()) diff --git a/src/lib_gui/qt/window/QtStartScreen.cpp b/src/lib_gui/qt/window/QtStartScreen.cpp index 402760d7..d5a06b04 100644 --- a/src/lib_gui/qt/window/QtStartScreen.cpp +++ b/src/lib_gui/qt/window/QtStartScreen.cpp @@ -98,7 +98,6 @@ void QtStartScreen::updateButtons() button->setProjectPath(recentProjects[i]); button->setFixedWidth(button->fontMetrics().width(button->text()) + 45); connect(button, SIGNAL(clicked()), button, SLOT(handleButtonClick())); - //button->setGeometry(292, button->pos().y(), button->fontMetrics().width(button->text()) + 45, 40); if (button->projectExists()) { button->setObjectName("recentButton"); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp index f63026b6..8c066789 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp @@ -6,6 +6,7 @@ #include "qt/element/QtDirectoryListBox.h" #include "settings/ApplicationSettings.h" +#include "utility/file/FileManager.h" #include "utility/file/FileSystem.h" #include "utility/headerSearch/StandardHeaderDetection.h" #include "utility/utility.h" @@ -207,6 +208,25 @@ bool QtProjectWizzardContentPathsSource::check() msgBox.exec(); return false; } + QString missingPaths; + for(FilePath f : m_list->getList()) + { + if(!f.exists()) + { + if(!missingPaths.isEmpty()) + { + missingPaths.append("\n"); + } + missingPaths.append(f.expandEnvironmentVariables().str().c_str()); + } + if(!missingPaths.isEmpty()) + { + QMessageBox msgBox; + msgBox.setText("The following paths do not exist:\n" + missingPaths ); + msgBox.exec(); + return false; + } + } return true; }