mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
Disk: add volume name detection
This commit is contained in:
@@ -16,6 +16,7 @@ typedef struct FFDisk
|
||||
{
|
||||
FFstrbuf mountpoint;
|
||||
FFstrbuf filesystem;
|
||||
FFstrbuf name;
|
||||
FFDiskType type;
|
||||
|
||||
uint64_t bytesUsed;
|
||||
|
||||
@@ -4,16 +4,6 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
static bool getBool(NSURL* url, NSURLResourceKey key)
|
||||
{
|
||||
NSError *error;
|
||||
NSNumber* result;
|
||||
if([url getResourceValue:&result forKey:key error:&error] == NO)
|
||||
return false;
|
||||
|
||||
return result.boolValue;
|
||||
}
|
||||
|
||||
void ffDetectDisksImpl(FFDiskResult* disks)
|
||||
{
|
||||
NSArray *keys = [NSArray arrayWithObjects:NSURLVolumeNameKey, nil];
|
||||
@@ -32,8 +22,9 @@ void ffDetectDisksImpl(FFDiskResult* disks)
|
||||
ffStrbufInitS(&disk->mountpoint, [url.relativePath cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
|
||||
NSString* filesystem;
|
||||
[[NSWorkspace sharedWorkspace] getFileSystemInfoForPath:url.relativePath
|
||||
isRemovable:nil
|
||||
BOOL removable;
|
||||
[NSWorkspace.sharedWorkspace getFileSystemInfoForPath:url.relativePath
|
||||
isRemovable:&removable
|
||||
isWritable:nil
|
||||
isUnmountable:nil
|
||||
description:nil
|
||||
@@ -41,13 +32,22 @@ void ffDetectDisksImpl(FFDiskResult* disks)
|
||||
];
|
||||
ffStrbufInitS(&disk->filesystem, [filesystem cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
|
||||
if(getBool(url, NSURLVolumeIsRemovableKey))
|
||||
NSError* error;
|
||||
|
||||
NSNumber* isBrowsable;
|
||||
if(removable)
|
||||
disk->type = FF_DISK_TYPE_EXTERNAL;
|
||||
else if(getBool(url, NSURLVolumeIsBrowsableKey))
|
||||
else if([url getResourceValue:&isBrowsable forKey:NSURLVolumeIsBrowsableKey error:&error] == YES && isBrowsable.boolValue)
|
||||
disk->type = FF_DISK_TYPE_REGULAR;
|
||||
else
|
||||
disk->type = FF_DISK_TYPE_HIDDEN;
|
||||
|
||||
NSString* volumeName;
|
||||
if([url getResourceValue:&volumeName forKey:NSURLVolumeNameKey error:&error] == YES)
|
||||
ffStrbufInitS(&disk->name, [volumeName cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
else
|
||||
ffStrbufInit(&disk->name);
|
||||
|
||||
struct statvfs fs;
|
||||
if(statvfs(disk->mountpoint.chars, &fs) != 0)
|
||||
memset(&fs, 0, sizeof(struct statvfs)); //Set all values to 0, so our values get initialized to 0 too
|
||||
|
||||
@@ -72,6 +72,8 @@ void ffDetectDisksImpl(FFDiskResult* disks)
|
||||
|
||||
disk->filesTotal = (uint32_t) fs.f_files;
|
||||
disk->filesUsed = (uint32_t) (disk->filesTotal - fs.f_ffree);
|
||||
|
||||
ffStrbufInit(&disk->name); //TODO: implement this
|
||||
}
|
||||
|
||||
if(line != NULL)
|
||||
|
||||
@@ -22,7 +22,7 @@ void ffDetectDisksImpl(FFDiskResult* disks)
|
||||
UINT driveType = GetDriveTypeA(mountpoint);
|
||||
if(driveType == DRIVE_NO_ROOT_DIR)
|
||||
{
|
||||
i += strlen(mountpoint);
|
||||
i += (uint32_t)strlen(mountpoint);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -45,13 +45,18 @@ void ffDetectDisksImpl(FFDiskResult* disks)
|
||||
disk->type = FF_DISK_TYPE_HIDDEN;
|
||||
|
||||
ffStrbufInitA(&disk->filesystem, MAX_PATH + 1);
|
||||
ffStrbufInitA(&disk->name, MAX_PATH + 1);
|
||||
//https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumeinformationa#remarks
|
||||
UINT errorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
|
||||
GetVolumeInformationA(mountpoint,
|
||||
NULL, 0, //Volume name
|
||||
disk->name.chars, disk->name.allocated, //Volume name
|
||||
NULL, //Serial number
|
||||
NULL, //Max component length
|
||||
NULL, //File system flags
|
||||
disk->filesystem.chars, disk->filesystem.allocated
|
||||
);
|
||||
SetErrorMode(errorMode);
|
||||
ffStrbufRecalculateLength(&disk->name);
|
||||
ffStrbufRecalculateLength(&disk->filesystem);
|
||||
|
||||
//TODO: implement
|
||||
|
||||
Reference in New Issue
Block a user