Fix Unicode characters not handled correctly on Windows platform (#74)

* Fix Unicode characters not handled correctly on Windows platform

* Fix build error
This commit is contained in:
ShiinaSekiu 2024-05-05 20:55:42 +08:00 committed by GitHub
parent d85537a909
commit e3bae10048
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,6 +15,14 @@
#include "applet/notification.h"
#include "applet/version.h"
#ifdef WIN32
#include <windef.h>
#include <processthreadsapi.h>
#include <shellapi.h>
#include <stringapiset.h>
#include <processenv.h>
#endif
static int driver_applet_main(int argc, char **argv)
{
const struct applet_entry *applets[] = {
@ -68,8 +76,43 @@ void main_fini_euicc()
euicc_ctx_inited = 0;
}
#ifdef WIN32
char** warg_to_arg(const int wargc, wchar_t **wargv)
{
char **argv = malloc(wargc * sizeof(char *));
if (argv == NULL)
{
return NULL;
}
for (int i = 0; i < wargc; ++i)
{
const int size = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
argv[i] = malloc(size);
if (argv[i] == NULL)
{
for (int j = 0; j < i; ++j)
{
free(argv[j]);
}
free(argv);
return NULL;
}
WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], size, NULL, NULL);
}
return argv;
}
#endif
int main(int argc, char **argv)
{
#ifdef WIN32
argv = warg_to_arg(argc, CommandLineToArgvW(GetCommandLineW(), &argc));
if (argv == NULL)
{
return -1;
}
#endif
int ret = 0;
memset(&euicc_ctx, 0, sizeof(euicc_ctx));