From 2c16c6870c2d59ca31c6dae7038fbd8485d60599 Mon Sep 17 00:00:00 2001 From: Dan Guzek Date: Wed, 25 Mar 2015 22:53:42 -0400 Subject: [PATCH] log OS X version properly - take 2 There was code in place to log the OS X kernel version (14.1.0, for example) to log, but it stopped working some time ago. "Mac OS X unknown." has been logged for the last several releases. This commit swaps out that C++ code for a some Obj-C which logs the OS X release version (10.10.2, for example) correctly. In order to mix Obj-C with an otherwise C++ file, I changed the file extension from .cpp to .mm to make it Objective-C++. At the suggestion of wolfman2000, I have updated src/CMakeData-arch.cmake to reflect the changes in this commit; that will follow in the next commit from me. --- ...chHooks_MacOSX.cpp => ArchHooks_MacOSX.mm} | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) rename src/arch/ArchHooks/{ArchHooks_MacOSX.cpp => ArchHooks_MacOSX.mm} (95%) diff --git a/src/arch/ArchHooks/ArchHooks_MacOSX.cpp b/src/arch/ArchHooks/ArchHooks_MacOSX.mm similarity index 95% rename from src/arch/ArchHooks/ArchHooks_MacOSX.cpp rename to src/arch/ArchHooks/ArchHooks_MacOSX.mm index 7b34ce7335..d434b622f1 100644 --- a/src/arch/ArchHooks/ArchHooks_MacOSX.cpp +++ b/src/arch/ArchHooks/ArchHooks_MacOSX.mm @@ -21,6 +21,8 @@ extern "C" { #include #include +#import + static bool IsFatalSignal( int signal ) { switch( signal ) @@ -140,16 +142,13 @@ RString ArchHooks_MacOSX::GetArchName() const void ArchHooks_MacOSX::DumpDebugInfo() { - // Get system version - RString sSystemVersion; + // Get system version (like 10.x.x) + RString SystemVersion; { - char osrelease[256]; - size_t size = sizeof(osrelease); - - if( sysctlbyname( "kern.osrelease", osrelease, &size, NULL, 0 ) ) - sSystemVersion = ssprintf( "Mac OS X %s", osrelease ); - else - sSystemVersion = ssprintf( "Mac OS X Unknown" ); + // http://stackoverflow.com/a/891336 + NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]; + NSString *productVersion = [version objectForKey:@"ProductVersion"]; + SystemVersion = ssprintf("Mac OS X %s", [productVersion cStringUsingEncoding:[NSString defaultCStringEncoding]]); } size_t size; @@ -232,10 +231,10 @@ void ArchHooks_MacOSX::DumpDebugInfo() } while( false ); #undef GET_PARAM - // Send all of the information to the log + // Send all of the information to the log LOG->Info( "Model: %s (%d/%d)", sModel.c_str(), iCPUs, iMaxCPUs ); LOG->Info( "Clock speed %.2f %cHz", fFreq, freqPower ); - LOG->Info( "%s", sSystemVersion.c_str()); + LOG->Info( "%s", SystemVersion.c_str()); LOG->Info( "Memory: %.2f %cB", fRam, ramPower ); } @@ -389,12 +388,12 @@ float ArchHooks_MacOSX::GetDisplayAspectRatio() if( width && height ) return float(width)/height; return 4/3.f; -} +} /* * (c) 2003-2006 Steve Checkoway * All rights reserved. - * + * * 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 @@ -404,7 +403,7 @@ float ArchHooks_MacOSX::GetDisplayAspectRatio() * copyright notice(s) and this permission notice appear in all copies of * the Software and that both the above copyright notice(s) and this * permission notice appear in supporting documentation. - * + * * 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 OF