diff --git a/gui/gui.pro b/gui/gui.pro index 78d3feeab..44f850a96 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -145,9 +145,3 @@ win32 { HEADERS += ../lib/version.h LIBS += -lshlwapi } - - -# CFGDIR=xyz -contains(CFGDIR, .+) { - DEFINES += CFGDIR=\\\"$${CFGDIR}\\\" -} diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index b926b8c4a..41753a393 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -512,31 +512,6 @@ void MainWindow::AddIncludeDirs(const QStringList &includeDirs, Settings &result } } -bool MainWindow::LoadLibrary(Library *library, QString filename) -{ - // Try to load the library from the project folder.. - if (mProject) { - QString path = QFileInfo(mProject->GetProjectFile()->GetFilename()).canonicalPath(); - if (library->load(NULL, (path+"/"+filename).toLatin1())) - return true; - } - - if (Library::cfgdir() && library->load(NULL, (Library::cfgdir()+('/'+filename)).toLatin1())) - return true; - - // Try to load the library from the application folder.. - QString path = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath(); - if (library->load(NULL, (path+"/"+filename).toLatin1())) - return true; - - // Try to load the library from the cfg subfolder.. - path = path + "/cfg"; - if (library->load(NULL, (path+"/"+filename).toLatin1())) - return true; - - return false; -} - Settings MainWindow::GetCppcheckSettings() { Settings result; @@ -558,8 +533,23 @@ Settings MainWindow::GetCppcheckSettings() QStringList libraries = pfile->GetLibraries(); foreach(QString library, libraries) { const QString filename = library + ".cfg"; - if (!LoadLibrary(&result.library, filename)) - QMessageBox::information(this, tr("Information"), tr("Failed to load the selected library %1").arg(filename)); + + // Try to load the library from the project folder.. + QString path = QFileInfo(pfile->GetFilename()).canonicalPath(); + if (result.library.load("", (path+"/"+filename).toLatin1())) + continue; + + // Try to load the library from the application folder.. + path = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath(); + if (result.library.load("", (path+"/"+filename).toLatin1())) + continue; + + // Try to load the library from the cfg subfolder.. + path = path + "/cfg"; + if (result.library.load("", (path+"/"+filename).toLatin1())) + continue; + + QMessageBox::information(this, tr("Information"), tr("Failed to load the selected library %1").arg(filename)); } QStringList suppressions = pfile->GetSuppressions(); @@ -601,10 +591,11 @@ Settings MainWindow::GetCppcheckSettings() result.standards.c = mSettings->value(SETTINGS_STD_C99, true).toBool() ? Standards::C99 : (mSettings->value(SETTINGS_STD_C11, false).toBool() ? Standards::C11 : Standards::C89); result.standards.posix = mSettings->value(SETTINGS_STD_POSIX, false).toBool(); - bool std = LoadLibrary(&result.library, "std.cfg"); + const QString applicationFilePath = QCoreApplication::applicationFilePath(); + bool std = result.library.load(applicationFilePath.toLatin1(), "std.cfg"); bool posix = true; if (result.standards.posix) - posix = LoadLibrary(&result.library, "posix.cfg"); + posix = result.library.load(applicationFilePath.toLatin1(), "posix.cfg"); if (!std || !posix) QMessageBox::warning(this, tr("Error"), tr("Failed to load %1. Your Cppcheck installation is broken.").arg(!std ? "std.cfg" : "posix.cfg")); diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 3ecfca49a..d6bf7ac69 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -424,14 +424,6 @@ private: */ void LoadProjectFile(const QString &filePath); - /** - * @brief Load library file - * @param Library library to use - * @param filename filename (no path) - * @return True if successful - */ - bool LoadLibrary(Library *library, QString filename); - /** * @brief Update project MRU items in File-menu. */ diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp index 73467a215..e7981a017 100644 --- a/gui/projectfiledialog.cpp +++ b/gui/projectfiledialog.cpp @@ -46,33 +46,23 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent) // Checkboxes for the libraries.. const QString applicationFilePath = QCoreApplication::applicationFilePath(); const QString appPath = QFileInfo(applicationFilePath).canonicalPath(); - QStringList searchPaths; - if (Library::cfgdir()) - searchPaths << Library::cfgdir(); - searchPaths << inf.canonicalPath(); - searchPaths << appPath; - searchPaths << (appPath + "/cfg"); - QStringList libraries; - foreach(const QString path, searchPaths) { - QDir dir(path); + const QString searchPaths[] = { appPath, appPath + "/cfg", inf.canonicalPath() }; + for (int i = 0; i < 3; i++) { + QDir dir(searchPaths[i]); dir.setSorting(QDir::Name); dir.setNameFilters(QStringList("*.cfg")); dir.setFilter(QDir::Files | QDir::NoDotAndDotDot); foreach(QFileInfo item, dir.entryInfoList()) { - libraries << item.fileName(); + QString library = item.fileName(); + library.chop(4); + if (library.compare("std", Qt::CaseInsensitive) == 0) + continue; + QCheckBox *checkbox = new QCheckBox(this); + checkbox->setText(library); + mUI.librariesLayout->addWidget(checkbox); + mLibraryCheckboxes << checkbox; } } - libraries.removeDuplicates(); - libraries.sort(); - foreach(QString library, libraries) { - library.chop(4); - if (library.compare("std", Qt::CaseInsensitive) == 0) - continue; - QCheckBox *checkbox = new QCheckBox(this); - checkbox->setText(library); - mUI.librariesLayout->addWidget(checkbox); - mLibraryCheckboxes << checkbox; - } connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(accept())); connect(mUI.mBtnAddInclude, SIGNAL(clicked()), this, SLOT(AddIncludeDir())); diff --git a/lib/library.h b/lib/library.h index 88454b60c..36ce11978 100644 --- a/lib/library.h +++ b/lib/library.h @@ -44,15 +44,6 @@ class CPPCHECKLIB Library { public: Library(); - /** return cfgdir or NULL */ - static const char *cfgdir() { -#ifdef CFGDIR - return CFGDIR; -#else - return NULL; -#endif - } - bool load(const char exename [], const char path []); bool load(const tinyxml2::XMLDocument &doc);