Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
osx_sys_version.mm
Go to the documentation of this file.
1 /* Copyright (c) 2013 Wildfire Games
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 
24 #import <AvailabilityMacros.h> // MAC_OS_X_VERSION_MIN_REQUIRED
25 #import <Foundation/Foundation.h>
26 #import <string>
27 
28 #import "osx_bundle.h"
29 
30 #define STRINGIZE2(id) # id
31 #define STRINGIZE(id) STRINGIZE2(id)
32 
33 // Pass the bundle identifier string as a build option
34 #ifdef BUNDLE_IDENTIFIER
35 static const char* BUNDLE_ID_STR = STRINGIZE(BUNDLE_IDENTIFIER);
36 #else
37 static const char* BUNDLE_ID_STR = "";
38 #endif
39 
40 
41 void GetSystemVersion( int &major, int &minor, int &bugfix )
42 {
43  // sensible default
44  static int mMajor = 10;
45  static int mMinor = 8;
46  static int mBugfix = 0;
47 
48  static dispatch_once_t onceToken;
49  dispatch_once(&onceToken, ^{
50  NSString* versionString = [[NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"] objectForKey:@"ProductVersion"];
51  NSArray* versions = [versionString componentsSeparatedByString:@"."];
52  check( versions.count >= 2 );
53  if ( versions.count >= 1 ) {
54  mMajor = [[versions objectAtIndex:0] integerValue];
55  }
56  if ( versions.count >= 2 ) {
57  mMinor = [[versions objectAtIndex:1] integerValue];
58  }
59  if ( versions.count >= 3 ) {
60  mBugfix = [[versions objectAtIndex:2] integerValue];
61  }
62  });
63 
64  major = mMajor;
65  minor = mMinor;
66  bugfix = mBugfix;
67 }
void GetSystemVersion(int &major, int &minor, int &bugfix)
C++ interface to Cocoa implementation for getting bundle information.
#define STRINGIZE(id)
static const char * BUNDLE_ID_STR