Make the (new and old) download code UTF-8 compatible.

- Replace all remove() with Sys_Remove().
- Implement Sys_Rename() and replace all rename() with it.

This is believed to close #348.
This commit is contained in:
Yamagi Burmeister 2018-12-18 19:11:39 +01:00
parent 49bb6bf9f0
commit 5b44c9f3b4
5 changed files with 26 additions and 6 deletions

View file

@ -487,6 +487,12 @@ Sys_Remove(const char *path)
remove(path);
}
int
Sys_Rename(const char *from, const char *to)
{
return rename(from, to);
}
/* ================================================================ */
void *

View file

@ -535,6 +535,7 @@ Sys_GetHomeDir(void)
return gdir;
}
void
Sys_Remove(const char *path)
{
WCHAR wpath[MAX_OSPATH] = {0};
@ -543,6 +544,18 @@ Sys_Remove(const char *path)
_wremove(wpath);
}
int
Sys_Rename(const char *from, const char *to)
{
WCHAR wfrom[MAX_OSPATH] = {0};
MultiByteToWideChar(CP_UTF8, 0, from, -1, wfrom, MAX_OSPATH);
WCHAR wto[MAX_OSPATH] = {0};
MultiByteToWideChar(CP_UTF8, 0, to, -1, wto, MAX_OSPATH);
return _wrename(wfrom, wto);
}
/* ======================================================================= */
void *

View file

@ -655,7 +655,7 @@ CL_ParseDownload(void)
/* rename the temp file to it's final name */
CL_DownloadFileName(oldn, sizeof(oldn), cls.downloadtempname);
CL_DownloadFileName(newn, sizeof(newn), cls.downloadname);
r = rename(oldn, newn);
r = Sys_Rename(oldn, newn);
if (r)
{

View file

@ -578,7 +578,7 @@ static void CL_FinishHTTPDownload(void)
// We got a 404, remove the target file.
if (isFile)
{
remove(dl->filePath);
Sys_Remove(dl->filePath);
isFile = false;
}
@ -616,7 +616,7 @@ static void CL_FinishHTTPDownload(void)
// The download failed. Remove the temporary file...
if (isFile)
{
remove(dl->filePath);
Sys_Remove(dl->filePath);
isFile = false;
}
@ -645,7 +645,7 @@ static void CL_FinishHTTPDownload(void)
// The download failed. Remove the temporary file...
if (isFile)
{
remove(dl->filePath);
Sys_Remove(dl->filePath);
isFile = false;
}
@ -661,7 +661,7 @@ static void CL_FinishHTTPDownload(void)
{
// Rename the temporary file to it's final location
Com_sprintf(tempName, sizeof(tempName), "%s/%s", FS_Gamedir(), dl->queueEntry->quakePath);
rename(dl->filePath, tempName);
Sys_Rename(dl->filePath, tempName);
// Pak files are special because they contain
// other files that we may be downloading...
@ -790,7 +790,7 @@ void CL_HTTP_Cleanup(qboolean fullShutdown)
if (dl->file)
{
fclose (dl->file);
remove (dl->filePath);
Sys_Remove (dl->filePath);
dl->file = NULL;
}

View file

@ -784,6 +784,7 @@ void Sys_Quit(void);
void Sys_Init(void);
char *Sys_GetHomeDir(void);
void Sys_Remove(const char *path);
int Sys_Rename(const char *from, const char *to);
long long Sys_Microseconds(void);
void Sys_Nanosleep(int);
void *Sys_GetProcAddress(void *handle, const char *sym);