added windows implementation of sys_removedir and used snprintf in the unix one

This commit is contained in:
Jonathan Bergeron 2019-01-04 13:20:17 -05:00 committed by Daniel Gibson
parent 867046bb8b
commit d82708b448
2 changed files with 32 additions and 1 deletions

View file

@ -504,7 +504,7 @@ Sys_RemoveDir(const char *path)
{
while ((file = readdir(directory)) != NULL)
{
sprintf(filepath, "%s/%s", path, file->d_name);
snprintf(filepath, MAX_OSPATH, "%s/%s", path, file->d_name);
Sys_Remove(filepath);
}

View file

@ -556,6 +556,37 @@ Sys_Rename(const char *from, const char *to)
return _wrename(wfrom, wto);
}
void
Sys_RemoveDir(const char *path)
{
WCHAR wpath[MAX_OSPATH] = {0};
WCHAR wpathwithwildcard[MAX_OSPATH] = {0};
WCHAR wpathwithfilename[MAX_OSPATH] = {0};
WIN32_FIND_DATAW fd;
MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, MAX_OSPATH);
wcscat_s(wpathwithwildcard, MAX_OSPATH, wpath);
wcscat_s(wpathwithwildcard, MAX_OSPATH, L"\\*.*");
HANDLE hFind = FindFirstFileW(wpathwithwildcard, &fd);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
wmemset(wpathwithfilename, 0, MAX_OSPATH);
wcscat_s(wpathwithfilename, MAX_OSPATH, wpath);
wcscat_s(wpathwithfilename, MAX_OSPATH, fd.cFileName);
DeleteFileW(wpathwithfilename);
}
while (FindNextFileW(hFind, &fd));
FindClose(hFind);
}
RemoveDirectoryW(wpath);
}
/* ======================================================================= */
void *