~ubuntu-branches/ubuntu/trusty/scribus/trusty

« back to all changes in this revision

Viewing changes to scribus/util_ghostscript.cpp

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2013-05-16 20:34:07 UTC
  • mfrom: (1.1.13) (32.1.2 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130516203407-ztj7ebsivoo41dih
Tags: 1.4.2.dfsg+r18267-1ubuntu2
Avoid qreal/double type clashes on ARM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
#if defined(_WIN32)
42
42
#include <windows.h>
 
43
#ifndef KEY_WOW64_32KEY
 
44
        #define KEY_WOW64_32KEY (0x0200)
 
45
#endif
 
46
#ifndef KEY_WOW64_64KEY
 
47
        #define KEY_WOW64_64KEY (0x0100)
 
48
#endif
43
49
#endif
44
50
 
45
51
#include "prefsfile.h"
266
272
        // Set gsName to its default value
267
273
        gsName = "gswin32c.exe";
268
274
 
269
 
        QMap<int, QString> gplGS  = getGSExePaths("SOFTWARE\\GPL Ghostscript");
270
 
        QMap<int, QString> afplGS = getGSExePaths("SOFTWARE\\AFPL Ghostscript");
271
 
        QMap<int, QString> gsVersions = gplGS.unite(afplGS);
 
275
        // Test is we are running a 64bit version of WINDOWS
 
276
        bool isWindows64 = false;
 
277
        wchar_t* procArch = _wgetenv(L"PROCESSOR_ARCHITECTURE");
 
278
        if (procArch)
 
279
        {
 
280
                isWindows64 |= (wcscmp(procArch, L"AMD64") == 0);
 
281
                isWindows64 |= (wcscmp(procArch, L"IA64") == 0);
 
282
        }
 
283
        wchar_t* procArchWow64 = _wgetenv(L"PROCESSOR_ARCHITEW6432");
 
284
        if (procArchWow64) isWindows64 = true;
 
285
 
 
286
        // Search for Ghostsscript executable in native registry
 
287
        QMap<int, QString> gsVersions;
 
288
        gsVersions.unite( getGSExePaths("SOFTWARE\\GPL Ghostscript") );
 
289
        gsVersions.unite( getGSExePaths("SOFTWARE\\AFPL Ghostscript") );
 
290
 
 
291
        // If running on Windows 64bit, search alternate registry view,
 
292
        // ie 32bit registry if process is 64bit, 64bit registry if process is 32bit
 
293
        if (isWindows64)
 
294
        {
 
295
                gsVersions.unite( getGSExePaths("SOFTWARE\\GPL Ghostscript", true) );
 
296
                gsVersions.unite( getGSExePaths("SOFTWARE\\AFPL Ghostscript", true) );
 
297
        }
272
298
 
273
299
        if (gsVersions.isEmpty())
274
300
                return gsName;
307
333
        return gsName;
308
334
}
309
335
 
310
 
QMap<int, QString> SCRIBUS_API getGSExePaths(const QString& regKey)
 
336
QMap<int, QString> SCRIBUS_API getGSExePaths(const QString& regKey, bool alternateView)
311
337
{
312
338
        QMap<int, QString> gsVersions;
313
339
#if defined _WIN32
315
341
        DWORD size;
316
342
        HKEY hKey1, hKey2;
317
343
        DWORD regType = REG_SZ;
 
344
        REGSAM flags  = KEY_READ;
318
345
        WCHAR regVersion[MAX_PATH];
319
346
        WCHAR regPath[MAX_PATH];
320
347
        WCHAR gsPath[MAX_PATH];
321
 
        QString gsVersion, gsName;
322
 
 
323
 
        if( RegOpenKeyW(HKEY_LOCAL_MACHINE, (LPCWSTR) regKey.utf16(), &hKey1) == ERROR_SUCCESS )
 
348
        QString gsVersion, gsExeName, gsName;
 
349
 
 
350
        bool isWin64Api = false;
 
351
#if defined(_WIN64)
 
352
        isWin64Api = true;
 
353
#endif
 
354
 
 
355
        gsExeName = isWin64Api ? "gswin64c.exe" : "gswin32c.exe";
 
356
        if (alternateView)
 
357
        {
 
358
                gsExeName = isWin64Api ? "gswin32c.exe" : "gswin64c.exe";
 
359
                flags |= (isWin64Api ? KEY_WOW64_32KEY : KEY_WOW64_64KEY);
 
360
        }
 
361
 
 
362
        if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, (LPCWSTR) regKey.utf16(), 0, flags, &hKey1) == ERROR_SUCCESS)
324
363
        {
325
364
                size = sizeof(regVersion)/sizeof(WCHAR) - 1;
326
365
                DWORD keyIndex = 0;
327
 
                while ( RegEnumKeyExW(hKey1, keyIndex, regVersion, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS )
 
366
                while (RegEnumKeyExW(hKey1, keyIndex, regVersion, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
328
367
                {
329
368
                        int gsNumericVer, gsMajor, gsMinor;
330
369
                        wcscpy(regPath, (const wchar_t*) regKey.utf16());
331
370
                        wcscat(regPath, L"\\");
332
371
                        wcscat(regPath, regVersion);
333
 
                        if (RegOpenKeyW(HKEY_LOCAL_MACHINE, regPath, &hKey2) == ERROR_SUCCESS)
 
372
                        if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, regPath, 0, flags, &hKey2) == ERROR_SUCCESS)
334
373
                        {
335
374
                                size = sizeof(gsPath) - 1;
336
375
                                if (RegQueryValueExW(hKey2, L"GS_DLL", 0, &regType, (LPBYTE) gsPath, &size) == ERROR_SUCCESS)
345
384
                                                if (size > 0)
346
385
                                                {
347
386
                                                        gsName  = gsName.left(size + 1);
348
 
                                                        gsName += "gswin32c.exe";
 
387
                                                        gsName += gsExeName;
349
388
                                                        gsName.replace("\\", "/");
350
389
                                                        gsVersions.insert(gsNumericVer, gsName);
351
390
                                                }