diff -r 9b48b772189c src/os/macosx/macos.h --- a/src/os/macosx/macos.h Sun Aug 30 05:42:03 2009 +0200 +++ b/src/os/macosx/macos.h Mon Aug 31 08:26:56 2009 +0200 @@ -50,25 +50,7 @@ (__builtin_expect(!(e), 0) ? ShowMacAssertDialog ( __func__, __FILE__, __LINE__, #e ): (void)0 ) #endif - - -/** - * Get the major version of Mac OS we are running under. Useful for things like the cocoa driver. - * @return major version of the os. This would be 10 in the case of 10.4.11. - */ -long GetMacOSVersionMajor(); - -/** - * Get the minor version of Mac OS we are running under. Useful for things like the cocoa driver. - * @return minor version of the os. This would be 4 in the case of 10.4.11. - */ -long GetMacOSVersionMinor(); - -/** - * Get the bugfix version of Mac OS we are running under. Useful for things like the cocoa driver. - * @return bugfix version of the os. This would be 11 in the case of 10.4.11. - */ -long GetMacOSVersionBugfix(); +void GetMacOSVersion(int *return_major, int *return_minor, int *return_bugfix); /** * Check if we are at least running on the specified version of Mac OS. @@ -79,13 +61,12 @@ */ static inline bool MacOSVersionIsAtLeast(long major, long minor, long bugfix) { - long maj = GetMacOSVersionMajor(); - long min = GetMacOSVersionMinor(); - long bf = GetMacOSVersionBugfix(); + int version_major, version_minor, version_bugfix; + GetMacOSVersion(&version_major, &version_minor, &version_bugfix); - if (maj < major) return false; - if (maj == major && min < minor) return false; - if (maj == major && min == minor && bf < bugfix) return false; + if (version_major < major) return false; + if (version_major == major && version_minor < minor) return false; + if (version_major == major && version_minor == minor && version_bugfix < bugfix) return false; return true; } diff -r 9b48b772189c src/os/macosx/macos.mm --- a/src/os/macosx/macos.mm Sun Aug 30 05:42:03 2009 +0200 +++ b/src/os/macosx/macos.mm Mon Aug 31 08:26:56 2009 +0200 @@ -34,16 +34,41 @@ * To insure that the crosscompiler still works, let him try any changes before they are committed */ + +/** + * Get the version of the MacOS we are running under. Code adopted + * from http://www.cocoadev.com/index.pl?DeterminingOSVersion + * @param return_major major version of the os. This would be 10 in the case of 10.4.11 + * @param return_minor minor version of the os. This would be 4 in the case of 10.4.11 + * @param return_bugfix bugfix version of the os. This would be 11 in the case of 10.4.11 + * A return value of -1 indicates that something went wrong and we don't know. + */ +void GetMacOSVersion(int *return_major, int *return_minor, int *return_bugfix) +{ + *return_major = -1; + *return_minor = -1; + *return_bugfix = -1; + SInt32 systemVersion, version_major, version_minor, version_bugfix; + if (Gestalt(gestaltSystemVersion, &systemVersion) == noErr) { + if (systemVersion < 0x1040) { + *return_major = GB(systemVersion, 12, 4) * 10 + GB(systemVersion, 8, 4); + *return_minor = GB(systemVersion, 4, 4); + *return_bugfix = GB(systemVersion, 0, 4); + } else { + if (Gestalt(gestaltSystemVersionMajor, &version_major) == noErr) *return_major = (int)version_major; + if (Gestalt(gestaltSystemVersionMinor, &version_minor) == noErr) *return_minor = (int)version_minor; + if (Gestalt(gestaltSystemVersionBugFix, &version_bugfix) == noErr) *return_bugfix = (int)version_bugfix; + } + } +} + void ToggleFullScreen(bool fs); static char *GetOSString() { - static char buffer[175]; + static char buffer[195]; const char *CPU; - char OS[20]; char newgrf[125]; - SInt32 sysVersion; - // get the hardware info host_basic_info_data_t hostInfo; mach_msg_type_number_t infoCount; @@ -70,16 +95,15 @@ #endif } - // get the version of OSX - if (Gestalt(gestaltSystemVersion, &sysVersion) != noErr) { - sprintf(OS, "Undetected"); + /* Get the version of OSX */ + char OS[40]; + int version_major, version_minor, version_bugfix; + GetMacOSVersion(&version_major, &version_minor, &version_bugfix); + + if ((version_major) != -1 && (version_minor != -1) && (version_bugfix != -1)) { + snprintf(OS, sizeof(OS), "%d.%d.%d", version_major, version_minor, version_bugfix); } else { - int majorHiNib = GB(sysVersion, 12, 4); - int majorLoNib = GB(sysVersion, 8, 4); - int minorNib = GB(sysVersion, 4, 4); - int bugNib = GB(sysVersion, 0, 4); - - sprintf(OS, "%d%d.%d.%d", majorHiNib, majorLoNib, minorNib, bugNib); + snprintf(OS, sizeof(OS), "uncertain %d.%d.%d", version_major, version_minor, version_bugfix); } // make a list of used newgrf files @@ -92,7 +116,7 @@ n = strecpy(n, file->filename, lastof(newgrf)); } } else {*/ - sprintf(newgrf, "none"); + sprintf(newgrf, "unkown"); // } snprintf( @@ -202,72 +226,3 @@ } -/* - * This will only give an accurate result for versions before OS X 10.8 since it uses bcd encoding - * for the minor and bugfix version numbers and a scheme of representing all numbers from 9 and up - * with 9. This means we can't tell OS X 10.9 from 10.9 or 10.11. Please use GetMacOSVersionMajor() - * and GetMacOSVersionMinor() instead. - */ -static long GetMacOSVersion() -{ - static SInt32 sysVersion = -1; - - if (sysVersion != -1) return sysVersion; - - if (Gestalt(gestaltSystemVersion, &sysVersion) != noErr) sysVersion = -1; - return sysVersion; -} - -long GetMacOSVersionMajor() -{ - static SInt32 sysVersion = -1; - - if (sysVersion != -1) return sysVersion; - - sysVersion = GetMacOSVersion(); - if (sysVersion == -1) return -1; - - if (sysVersion >= 0x1040) { - if (Gestalt(gestaltSystemVersionMajor, &sysVersion) != noErr) sysVersion = -1; - } else { - sysVersion = GB(sysVersion, 12, 4) * 10 + GB(sysVersion, 8, 4); - } - - return sysVersion; -} - -long GetMacOSVersionMinor() -{ - static SInt32 sysVersion = -1; - - if (sysVersion != -1) return sysVersion; - - sysVersion = GetMacOSVersion(); - if (sysVersion == -1) return -1; - - if (sysVersion >= 0x1040) { - if (Gestalt(gestaltSystemVersionMinor, &sysVersion) != noErr) sysVersion = -1; - } else { - sysVersion = GB(sysVersion, 4, 4); - } - - return sysVersion; -} - -long GetMacOSVersionBugfix() -{ - static SInt32 sysVersion = -1; - - if (sysVersion != -1) return sysVersion; - - sysVersion = GetMacOSVersion(); - if (sysVersion == -1) return -1; - - if (sysVersion >= 0x1040) { - if (Gestalt(gestaltSystemVersionBugFix, &sysVersion) != noErr) sysVersion = -1; - } else { - sysVersion = GB(sysVersion, 0, 4); - } - - return sysVersion; -}