1 /* $Id$ */ |
1 /* $Id$ */ |
|
2 |
|
3 #include <AvailabilityMacros.h> |
2 |
4 |
3 #include <AppKit/AppKit.h> |
5 #include <AppKit/AppKit.h> |
4 |
6 |
5 #include <mach/mach.h> |
7 #include <mach/mach.h> |
6 #include <mach/mach_host.h> |
8 #include <mach/mach_host.h> |
7 #include <mach/host_info.h> |
9 #include <mach/host_info.h> |
8 #include <mach/machine.h> |
10 #include <mach/machine.h> |
9 #include <stdio.h> |
11 #include <stdio.h> |
10 #include "../../stdafx.h" |
12 #include "../../stdafx.h" |
11 #include "../../macros.h" |
13 #include "../../core/bitmath_func.hpp" |
12 |
14 |
13 #ifndef CPU_SUBTYPE_POWERPC_970 |
15 #ifndef CPU_SUBTYPE_POWERPC_970 |
14 #define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100) |
16 #define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100) |
15 #endif |
17 #endif |
16 |
18 |
166 static char retbuf[32] = { '\0' }; |
168 static char retbuf[32] = { '\0' }; |
167 NSUserDefaults* defs = [NSUserDefaults standardUserDefaults]; |
169 NSUserDefaults* defs = [NSUserDefaults standardUserDefaults]; |
168 NSArray* languages = [defs objectForKey:@"AppleLanguages"]; |
170 NSArray* languages = [defs objectForKey:@"AppleLanguages"]; |
169 NSString* preferredLang = [languages objectAtIndex:0]; |
171 NSString* preferredLang = [languages objectAtIndex:0]; |
170 /* preferredLang is either 2 or 5 characters long ("xx" or "xx_YY"). */ |
172 /* preferredLang is either 2 or 5 characters long ("xx" or "xx_YY"). */ |
171 [ preferredLang getCString:retbuf maxLength:32 encoding:NSASCIIStringEncoding ]; |
173 |
|
174 /* MacOS 10.3.9 can't handle encoding:NSASCIIStringEncoding |
|
175 * we will completely disable compiling it for such old targets to avoid a warning */ |
|
176 #if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_3) |
|
177 /* Note: MAC_OS_X_VERSION_MAX_ALLOWED is the current OSX version/SDK by default */ |
|
178 if (MacOSVersionIsAtLeast(10, 4, 0)) { |
|
179 [ preferredLang getCString:retbuf maxLength:32 encoding:NSASCIIStringEncoding ]; |
|
180 } else { |
|
181 #else |
|
182 /* 10.3.9 needs to start the { too */ |
|
183 { |
|
184 #endif |
|
185 [ preferredLang getCString:retbuf maxLength:32 ]; |
|
186 } |
172 return retbuf; |
187 return retbuf; |
173 } |
188 } |
|
189 |
|
190 |
|
191 /* |
|
192 * This will only give an accurate result for versions before OS X 10.8 since it uses bcd encoding |
|
193 * for the minor and bugfix version numbers and a scheme of representing all numbers from 9 and up |
|
194 * with 9. This means we can't tell OS X 10.9 from 10.9 or 10.11. Please use GetMacOSVersionMajor() |
|
195 * and GetMacOSVersionMinor() instead. |
|
196 */ |
|
197 static long GetMacOSVersion() |
|
198 { |
|
199 static long sysVersion = -1; |
|
200 |
|
201 if (sysVersion != -1) return sysVersion; |
|
202 |
|
203 if (Gestalt(gestaltSystemVersion, &sysVersion) != noErr) sysVersion = -1; |
|
204 return sysVersion; |
|
205 } |
|
206 |
|
207 long GetMacOSVersionMajor() |
|
208 { |
|
209 static long sysVersion = -1; |
|
210 |
|
211 if (sysVersion != -1) return sysVersion; |
|
212 |
|
213 sysVersion = GetMacOSVersion(); |
|
214 if (sysVersion == -1) return -1; |
|
215 |
|
216 if (sysVersion >= 0x1040) { |
|
217 if (Gestalt(gestaltSystemVersionMajor, &sysVersion) != noErr) sysVersion = -1; |
|
218 } else { |
|
219 sysVersion = GB(sysVersion, 12, 4) * 10 + GB(sysVersion, 8, 4); |
|
220 } |
|
221 |
|
222 return sysVersion; |
|
223 } |
|
224 |
|
225 long GetMacOSVersionMinor() |
|
226 { |
|
227 static long sysVersion = -1; |
|
228 |
|
229 if (sysVersion != -1) return sysVersion; |
|
230 |
|
231 sysVersion = GetMacOSVersion(); |
|
232 if (sysVersion == -1) return -1; |
|
233 |
|
234 if (sysVersion >= 0x1040) { |
|
235 if (Gestalt(gestaltSystemVersionMinor, &sysVersion) != noErr) sysVersion = -1; |
|
236 } else { |
|
237 sysVersion = GB(sysVersion, 4, 4); |
|
238 } |
|
239 |
|
240 return sysVersion; |
|
241 } |
|
242 |
|
243 long GetMacOSVersionBugfix() |
|
244 { |
|
245 static long sysVersion = -1; |
|
246 |
|
247 if (sysVersion != -1) return sysVersion; |
|
248 |
|
249 sysVersion = GetMacOSVersion(); |
|
250 if (sysVersion == -1) return -1; |
|
251 |
|
252 if (sysVersion >= 0x1040) { |
|
253 if (Gestalt(gestaltSystemVersionBugFix, &sysVersion) != noErr) sysVersion = -1; |
|
254 } else { |
|
255 sysVersion = GB(sysVersion, 0, 4); |
|
256 } |
|
257 |
|
258 return sysVersion; |
|
259 } |