Add wide character support to language file handling

This commit is contained in:
MysterD 2023-05-14 18:33:14 -07:00
parent 9a99ee492e
commit 05592d524b
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)
# 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)
SRC_DIRS += src/pc/discord

View file

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