mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
PhysicalMemory (macOS): add support
This commit is contained in:
parent
68efcdd0dd
commit
07747aa819
@ -594,7 +594,7 @@ elseif(APPLE)
|
||||
src/detection/cursor/cursor_apple.m
|
||||
src/detection/disk/disk_bsd.c
|
||||
src/detection/physicaldisk/physicaldisk_apple.c
|
||||
src/detection/physicalmemory/physicalmemory_nosupport.c
|
||||
src/detection/physicalmemory/physicalmemory_apple.m
|
||||
src/detection/diskio/diskio_apple.c
|
||||
src/detection/displayserver/displayserver_apple.c
|
||||
src/detection/font/font_apple.m
|
||||
|
109
src/detection/physicalmemory/physicalmemory_apple.m
Normal file
109
src/detection/physicalmemory/physicalmemory_apple.m
Normal file
@ -0,0 +1,109 @@
|
||||
#include "physicalmemory.h"
|
||||
#include "common/processing.h"
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
static void appendDevice(
|
||||
FFlist* result,
|
||||
NSString* type,
|
||||
NSString* vendor,
|
||||
NSString* size,
|
||||
|
||||
// Intel only
|
||||
NSString* deviceLocator,
|
||||
NSString* serial,
|
||||
NSString* speed)
|
||||
{
|
||||
FFPhysicalMemoryResult* device = ffListAdd(result);
|
||||
ffStrbufInitS(&device->type, type.UTF8String);
|
||||
ffStrbufInit(&device->formFactor);
|
||||
ffStrbufInitS(&device->deviceLocator, deviceLocator.UTF8String);
|
||||
ffStrbufInitS(&device->vendor, vendor.UTF8String);
|
||||
ffStrbufInitS(&device->serial, serial.UTF8String);
|
||||
device->size = 0;
|
||||
device->maxSpeed = 0;
|
||||
device->runningSpeed = 0;
|
||||
|
||||
if (size)
|
||||
{
|
||||
char* unit = NULL;
|
||||
device->size = strtoul(size.UTF8String, &unit, 10);
|
||||
if (*unit == ' ') ++unit;
|
||||
|
||||
switch (*unit)
|
||||
{
|
||||
case 'G': device->size *= 1024ULL * 1024 * 1024; break;
|
||||
case 'M': device->size *= 1024ULL * 1024; break;
|
||||
case 'K': device->size *= 1024ULL; break;
|
||||
case 'T': device->size *= 1024ULL * 1024 * 1024 * 1024; break;
|
||||
}
|
||||
}
|
||||
|
||||
if (speed)
|
||||
{
|
||||
char* unit = NULL;
|
||||
device->maxSpeed = (uint32_t) strtoul(speed.UTF8String, &unit, 10);
|
||||
if (*unit == ' ') ++unit;
|
||||
|
||||
switch (*unit)
|
||||
{
|
||||
case 'T': device->maxSpeed *= 1000 * 1000; break;
|
||||
case 'G': device->maxSpeed *= 1000; break;
|
||||
case 'K': device->maxSpeed /= 1000; break;
|
||||
}
|
||||
device->runningSpeed = device->maxSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
const char* ffDetectPhysicalMemory(FFlist* result)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
|
||||
if (ffProcessAppendStdOut(&buffer, (char* const[]) {
|
||||
"system_profiler",
|
||||
"SPMemoryDataType",
|
||||
"-xml",
|
||||
"-detailLevel",
|
||||
"full",
|
||||
NULL
|
||||
}) != NULL)
|
||||
return "Starting `system_profiler SPMemoryDataType -xml -detailLevel full` failed";
|
||||
|
||||
NSArray* arr = [NSPropertyListSerialization propertyListWithData:[NSData dataWithBytes:buffer.chars length:buffer.length]
|
||||
options:NSPropertyListImmutable
|
||||
format:nil
|
||||
error:nil];
|
||||
if (!arr || !arr.count)
|
||||
return "system_profiler SPMemoryDataType returned an empty array";
|
||||
|
||||
for (NSDictionary* data in arr[0][@"_items"])
|
||||
{
|
||||
if (data[@"_items"])
|
||||
{
|
||||
// for Intel
|
||||
for (NSDictionary* item in data[@"_items"])
|
||||
{
|
||||
appendDevice(result,
|
||||
item[@"dimm_type"],
|
||||
item[@"dimm_manufacturer"],
|
||||
item[@"dimm_size"],
|
||||
item[@"_name"],
|
||||
item[@"dimm_serial_number"],
|
||||
item[@"dimm_speed"]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// for Apple Silicon
|
||||
appendDevice(result,
|
||||
data[@"dimm_type"],
|
||||
data[@"dimm_manufacturer"],
|
||||
data[@"SPMemoryDataType"],
|
||||
nil,
|
||||
nil,
|
||||
nil);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
@ -32,7 +32,10 @@ void ffPrintPhysicalMemory(FFPhysicalMemoryOptions* options)
|
||||
|
||||
if(options->moduleArgs.key.length == 0)
|
||||
{
|
||||
ffStrbufSetF(&key, "%s (%s %s-%u)", FF_PHYSICALMEMORY_DISPLAY_NAME, device->vendor.chars, device->type.chars, device->maxSpeed);
|
||||
if (device->maxSpeed)
|
||||
ffStrbufSetF(&key, "%s (%s %s-%u)", FF_PHYSICALMEMORY_DISPLAY_NAME, device->vendor.chars, device->type.chars, device->maxSpeed);
|
||||
else
|
||||
ffStrbufSetF(&key, "%s (%s %s)", FF_PHYSICALMEMORY_DISPLAY_NAME, device->vendor.chars, device->type.chars);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -48,7 +51,10 @@ void ffPrintPhysicalMemory(FFPhysicalMemoryOptions* options)
|
||||
if (options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
|
||||
printf("%s, running at %u MT/s\n", prettySize.chars, device->runningSpeed);
|
||||
if (device->runningSpeed > 0 && device->runningSpeed != device->maxSpeed)
|
||||
printf("%s, running at %u MT/s\n", prettySize.chars, device->runningSpeed);
|
||||
else
|
||||
puts(prettySize.chars);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user