mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
Disk: add option --disk-hidden-folders
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "disk.h"
|
||||
|
||||
bool ffDiskMatchMountpoint(FFDiskOptions* options, const char* mountpoint)
|
||||
bool ffDiskMatchMountpoint(FFstrbuf* folders, const char* mountpoint)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
const char separator = ';';
|
||||
@@ -11,12 +11,12 @@ bool ffDiskMatchMountpoint(FFDiskOptions* options, const char* mountpoint)
|
||||
uint32_t mountpointLength = (uint32_t) strlen(mountpoint);
|
||||
|
||||
uint32_t startIndex = 0;
|
||||
while(startIndex < options->folders.length)
|
||||
while(startIndex < folders->length)
|
||||
{
|
||||
uint32_t colonIndex = ffStrbufNextIndexC(&options->folders, startIndex, separator);
|
||||
uint32_t colonIndex = ffStrbufNextIndexC(folders, startIndex, separator);
|
||||
|
||||
uint32_t folderLength = colonIndex - startIndex;
|
||||
if (folderLength == mountpointLength && memcmp(options->folders.chars + startIndex, mountpoint, mountpointLength) == 0)
|
||||
if (folderLength == mountpointLength && memcmp(folders->chars + startIndex, mountpoint, mountpointLength) == 0)
|
||||
return true;
|
||||
|
||||
startIndex = colonIndex + 1;
|
||||
@@ -54,5 +54,14 @@ const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks)
|
||||
}
|
||||
}
|
||||
|
||||
if (options->hiddenFolders.length)
|
||||
{
|
||||
FF_LIST_FOR_EACH(FFDisk, disk, *disks)
|
||||
{
|
||||
if (ffDiskMatchMountpoint(&options->hiddenFolders, disk->mountpoint.chars))
|
||||
disk->type |= FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -28,4 +28,4 @@ typedef struct FFDisk
|
||||
const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks /* list of FFDisk */);
|
||||
|
||||
const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks);
|
||||
bool ffDiskMatchMountpoint(FFDiskOptions* options, const char* mountpoint);
|
||||
bool ffDiskMatchMountpoint(FFstrbuf* folders, const char* mountpoint);
|
||||
|
||||
@@ -145,7 +145,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
|
||||
{
|
||||
if(__builtin_expect(options->folders.length > 0, 0))
|
||||
{
|
||||
if(!ffDiskMatchMountpoint(options, fs->f_mntonname))
|
||||
if(!ffDiskMatchMountpoint(&options->folders, fs->f_mntonname))
|
||||
continue;
|
||||
}
|
||||
else if(!ffStrEquals(fs->f_mntonname, "/") && !ffStrStartsWith(fs->f_mntfromname, "/dev/") && !ffStrEquals(fs->f_fstypename, "zfs"))
|
||||
|
||||
@@ -23,7 +23,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
|
||||
|
||||
if (__builtin_expect(options->folders.length, 0))
|
||||
{
|
||||
if (!ffDiskMatchMountpoint(options, path.Path()))
|
||||
if (!ffDiskMatchMountpoint(&options->folders, path.Path()))
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -281,7 +281,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
|
||||
{
|
||||
if (__builtin_expect(options->folders.length, 0))
|
||||
{
|
||||
if (!ffDiskMatchMountpoint(options, device->mnt_dir))
|
||||
if (!ffDiskMatchMountpoint(&options->folders, device->mnt_dir))
|
||||
continue;
|
||||
}
|
||||
else if(!isPhysicalDevice(device))
|
||||
|
||||
@@ -113,7 +113,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
|
||||
{
|
||||
if (__builtin_expect(options->folders.length, 0))
|
||||
{
|
||||
if (!ffDiskMatchMountpoint(options, device.mnt_mountp))
|
||||
if (!ffDiskMatchMountpoint(&options->folders, device.mnt_mountp))
|
||||
continue;
|
||||
}
|
||||
else if(!isPhysicalDevice(&device))
|
||||
|
||||
@@ -47,7 +47,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
|
||||
|
||||
if (__builtin_expect((long) options->folders.length, 0))
|
||||
{
|
||||
if (!ffDiskMatchMountpoint(options, buffer.chars))
|
||||
if (!ffDiskMatchMountpoint(&options->folders, buffer.chars))
|
||||
continue;
|
||||
}
|
||||
else if(driveType == DRIVE_NO_ROOT_DIR)
|
||||
|
||||
@@ -205,6 +205,12 @@ bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const ch
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ffStrEqualsIgnCase(subKey, "hidden-folders"))
|
||||
{
|
||||
ffOptionParseString(key, value, &options->hiddenFolders);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ffStrEqualsIgnCase(subKey, "show-regular"))
|
||||
{
|
||||
if (ffOptionParseBoolean(value))
|
||||
@@ -293,6 +299,12 @@ void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ffStrEqualsIgnCase(key, "hiddenFolders"))
|
||||
{
|
||||
ffStrbufSetS(&options->hiddenFolders, yyjson_get_str(val));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ffStrEqualsIgnCase(key, "showExternal"))
|
||||
{
|
||||
if (yyjson_get_bool(val))
|
||||
@@ -496,6 +508,11 @@ void ffInitDiskOptions(FFDiskOptions* options)
|
||||
ffOptionInitModuleArg(&options->moduleArgs, "");
|
||||
|
||||
ffStrbufInit(&options->folders);
|
||||
#if _WIN32 || __APPLE__ || __ANDROID__
|
||||
ffStrbufInit(&options->hiddenFolders);
|
||||
#else
|
||||
ffStrbufInitStatic(&options->hiddenFolders, "/efi:/boot:/boot/efi");
|
||||
#endif
|
||||
options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT | FF_DISK_VOLUME_TYPE_READONLY_BIT;
|
||||
options->calcType = FF_DISK_CALC_TYPE_FREE;
|
||||
options->percent = (FFPercentageModuleConfig) { 50, 80, 0 };
|
||||
|
||||
@@ -29,6 +29,7 @@ typedef struct FFDiskOptions
|
||||
FFModuleArgs moduleArgs;
|
||||
|
||||
FFstrbuf folders;
|
||||
FFstrbuf hiddenFolders;
|
||||
FFDiskVolumeType showTypes;
|
||||
FFDiskCalcType calcType;
|
||||
FFPercentageModuleConfig percent;
|
||||
|
||||
Reference in New Issue
Block a user