Add wide character support to language file handling

This commit is contained in:
MysterD 2023-05-14 18:33:14 -07:00
parent 1b5e1cee9a
commit 8500516159
6 changed files with 58 additions and 7 deletions

View File

@ -534,7 +534,7 @@ SRC_DIRS := src src/engine src/game src/audio src/bass_audio src/menu src/buffer
BIN_DIRS := bin bin/$(VERSION) BIN_DIRS := bin bin/$(VERSION)
# PC files # PC files
SRC_DIRS += src/pc src/pc/gfx src/pc/audio src/pc/controller src/pc/fs src/pc/fs/packtypes src/pc/mods src/dev src/pc/network src/pc/network/packets src/pc/network/socket src/pc/network/coopnet src/pc/utils src/pc/utils/miniz src/pc/djui src/pc/lua src/pc/lua/utils SRC_DIRS += src/pc src/pc/gfx src/pc/audio src/pc/controller src/pc/fs src/pc/fs/packtypes src/pc/mods src/dev src/pc/network src/pc/network/packets src/pc/network/socket src/pc/network/coopnet src/pc/utils src/pc/utils/miniz src/pc/djui src/pc/lua src/pc/lua/utils src/pc/os
ifeq ($(DISCORD_SDK),1) ifeq ($(DISCORD_SDK),1)
SRC_DIRS += src/pc/discord SRC_DIRS += src/pc/discord

View File

@ -8,6 +8,7 @@
#include "pc/debuglog.h" #include "pc/debuglog.h"
#include "pc/utils/misc.h" #include "pc/utils/misc.h"
#include "pc/configfile.h" #include "pc/configfile.h"
#include "pc/os/os.h"
extern bool directory_sanity_check(struct dirent* dir, char* dirPath, char* outPath); extern bool directory_sanity_check(struct dirent* dir, char* dirPath, char* outPath);
static bool sTrue = true; static bool sTrue = true;
@ -83,8 +84,9 @@ void djui_panel_language_create(struct DjuiBase* caller) {
snprintf(lpath, SYS_MAX_PATH, "%s/lang", sys_exe_path()); snprintf(lpath, SYS_MAX_PATH, "%s/lang", sys_exe_path());
// open directory // open directory
struct dirent* dir = NULL; os_dirent* dir = NULL;
DIR* d = opendir(lpath);
OS_DIR* d = os_opendir(lpath);
if (!d) { if (!d) {
LOG_ERROR("Could not open directory '%s'", lpath); LOG_ERROR("Could not open directory '%s'", lpath);
@ -106,10 +108,10 @@ void djui_panel_language_create(struct DjuiBase* caller) {
// iterate // iterate
char path[SYS_MAX_PATH] = { 0 }; char path[SYS_MAX_PATH] = { 0 };
while ((dir = readdir(d)) != NULL) { while ((dir = os_readdir(d)) != NULL) {
// sanity check / fill path[] // sanity check / fill path[]
if (!directory_sanity_check(dir, lpath, path)) { continue; } //if (!directory_sanity_check(dir, lpath, path)) { continue; }
snprintf(path, SYS_MAX_PATH, "%s", dir->d_name); snprintf(path, SYS_MAX_PATH, "%s", os_get_dir_name(dir));
// strip the name before the . // strip the name before the .
char* c = path; char* c = path;
@ -125,7 +127,7 @@ void djui_panel_language_create(struct DjuiBase* caller) {
if (!strcmp(path, "English")) { chkEnglish = checkbox; } if (!strcmp(path, "English")) { chkEnglish = checkbox; }
} }
closedir(d); os_closedir(d);
if (!foundMatch && chkEnglish) { if (!foundMatch && chkEnglish) {
chkEnglish->value = &sTrue; chkEnglish->value = &sTrue;

6
src/pc/os/os.h Normal file
View File

@ -0,0 +1,6 @@
#pragma once
#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64)
#include "os_win.h"
#else
#include "os_other.h"
#endif

10
src/pc/os/os_other.h Normal file
View File

@ -0,0 +1,10 @@
#pragma once
#include <dirent.h>
#define os_dirent struct dirent
#define OS_DIR DIR
#define os_opendir(_x) opendir(_x)
#define os_readdir(_x) readdir(_x)
#define os_closedir(_x) closedir(_x)
#define os_get_dir_name(_x) _x->d_name

20
src/pc/os/os_win.c Normal file
View File

@ -0,0 +1,20 @@
#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64)
#include <stdio.h>
#include <stringapiset.h>
#include "os_win.h"
#include "pc/platform.h"
OS_DIR* os_opendir(char* path) {
wchar_t wpath[SYS_MAX_PATH] = { 0 };
MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, SYS_MAX_PATH);
return _wopendir(wpath);
}
char* os_get_dir_name(os_dirent* dir) {
static char path[SYS_MAX_PATH] = { 0 };
snprintf(path, SYS_MAX_PATH, "%ls", dir->d_name);
return path;
}
#endif

13
src/pc/os/os_win.h Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include <wchar.h>
#include <dirent.h>
#define os_dirent struct _wdirent
#define OS_DIR _WDIR
#define os_closedir(_x) _wclosedir(_x)
#define os_readdir(_x) _wreaddir(_x)
OS_DIR* os_opendir(char* path);
char* os_get_dir_name(os_dirent* dir);