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;
}
commandLineParser.projectLoad();
if (commandLineParser.hasError() )
{
std::cout << commandLineParser.getError() << std::endl;
}
else
{
commandLineParser.projectLoad();
}
return qtApp.exec();
}
else
@@ -176,7 +183,14 @@ int main(int argc, char *argv[])
Application::getInstance()->addProjectFactoryModule(std::make_shared<ProjectFactoryModuleCpp>());
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(), ".ttf");
@@ -120,6 +120,16 @@ void CommandLineParser::processLicense(const bool isLoaded)
m_withoutGUI = true;
}
bool CommandLineParser::hasError()
{
return !m_errorString.empty();
}
std::string CommandLineParser::getError()
{
return m_errorString;
}
CommandLineParser::~CommandLineParser()
{
}
@@ -142,36 +152,28 @@ bool CommandLineParser::startedWithLicense()
void CommandLineParser::processProjectfile(const std::string& file)
{
FilePath projectfile(file);
bool isValidProjectfile = true;
std::string errorstring = "Provided Projectfile is not valid:\n";
std::string errorProjectfile = "\tProvided Projectfile('" + projectfile.fileName() + ") ";
const std::string errorstring =
"Provided Projectfile is not valid:\n* Provided Projectfile('" + projectfile.fileName() + "') ";
if (!projectfile.exists())
{
errorstring += errorProjectfile + " does not exist\n";
isValidProjectfile = false;
m_errorString = errorstring + " does not exist";
return;
}
if (projectfile.extension() != ".coatiproject")
{
errorstring += errorProjectfile + " has a wrong fileending\n";
isValidProjectfile = false;
m_errorString = errorstring + " has a wrong fileending";
return;
}
std::shared_ptr<ConfigManager> configManager = ConfigManager::createEmpty();
if (!configManager->load(TextAccess::createFromFile(projectfile.str())))
{
errorstring += errorProjectfile + " could not be loaded\n";
isValidProjectfile = false;
m_errorString = errorstring + " could not be loaded(invalid)";
return;
}
if (isValidProjectfile)
{
m_projectFile = projectfile;
}
else
{
std::cout << errorstring << std::endl;
}
m_projectFile = projectfile;
}
void CommandLineParser::projectLoad()
@@ -16,6 +16,8 @@ public:
bool exitApplication();
void projectLoad();
bool startedWithLicense();
bool hasError();
std::string getError();
License getLicense();
private:
void processProjectfile(const std::string& file);
@@ -27,6 +29,7 @@ private:
bool m_withLicense;
bool m_withoutGUI;
std::string m_errorString;
License m_license;
};
-1
View File
@@ -78,7 +78,6 @@ QtStartScreen::QtStartScreen(QWidget *parent)
: QtWindow(parent)
{
this->raise();
setWindowModality(Qt::ApplicationModal);
}
QSize QtStartScreen::sizeHint() const