utility: commandlineparser crash

* commandlineparser crash when no/invalid project file
* filepath instead of string in commandlineparser
This commit is contained in:
Andreas Stallinger
2016-10-19 16:40:01 +02:00
parent b11f583729
commit ea207c786d
4 changed files with 38 additions and 20 deletions
+16 -2
View File
@@ -145,7 +145,14 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
commandLineParser.projectLoad(); if (commandLineParser.hasError() )
{
std::cout << commandLineParser.getError() << std::endl;
}
else
{
commandLineParser.projectLoad();
}
return qtApp.exec(); return qtApp.exec();
} }
else else
@@ -176,7 +183,14 @@ int main(int argc, char *argv[])
Application::getInstance()->addProjectFactoryModule(std::make_shared<ProjectFactoryModuleCpp>()); Application::getInstance()->addProjectFactoryModule(std::make_shared<ProjectFactoryModuleCpp>());
Application::getInstance()->addProjectFactoryModule(std::make_shared<ProjectFactoryModuleJava>()); Application::getInstance()->addProjectFactoryModule(std::make_shared<ProjectFactoryModuleJava>());
commandLineParser.projectLoad(); if (commandLineParser.hasError())
{
Application::getInstance()->handleDialog(commandLineParser.getError());
}
else
{
commandLineParser.projectLoad();
}
utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf"); utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf");
utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".ttf"); utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".ttf");
@@ -120,6 +120,16 @@ void CommandLineParser::processLicense(const bool isLoaded)
m_withoutGUI = true; m_withoutGUI = true;
} }
bool CommandLineParser::hasError()
{
return !m_errorString.empty();
}
std::string CommandLineParser::getError()
{
return m_errorString;
}
CommandLineParser::~CommandLineParser() CommandLineParser::~CommandLineParser()
{ {
} }
@@ -142,36 +152,28 @@ bool CommandLineParser::startedWithLicense()
void CommandLineParser::processProjectfile(const std::string& file) void CommandLineParser::processProjectfile(const std::string& file)
{ {
FilePath projectfile(file); FilePath projectfile(file);
bool isValidProjectfile = true; const std::string errorstring =
std::string errorstring = "Provided Projectfile is not valid:\n"; "Provided Projectfile is not valid:\n* Provided Projectfile('" + projectfile.fileName() + "') ";
std::string errorProjectfile = "\tProvided Projectfile('" + projectfile.fileName() + ") ";
if (!projectfile.exists()) if (!projectfile.exists())
{ {
errorstring += errorProjectfile + " does not exist\n"; m_errorString = errorstring + " does not exist";
isValidProjectfile = false; return;
} }
if (projectfile.extension() != ".coatiproject") if (projectfile.extension() != ".coatiproject")
{ {
errorstring += errorProjectfile + " has a wrong fileending\n"; m_errorString = errorstring + " has a wrong fileending";
isValidProjectfile = false; return;
} }
std::shared_ptr<ConfigManager> configManager = ConfigManager::createEmpty(); std::shared_ptr<ConfigManager> configManager = ConfigManager::createEmpty();
if (!configManager->load(TextAccess::createFromFile(projectfile.str()))) if (!configManager->load(TextAccess::createFromFile(projectfile.str())))
{ {
errorstring += errorProjectfile + " could not be loaded\n"; m_errorString = errorstring + " could not be loaded(invalid)";
isValidProjectfile = false; return;
} }
if (isValidProjectfile) m_projectFile = projectfile;
{
m_projectFile = projectfile;
}
else
{
std::cout << errorstring << std::endl;
}
} }
void CommandLineParser::projectLoad() void CommandLineParser::projectLoad()
@@ -16,6 +16,8 @@ public:
bool exitApplication(); bool exitApplication();
void projectLoad(); void projectLoad();
bool startedWithLicense(); bool startedWithLicense();
bool hasError();
std::string getError();
License getLicense(); License getLicense();
private: private:
void processProjectfile(const std::string& file); void processProjectfile(const std::string& file);
@@ -27,6 +29,7 @@ private:
bool m_withLicense; bool m_withLicense;
bool m_withoutGUI; bool m_withoutGUI;
std::string m_errorString;
License m_license; License m_license;
}; };
-1
View File
@@ -78,7 +78,6 @@ QtStartScreen::QtStartScreen(QWidget *parent)
: QtWindow(parent) : QtWindow(parent)
{ {
this->raise(); this->raise();
setWindowModality(Qt::ApplicationModal);
} }
QSize QtStartScreen::sizeHint() const QSize QtStartScreen::sizeHint() const