From 519dccf64bd3be966d84880b7d9b4b1df1535824 Mon Sep 17 00:00:00 2001 From: Zachary Waldowski Date: Sun, 27 Oct 2013 02:47:01 -0400 Subject: [PATCH] Replace deprecated Gestalt. --- SUHost.m | 20 ++------------------ SUSystemProfiler.m | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/SUHost.m b/SUHost.m index 0b6c4019..1de78a4d 100644 --- a/SUHost.m +++ b/SUHost.m @@ -240,24 +240,8 @@ + (NSString *)systemVersionString { - // This returns a version string of the form X.Y.Z - // There may be a better way to deal with the problem that gestaltSystemVersionMajor - // et al. are not defined in 10.3, but this is probably good enough. - NSString* verStr = nil; - SInt32 major, minor, bugfix; - OSErr err1 = Gestalt(gestaltSystemVersionMajor, &major); - OSErr err2 = Gestalt(gestaltSystemVersionMinor, &minor); - OSErr err3 = Gestalt(gestaltSystemVersionBugFix, &bugfix); - if (!err1 && !err2 && !err3) - { - verStr = [NSString stringWithFormat:@"%ld.%ld.%ld", (long)major, (long)minor, (long)bugfix]; - } - else - { - NSString *versionPlistPath = @"/System/Library/CoreServices/SystemVersion.plist"; - verStr = [[NSDictionary dictionaryWithContentsOfFile:versionPlistPath] objectForKey:@"ProductVersion"]; - } - return verStr; + NSString *versionPlistPath = @"/System/Library/CoreServices/SystemVersion.plist"; + return [[NSDictionary dictionaryWithContentsOfFile:versionPlistPath] objectForKey:@"ProductVersion"]; } @end diff --git a/SUSystemProfiler.m b/SUSystemProfiler.m index 5b4cde0f..05d5e18d 100644 --- a/SUSystemProfiler.m +++ b/SUSystemProfiler.m @@ -123,16 +123,22 @@ [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"appVersion",@"Application Version", appVersion, appVersion,nil] forKeys:profileDictKeys]]; // Number of displays? + // CPU speed - SInt32 gestaltInfo; - OSErr err = Gestalt(gestaltProcClkSpeedMHz,&gestaltInfo); - if (err == noErr) - [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"cpuFreqMHz",@"CPU Speed (GHz)", [NSNumber numberWithInt:gestaltInfo], [NSNumber numberWithDouble:gestaltInfo/1000.0],nil] forKeys:profileDictKeys]]; + unsigned long hz; + size_t hz_size = sizeof(unsigned long); + if (sysctlbyname("hw.cpufrequency", &hz, &hz_size, NULL, 0) == 0) { + unsigned long mhz = hz / 1000000; + [profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"cpuFreqMHz",@"CPU Speed (GHz)", @(mhz), @(mhz / 1000.)] forKeys:profileDictKeys]]; + } // amount of RAM - err = Gestalt(gestaltPhysicalRAMSizeInMegabytes,&gestaltInfo); - if (err == noErr) - [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"ramMB",@"Memory (MB)", [NSNumber numberWithInt:gestaltInfo], [NSNumber numberWithInt:gestaltInfo],nil] forKeys:profileDictKeys]]; + unsigned long bytes; + size_t bytes_size = sizeof(unsigned long); + if (sysctlbyname("hw.memsize", &bytes, &bytes_size, NULL, 0) == 0) { + double megabytes = bytes / (1024.*1024.); + [profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"ramMB",@"Memory (MB)", @(megabytes), @(megabytes)] forKeys:profileDictKeys]]; + } return profileArray; }