Skip to content
This repository
Newer
Older
100644 141 lines (123 sloc) 6.056 kb
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
1 //
2 // SUSystemProfiler.m
3 // Sparkle
4 //
5 // Created by Andy Matuschak on 12/22/07.
87f28934 »
2007-12-30 Fixed warnings for missing newlines at the end of the file.
6 // Copyright 2007 Andy Matuschak. All rights reserved.
7 // Adapted from Sparkle+, by Tom Harrington.
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
8 //
9
10 #import "SUSystemProfiler.h"
5aa1e18b »
2007-12-25 Improved headers from Charles D. H. Williams.
11
f815eec2 »
2008-07-23 Fixes 243884
12 #import "SUHost.h"
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
13 #import <sys/sysctl.h>
14
15 @implementation SUSystemProfiler
645a96e1 »
2008-01-24 Made a good deal more progress integrating the profile checking featu…
16 + (SUSystemProfiler *)sharedSystemProfiler
17 {
18 static SUSystemProfiler *sharedSystemProfiler = nil;
19 if (!sharedSystemProfiler)
20 sharedSystemProfiler = [[self alloc] init];
21 return sharedSystemProfiler;
22 }
23
24 - (NSDictionary *)modelTranslationTable
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
25 {
26 NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"SUModelTranslation" ofType:@"plist"];
a7148d97 »
2008-01-14 Numerous minor changes courtesy Sean McBride. Mostly clarifications.
27 return [[[NSDictionary alloc] initWithContentsOfFile:path] autorelease];
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
28 }
29
98832c49 »
2008-07-15 Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
30 - (NSMutableArray *)systemProfileArrayForHost:(SUHost *)host
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
31 {
32 NSDictionary *modelTranslation = [self modelTranslationTable];
33
34 // Gather profile information and append it to the URL.
35 NSMutableArray *profileArray = [NSMutableArray array];
4da902b4 »
2008-08-10 Fixes 251968
36 NSArray *profileDictKeys = [NSArray arrayWithObjects:@"key", @"displayKey", @"value", @"displayValue", nil];
d7774c0d »
2009-10-31 performed a code review, specifically:
37 int error = 0;
38 int value = 0;
39 size_t length = sizeof(value);
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
40
a7148d97 »
2008-01-14 Numerous minor changes courtesy Sean McBride. Mostly clarifications.
41 // OS version
de9be8b4 »
2008-07-23 Fixes 244428
42 NSString *currentSystemVersion = [SUHost systemVersionString];
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
43 if (currentSystemVersion != nil)
44 [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"osVersion",@"OS Version",currentSystemVersion,currentSystemVersion,nil] forKeys:profileDictKeys]];
45
46 // CPU type (decoder info for values found here is in mach/machine.h)
47 error = sysctlbyname("hw.cputype", &value, &length, NULL, 0);
48 int cpuType = -1;
49 if (error == 0) {
50 cpuType = value;
51 NSString *visibleCPUType;
52 switch(value) {
b4210d8f »
2010-02-21 Use symbolic constants, that's what they're for ;-)
53 case CPU_TYPE_X86: visibleCPUType = @"Intel"; break;
54 case CPU_TYPE_POWERPC: visibleCPUType = @"PowerPC"; break;
55 default: visibleCPUType = @"Unknown"; break;
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
56 }
57 [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"cputype",@"CPU Type", [NSNumber numberWithInt:value], visibleCPUType,nil] forKeys:profileDictKeys]];
58 }
918217f6 »
2008-07-04 Detect 64 bit support and a) report that, b) use it to tell Core 2 fr…
59 error = sysctlbyname("hw.cpu64bit_capable", &value, &length, NULL, 0);
60 if(error != 0)
61 error = sysctlbyname("hw.optional.x86_64", &value, &length, NULL, 0); //x86 specific
62 if(error != 0)
63 error = sysctlbyname("hw.optional.64bitops", &value, &length, NULL, 0); //PPC specific
64
65 BOOL is64bit = NO;
66
67 if (error == 0) {
68 is64bit = value == 1;
44a54734 »
2008-07-05 Now reporting 64-bit capability of the host system.
69 [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"cpu64bit", @"CPU is 64-Bit?", [NSNumber numberWithBool:is64bit], is64bit ? @"Yes" : @"No", nil] forKeys:profileDictKeys]];
918217f6 »
2008-07-04 Detect 64 bit support and a) report that, b) use it to tell Core 2 fr…
70 }
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
71 error = sysctlbyname("hw.cpusubtype", &value, &length, NULL, 0);
72 if (error == 0) {
73 NSString *visibleCPUSubType;
74 if (cpuType == 7) {
75 // Intel
918217f6 »
2008-07-04 Detect 64 bit support and a) report that, b) use it to tell Core 2 fr…
76 visibleCPUSubType = is64bit ? @"Intel Core 2" : @"Intel Core"; // If anyone knows how to tell a Core Duo from a Core Solo, please email tph@atomicbird.com
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
77 } else if (cpuType == 18) {
78 // PowerPC
79 switch(value) {
80 case 9: visibleCPUSubType=@"G3"; break;
81 case 10: case 11: visibleCPUSubType=@"G4"; break;
82 case 100: visibleCPUSubType=@"G5"; break;
83 default: visibleCPUSubType=@"Other"; break;
84 }
85 } else {
86 visibleCPUSubType = @"Other";
87 }
88 [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"cpusubtype",@"CPU Subtype", [NSNumber numberWithInt:value], visibleCPUSubType,nil] forKeys:profileDictKeys]];
89 }
90 error = sysctlbyname("hw.model", NULL, &length, NULL, 0);
91 if (error == 0) {
d7774c0d »
2009-10-31 performed a code review, specifically:
92 char *cpuModel = (char *)malloc(sizeof(char) * length);
93 if (cpuModel != NULL) {
94 error = sysctlbyname("hw.model", cpuModel, &length, NULL, 0);
95 if (error == 0) {
96 NSString *rawModelName = [NSString stringWithUTF8String:cpuModel];
97 NSString *visibleModelName = [modelTranslation objectForKey:rawModelName];
98 if (visibleModelName == nil)
99 visibleModelName = rawModelName;
100 [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"model",@"Mac Model", rawModelName, visibleModelName, nil] forKeys:profileDictKeys]];
101 }
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
102 free(cpuModel);
d7774c0d »
2009-10-31 performed a code review, specifically:
103 }
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
104 }
105
106 // Number of CPUs
107 error = sysctlbyname("hw.ncpu", &value, &length, NULL, 0);
108 if (error == 0)
109 [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"ncpu",@"Number of CPUs", [NSNumber numberWithInt:value], [NSNumber numberWithInt:value],nil] forKeys:profileDictKeys]];
110
111 // User preferred language
112 NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
113 NSArray *languages = [defs objectForKey:@"AppleLanguages"];
d7774c0d »
2009-10-31 performed a code review, specifically:
114 if ([languages count] > 0)
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
115 [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"lang",@"Preferred Language", [languages objectAtIndex:0], [languages objectAtIndex:0],nil] forKeys:profileDictKeys]];
116
117 // Application sending the request
98832c49 »
2008-07-15 Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
118 NSString *appName = [host name];
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
119 if (appName)
120 [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"appName",@"Application Name", appName, appName,nil] forKeys:profileDictKeys]];
98832c49 »
2008-07-15 Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
121 NSString *appVersion = [host version];
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
122 if (appVersion)
123 [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"appVersion",@"Application Version", appVersion, appVersion,nil] forKeys:profileDictKeys]];
124
125 // Number of displays?
126 // CPU speed
127 SInt32 gestaltInfo;
d7774c0d »
2009-10-31 performed a code review, specifically:
128 OSErr err = Gestalt(gestaltProcClkSpeedMHz,&gestaltInfo);
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
129 if (err == noErr)
44a54734 »
2008-07-05 Now reporting 64-bit capability of the host system.
130 [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"cpuFreqMHz",@"CPU Speed (GHz)", [NSNumber numberWithInt:gestaltInfo], [NSNumber numberWithDouble:gestaltInfo/1000.0],nil] forKeys:profileDictKeys]];
bed9e983 »
2007-12-24 Initial merge of SparklePlus.
131
132 // amount of RAM
133 err = Gestalt(gestaltPhysicalRAMSizeInMegabytes,&gestaltInfo);
134 if (err == noErr)
135 [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"ramMB",@"Memory (MB)", [NSNumber numberWithInt:gestaltInfo], [NSNumber numberWithInt:gestaltInfo],nil] forKeys:profileDictKeys]];
136
137 return profileArray;
138 }
139
140 @end
Something went wrong with that request. Please try again.