2022-10-09 19:47:13 +08:00
|
|
|
#include "disk.h"
|
|
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN 1
|
2022-10-17 13:19:48 +02:00
|
|
|
#include <windows.h>
|
2022-10-09 19:47:13 +08:00
|
|
|
|
2022-10-17 13:19:48 +02:00
|
|
|
void ffDetectDisksImpl(FFDiskResult* disks)
|
2022-10-09 19:47:13 +08:00
|
|
|
{
|
2022-10-17 13:19:48 +02:00
|
|
|
uint32_t length = GetLogicalDriveStringsA(0, NULL);
|
|
|
|
|
if(length == 0)
|
|
|
|
|
{
|
|
|
|
|
ffStrbufAppendS(&disks->error, "GetLogicalDriveStringsA failed");
|
|
|
|
|
return;
|
2022-10-09 19:47:13 +08:00
|
|
|
}
|
|
|
|
|
|
2022-10-17 17:35:06 +02:00
|
|
|
char* buf = malloc(length + 1);
|
2022-10-17 13:19:48 +02:00
|
|
|
GetLogicalDriveStringsA(length, buf);
|
2022-10-09 19:47:13 +08:00
|
|
|
|
2022-10-17 13:19:48 +02:00
|
|
|
for(uint32_t i = 0; i < length; i++)
|
2022-10-09 19:47:13 +08:00
|
|
|
{
|
2022-10-17 13:19:48 +02:00
|
|
|
const char* mountpoint = buf + i;
|
2022-10-09 19:47:13 +08:00
|
|
|
|
2022-10-17 13:19:48 +02:00
|
|
|
UINT driveType = GetDriveTypeA(mountpoint);
|
|
|
|
|
if(driveType == DRIVE_NO_ROOT_DIR)
|
|
|
|
|
{
|
|
|
|
|
i += strlen(mountpoint);
|
2022-10-09 19:47:13 +08:00
|
|
|
continue;
|
2022-10-17 13:19:48 +02:00
|
|
|
}
|
2022-10-09 19:47:13 +08:00
|
|
|
|
2022-10-17 13:19:48 +02:00
|
|
|
FFDisk* disk = ffListAdd(&disks->disks);
|
|
|
|
|
ffStrbufInitS(&disk->mountpoint, mountpoint);
|
2022-10-09 19:47:13 +08:00
|
|
|
|
2022-10-17 13:19:48 +02:00
|
|
|
uint64_t bytesFree;
|
|
|
|
|
if(!GetDiskFreeSpaceExA(mountpoint, NULL, (PULARGE_INTEGER)&disk->bytesTotal, (PULARGE_INTEGER)&bytesFree))
|
|
|
|
|
{
|
|
|
|
|
disk->bytesTotal = 0;
|
|
|
|
|
bytesFree = 0;
|
|
|
|
|
}
|
|
|
|
|
disk->bytesUsed = disk->bytesTotal - bytesFree;
|
2022-10-09 19:47:13 +08:00
|
|
|
|
2022-10-17 13:19:48 +02:00
|
|
|
if(driveType == DRIVE_REMOVABLE || driveType == DRIVE_REMOTE || driveType == DRIVE_CDROM)
|
|
|
|
|
disk->type = FF_DISK_TYPE_EXTERNAL;
|
|
|
|
|
else if(driveType == DRIVE_FIXED)
|
|
|
|
|
disk->type = FF_DISK_TYPE_REGULAR;
|
|
|
|
|
else
|
|
|
|
|
disk->type = FF_DISK_TYPE_HIDDEN;
|
2022-10-09 19:47:13 +08:00
|
|
|
|
2022-10-17 13:19:48 +02:00
|
|
|
ffStrbufInitA(&disk->filesystem, MAX_PATH + 1);
|
|
|
|
|
GetVolumeInformationA(mountpoint
|
|
|
|
|
NULL, 0, //Volume name
|
|
|
|
|
NULL, //Serial number
|
|
|
|
|
NULL, //Max component length
|
|
|
|
|
NULL, //File system flags
|
|
|
|
|
disk->filesystem.chars, ffStrbufGetFree(&disk->filesystem)
|
|
|
|
|
);
|
|
|
|
|
ffStrbufRecalculateLength(&disk->filesystem);
|
2022-10-09 19:47:13 +08:00
|
|
|
|
2022-10-17 13:19:48 +02:00
|
|
|
//TODO: implement
|
|
|
|
|
disk->filesUsed = 0;
|
|
|
|
|
disk->filesTotal = 0;
|
2022-10-09 19:47:13 +08:00
|
|
|
|
2022-10-17 13:19:48 +02:00
|
|
|
i += disk->mountpoint.length;
|
2022-10-09 19:47:13 +08:00
|
|
|
}
|
|
|
|
|
|
2022-10-17 13:19:48 +02:00
|
|
|
free(buff);
|
2022-10-09 19:47:13 +08:00
|
|
|
}
|