ExternalInterface: fix conversion of std::wstring to std:string on non-Windows systems for file dialog functions (closes #1622)
This commit is contained in:
@@ -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 () {
|
value lime_application_create () {
|
||||||
|
|
||||||
Application* application = CreateApplication ();
|
Application* application = CreateApplication ();
|
||||||
@@ -687,7 +735,7 @@ namespace lime {
|
|||||||
|
|
||||||
if (path) {
|
if (path) {
|
||||||
|
|
||||||
value _path = alloc_wstring (path->c_str ());
|
value _path = wstring_to_value (path);
|
||||||
delete path;
|
delete path;
|
||||||
return _path;
|
return _path;
|
||||||
|
|
||||||
@@ -720,13 +768,9 @@ namespace lime {
|
|||||||
|
|
||||||
if (path) {
|
if (path) {
|
||||||
|
|
||||||
int size = std::wcslen (path->c_str ());
|
vbyte* _path = wstring_to_vbytes (path);
|
||||||
char* result = (char*)malloc (size + 1);
|
|
||||||
std::wcstombs (result, path->c_str (), size);
|
|
||||||
result[size] = '\0';
|
|
||||||
delete path;
|
delete path;
|
||||||
|
return _path;
|
||||||
return (vbyte*)result;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -757,7 +801,7 @@ namespace lime {
|
|||||||
|
|
||||||
if (path) {
|
if (path) {
|
||||||
|
|
||||||
value _path = alloc_wstring (path->c_str ());
|
value _path = wstring_to_value (path);
|
||||||
delete path;
|
delete path;
|
||||||
return _path;
|
return _path;
|
||||||
|
|
||||||
@@ -790,13 +834,9 @@ namespace lime {
|
|||||||
|
|
||||||
if (path) {
|
if (path) {
|
||||||
|
|
||||||
int size = std::wcslen (path->c_str ());
|
vbyte* _path = wstring_to_vbytes (path);
|
||||||
char* result = (char*)malloc (size + 1);
|
|
||||||
std::wcstombs (result, path->c_str (), size);
|
|
||||||
result[size] = '\0';
|
|
||||||
delete path;
|
delete path;
|
||||||
|
return _path;
|
||||||
return (vbyte*)result;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -830,7 +870,8 @@ namespace lime {
|
|||||||
|
|
||||||
for (int i = 0; i < files.size (); i++) {
|
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];
|
delete files[i];
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -864,12 +905,8 @@ namespace lime {
|
|||||||
|
|
||||||
for (int i = 0; i < files.size (); i++) {
|
for (int i = 0; i < files.size (); i++) {
|
||||||
|
|
||||||
int size = std::wcslen (files[i]->c_str ());
|
vbyte* _file = wstring_to_vbytes (files[i]);
|
||||||
char* _file = (char*)malloc (size + 1);
|
*resultData++ = _file;
|
||||||
std::wcstombs (_file, files[i]->c_str (), size);
|
|
||||||
_file[size] = '\0';
|
|
||||||
|
|
||||||
*resultData++ = (vbyte*)_file;
|
|
||||||
delete files[i];
|
delete files[i];
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -899,7 +936,7 @@ namespace lime {
|
|||||||
|
|
||||||
if (path) {
|
if (path) {
|
||||||
|
|
||||||
value _path = alloc_wstring (path->c_str ());
|
value _path = wstring_to_value (path);
|
||||||
delete path;
|
delete path;
|
||||||
return _path;
|
return _path;
|
||||||
|
|
||||||
@@ -932,13 +969,9 @@ namespace lime {
|
|||||||
|
|
||||||
if (path) {
|
if (path) {
|
||||||
|
|
||||||
int size = std::wcslen (path->c_str ());
|
vbyte* _path = wstring_to_vbytes (path);
|
||||||
char* result = (char*)malloc (size + 1);
|
|
||||||
std::wcstombs (result, path->c_str (), size);
|
|
||||||
result[size] = '\0';
|
|
||||||
delete path;
|
delete path;
|
||||||
|
return _path;
|
||||||
return (vbyte*)result;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user