Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Feb 1, 2024
1 parent 138d7f9 commit 79b1d88
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
42 changes: 21 additions & 21 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,10 @@ void MainWindow::saveSettings() const

void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, const bool checkConfiguration)
{
QSharedPointer<Settings> checkSettingsPtr = getCppcheckSettings();
if (!checkSettingsPtr)
QPair<bool,Settings> checkSettingsPair = getCppcheckSettings();
if (!checkSettingsPair.first)
return;
Settings& checkSettings = *checkSettingsPtr;
Settings& checkSettings = checkSettingsPair.second;

clearResults();

Expand Down Expand Up @@ -557,10 +557,10 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrar
if (files.isEmpty())
return;

QSharedPointer<Settings> checkSettingsPtr = getCppcheckSettings();
if (!checkSettingsPtr)
QPair<bool, Settings> checkSettingsPair = getCppcheckSettings();
if (!checkSettingsPair.first)
return;
Settings& checkSettings = *checkSettingsPtr;
Settings& checkSettings = checkSettingsPair.second;

clearResults();

Expand Down Expand Up @@ -622,10 +622,10 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrar

void MainWindow::analyzeCode(const QString& code, const QString& filename)
{
const QSharedPointer<Settings> checkSettingsPtr = getCppcheckSettings();
if (!checkSettingsPtr)
const QPair<bool, Settings>& checkSettingsPair = getCppcheckSettings();
if (!checkSettingsPair.first)
return;
const Settings& checkSettings = *checkSettingsPtr;
const Settings& checkSettings = checkSettingsPair.second;

// Initialize dummy ThreadResult as ErrorLogger
ThreadResult result;
Expand Down Expand Up @@ -955,7 +955,7 @@ QString MainWindow::loadAddon(Settings &settings, const QString &filesDir, const
return "";
}

QSharedPointer<Settings> MainWindow::getCppcheckSettings()
QPair<bool,Settings> MainWindow::getCppcheckSettings()
{
saveSettings(); // Save settings

Expand All @@ -967,7 +967,7 @@ QSharedPointer<Settings> MainWindow::getCppcheckSettings()
const bool std = tryLoadLibrary(&result.library, "std.cfg");
if (!std) {
QMessageBox::critical(this, tr("Error"), tr("Failed to load %1. Your Cppcheck installation is broken. You can use --data-dir=<directory> at the command line to specify where this file is located. Please note that --data-dir is supposed to be used by installation scripts and therefore the GUI does not start when it is used, all that happens is that the setting is configured.\n\nAnalysis is aborted.").arg("std.cfg"));
return nullptr;
return {false, {}};
}

const QString filesDir(getDataDir());
Expand All @@ -977,7 +977,7 @@ QSharedPointer<Settings> MainWindow::getCppcheckSettings()
const QString cfgErr = QString::fromStdString(result.loadCppcheckCfg());
if (!cfgErr.isEmpty()) {
QMessageBox::critical(this, tr("Error"), tr("Failed to load %1 - %2\n\nAnalysis is aborted.").arg("cppcheck.cfg").arg(cfgErr));
return nullptr;
return {false, {}};
}

const auto cfgAddons = result.addons;
Expand All @@ -987,7 +987,7 @@ QSharedPointer<Settings> MainWindow::getCppcheckSettings()
const QString addonError = loadAddon(result, filesDir, pythonCmd, QString::fromStdString(addon));
if (!addonError.isEmpty()) {
QMessageBox::critical(this, tr("Error"), tr("%1\n\nAnalysis is aborted.").arg(addonError));
return nullptr;
return {false, {}};
}
}
}
Expand Down Expand Up @@ -1072,7 +1072,7 @@ QSharedPointer<Settings> MainWindow::getCppcheckSettings()
const QString addonError = loadAddon(result, filesDir, pythonCmd, addon);
if (!addonError.isEmpty()) {
QMessageBox::critical(this, tr("Error"), tr("%1\n\nAnalysis is aborted.").arg(addonError));
return nullptr;
return {false, {}};
}
}

Expand Down Expand Up @@ -1127,7 +1127,7 @@ QSharedPointer<Settings> MainWindow::getCppcheckSettings()

Settings::terminate(false);

return QSharedPointer<Settings>(new Settings(result));
return {true, std::move(result)};
}

void MainWindow::analysisDone()
Expand Down Expand Up @@ -1251,10 +1251,10 @@ void MainWindow::reAnalyzeSelected(const QStringList& files)
if (mThread->isChecking())
return;

const QSharedPointer<Settings> checkSettingsPtr = getCppcheckSettings();
if (!checkSettingsPtr)
const QPair<bool, Settings> checkSettingsPair = getCppcheckSettings();
if (!checkSettingsPair.first)
return;
const Settings& checkSettings = *checkSettingsPtr;
const Settings& checkSettings = checkSettingsPair.second;

// Clear details, statistics and progress
mUI->mResults->clear(false);
Expand Down Expand Up @@ -1286,10 +1286,10 @@ void MainWindow::reAnalyze(bool all)
if (files.empty())
return;

const QSharedPointer<Settings> checkSettingsPtr = getCppcheckSettings();
if (!checkSettingsPtr)
const QPair<bool, Settings>& checkSettingsPair = getCppcheckSettings();
if (!checkSettingsPair.first)
return;
const Settings& checkSettings = *checkSettingsPtr;
const Settings& checkSettings = checkSettingsPair.second;

// Clear details, statistics and progress
mUI->mResults->clear(all);
Expand Down
2 changes: 1 addition & 1 deletion gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ private slots:
*
* @return Default cppcheck settings
*/
QSharedPointer<Settings> getCppcheckSettings();
QPair<bool, Settings> getCppcheckSettings();

/** @brief Load program settings */
void loadSettings();
Expand Down
10 changes: 9 additions & 1 deletion lib/addoninfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ static std::string parseAddonInfo(AddonInfo& addoninfo, const picojson::value &j
const auto& val = it->second;
if (!val.is<std::string>())
return "Loading " + fileName + " failed. 'executable' must be a string.";
addoninfo.executable = getFullPath(val.get<std::string>(), fileName);
const std::string e = val.get<std::string>();
addoninfo.executable = getFullPath(e, fileName);
if (addoninfo.executable.empty())
addoninfo.executable = e;
return ""; // <- do not load both "executable" and "script".
}
}
Expand Down Expand Up @@ -157,6 +160,11 @@ std::string AddonInfo::getAddonInfo(const std::string &fileName, const std::stri
std::ifstream fin(fileName);
if (!fin.is_open())
return "Failed to open " + fileName;
if (name.empty()) {
name = Path::fromNativeSeparators(fileName);
if (name.find("/") != std::string::npos)
name = name.substr(name.rfind("/") + 1);
}
picojson::value json;
fin >> json;
return parseAddonInfo(*this, json, fileName, exename);
Expand Down

0 comments on commit 79b1d88

Please sign in to comment.