Compare commits

..

16 Commits

Author SHA1 Message Date
Carter Li a3f13bdca9 Merge pull request #545 from fastfetch-cli/dev
Release v2.0.5
2023-08-26 20:31:27 +08:00
李通洲 55444b9c4e Release v2.0.5 2023-08-26 08:16:06 -04:00
李通洲 2f14d7742e Display (Linux): fix memleaks 2023-08-26 05:52:06 -04:00
李通洲 0534882f4e Cursor: Don't print 0px 2023-08-26 05:43:15 -04:00
李通洲 ce2f2f4416 Doc: update changelog 2023-08-26 05:31:00 -04:00
李通洲 5259aeb039 Display: fix segfault when using libxrandr
Fix #544
2023-08-26 05:28:21 -04:00
李通洲 e51999edd1 Doc: update changelog 2023-08-26 13:43:33 +08:00
李通洲 2f96c847b9 Disk: print Read-only 2023-08-26 13:43:33 +08:00
李通洲 32d6436027 Disk: add --disk-show-readonly 2023-08-26 13:43:33 +08:00
李通洲 7358326a13 Disk: add --disk-use-available
fix #543
2023-08-26 13:43:13 +08:00
李通洲 434a879538 Disk: rename FFDiskType to FFDiskVolumeType 2023-08-26 13:40:40 +08:00
Carter Li 745a8dda65 Merge pull request #540 from fastfetch-cli/dev
Release v2.0.4
2023-08-25 15:41:50 +08:00
李通洲 c40086615f Release v2.0.4 2023-08-25 15:05:39 +08:00
李通洲 fe3d38e542 Logo: trait - as an alias for /dev/stdin
which can be useful where `/dev/stdin` is not available, eg. on Windows
2023-08-25 11:03:37 +08:00
李通洲 f19a3b5549 Logo: fix --file-raw doesn't work
Fix #539
Ref https://github.com/hykilpikonna/hyfetch/issues/173
2023-08-25 11:01:48 +08:00
李通洲 eb308e1861 Memory (BSD): fix building on 32-bit FreeBSD
fix #538
2023-08-25 08:47:16 +08:00
18 changed files with 203 additions and 78 deletions
+19
View File
@@ -1,3 +1,22 @@
# 2.0.5
Bugfixes:
* Fix segfault when using libxrandr (#544, Display, Linux)
* Don't print 0px (#544, Cursor)
Features:
* Add option `--disk-use-available` (#543)
* Add option `--disk-show-readonly`
# 2.0.4
Bugfixes:
* Fix building on 32-bit FreeBSD (Memory, BSD)
* Fix `--file-raw` doesn't work (Logo)
Features:
* Trait `-` as an alias for `/dev/stdin`. Available for `--file`, `--file-raw` and `--raw` (Logo)
# 2.0.3
Bugfixes:
+1 -1
View File
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url
project(fastfetch
VERSION 2.0.3
VERSION 2.0.5
LANGUAGES C
DESCRIPTION "Fast system information tool"
HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch"
+10
View File
@@ -884,11 +884,21 @@
"title": "Set if subvolumes should be printed",
"default": false
},
"showReadOnly": {
"type": "boolean",
"title": "Set if read only volumes should be printed",
"default": false
},
"showUnknown": {
"type": "boolean",
"title": "Set if unknown (unable to detect sizes) volumes should be printed",
"default": false
},
"useAvailable": {
"type": "boolean",
"title": "Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes",
"default": false
},
"key": {
"$ref": "#/$defs/key"
},
+2
View File
@@ -129,7 +129,9 @@ Module specific options:
--disk-show-external <?value>: Set if external volume should be printed. Default is true
--disk-show-hidden <?value>: Set if hidden volumes should be printed. Default is false
--disk-show-subvolumes <?value>: Set if subvolumes should be printed. Default is false
--disk-show-readonly <?value>: Set if read only volumes should be printed. Default is false
--disk-show-unknown <?value>: Set if unknown (unable to detect sizes) volumes should be printed. Default is false
--disk-use-available <?value>: Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes. Default is false
--bluetooth-show-disconnected: <?value>: Set if disconnected bluetooth devices should be printed. Default is false
--display-compact-type: <?string>: Set if all displays should be printed in one line. Default is none
--display-detect-name: <?value>: Set if display name should be detected and printed (if supported). Default is false
+8 -2
View File
@@ -7,7 +7,7 @@ static int compareDisks(const void* disk1, const void* disk2)
return ffStrbufCompAlphabetically(&((const FFDisk*) disk1)->mountpoint, &((const FFDisk*) disk2)->mountpoint);
}
const char* ffDetectDisks(FFlist* disks)
const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks)
{
const char* error = ffDetectDisksImpl(disks);
@@ -22,7 +22,13 @@ const char* ffDetectDisks(FFlist* disks)
FF_LIST_FOR_EACH(FFDisk, disk, *disks)
{
if(disk->bytesTotal == 0)
disk->type |= FF_DISK_TYPE_UNKNOWN_BIT;
disk->type |= FF_DISK_VOLUME_TYPE_UNKNOWN_BIT;
else
{
disk->bytesUsed = disk->bytesTotal - (
options->calcType == FF_DISK_CALC_TYPE_FREE ? disk->bytesFree : disk->bytesAvailable
);
}
}
return NULL;
+4 -2
View File
@@ -10,9 +10,11 @@ typedef struct FFDisk
FFstrbuf mountpoint;
FFstrbuf filesystem;
FFstrbuf name;
FFDiskType type;
FFDiskVolumeType type;
uint64_t bytesUsed;
uint64_t bytesFree;
uint64_t bytesAvailable;
uint64_t bytesTotal;
uint32_t filesUsed;
@@ -23,6 +25,6 @@ typedef struct FFDisk
* Returns a List of FFDisk, sorted alphabetically by mountpoint.
* If error is not set, disks contains at least one disk.
*/
const char* ffDetectDisks(FFlist* result /* list of FFDisk */);
const char* ffDetectDisks(FFDiskOptions* options, FFlist* result /* list of FFDisk */);
#endif
+3 -3
View File
@@ -7,11 +7,11 @@ void detectFsInfo(struct statfs* fs, FFDisk* disk)
{
// FreeBSD doesn't support these flags
if(fs->f_flags & MNT_DONTBROWSE)
disk->type = FF_DISK_TYPE_HIDDEN_BIT;
disk->type = FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
else if(fs->f_flags & MNT_REMOVABLE)
disk->type = FF_DISK_TYPE_EXTERNAL_BIT;
disk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT;
else
disk->type = FF_DISK_TYPE_REGULAR_BIT;
disk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT;
ffStrbufInitS(&disk->name, [NSFileManager.defaultManager displayNameAtPath:@(fs->f_mntonname)].UTF8String);
}
+11 -6
View File
@@ -10,15 +10,15 @@ static void detectFsInfo(struct statfs* fs, FFDisk* disk)
if(ffStrbufEqualS(&disk->filesystem, "zfs"))
{
disk->type = !ffStrStartsWith(fs->f_mntfromname, "zroot/") || ffStrStartsWith(fs->f_mntfromname, "zroot/ROOT/")
? FF_DISK_TYPE_REGULAR_BIT
: FF_DISK_TYPE_SUBVOLUME_BIT;
? FF_DISK_VOLUME_TYPE_REGULAR_BIT
: FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT;
}
else if(!ffStrStartsWith(fs->f_mntfromname, "/dev/"))
disk->type = FF_DISK_TYPE_HIDDEN_BIT;
disk->type = FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
else if(!(fs->f_flags & MNT_LOCAL))
disk->type = FF_DISK_TYPE_EXTERNAL_BIT;
disk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT;
else
disk->type = FF_DISK_TYPE_REGULAR_BIT;
disk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT;
ffStrbufInit(&disk->name);
}
@@ -45,7 +45,9 @@ const char* ffDetectDisksImpl(FFlist* disks)
#endif
disk->bytesTotal = fs->f_blocks * fs->f_bsize;
disk->bytesUsed = disk->bytesTotal - ((uint64_t)fs->f_bfree * fs->f_bsize);
disk->bytesFree = (uint64_t)fs->f_bfree * fs->f_bsize;
disk->bytesAvailable = (uint64_t)fs->f_bavail * fs->f_bsize;
disk->bytesUsed = 0; // To be filled in ./disk.c
disk->filesTotal = (uint32_t) fs->f_files;
disk->filesUsed = (uint32_t) (disk->filesTotal - (uint64_t)fs->f_ffree);
@@ -53,6 +55,9 @@ const char* ffDetectDisksImpl(FFlist* disks)
ffStrbufInitS(&disk->mountpoint, fs->f_mntonname);
ffStrbufInitS(&disk->filesystem, fs->f_fstypename);
detectFsInfo(fs, disk);
if(fs->f_flags & MNT_RDONLY)
disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
}
return NULL;
+13 -8
View File
@@ -155,11 +155,11 @@ static void detectName(FFDisk* disk, const FFstrbuf* device)
static void detectType(FF_MAYBE_UNUSED const FFlist* devices, FFDisk* currentDisk, FF_MAYBE_UNUSED const char* options)
{
if(ffStrbufEqualS(&currentDisk->mountpoint, "/") || ffStrbufEqualS(&currentDisk->mountpoint, "/storage/emulated"))
currentDisk->type = FF_DISK_TYPE_REGULAR_BIT;
currentDisk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT;
else if(ffStrbufStartsWithS(&currentDisk->mountpoint, "/mnt/media_rw/"))
currentDisk->type = FF_DISK_TYPE_EXTERNAL_BIT;
currentDisk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT;
else
currentDisk->type = FF_DISK_TYPE_HIDDEN_BIT;
currentDisk->type = FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
}
#else
@@ -191,13 +191,13 @@ static bool isSubvolume(const FFlist* devices)
static void detectType(const FFlist* devices, FFDisk* currentDisk, const char* options)
{
if(isSubvolume(devices))
currentDisk->type = FF_DISK_TYPE_SUBVOLUME_BIT;
currentDisk->type = FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT;
else if(strstr(options, "nosuid") != NULL || strstr(options, "nodev") != NULL)
currentDisk->type = FF_DISK_TYPE_EXTERNAL_BIT;
currentDisk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT;
else if(ffStrbufStartsWithS(&currentDisk->mountpoint, "/boot") || ffStrbufStartsWithS(&currentDisk->mountpoint, "/efi"))
currentDisk->type = FF_DISK_TYPE_HIDDEN_BIT;
currentDisk->type = FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
else
currentDisk->type = FF_DISK_TYPE_REGULAR_BIT;
currentDisk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT;
}
#endif
@@ -209,10 +209,15 @@ static void detectStats(FFDisk* disk)
memset(&fs, 0, sizeof(struct statvfs)); //Set all values to 0, so our values get initialized to 0 too
disk->bytesTotal = fs.f_blocks * fs.f_frsize;
disk->bytesUsed = disk->bytesTotal - (fs.f_bfree * fs.f_frsize);
disk->bytesFree = fs.f_bfree * fs.f_frsize;
disk->bytesAvailable = fs.f_bavail * fs.f_frsize;
disk->bytesUsed = 0; // To be filled in ./disk.c
disk->filesTotal = (uint32_t) fs.f_files;
disk->filesUsed = (uint32_t) (disk->filesTotal - fs.f_ffree);
if(fs.f_flag & ST_RDONLY)
disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
}
const char* ffDetectDisksImpl(FFlist* disks)
+16 -8
View File
@@ -25,20 +25,25 @@ const char* ffDetectDisksImpl(FFlist* disks)
FFDisk* disk = ffListAdd(disks);
ffStrbufInitWS(&disk->mountpoint, mountpoint);
uint64_t bytesFree;
if(!GetDiskFreeSpaceExW(mountpoint, NULL, (PULARGE_INTEGER)&disk->bytesTotal, (PULARGE_INTEGER)&bytesFree))
if(!GetDiskFreeSpaceExW(
mountpoint,
(PULARGE_INTEGER)&disk->bytesAvailable,
(PULARGE_INTEGER)&disk->bytesTotal,
(PULARGE_INTEGER)&disk->bytesFree
))
{
disk->bytesTotal = 0;
bytesFree = 0;
disk->bytesFree = 0;
disk->bytesAvailable = 0;
}
disk->bytesUsed = disk->bytesTotal - bytesFree;
disk->bytesUsed = 0; // To be filled in ./disk.c
if(driveType == DRIVE_REMOVABLE || driveType == DRIVE_REMOTE || driveType == DRIVE_CDROM)
disk->type = FF_DISK_TYPE_EXTERNAL_BIT;
disk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT;
else if(driveType == DRIVE_FIXED)
disk->type = FF_DISK_TYPE_REGULAR_BIT;
disk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT;
else
disk->type = FF_DISK_TYPE_HIDDEN_BIT;
disk->type = FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
ffStrbufInit(&disk->filesystem);
ffStrbufInit(&disk->name);
@@ -47,11 +52,12 @@ const char* ffDetectDisksImpl(FFlist* disks)
//https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumeinformationa#remarks
UINT errorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
DWORD diskFlags;
BOOL result = GetVolumeInformationW(mountpoint,
diskName, sizeof(diskName) / sizeof(*diskName), //Volume name
NULL, //Serial number
NULL, //Max component length
NULL, //File system flags
&diskFlags, //File system flags
diskFileSystem, sizeof(diskFileSystem) / sizeof(*diskFileSystem)
);
SetErrorMode(errorMode);
@@ -60,6 +66,8 @@ const char* ffDetectDisksImpl(FFlist* disks)
{
ffStrbufSetWS(&disk->filesystem, diskFileSystem);
ffStrbufSetWS(&disk->name, diskName);
if(diskFlags & FILE_READ_ONLY_VOLUME)
disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
}
//Unsupported
+11 -4
View File
@@ -116,6 +116,7 @@ typedef struct XrandrData
{
FF_LIBRARY_SYMBOL(XInternAtom)
FF_LIBRARY_SYMBOL(XGetAtomName);
FF_LIBRARY_SYMBOL(XFree);
FF_LIBRARY_SYMBOL(XRRGetScreenInfo)
FF_LIBRARY_SYMBOL(XRRConfigCurrentConfiguration)
FF_LIBRARY_SYMBOL(XRRConfigCurrentRate)
@@ -207,9 +208,11 @@ static bool xrandrHandleOutput(XrandrData* data, RROutput output, FFstrbuf* name
Atom atomEdid = data->ffXInternAtom(data->display, "EDID", true);
if (atomEdid != None)
{
unsigned long nitems = 0;
int actual_format = 0;
unsigned long nitems = 0, bytes_after = 0;
Atom actual_type = None;
uint8_t* edidData = NULL;
if (data->ffXRRGetOutputProperty(data->display, output, atomEdid, 0, 100, 0, 0, AnyPropertyType, NULL, NULL, &nitems, NULL, &edidData) == Success)
if (data->ffXRRGetOutputProperty(data->display, output, atomEdid, 0, 100, false, false, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &edidData) == Success)
{
if (nitems >= 128)
{
@@ -217,6 +220,8 @@ static bool xrandrHandleOutput(XrandrData* data, RROutput output, FFstrbuf* name
ffEdidGetName(edidData, name);
}
}
if (edidData)
data->ffXFree(edidData);
}
bool res = xrandrHandleCrtc(data, outputInfo->crtc, name, primary);
@@ -228,8 +233,9 @@ static bool xrandrHandleOutput(XrandrData* data, RROutput output, FFstrbuf* name
static bool xrandrHandleMonitor(XrandrData* data, XRRMonitorInfo* monitorInfo)
{
bool foundOutput = false;
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreateS(data->ffXGetAtomName(data->display, monitorInfo->name));
char* xname = data->ffXGetAtomName(data->display, monitorInfo->name);
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreateS(xname);
data->ffXFree(xname);
for(int i = 0; i < monitorInfo->noutput; i++)
{
if(xrandrHandleOutput(data, monitorInfo->outputs[i], &name, monitorInfo->primary))
@@ -341,6 +347,7 @@ void ffdsConnectXrandr(FFDisplayServerResult* result)
FF_LIBRARY_LOAD_SYMBOL_VAR(xrandr, data, XInternAtom,);
FF_LIBRARY_LOAD_SYMBOL_VAR(xrandr, data, XGetAtomName,);
FF_LIBRARY_LOAD_SYMBOL_VAR(xrandr, data, XFree,);
FF_LIBRARY_LOAD_SYMBOL_VAR(xrandr, data, XRRGetScreenInfo,)
FF_LIBRARY_LOAD_SYMBOL_VAR(xrandr, data, XRRConfigCurrentRate,);
FF_LIBRARY_LOAD_SYMBOL_VAR(xrandr, data, XRRConfigCurrentConfiguration,);
+1 -1
View File
@@ -3,7 +3,7 @@
const char* ffDetectMemory(FFMemoryResult* ram)
{
uint64_t length = sizeof(ram->bytesTotal);
size_t length = sizeof(ram->bytesTotal);
if (sysctl((int[]){ CTL_HW, HW_PHYSMEM }, 2, &ram->bytesTotal, &length, NULL, 0))
return "Failed to read hw.physmem";
+2 -1
View File
@@ -1205,7 +1205,8 @@ static void parseArguments(FFdata* data, int argc, const char** argv)
}
if(i == argc - 1 || (
*argv[i + 1] == '-' &&
argv[i + 1][0] == '-' &&
argv[i + 1][1] != '\0' && // `-` is used as an alias for `/dev/stdin`
strcasecmp(argv[i], "--separator-string") != 0 // Separator string can start with a -
)) {
parseOption(data, argv[i], NULL);
+4 -1
View File
@@ -359,7 +359,10 @@ static bool logoPrintFileIfExists(bool doColorReplacement, bool raw)
FF_STRBUF_AUTO_DESTROY content = ffStrbufCreate();
if(!ffAppendFileBuffer(options->source.chars, &content))
if(ffStrbufEqualS(&options->source, "-")
? !ffAppendFDBuffer(FFUnixFD2NativeFD(STDIN_FILENO), &content)
: !ffAppendFileBuffer(options->source.chars, &content)
)
{
fprintf(stderr, "Logo: Failed to load file content from logo source: %s \n", options->source.chars);
return false;
+1 -1
View File
@@ -126,7 +126,7 @@ logoType:
ffOptionParseString(key, value, &options->source);
options->type = FF_LOGO_TYPE_FILE;
}
else if(strcasecmp(key, "raw") == 0)
else if(strcasecmp(subKey, "raw") == 0)
{
ffOptionParseString(key, value, &options->source);
options->type = FF_LOGO_TYPE_FILE_RAW;
+1 -1
View File
@@ -31,7 +31,7 @@ void ffPrintCursor(FFCursorOptions* options)
ffPrintLogoAndKey(FF_CURSOR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffStrbufWriteTo(&result.theme, stdout);
if(result.size.length > 0)
if(result.size.length > 0 && !ffStrbufEqualS(&result.size, "0"))
printf(" (%spx)", result.size.chars);
putchar('\n');
+79 -30
View File
@@ -79,12 +79,22 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
if(disk->filesystem.length)
ffStrbufAppendF(&str, "- %s ", disk->filesystem.chars);
if(disk->type & FF_DISK_TYPE_EXTERNAL_BIT)
ffStrbufAppendS(&str, "[External]");
else if(disk->type & FF_DISK_TYPE_SUBVOLUME_BIT)
ffStrbufAppendS(&str, "[Subvolume]");
else if(disk->type & FF_DISK_TYPE_HIDDEN_BIT)
ffStrbufAppendS(&str, "[Hidden]");
ffStrbufAppendC(&str, '[');
if(disk->type & FF_DISK_VOLUME_TYPE_EXTERNAL_BIT)
ffStrbufAppendS(&str, "External, ");
if(disk->type & FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT)
ffStrbufAppendS(&str, "Subvolume, ");
if(disk->type & FF_DISK_VOLUME_TYPE_HIDDEN_BIT)
ffStrbufAppendS(&str, "Hidden, ");
if(disk->type & FF_DISK_VOLUME_TYPE_READONLY_BIT)
ffStrbufAppendS(&str, "Read-only, ");
if (str.chars[str.length - 1] == '[')
ffStrbufSubstrBefore(&str, str.length - 1);
else
{
ffStrbufTrimRight(&str, ' ');
str.chars[str.length - 1] = ']';
}
}
ffStrbufTrimRight(&str, ' ');
@@ -98,8 +108,9 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
double filesPercentage = disk->filesTotal > 0 ? ((double) disk->filesUsed / (double) disk->filesTotal) * 100.0 : 0;
ffAppendPercentNum(&filesPercentageStr, filesPercentage, 50, 80, false);
bool isExternal = !!(disk->type & FF_DISK_TYPE_EXTERNAL_BIT);
bool isHidden = !!(disk->type & FF_DISK_TYPE_HIDDEN_BIT);
bool isExternal = !!(disk->type & FF_DISK_VOLUME_TYPE_EXTERNAL_BIT);
bool isHidden = !!(disk->type & FF_DISK_VOLUME_TYPE_HIDDEN_BIT);
bool isReadOnly = !!(disk->type & FF_DISK_VOLUME_TYPE_READONLY_BIT);
ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_DISK_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty},
{FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty},
@@ -110,7 +121,8 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
{FF_FORMAT_ARG_TYPE_BOOL, &isExternal},
{FF_FORMAT_ARG_TYPE_BOOL, &isHidden},
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->filesystem},
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->name}
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->name},
{FF_FORMAT_ARG_TYPE_BOOL, &isReadOnly},
});
}
}
@@ -156,7 +168,7 @@ static void printAutodetected(FFDiskOptions* options, const FFlist* disks)
{
FF_LIST_FOR_EACH(FFDisk, disk, *disks)
{
if(!(disk->type & options->showTypes))
if(disk->type & ~options->showTypes)
continue;
printDisk(options, disk);
@@ -166,7 +178,7 @@ static void printAutodetected(FFDiskOptions* options, const FFlist* disks)
void ffPrintDisk(FFDiskOptions* options)
{
FF_LIST_AUTO_DESTROY disks = ffListCreate(sizeof (FFDisk));
const char* error = ffDetectDisks(&disks);
const char* error = ffDetectDisks(options, &disks);
if(error)
{
@@ -194,7 +206,8 @@ void ffInitDiskOptions(FFDiskOptions* options)
ffOptionInitModuleArg(&options->moduleArgs);
ffStrbufInit(&options->folders);
options->showTypes = FF_DISK_TYPE_REGULAR_BIT | FF_DISK_TYPE_EXTERNAL_BIT;
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;
}
bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const char* value)
@@ -213,45 +226,63 @@ bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const ch
if (ffStrEqualsIgnCase(subKey, "show-regular"))
{
if (ffOptionParseBoolean(value))
options->showTypes |= FF_DISK_TYPE_REGULAR_BIT;
options->showTypes |= FF_DISK_VOLUME_TYPE_REGULAR_BIT;
else
options->showTypes &= ~FF_DISK_TYPE_REGULAR_BIT;
options->showTypes &= ~FF_DISK_VOLUME_TYPE_REGULAR_BIT;
return true;
}
if (ffStrEqualsIgnCase(subKey, "show-external"))
{
if (ffOptionParseBoolean(value))
options->showTypes |= FF_DISK_TYPE_EXTERNAL_BIT;
options->showTypes |= FF_DISK_VOLUME_TYPE_EXTERNAL_BIT;
else
options->showTypes &= ~FF_DISK_TYPE_EXTERNAL_BIT;
options->showTypes &= ~FF_DISK_VOLUME_TYPE_EXTERNAL_BIT;
return true;
}
if (ffStrEqualsIgnCase(subKey, "show-hidden"))
{
if (ffOptionParseBoolean(value))
options->showTypes |= FF_DISK_TYPE_HIDDEN_BIT;
options->showTypes |= FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
else
options->showTypes &= ~FF_DISK_TYPE_HIDDEN_BIT;
options->showTypes &= ~FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
return true;
}
if (ffStrEqualsIgnCase(subKey, "show-subvolumes"))
{
if (ffOptionParseBoolean(value))
options->showTypes |= FF_DISK_TYPE_SUBVOLUME_BIT;
options->showTypes |= FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT;
else
options->showTypes &= ~FF_DISK_TYPE_SUBVOLUME_BIT;
options->showTypes &= ~FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT;
return true;
}
if (ffStrEqualsIgnCase(subKey, "show-readonly"))
{
if (ffOptionParseBoolean(value))
options->showTypes |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
else
options->showTypes &= ~FF_DISK_VOLUME_TYPE_READONLY_BIT;
return true;
}
if (ffStrEqualsIgnCase(subKey, "show-unknown"))
{
if (ffOptionParseBoolean(value))
options->showTypes |= FF_DISK_TYPE_UNKNOWN_BIT;
options->showTypes |= FF_DISK_VOLUME_TYPE_UNKNOWN_BIT;
else
options->showTypes &= ~FF_DISK_TYPE_UNKNOWN_BIT;
options->showTypes &= ~FF_DISK_VOLUME_TYPE_UNKNOWN_BIT;
return true;
}
if (ffStrEqualsIgnCase(subKey, "use-available"))
{
if (ffOptionParseBoolean(value))
options->calcType = FF_DISK_CALC_TYPE_AVAILABLE;
else
options->calcType = FF_DISK_CALC_TYPE_FREE;
return true;
}
@@ -285,36 +316,54 @@ void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module)
if (ffStrEqualsIgnCase(key, "showExternal"))
{
if (yyjson_get_bool(val))
options->showTypes |= FF_DISK_TYPE_EXTERNAL_BIT;
options->showTypes |= FF_DISK_VOLUME_TYPE_EXTERNAL_BIT;
else
options->showTypes &= ~FF_DISK_TYPE_EXTERNAL_BIT;
options->showTypes &= ~FF_DISK_VOLUME_TYPE_EXTERNAL_BIT;
continue;
}
if (ffStrEqualsIgnCase(key, "showHidden"))
{
if (yyjson_get_bool(val))
options->showTypes |= FF_DISK_TYPE_HIDDEN_BIT;
options->showTypes |= FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
else
options->showTypes &= ~FF_DISK_TYPE_HIDDEN_BIT;
options->showTypes &= ~FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
continue;
}
if (ffStrEqualsIgnCase(key, "showSubvolumes"))
{
if (yyjson_get_bool(val))
options->showTypes |= FF_DISK_TYPE_SUBVOLUME_BIT;
options->showTypes |= FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT;
else
options->showTypes &= ~FF_DISK_TYPE_SUBVOLUME_BIT;
options->showTypes &= ~FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT;
continue;
}
if (ffStrEqualsIgnCase(key, "showReadOnly"))
{
if (yyjson_get_bool(val))
options->showTypes |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
else
options->showTypes &= ~FF_DISK_VOLUME_TYPE_READONLY_BIT;
continue;
}
if (ffStrEqualsIgnCase(key, "showUnknown"))
{
if (yyjson_get_bool(val))
options->showTypes |= FF_DISK_TYPE_UNKNOWN_BIT;
options->showTypes |= FF_DISK_VOLUME_TYPE_UNKNOWN_BIT;
else
options->showTypes &= ~FF_DISK_TYPE_UNKNOWN_BIT;
options->showTypes &= ~FF_DISK_VOLUME_TYPE_UNKNOWN_BIT;
continue;
}
if (ffStrEqualsIgnCase(key, "useAvailable"))
{
if (yyjson_get_bool(val))
options->calcType = FF_DISK_CALC_TYPE_AVAILABLE;
else
options->calcType = FF_DISK_CALC_TYPE_FREE;
continue;
}
+17 -9
View File
@@ -4,15 +4,22 @@
#include "common/option.h"
typedef enum FFDiskType
typedef enum FFDiskVolumeType
{
FF_DISK_TYPE_NONE = 0,
FF_DISK_TYPE_REGULAR_BIT = 1 << 0,
FF_DISK_TYPE_HIDDEN_BIT = 1 << 1,
FF_DISK_TYPE_EXTERNAL_BIT = 1 << 2,
FF_DISK_TYPE_SUBVOLUME_BIT = 1 << 3,
FF_DISK_TYPE_UNKNOWN_BIT = 1 << 4,
} FFDiskType;
FF_DISK_VOLUME_TYPE_NONE = 0,
FF_DISK_VOLUME_TYPE_REGULAR_BIT = 1 << 0,
FF_DISK_VOLUME_TYPE_HIDDEN_BIT = 1 << 1,
FF_DISK_VOLUME_TYPE_EXTERNAL_BIT = 1 << 2,
FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT = 1 << 3,
FF_DISK_VOLUME_TYPE_UNKNOWN_BIT = 1 << 4,
FF_DISK_VOLUME_TYPE_READONLY_BIT = 1 << 5,
} FFDiskVolumeType;
typedef enum FFDiskCalcType
{
FF_DISK_CALC_TYPE_FREE,
FF_DISK_CALC_TYPE_AVAILABLE,
} FFDiskCalcType;
typedef struct FFDiskOptions
{
@@ -20,5 +27,6 @@ typedef struct FFDiskOptions
FFModuleArgs moduleArgs;
FFstrbuf folders;
FFDiskType showTypes;
FFDiskVolumeType showTypes;
FFDiskCalcType calcType;
} FFDiskOptions;