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 Sun Aug 30 23:01:25 2009 +0200 @@ -50,25 +50,14 @@ (__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. + * Get the version of the MacOS we are running under + * @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. */ -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 +68,14 @@ */ static inline bool MacOSVersionIsAtLeast(long major, long minor, long bugfix) { - long maj = GetMacOSVersionMajor(); - long min = GetMacOSVersionMinor(); - long bf = GetMacOSVersionBugfix(); + int version_major = -1; + int version_minor = -1; + int version_bugfix = -1; + 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 Sun Aug 30 23:01:25 2009 +0200 @@ -34,16 +34,39 @@ * To insure that the crosscompiler still works, let him try any changes before they are committed */ +/** + * This should give the version correct irrespective of version details + * 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) +{ + /* Default value = -1 in case an error occurs */ + *return_major = -1; + *return_minor = -1; + *return_bugfix = -1; + SInt32 systemVersion, version_major, version_minor, version_bugfix = -1; + 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]; - 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; @@ -54,6 +77,7 @@ ); // replace the hardware info with strings, that tells a bit more than just an int + const char *CPU; switch (hostInfo.cpu_subtype) { #ifdef __POWERPC__ case CPU_SUBTYPE_POWERPC_750: CPU = "G3"; break; @@ -70,19 +94,24 @@ #endif } - // get the version of OSX - if (Gestalt(gestaltSystemVersion, &sysVersion) != noErr) { - sprintf(OS, "Undetected"); + /** + * Get the version of OSX + * Maximum length of the OS-Version string should not exceed 40 chars. + */ + char OS[40]; + int version_major; + int version_minor; + int version_bugfix; + GetMacOSVersion( &version_major, &version_minor, &version_bugfix); + + if ((version_major) != -1 && (version_minor != -1) && (version_bugfix != -1)) { + sprintf(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); + sprintf(OS, "uncertain %d.%d.%d", version_major, version_minor, version_bugfix); } - // make a list of used newgrf files + /* Make a list of used newgrf files */ + char newgrf[125]; /* if (_first_grffile != NULL) { char *n = newgrf; const GRFFile *file; @@ -92,9 +121,10 @@ n = strecpy(n, file->filename, lastof(newgrf)); } } else {*/ - sprintf(newgrf, "none"); + sprintf(newgrf, "unkown"); // } + static char buffer[195]; snprintf( buffer, lengthof(buffer), "Please add this info: (tip: copy-paste works)\n" @@ -202,72 +232,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; -}