mirror of
https://github.com/libretro/RetroArch
synced 2025-03-01 07:13:35 +00:00
win32: add Unicode versions of getenv, GetModuleFileName, LoadLibrary and _mkdir
This commit is contained in:
parent
fee7ab9dc8
commit
a3a5f6e07e
@ -13,6 +13,14 @@
|
|||||||
* If not, see <http://www.gnu.org/licenses/>.
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Assume W-functions do not work below Win2K and Xbox platforms */
|
||||||
|
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500 || defined(_XBOX)
|
||||||
|
|
||||||
|
#ifndef LEGACY_WIN32
|
||||||
|
#define LEGACY_WIN32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
@ -45,6 +53,7 @@
|
|||||||
#include <compat/posix_string.h>
|
#include <compat/posix_string.h>
|
||||||
#include <retro_assert.h>
|
#include <retro_assert.h>
|
||||||
#include <retro_miscellaneous.h>
|
#include <retro_miscellaneous.h>
|
||||||
|
#include <encodings/utf.h>
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@ -171,6 +180,7 @@ void fill_pathname_abbreviate_special(char *out_path,
|
|||||||
bool fill_pathname_application_data(char *s, size_t len)
|
bool fill_pathname_application_data(char *s, size_t len)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32) && !defined(_XBOX)
|
#if defined(_WIN32) && !defined(_XBOX)
|
||||||
|
#ifdef LEGACY_WIN32
|
||||||
const char *appdata = getenv("APPDATA");
|
const char *appdata = getenv("APPDATA");
|
||||||
|
|
||||||
if (appdata)
|
if (appdata)
|
||||||
@ -178,6 +188,21 @@ bool fill_pathname_application_data(char *s, size_t len)
|
|||||||
strlcpy(s, appdata, len);
|
strlcpy(s, appdata, len);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
const wchar_t *appdataW = _wgetenv(L"APPDATA");
|
||||||
|
|
||||||
|
if (appdataW)
|
||||||
|
{
|
||||||
|
char *appdata = utf16_to_utf8_string_alloc(appdataW);
|
||||||
|
|
||||||
|
if (appdata)
|
||||||
|
{
|
||||||
|
strlcpy(s, appdata, len);
|
||||||
|
free(appdata);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#elif defined(OSX)
|
#elif defined(OSX)
|
||||||
const char *appdata = getenv("HOME");
|
const char *appdata = getenv("HOME");
|
||||||
@ -224,7 +249,8 @@ void fill_pathname_application_path(char *s, size_t len)
|
|||||||
#endif
|
#endif
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
DWORD ret;
|
DWORD ret;
|
||||||
wchar_t ws[PATH_MAX_LENGTH] = {0};
|
char *str;
|
||||||
|
wchar_t wstr[PATH_MAX_LENGTH] = {0};
|
||||||
#endif
|
#endif
|
||||||
#ifdef __HAIKU__
|
#ifdef __HAIKU__
|
||||||
image_info info;
|
image_info info;
|
||||||
@ -236,7 +262,22 @@ void fill_pathname_application_path(char *s, size_t len)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
ret = GetModuleFileName(GetModuleHandle(NULL), s, len - 1);
|
#ifdef LEGACY_WIN32
|
||||||
|
ret = GetModuleFileNameA(GetModuleHandle(NULL), s, len);
|
||||||
|
#else
|
||||||
|
ret = GetModuleFileNameW(GetModuleHandle(NULL), wstr, ARRAY_SIZE(wstr));
|
||||||
|
|
||||||
|
if (*wstr)
|
||||||
|
{
|
||||||
|
str = utf16_to_utf8_string_alloc(wstr);
|
||||||
|
|
||||||
|
if (str)
|
||||||
|
{
|
||||||
|
strlcpy(s, str, len);
|
||||||
|
free(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
s[ret] = '\0';
|
s[ret] = '\0';
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
if (bundle)
|
if (bundle)
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <dynamic/dylib.h>
|
#include <dynamic/dylib.h>
|
||||||
|
#include <encodings/utf.h>
|
||||||
|
|
||||||
#ifdef NEED_DYNAMIC
|
#ifdef NEED_DYNAMIC
|
||||||
|
|
||||||
@ -33,6 +34,15 @@
|
|||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Assume W-functions do not work below Win2K and Xbox platforms */
|
||||||
|
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500 || defined(_XBOX)
|
||||||
|
|
||||||
|
#ifndef LEGACY_WIN32
|
||||||
|
#define LEGACY_WIN32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static char last_dyn_error[512];
|
static char last_dyn_error[512];
|
||||||
|
|
||||||
@ -65,7 +75,14 @@ dylib_t dylib_load(const char *path)
|
|||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
int prevmode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
|
int prevmode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
|
||||||
|
#ifdef LEGACY_WIN32
|
||||||
dylib_t lib = LoadLibrary(path);
|
dylib_t lib = LoadLibrary(path);
|
||||||
|
#else
|
||||||
|
wchar_t *pathW = utf8_to_utf16_string_alloc(path);
|
||||||
|
dylib_t lib = LoadLibraryW(pathW);
|
||||||
|
|
||||||
|
free(pathW);
|
||||||
|
#endif
|
||||||
|
|
||||||
SetErrorMode(prevmode);
|
SetErrorMode(prevmode);
|
||||||
|
|
||||||
|
@ -275,7 +275,18 @@ bool path_mkdir(const char *dir)
|
|||||||
if (norecurse)
|
if (norecurse)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
#ifdef LEGACY_WIN32
|
||||||
int ret = _mkdir(dir);
|
int ret = _mkdir(dir);
|
||||||
|
#else
|
||||||
|
wchar_t *dirW = utf8_to_utf16_string_alloc(dir);
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (dirW)
|
||||||
|
{
|
||||||
|
ret = _wmkdir(dirW);
|
||||||
|
free(dirW);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#elif defined(IOS)
|
#elif defined(IOS)
|
||||||
int ret = mkdir(dir, 0755);
|
int ret = mkdir(dir, 0755);
|
||||||
#elif defined(VITA) || defined(PSP)
|
#elif defined(VITA) || defined(PSP)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user