logic: enviroment variable handling

* expanding env vars for existsens check
* expand source paths in filemanager
This commit is contained in:
Andreas Stallinger
2016-04-14 13:39:48 +02:00
parent 9534ccb454
commit a2cba0b94f
9 changed files with 78 additions and 19 deletions
+1
View File
@@ -242,6 +242,7 @@ void ProjectSettings::makePathsAbsolute(std::vector<FilePath>& 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();
+8 -2
View File
@@ -26,8 +26,14 @@ void FileManager::setPaths(
std::vector<std::string> sourceExtensions,
std::vector<std::string> 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;
}
+28 -1
View File
@@ -1,5 +1,8 @@
#include "utility/file/FilePath.h"
#include <regex>
#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;
}
+2
View File
@@ -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;
@@ -76,13 +76,13 @@ void QtListItemWidget::handleButtonPress()
QListView *l = dialog.findChild<QListView*>("listView");
if (l)
{
l->setSelectionMode(QAbstractItemView::SingleSelection);
}
QTreeView *t = dialog.findChild<QTreeView*>();
{
l->setSelectionMode(QAbstractItemView::SingleSelection);
}
QTreeView *t = dialog.findChild<QTreeView*>();
if (t)
{
t->setSelectionMode(QAbstractItemView::SingleSelection);
t->setSelectionMode(QAbstractItemView::SingleSelection);
}
if (dialog.exec())
-1
View File
@@ -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");
@@ -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;
}