ExternalInterface: fix conversion of std::wstring to std:string on non-Windows systems for file dialog functions (closes #1622)

This commit is contained in:
Josh Tynjala
2023-03-28 12:06:41 -07:00
parent 3b5588267b
commit 95411acb8c

View File

@@ -175,6 +175,54 @@ namespace lime {
}
value wstring_to_value (std::wstring* val) {
if (val) {
#ifdef HX_WINDOWS
return alloc_wstring (val->c_str ());
#else
std::string _val = std::string (val->begin (), val->end ());
return alloc_string (_val.c_str ());
#endif
} else {
return 0;
}
}
vbyte* wstring_to_vbytes (std::wstring* val) {
if (val) {
#ifdef HX_WINDOWS
int size = std::wcslen (val->c_str ());
char* result = (char*)malloc (size + 1);
std::wcstombs (result, val->c_str (), size);
result[size] = '\0';
return (vbyte*)result;
#else
std::string _val = std::string (val->begin (), val->end ());
int size = std::strlen (_val.c_str ());
char* result = (char*)malloc (size + 1);
std::strncpy (result, _val.c_str (), size);
result[size] = '\0';
return (vbyte*)result;
#endif
} else {
return 0;
}
}
value lime_application_create () {
Application* application = CreateApplication ();
@@ -687,7 +735,7 @@ namespace lime {
if (path) {
value _path = alloc_wstring (path->c_str ());
value _path = wstring_to_value (path);
delete path;
return _path;
@@ -720,13 +768,9 @@ namespace lime {
if (path) {
int size = std::wcslen (path->c_str ());
char* result = (char*)malloc (size + 1);
std::wcstombs (result, path->c_str (), size);
result[size] = '\0';
vbyte* _path = wstring_to_vbytes (path);
delete path;
return (vbyte*)result;
return _path;
} else {
@@ -757,7 +801,7 @@ namespace lime {
if (path) {
value _path = alloc_wstring (path->c_str ());
value _path = wstring_to_value (path);
delete path;
return _path;
@@ -790,13 +834,9 @@ namespace lime {
if (path) {
int size = std::wcslen (path->c_str ());
char* result = (char*)malloc (size + 1);
std::wcstombs (result, path->c_str (), size);
result[size] = '\0';
vbyte* _path = wstring_to_vbytes (path);
delete path;
return (vbyte*)result;
return _path;
} else {
@@ -830,7 +870,8 @@ namespace lime {
for (int i = 0; i < files.size (); i++) {
val_array_set_i (result, i, alloc_wstring (files[i]->c_str ()));
value _file = wstring_to_value (files[i]);
val_array_set_i (result, i, _file);
delete files[i];
}
@@ -864,12 +905,8 @@ namespace lime {
for (int i = 0; i < files.size (); i++) {
int size = std::wcslen (files[i]->c_str ());
char* _file = (char*)malloc (size + 1);
std::wcstombs (_file, files[i]->c_str (), size);
_file[size] = '\0';
*resultData++ = (vbyte*)_file;
vbyte* _file = wstring_to_vbytes (files[i]);
*resultData++ = _file;
delete files[i];
}
@@ -899,7 +936,7 @@ namespace lime {
if (path) {
value _path = alloc_wstring (path->c_str ());
value _path = wstring_to_value (path);
delete path;
return _path;
@@ -932,13 +969,9 @@ namespace lime {
if (path) {
int size = std::wcslen (path->c_str ());
char* result = (char*)malloc (size + 1);
std::wcstombs (result, path->c_str (), size);
result[size] = '\0';
vbyte* _path = wstring_to_vbytes (path);
delete path;
return (vbyte*)result;
return _path;
} else {