mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
OS: print codename ( macOS )
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "common/sysctl.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef enum PListKey
|
||||
{
|
||||
@@ -12,7 +13,7 @@ typedef enum PListKey
|
||||
PLIST_KEY_OTHER
|
||||
} PListKey;
|
||||
|
||||
static void parseFile(FFOSResult* os)
|
||||
static void parseSystemVersion(FFOSResult* os)
|
||||
{
|
||||
FILE* plist = fopen("/System/Library/CoreServices/SystemVersion.plist", "r");
|
||||
if(plist == NULL)
|
||||
@@ -58,6 +59,33 @@ static void parseFile(FFOSResult* os)
|
||||
fclose(plist);
|
||||
}
|
||||
|
||||
void parseOSXSoftwareLicense(FFOSResult* os)
|
||||
{
|
||||
FILE* rtf = fopen("/System/Library/CoreServices/Setup Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf", "r");
|
||||
if(rtf == NULL)
|
||||
return;
|
||||
|
||||
char* line = NULL;
|
||||
size_t len = 0;
|
||||
const char* searchStr = "\\f0\\b SOFTWARE LICENSE AGREEMENT FOR macOS ";
|
||||
const size_t searchLen = strlen(searchStr);
|
||||
while(getline(&line, &len, rtf) != EOF)
|
||||
{
|
||||
if (strncmp(line, searchStr, searchLen) == 0)
|
||||
{
|
||||
ffStrbufAppendS(&os->codename, line + searchLen);
|
||||
ffStrbufTrimRight(&os->codename, '\n');
|
||||
ffStrbufTrimRight(&os->codename, '\\');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(line != NULL)
|
||||
free(line);
|
||||
|
||||
fclose(rtf);
|
||||
}
|
||||
|
||||
void ffDetectOSImpl(FFOSResult* os, const FFinstance* instance)
|
||||
{
|
||||
FF_UNUSED(instance);
|
||||
@@ -76,7 +104,7 @@ void ffDetectOSImpl(FFOSResult* os, const FFinstance* instance)
|
||||
ffStrbufInitA(&os->variant, 0);
|
||||
ffStrbufInitA(&os->variantID, 0);
|
||||
|
||||
parseFile(os);
|
||||
parseSystemVersion(os);
|
||||
|
||||
if(ffStrbufStartsWithIgnCaseS(&os->name, "MacOS"))
|
||||
ffStrbufAppendS(&os->id, "macos");
|
||||
@@ -84,9 +112,13 @@ void ffDetectOSImpl(FFOSResult* os, const FFinstance* instance)
|
||||
if(os->version.length == 0)
|
||||
ffSysctlGetString("kern.osproductversion", &os->version);
|
||||
|
||||
//TODO map version to pretty name
|
||||
if(os->buildID.length == 0)
|
||||
ffSysctlGetString("kern.osversion", &os->buildID);
|
||||
|
||||
ffStrbufAppend(&os->prettyName, &os->name);
|
||||
ffStrbufAppend(&os->versionID, &os->version);
|
||||
ffSysctlGetString("kern.ostype", &os->systemName);
|
||||
ffSysctlGetString("hw.machine", &os->architecture);
|
||||
|
||||
parseOSXSoftwareLicense(os);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,14 @@ static void buildOutputDefault(const FFOSResult* os, FFstrbuf* result)
|
||||
else
|
||||
ffStrbufAppend(result, &os->systemName);
|
||||
|
||||
#ifdef __APPLE__
|
||||
if(os->codename.length > 0)
|
||||
{
|
||||
ffStrbufAppendC(result, ' ');
|
||||
ffStrbufAppend(result, &os->codename);
|
||||
}
|
||||
#endif
|
||||
|
||||
//Append version if it is missing
|
||||
if(os->versionID.length > 0 && ffStrbufFirstIndex(result, &os->versionID) == result->length)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user