mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-12-05 06:22:18 +00:00
Windows fixed volume reporting
This commit is contained in:
1 file changed
+79
-28
@@ -544,49 +544,100 @@ sysinfo_backend_get_memory (void)
|
|||||||
return format_usage ((guint64) memory.ullTotalPhys, (guint64) memory.ullAvailPhys);
|
return format_usage ((guint64) memory.ullTotalPhys, (guint64) memory.ullAvailPhys);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
static char *
|
||||||
sysinfo_backend_get_disk (void)
|
get_system_volume_usage (void)
|
||||||
{
|
{
|
||||||
WCHAR windows_dir[MAX_PATH];
|
WCHAR windows_dir[MAX_PATH];
|
||||||
WCHAR volume_path[MAX_PATH];
|
WCHAR volume_path[MAX_PATH];
|
||||||
ULARGE_INTEGER available;
|
ULARGE_INTEGER available, total, total_free;
|
||||||
ULARGE_INTEGER total;
|
UINT length;
|
||||||
ULARGE_INTEGER total_free;
|
char *usage, *result;
|
||||||
char *usage;
|
|
||||||
char *volume_utf8;
|
|
||||||
char *result;
|
|
||||||
|
|
||||||
if (GetWindowsDirectoryW (windows_dir, G_N_ELEMENTS (windows_dir)) == 0)
|
length = GetWindowsDirectoryW (windows_dir, G_N_ELEMENTS (windows_dir));
|
||||||
{
|
if (!length || length >= G_N_ELEMENTS (windows_dir))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
if (!GetVolumePathNameW (windows_dir, volume_path, G_N_ELEMENTS (volume_path)))
|
if (!GetVolumePathNameW (windows_dir, volume_path, G_N_ELEMENTS (volume_path)))
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
if (GetDriveTypeW (volume_path) != DRIVE_FIXED ||
|
||||||
if (!GetDiskFreeSpaceExW (volume_path, &available, &total, &total_free))
|
!GetDiskFreeSpaceExW (volume_path, &available, &total, &total_free))
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
usage = format_usage ((guint64) total.QuadPart, (guint64) available.QuadPart);
|
usage = format_usage ((guint64) total.QuadPart, (guint64) available.QuadPart);
|
||||||
if (!usage)
|
if (!usage)
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
result = g_strdup_printf ("%s (system volume only)", usage);
|
||||||
|
|
||||||
volume_utf8 = wide_to_utf8 (volume_path);
|
|
||||||
if (!volume_utf8)
|
|
||||||
{
|
|
||||||
return usage;
|
|
||||||
}
|
|
||||||
g_strchomp (volume_utf8);
|
|
||||||
result = g_strdup_printf ("%s" SYSINFO_SEP "%s", usage, volume_utf8);
|
|
||||||
g_free (volume_utf8);
|
|
||||||
g_free (usage);
|
g_free (usage);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
sysinfo_backend_get_disk (void)
|
||||||
|
{
|
||||||
|
DWORD drives = GetLogicalDrives ();
|
||||||
|
DWORD previous_mode = 0;
|
||||||
|
BOOL error_mode_changed;
|
||||||
|
guint i;
|
||||||
|
guint64 total = 0, available = 0;
|
||||||
|
GHashTable *seen = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||||
|
char *usage, *result;
|
||||||
|
|
||||||
|
/* Offline or empty local devices must not open a system error dialog. */
|
||||||
|
error_mode_changed = SetThreadErrorMode (GetThreadErrorMode () | SEM_FAILCRITICALERRORS, &previous_mode);
|
||||||
|
for (i = 0; i < 26; i++)
|
||||||
|
{
|
||||||
|
WCHAR root[] = L"A:\\";
|
||||||
|
WCHAR volume[MAX_PATH];
|
||||||
|
ULARGE_INTEGER caller_free, caller_total, total_free;
|
||||||
|
char *key;
|
||||||
|
|
||||||
|
if (!(drives & (1UL << i)))
|
||||||
|
continue;
|
||||||
|
root[0] = (WCHAR) (L'A' + i);
|
||||||
|
/* Don't query mapped network shares or removable media. */
|
||||||
|
if (GetDriveTypeW (root) != DRIVE_FIXED)
|
||||||
|
continue;
|
||||||
|
/* A stable volume GUID deduplicates aliases. SUBST paths without a
|
||||||
|
* volume GUID are deliberately skipped rather than double-counted. */
|
||||||
|
if (!GetVolumeNameForVolumeMountPointW (root, volume, G_N_ELEMENTS (volume)))
|
||||||
|
continue;
|
||||||
|
key = wide_to_utf8 (volume);
|
||||||
|
if (!key)
|
||||||
|
continue;
|
||||||
|
{
|
||||||
|
char *lower = g_ascii_strdown (key, -1);
|
||||||
|
g_free (key);
|
||||||
|
key = lower;
|
||||||
|
}
|
||||||
|
if (g_hash_table_contains (seen, key) ||
|
||||||
|
!GetDiskFreeSpaceExW (root, &caller_free, &caller_total, &total_free) ||
|
||||||
|
!caller_total.QuadPart)
|
||||||
|
{
|
||||||
|
g_free (key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ((guint64) caller_total.QuadPart > G_MAXUINT64 - total)
|
||||||
|
{
|
||||||
|
g_free (key);
|
||||||
|
total = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
g_hash_table_add (seen, key);
|
||||||
|
total += (guint64) caller_total.QuadPart;
|
||||||
|
available += MIN ((guint64) caller_free.QuadPart, (guint64) caller_total.QuadPart);
|
||||||
|
}
|
||||||
|
g_hash_table_unref (seen);
|
||||||
|
usage = format_usage (total, available);
|
||||||
|
if (!usage)
|
||||||
|
result = get_system_volume_usage ();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = g_strdup_printf ("%s (fixed volumes)", usage);
|
||||||
|
g_free (usage);
|
||||||
|
}
|
||||||
|
if (error_mode_changed)
|
||||||
|
SetThreadErrorMode (previous_mode, NULL);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
sysinfo_backend_get_uptime (void)
|
sysinfo_backend_get_uptime (void)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user