|
1 | 1 | #include "os.h" |
2 | | -#include "common/properties.h" |
3 | 2 | #include "common/sysctl.h" |
4 | 3 |
|
5 | 4 | #include <stdlib.h> |
6 | 5 | #include <string.h> |
7 | | - |
8 | | -typedef enum PListKey |
9 | | -{ |
10 | | - PLIST_KEY_NAME, |
11 | | - PLIST_KEY_VERSION, |
12 | | - PLIST_KEY_BUILD, |
13 | | - PLIST_KEY_OTHER |
14 | | -} PListKey; |
| 6 | +#import <Foundation/Foundation.h> |
15 | 7 |
|
16 | 8 | static void parseSystemVersion(FFOSResult* os) |
17 | 9 | { |
18 | | - FILE* plist = fopen("/System/Library/CoreServices/SystemVersion.plist", "r"); |
19 | | - if(plist == NULL) |
20 | | - return; |
21 | | - |
22 | | - char* line = NULL; |
23 | | - size_t len = 0; |
24 | | - PListKey key = PLIST_KEY_OTHER; |
25 | | - |
26 | | - FFstrbuf keyBuffer; |
27 | | - ffStrbufInit(&keyBuffer); |
28 | | - |
29 | | - while(getline(&line, &len, plist) != EOF) |
30 | | - { |
31 | | - if(ffParsePropLine(line, "<key>", &keyBuffer)) |
32 | | - { |
33 | | - if(ffStrbufIgnCaseCompS(&keyBuffer, "ProductName") == 0) |
34 | | - key = PLIST_KEY_NAME; |
35 | | - else if(ffStrbufIgnCaseCompS(&keyBuffer, "ProductUserVisibleVersion") == 0) |
36 | | - key = PLIST_KEY_VERSION; |
37 | | - else if(ffStrbufIgnCaseCompS(&keyBuffer, "ProductBuildVersion") == 0) |
38 | | - key = PLIST_KEY_BUILD; |
39 | | - else |
40 | | - key = PLIST_KEY_OTHER; |
41 | | - |
42 | | - ffStrbufClear(&keyBuffer); |
43 | | - continue; |
44 | | - } |
45 | | - |
46 | | - if(key == PLIST_KEY_NAME) |
47 | | - ffParsePropLine(line, "<string>", &os->name); |
48 | | - else if(key == PLIST_KEY_VERSION) |
49 | | - ffParsePropLine(line, "<string>", &os->version); |
50 | | - else if(key == PLIST_KEY_BUILD) |
51 | | - ffParsePropLine(line, "<string>", &os->buildID); |
52 | | - } |
53 | | - |
54 | | - ffStrbufDestroy(&keyBuffer); |
| 10 | + NSError* error; |
| 11 | + NSString* fileName = @"file:///System/Library/CoreServices/SystemVersion.plist"; |
| 12 | + NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:fileName] |
| 13 | + error:&error]; |
| 14 | + if(error) |
| 15 | + return; |
55 | 16 |
|
56 | | - if(line != NULL) |
57 | | - free(line); |
| 17 | + NSString* value; |
58 | 18 |
|
59 | | - fclose(plist); |
| 19 | + if((value = [dict valueForKey:@"ProductName"])) |
| 20 | + ffStrbufInitS(&os->name, value.UTF8String); |
| 21 | + if((value = [dict valueForKey:@"ProductUserVisibleVersion"])) |
| 22 | + ffStrbufInitS(&os->version, value.UTF8String); |
| 23 | + if((value = [dict valueForKey:@"ProductBuildVersion"])) |
| 24 | + ffStrbufInitS(&os->buildID, value.UTF8String); |
60 | 25 | } |
61 | 26 |
|
62 | 27 | void parseOSXSoftwareLicense(FFOSResult* os) |
|
0 commit comments