changeset 20:c1081e8d26a7

An attempt to accommodate 32-bit helper on 64-bit Windows
author Chris Cannam
date Tue, 01 Nov 2016 15:48:59 +0000
parents c80c55cabfcd
children fcaaabca1734
files checker/knownplugins.h src/knownplugins.cpp
diffstat 2 files changed, 53 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/checker/knownplugins.h	Tue Nov 01 15:16:08 2016 +0000
+++ b/checker/knownplugins.h	Tue Nov 01 15:48:59 2016 +0000
@@ -76,6 +76,9 @@
     std::string getDefaultPath(PluginType type);
 
     PluginCandidates m_candidates;
+    std::string m_helperExecutableName;
+
+    bool is32bit() const; // true if helper looks to be 32-bit on 64-bit system
 };
 
 #endif
--- a/src/knownplugins.cpp	Tue Nov 01 15:16:08 2016 +0000
+++ b/src/knownplugins.cpp	Tue Nov 01 15:48:59 2016 +0000
@@ -1,30 +1,30 @@
 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
 /*
-    Copyright (c) 2016 Queen Mary, University of London
+  Copyright (c) 2016 Queen Mary, University of London
 
-    Permission is hereby granted, free of charge, to any person
-    obtaining a copy of this software and associated documentation
-    files (the "Software"), to deal in the Software without
-    restriction, including without limitation the rights to use, copy,
-    modify, merge, publish, distribute, sublicense, and/or sell copies
-    of the Software, and to permit persons to whom the Software is
-    furnished to do so, subject to the following conditions:
+  Permission is hereby granted, free of charge, to any person
+  obtaining a copy of this software and associated documentation
+  files (the "Software"), to deal in the Software without
+  restriction, including without limitation the rights to use, copy,
+  modify, merge, publish, distribute, sublicense, and/or sell copies
+  of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
 
-    The above copyright notice and this permission notice shall be
-    included in all copies or substantial portions of the Software.
+  The above copyright notice and this permission notice shall be
+  included in all copies or substantial portions of the Software.
 
-    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
-    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
-    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-    Except as contained in this notice, the names of the Centre for
-    Digital Music and Queen Mary, University of London shall not be
-    used in advertising or otherwise to promote the sale, use or other
-    dealings in this Software without prior written authorization.
+  Except as contained in this notice, the names of the Centre for
+  Digital Music and Queen Mary, University of London shall not be
+  used in advertising or otherwise to promote the sale, use or other
+  dealings in this Software without prior written authorization.
 */
 
 #include "knownplugins.h"
@@ -41,7 +41,8 @@
 
 KnownPlugins::KnownPlugins(string helperExecutableName,
                            PluginCandidates::LogCallback *cb) :
-    m_candidates(helperExecutableName)
+    m_candidates(helperExecutableName),
+    m_helperExecutableName(helperExecutableName)
 {
     m_candidates.setLogCallback(cb);
     
@@ -75,6 +76,12 @@
     }
 }
 
+bool
+KnownPlugins::is32bit() const
+{
+    return m_helperExecutableName.find("-32") != std::string::npos;
+}
+
 string
 KnownPlugins::getDefaultPath(PluginType type)
 {
@@ -121,6 +128,10 @@
     char *cpath = getenv(var.c_str());
     if (cpath) path = cpath;
 
+#ifdef _WIN32
+    bool is32 = is32bit();
+#endif
+
     if (path == "") {
 
         path = getDefaultPath(type);
@@ -137,15 +148,25 @@
             }
 
 #ifdef _WIN32
-        const char *pfiles = getenv("ProgramFiles");
-            if (!pfiles) pfiles = "C:\\Program Files";
-            {
-                string::size_type f;
-                while ((f = path.find("%ProgramFiles%")) != string::npos &&
-                       f < path.length()) {
-                    path.replace(f, 14, pfiles);
+            const char *pfiles = 0;
+            if (is32) {
+                pfiles = getenv("ProgramFiles(x86)");
+            }
+            if (!pfiles) {
+                pfiles = getenv("ProgramFiles");
+            }
+            if (!pfiles) {
+                if (is32) {
+                    pfiles = "C:\\Program Files (x86)";
+                } else {
+                    pfiles = "C:\\Program Files";
                 }
             }
+            string::size_type f;
+            while ((f = path.find("%ProgramFiles%")) != string::npos &&
+                   f < path.length()) {
+                path.replace(f, 14, pfiles);
+            }
 #endif
         }
     }