OS (macOS): improves OS detection accuracy and sets pretty name

This commit is contained in:
李通洲
2025-09-30 13:35:48 +08:00
parent 09bef5f41d
commit e6e78a7aae
+11 -4
View File
@@ -8,14 +8,14 @@
#include <string.h>
#import <Foundation/Foundation.h>
static void parseSystemVersion(FFOSResult* os)
static bool parseSystemVersion(FFOSResult* os)
{
NSError* error;
NSString* fileName = @"file:///System/Library/CoreServices/SystemVersion.plist";
NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:fileName]
error:&error];
if(error)
return;
return false;
NSString* value;
@@ -30,6 +30,8 @@ static void parseSystemVersion(FFOSResult* os)
// macOS 26 Tahoe. #1809
os->version.chars[0] = '2';
}
return true;
}
static bool detectOSCodeName(FFOSResult* os)
@@ -86,13 +88,18 @@ void ffDetectOSImpl(FFOSResult* os)
ffStrbufSetStatic(&os->id, "macos");
if(os->version.length == 0)
if(__builtin_expect(os->name.length == 0, 0))
ffStrbufSetStatic(&os->name, "macOS");
if(__builtin_expect(os->version.length == 0, 0))
ffSysctlGetString("kern.osproductversion", &os->version);
if(os->buildID.length == 0)
if(__builtin_expect(os->buildID.length == 0, 0))
ffSysctlGetString("kern.osversion", &os->buildID);
ffStrbufAppend(&os->versionID, &os->version);
detectOSCodeName(os);
ffStrbufSetF(&os->prettyName, "%s %s %s (%s)", os->name.chars, os->codename.chars, os->version.chars, os->buildID.chars);
}