Fix invalid EXEFILE and EXEDIR on Windows (#1396)
* fix(main): fix get_exe_filename returning invalid result on Windows * fix(main): fix bootstrap not intepreting UTF-8 properly
This commit is contained in:
parent
a0de8ea81d
commit
ecb599e61b
19
src/main.c
19
src/main.c
|
@ -32,8 +32,18 @@ static double get_scale(void) {
|
||||||
|
|
||||||
static void get_exe_filename(char *buf, int sz) {
|
static void get_exe_filename(char *buf, int sz) {
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
int len = GetModuleFileName(NULL, buf, sz - 1);
|
int len;
|
||||||
buf[len] = '\0';
|
wchar_t *buf_w = malloc(sizeof(wchar_t) * sz);
|
||||||
|
if (buf_w) {
|
||||||
|
len = GetModuleFileNameW(NULL, buf_w, sz - 1);
|
||||||
|
buf_w[len] = L'\0';
|
||||||
|
// if the conversion failed we'll empty the string
|
||||||
|
if (!WideCharToMultiByte(CP_UTF8, 0, buf_w, -1, buf, sz, NULL, NULL))
|
||||||
|
buf[0] = '\0';
|
||||||
|
free(buf_w);
|
||||||
|
} else {
|
||||||
|
buf[0] = '\0';
|
||||||
|
}
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
char path[] = "/proc/self/exe";
|
char path[] = "/proc/self/exe";
|
||||||
ssize_t len = readlink(path, buf, sz - 1);
|
ssize_t len = readlink(path, buf, sz - 1);
|
||||||
|
@ -218,9 +228,10 @@ init_lua:
|
||||||
const char *init_lite_code = \
|
const char *init_lite_code = \
|
||||||
"local core\n"
|
"local core\n"
|
||||||
"xpcall(function()\n"
|
"xpcall(function()\n"
|
||||||
|
" local match = require('utf8extra').match\n"
|
||||||
" HOME = os.getenv('" LITE_OS_HOME "')\n"
|
" HOME = os.getenv('" LITE_OS_HOME "')\n"
|
||||||
" local exedir = EXEFILE:match('^(.*)" LITE_PATHSEP_PATTERN LITE_NONPATHSEP_PATTERN "$')\n"
|
" local exedir = match(EXEFILE, '^(.*)" LITE_PATHSEP_PATTERN LITE_NONPATHSEP_PATTERN "$')\n"
|
||||||
" local prefix = os.getenv('LITE_PREFIX') or exedir:match('^(.*)" LITE_PATHSEP_PATTERN "bin$')\n"
|
" local prefix = os.getenv('LITE_PREFIX') or match(exedir, '^(.*)" LITE_PATHSEP_PATTERN "bin$')\n"
|
||||||
" dofile((MACOS_RESOURCES or (prefix and prefix .. '/share/lite-xl' or exedir .. '/data')) .. '/core/start.lua')\n"
|
" dofile((MACOS_RESOURCES or (prefix and prefix .. '/share/lite-xl' or exedir .. '/data')) .. '/core/start.lua')\n"
|
||||||
" core = require(os.getenv('LITE_XL_RUNTIME') or 'core')\n"
|
" core = require(os.getenv('LITE_XL_RUNTIME') or 'core')\n"
|
||||||
" core.init()\n"
|
" core.init()\n"
|
||||||
|
|
Loading…
Reference in New Issue