Sdldraganddrop utf8 on windows
https://github.com/Indev450/SRB2Kart-Saturn/pull/60/
This commit is contained in:
parent
327e1e2f13
commit
90bcbd9944
2 changed files with 37 additions and 3 deletions
|
|
@ -1191,7 +1191,7 @@ void I_GetEvent(void)
|
|||
break;
|
||||
case SDL_DROPFILE:
|
||||
dropped_filedir = evt.drop.file;
|
||||
P_AddWadFile(dropped_filedir);
|
||||
P_AddWadFile(dropped_filedir, WC_AUTO);
|
||||
SDL_free(dropped_filedir); // Free dropped_filedir memory
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
|
|
|
|||
38
src/w_wad.c
38
src/w_wad.c
|
|
@ -149,6 +149,40 @@ void W_Shutdown(void)
|
|||
|
||||
static char filenamebuf[MAX_WADPATH];
|
||||
|
||||
// This #if is copied from filesrch.c, so not sure if it is 100% suitable for
|
||||
// this
|
||||
#if defined (_WIN32) && !defined (_XBOX)
|
||||
//#define WIN32_LEAN_AND_MEAN
|
||||
#define RPC_NO_WINDOWS_H
|
||||
#include <windows.h>
|
||||
|
||||
// Windows can't open utf-8 path so it must be converted to utf-16
|
||||
FILE* fopen_utf8(const char* filename, const char* mode)
|
||||
{
|
||||
static const int MY_PATH_MAX = 2048;
|
||||
WCHAR nameW[MY_PATH_MAX];
|
||||
memset(nameW, 0, sizeof(WCHAR)*MY_PATH_MAX);
|
||||
WCHAR modeW[16];
|
||||
memset(modeW, 0, sizeof(WCHAR)*16);
|
||||
// the following function converts the UTF-8 filename to UTF-16 (WCHAR) nameW
|
||||
int len = MultiByteToWideChar(CP_UTF8, 0, filename, -1, nameW, MY_PATH_MAX);
|
||||
if(len > 0 && MultiByteToWideChar(CP_UTF8, 0, mode, -1, modeW, 16) > 0)
|
||||
{
|
||||
// using _wfopen_s() shuts up MSVC's complaints
|
||||
// about _wfopen() being unsafe..
|
||||
FILE* ret = NULL;
|
||||
if(_wfopen_s(&ret, nameW, modeW) == 0)
|
||||
return ret;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define fopen_utf8 fopen
|
||||
|
||||
#endif
|
||||
|
||||
// W_OpenWadFile
|
||||
// Helper function for opening the WAD file.
|
||||
// Returns the FILE * handle for the file, or NULL if not found or could not be opened
|
||||
|
|
@ -169,7 +203,7 @@ FILE *W_OpenWadFile(const char **filename, boolean useerrors)
|
|||
}
|
||||
|
||||
// open wad file
|
||||
if ((handle = fopen(*filename, "rb")) == NULL)
|
||||
if ((handle = fopen_utf8(*filename, "rb")) == NULL)
|
||||
{
|
||||
// If we failed to load the file with the path as specified by
|
||||
// the user, strip the directories and search for the file.
|
||||
|
|
@ -179,7 +213,7 @@ FILE *W_OpenWadFile(const char **filename, boolean useerrors)
|
|||
// in filenamebuf == *filename.
|
||||
if (findfile(filenamebuf, NULL, true))
|
||||
{
|
||||
if ((handle = fopen(*filename, "rb")) == NULL)
|
||||
if ((handle = fopen_utf8(*filename, "rb")) == NULL)
|
||||
{
|
||||
if (useerrors)
|
||||
CONS_Alert(CONS_ERROR, M_GetText("Can't open %s\n"), *filename);
|
||||
|
|
|
|||
Loading…
Reference in a new issue