From 3cae726f7980ca45d8451f1750db4833c9aa4c12 Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Date: Tue, 19 May 2009 16:51:33 +0200
Subject: [PATCH] Improved CDB autodetection.

Check for x32 as well; pop up a message box on failure.
---
 src/plugins/debugger/cdb/cdboptions.cpp     |  8 ++++++--
 src/plugins/debugger/cdb/cdboptions.h       |  2 +-
 src/plugins/debugger/cdb/cdboptionspage.cpp | 14 ++++++++++++--
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/plugins/debugger/cdb/cdboptions.cpp b/src/plugins/debugger/cdb/cdboptions.cpp
index 999c49ea4cd..cb2ffd758ce 100644
--- a/src/plugins/debugger/cdb/cdboptions.cpp
+++ b/src/plugins/debugger/cdb/cdboptions.cpp
@@ -81,11 +81,11 @@ void CdbOptions::toSettings(QSettings *s) const
     s->endGroup();
 }
 
-bool CdbOptions::autoDetectPath(QString *outPath)
+bool CdbOptions::autoDetectPath(QString *outPath, QStringList *checkedDirectories /* = 0 */)
 {
     // Look for $ProgramFiles/"Debugging Tools For Windows" and its
     // :" (x86)", " (x64)" variations
-    static const char *postFixes[] = { " (x86)", " (x64)" };
+    static const char *postFixes[] = { " (x86)", " (x32)", " (x64)" };
 
     outPath->clear();
     const QByteArray programDirB = qgetenv("ProgramFiles");
@@ -95,6 +95,8 @@ bool CdbOptions::autoDetectPath(QString *outPath)
     const QString programDir = QString::fromLocal8Bit(programDirB) + QDir::separator();
     const QString installDir = QLatin1String("Debugging Tools For Windows");
     QString path = programDir + installDir;
+    if (checkedDirectories)
+        checkedDirectories->push_back(path);
     if (QFileInfo(path).isDir()) {
         *outPath = QDir::toNativeSeparators(path);
         return true;
@@ -103,6 +105,8 @@ bool CdbOptions::autoDetectPath(QString *outPath)
     for (int i = 0; i < sizeof(postFixes)/sizeof(const char*); i++) {
         path.truncate(rootLength);
         path += QLatin1String(postFixes[i]);
+        if (checkedDirectories)
+            checkedDirectories->push_back(path);
         if (QFileInfo(path).isDir()) {
             *outPath = QDir::toNativeSeparators(path);
             return true;
diff --git a/src/plugins/debugger/cdb/cdboptions.h b/src/plugins/debugger/cdb/cdboptions.h
index f783de66965..6e5994bb9b9 100644
--- a/src/plugins/debugger/cdb/cdboptions.h
+++ b/src/plugins/debugger/cdb/cdboptions.h
@@ -53,7 +53,7 @@ public:
     unsigned compare(const CdbOptions &s) const;
 
     // Locate the debugging tools
-    static bool autoDetectPath(QString *path);
+    static bool autoDetectPath(QString *path, QStringList *checkedDirectories = 0);
 
     bool enabled;
     QString path;
diff --git a/src/plugins/debugger/cdb/cdboptionspage.cpp b/src/plugins/debugger/cdb/cdboptionspage.cpp
index 878d3f846ed..e20214aaafa 100644
--- a/src/plugins/debugger/cdb/cdboptionspage.cpp
+++ b/src/plugins/debugger/cdb/cdboptionspage.cpp
@@ -32,7 +32,9 @@
 #include "debuggerconstants.h"
 
 #include <coreplugin/icore.h>
+
 #include <QtCore/QCoreApplication>
+#include <QtGui/QMessageBox>
 
 const char * const CDB_SETTINGS_ID = QT_TRANSLATE_NOOP("Debugger::Internal::CdbOptionsPageWidget", "Cdb");
 
@@ -70,10 +72,18 @@ CdbOptions CdbOptionsPageWidget::options() const
 void CdbOptionsPageWidget::autoDetect()
 {
     QString path;
-    const bool ok = CdbOptions::autoDetectPath(&path);
+    QStringList checkedDirectories;
+    const bool ok = CdbOptions::autoDetectPath(&path, &checkedDirectories);
     m_ui.cdbOptionsGroupBox->setChecked(ok);
-    if (ok)
+    if (ok) {
         m_ui.pathChooser->setPath(path);
+    } else {
+        const QString msg = tr("\"Debugging Tools for Windows\" could not be found.");
+        const QString details = tr("Checked:\n%1").arg(checkedDirectories.join(QString(QLatin1Char('\n'))));
+        QMessageBox msbBox(QMessageBox::Information, tr("Autodetection"), msg, QMessageBox::Ok, this);
+        msbBox.setDetailedText(details);
+        msbBox.exec();
+    }
 }
 
 void CdbOptionsPageWidget::setFailureMessage(const QString &msg)
-- 
GitLab