libobs/util: Add function to get free space

Meant as a part of solving mantis issue 105 ("Disk space usage monitor
when recording").

From pull request: jp9000/obs-studio#374
Relevant mantis issue: https://obsproject.com/mantis/view.php?id=105
This commit is contained in:
adray
2015-02-20 22:52:13 +00:00
committed by jp9000
parent 3e6db990fc
commit e354a433c7
3 changed files with 32 additions and 0 deletions

View File

@@ -362,6 +362,25 @@ void os_closedir(os_dir_t *dir)
}
}
int64_t os_get_free_space(const char *path)
{
ULARGE_INTEGER remainingSpace;
char abs_path[512];
wchar_t w_abs_path[512];
if (os_get_abs_path(path, abs_path, 512) > 0) {
if (os_utf8_to_wcs(abs_path, 0, w_abs_path, 512) > 0) {
BOOL success = GetDiskFreeSpaceExW(w_abs_path,
(PULARGE_INTEGER)&remainingSpace,
NULL, NULL);
if (success)
return (int64_t)remainingSpace.QuadPart;
}
}
return -1;
}
static void make_globent(struct os_globent *ent, WIN32_FIND_DATA *wfd,
const char *pattern)
{