fixed unicode conversion with iconv
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3585 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
f52f1c921f
commit
a4ea07f3fa
3 changed files with 23 additions and 19 deletions
|
@ -48,7 +48,7 @@ void ReadVarLenArr(BYTE* &seeker, char* &readInto, unsigned int uCodePage) {
|
|||
break;
|
||||
default:
|
||||
{
|
||||
int iStrLen = 1;
|
||||
int iStrLen;
|
||||
#ifdef _WIN32
|
||||
iStrLen = WideCharToMultiByte(uCodePage, 0, (WCHAR*)arr, -1, 0, 0, 0, 0);
|
||||
if (iStrLen)
|
||||
|
@ -62,28 +62,29 @@ void ReadVarLenArr(BYTE* &seeker, char* &readInto, unsigned int uCodePage) {
|
|||
seeker += sizeof(WCHAR);
|
||||
}
|
||||
#else
|
||||
char cp[128] = "";
|
||||
iStrLen = WCStrLen((WCHAR *) arr);
|
||||
|
||||
char cp[128] = "CP1252";
|
||||
if (uCodePage != CP_ACP)
|
||||
snprintf(cp, 128, "CP%d", uCodePage);
|
||||
iconv_t cd = iconv_open(cp, "UCS-2");
|
||||
if (cd != (iconv_t) -1)
|
||||
{
|
||||
iStrLen = WCStrLen((WCHAR *) arr);
|
||||
char *in = (char *) arr;
|
||||
char *out = readInto = new char[iStrLen + 1];
|
||||
size_t insize = (iStrLen * sizeof(WCHAR)) + 1;
|
||||
size_t insize = (iStrLen + 1) * sizeof(WCHAR);
|
||||
size_t outsize = iStrLen + 1;
|
||||
if (__iconv_adaptor(iconv, cd, &in, &insize, &out, &outsize) == (size_t) -1)
|
||||
{
|
||||
*arr = 0;
|
||||
iStrLen = 1;
|
||||
delete [] readInto;
|
||||
readInto = 0;
|
||||
}
|
||||
iconv_close(cd);
|
||||
}
|
||||
else
|
||||
*arr = 0;
|
||||
readInto = 0;
|
||||
#endif
|
||||
seeker += iStrLen*sizeof(WCHAR);
|
||||
seeker += iStrLen * sizeof(WCHAR);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -115,7 +116,7 @@ void ReadVarLenArr(BYTE* &seeker, char* &readInto, unsigned int uCodePage) {
|
|||
seeker += sizeof(WORD); \
|
||||
} \
|
||||
else { \
|
||||
char cp[128] = ""; \
|
||||
char cp[128] = "CP1252"; \
|
||||
if (m_uCodePage != CP_ACP) \
|
||||
snprintf(cp, 128, "CP%d", m_uCodePage); \
|
||||
iconv_t cd = iconv_open("UCS-2", cp); \
|
||||
|
@ -124,10 +125,10 @@ void ReadVarLenArr(BYTE* &seeker, char* &readInto, unsigned int uCodePage) {
|
|||
char *in = (char *) x; \
|
||||
char *out = (char *) seeker; \
|
||||
size_t insize = strlen(in) + 1; \
|
||||
size_t outsize = insize * 2; \
|
||||
size_t outsize = insize * sizeof(WCHAR); \
|
||||
if (__iconv_adaptor(iconv, cd, &in, &insize, &out, &outsize) == (size_t) -1) \
|
||||
{ \
|
||||
*seeker = 0; \
|
||||
*(WCHAR*)seeker = 0; \
|
||||
seeker += sizeof(WCHAR); \
|
||||
} \
|
||||
seeker = (BYTE *) out; \
|
||||
|
@ -135,7 +136,7 @@ void ReadVarLenArr(BYTE* &seeker, char* &readInto, unsigned int uCodePage) {
|
|||
} \
|
||||
else \
|
||||
{ \
|
||||
*seeker = 0; \
|
||||
*(WCHAR*)seeker = 0; \
|
||||
seeker += sizeof(WCHAR); \
|
||||
} \
|
||||
} \
|
||||
|
@ -160,7 +161,7 @@ CDialogTemplate::CDialogTemplate(BYTE* pbData, unsigned int uCodePage) {
|
|||
|
||||
WORD wItems = 0;
|
||||
|
||||
if (*(DWORD*)pbData == 0xFFFF0001) { // Extended dialog template signature
|
||||
if (*(DWORD*)pbData == EXTENDED_DIALOG) { // Extended dialog template signature
|
||||
m_bExtended = true;
|
||||
|
||||
DLGTEMPLATEEX* dTemplateEx = (DLGTEMPLATEEX*)pbData;
|
||||
|
@ -177,6 +178,7 @@ CDialogTemplate::CDialogTemplate(BYTE* pbData, unsigned int uCodePage) {
|
|||
}
|
||||
else {
|
||||
m_bExtended = false;
|
||||
|
||||
DLGTEMPLATE* dTemplate = (DLGTEMPLATE*)pbData;
|
||||
|
||||
m_dwStyle = dTemplate->style;
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
#include <stdexcept>
|
||||
using namespace std;
|
||||
|
||||
#define EXTENDED_DIALOG ((DWORD) 0xFFFF0001)
|
||||
|
||||
struct DialogItemTemplate {
|
||||
DWORD dwHelpId; // Extended only
|
||||
|
||||
|
|
|
@ -403,13 +403,13 @@ CResourceDirectory* CResourceEditor::ScanDirectory(PRESOURCE_DIRECTORY rdRoot, P
|
|||
szName[mbsSize] = 0;
|
||||
#else
|
||||
{
|
||||
iconv_t cd = iconv_open("", "UCS-2");
|
||||
iconv_t cd = iconv_open("CP1252", "UCS-2");
|
||||
if (cd != (iconv_t) -1)
|
||||
{
|
||||
char *in = (char *) rds->NameString;
|
||||
char *out = szName = new char[rds->Length * 2 + 1];
|
||||
char *out = szName = new char[(rds->Length + 1) * sizeof(WCHAR)];
|
||||
size_t insize = rds->Length;
|
||||
size_t outsize = rds->Length * 2 + 1;
|
||||
size_t outsize = (rds->Length + 1) * sizeof(WCHAR);
|
||||
if (__iconv_adaptor(iconv, cd, &in, &insize, &out, &outsize) == (size_t) -1)
|
||||
throw runtime_error("Unicode conversion failed");
|
||||
iconv_close(cd);
|
||||
|
@ -528,17 +528,17 @@ void CResourceEditor::WriteRsrcSec(BYTE* pbRsrcSec) {
|
|||
iLen = MultiByteToWideChar(CP_ACP, 0, szName, iLen, szwName, iLen) - 1;
|
||||
#else
|
||||
{
|
||||
iconv_t cd = iconv_open("UCS-2", "");
|
||||
iconv_t cd = iconv_open("UCS-2", "CP1252");
|
||||
if (cd != (iconv_t) -1)
|
||||
{
|
||||
char *in = szName;
|
||||
char *out = (char *) szwName;
|
||||
size_t insize = iLen + 1;
|
||||
size_t outsize = (iLen + 1) * sizeof(unsigned short);
|
||||
size_t outsize = insize * sizeof(WCHAR);
|
||||
if (__iconv_adaptor(iconv, cd, &in, &insize, &out, &outsize) == (size_t) -1)
|
||||
iLen = (WORD) -1;
|
||||
else
|
||||
iLen = (WORD) ((int) out - (int) szwName - 1);
|
||||
iLen = (WORD) (((int) out - (int) szwName - 2) / 2);
|
||||
iconv_close(cd);
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue