| [19899] | 1 | /* Copyright (C) 2013 Wildfire Games.
|
|---|
| [13821] | 2 | *
|
|---|
| 3 | * Permission is hereby granted, free of charge, to any person obtaining
|
|---|
| 4 | * a copy of this software and associated documentation files (the
|
|---|
| 5 | * "Software"), to deal in the Software without restriction, including
|
|---|
| 6 | * without limitation the rights to use, copy, modify, merge, publish,
|
|---|
| 7 | * distribute, sublicense, and/or sell copies of the Software, and to
|
|---|
| 8 | * permit persons to whom the Software is furnished to do so, subject to
|
|---|
| 9 | * the following conditions:
|
|---|
| 10 | *
|
|---|
| 11 | * The above copyright notice and this permission notice shall be included
|
|---|
| 12 | * in all copies or substantial portions of the Software.
|
|---|
| 13 | *
|
|---|
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|---|
| 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|---|
| 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|---|
| 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|---|
| 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|---|
| 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|---|
| 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|---|
| 21 | */
|
|---|
| 22 |
|
|---|
| 23 | #import <AvailabilityMacros.h> // MAC_OS_X_VERSION_MIN_REQUIRED
|
|---|
| 24 | #import <Foundation/Foundation.h>
|
|---|
| [14140] | 25 | #import <dispatch/dispatch.h>
|
|---|
| [13821] | 26 | #import <string>
|
|---|
| 27 |
|
|---|
| [14140] | 28 | #import "osx_sys_version.h"
|
|---|
| [13821] | 29 |
|
|---|
| [14140] | 30 | void GetSystemVersion(int &major, int &minor, int &bugfix)
|
|---|
| [13821] | 31 | {
|
|---|
| [14140] | 32 | // grand central dispatch only available on 10.6+
|
|---|
| 33 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
|---|
| 34 | if (dispatch_once != nil)
|
|---|
| 35 | {
|
|---|
| 36 | // sensible default
|
|---|
| 37 | static int mMajor = 10;
|
|---|
| 38 | static int mMinor = 8;
|
|---|
| 39 | static int mBugfix = 0;
|
|---|
| [13821] | 40 |
|
|---|
| [14140] | 41 | static dispatch_once_t onceToken;
|
|---|
| 42 | dispatch_once(&onceToken, ^{
|
|---|
| 43 | NSString* versionString = [[NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"] objectForKey:@"ProductVersion"];
|
|---|
| 44 | NSArray* versions = [versionString componentsSeparatedByString:@"."];
|
|---|
| [20530] | 45 |
|
|---|
| [14140] | 46 | if (versions.count >= 1)
|
|---|
| 47 | mMajor = [[versions objectAtIndex:0] integerValue];
|
|---|
| 48 | if (versions.count >= 2)
|
|---|
| 49 | mMinor = [[versions objectAtIndex:1] integerValue];
|
|---|
| 50 | if (versions.count >= 3)
|
|---|
| 51 | mBugfix = [[versions objectAtIndex:2] integerValue];
|
|---|
| 52 | });
|
|---|
| [13821] | 53 |
|
|---|
| [14140] | 54 | major = mMajor;
|
|---|
| 55 | minor = mMinor;
|
|---|
| 56 | bugfix = mBugfix;
|
|---|
| 57 | }
|
|---|
| 58 | else
|
|---|
| 59 | {
|
|---|
| 60 | #endif // fallback to 10.5 API
|
|---|
| 61 | // just return 10.5.0, it's unlikely we support an earlier OS
|
|---|
| 62 | // and unlikely we care about bugfix versions
|
|---|
| 63 | major = 10;
|
|---|
| 64 | minor = 5;
|
|---|
| 65 | bugfix = 0;
|
|---|
| 66 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
|---|
| 67 | }
|
|---|
| 68 | #endif
|
|---|
| [13821] | 69 | }
|
|---|