From b11f7c260ab584d473395aac3b8410d08f809db8 Mon Sep 17 00:00:00 2001 From: Mike Kremer Date: Wed, 22 Jul 2009 10:22:02 +0000 Subject: [PATCH] Fixed issue with filenames that are passed as command line parameters. Relative and absolute paths are now treated correctly. Changed internal file name storage data type from "const char *" to "std::string" since I experienced strange errors with the former version. Everything seems to work now! git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@6624 383ad7c9-94d9-4d36-a494-682f7c89f535 --- Core/Core.hh | 4 ++-- Core/openFunctions.cc | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Core/Core.hh b/Core/Core.hh index 6222683d..096d3a3d 100644 --- a/Core/Core.hh +++ b/Core/Core.hh @@ -424,8 +424,8 @@ private: void slotExecuteAfterStartup(); private: - std::vector< std::pair < const char* , bool > > commandLineFileNames_; - std::vector< const char* > commandLineScriptNames_; + std::vector< std::pair < std::string , bool > > commandLineFileNames_; + std::vector< std::string > commandLineScriptNames_; public: diff --git a/Core/openFunctions.cc b/Core/openFunctions.cc index c0f66fcd..142d9988 100644 --- a/Core/openFunctions.cc +++ b/Core/openFunctions.cc @@ -78,7 +78,17 @@ void Core::slotGetAllFilters ( QStringList& _list){ } void Core::commandLineOpen(const char* _filename, bool asPolyMesh ){ - commandLineFileNames_.push_back(std::pair< const char* , bool >(_filename,asPolyMesh)); + + QString file(_filename); + + if ( !file.startsWith("/") && !file.contains(":") ) { + + file = QDir::currentPath(); + file += OpenFlipper::Options::dirSeparator(); + file += _filename; + } + + commandLineFileNames_.push_back(std::pair< std::string , bool >(file.toStdString(), asPolyMesh)); } void Core::commandLineScript(const char* _filename ) { @@ -109,22 +119,23 @@ void Core::slotExecuteAfterStartup() { for ( uint i = 0 ; i < commandLineFileNames_.size() ; ++i ) { // Skip scripts here as they will be handled by a different function - QString tmp(commandLineFileNames_[i].first); + QString tmp = QString::fromStdString(commandLineFileNames_[i].first); if ( tmp.endsWith("ofs") ) { commandLineScriptNames_.push_back(commandLineFileNames_[i].first); continue; } if (commandLineFileNames_[i].second) - loadObject(DATA_POLY_MESH, commandLineFileNames_[i].first); - else - loadObject(commandLineFileNames_[i].first); + loadObject(DATA_POLY_MESH, QString::fromStdString(commandLineFileNames_[i].first)); + else { + loadObject(QString::fromStdString(commandLineFileNames_[i].first)); + } } if ( scriptingSupport ) for ( uint i = 0 ; i < commandLineScriptNames_.size() ; ++i ) { // Add the full path to the script to set scripting dir right - QString tmp(commandLineScriptNames_[i]); + QString tmp = QString::fromStdString(commandLineScriptNames_[i]); tmp = QDir::currentPath() + QDir::separator() + tmp; emit executeFileScript(tmp); } @@ -135,6 +146,7 @@ void Core::slotExecuteAfterStartup() { /// Load object by guessing DataType depending on the files extension int Core::loadObject ( QString _filename ) { + if (_filename.endsWith(".ini")) { // Load all information from the given ini file -- GitLab