wcs* use wchar_t on POSIX, which is not the same as WCHAR
so, winchar_* is introduced which uses WCHAR git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4883 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
33800e2160
commit
5b01b17f11
4 changed files with 125 additions and 13 deletions
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include "ResourceEditor.h"
|
||||
#include "util.h"
|
||||
#include <time.h>
|
||||
#include "winchar.h"
|
||||
#include <queue>
|
||||
using namespace std;
|
||||
|
||||
|
@ -555,7 +555,7 @@ CResourceDirectory* CResourceEditor::ScanDirectory(PRESOURCE_DIRECTORY rdRoot, P
|
|||
|
||||
size_t nameSize = ConvertEndianness(rds->Length);
|
||||
szName = new WCHAR[nameSize+1];
|
||||
wcsncpy(szName, rds->NameString, nameSize);
|
||||
winchar_strncpy(szName, rds->NameString, nameSize);
|
||||
szName[nameSize] = 0;
|
||||
}
|
||||
// Else, set the name to this entry's id
|
||||
|
@ -664,7 +664,7 @@ void CResourceEditor::WriteRsrcSec(BYTE* pbRsrcSec) {
|
|||
PMY_IMAGE_RESOURCE_DIRECTORY_ENTRY(cRDirE->m_dwWrittenAt)->NameString.NameOffset = ConvertEndianness(DWORD(seeker) - DWORD(pbRsrcSec));
|
||||
|
||||
WCHAR* szName = cRDirE->GetName();
|
||||
WORD iLen = wcslen(szName) + 1;
|
||||
WORD iLen = winchar_strlen(szName) + 1;
|
||||
|
||||
*(WORD*)seeker = ConvertEndianness(iLen);
|
||||
seeker += sizeof(WORD);
|
||||
|
@ -777,7 +777,7 @@ void CResourceDirectory::AddEntry(CResourceDirectoryEntry* entry) {
|
|||
WCHAR* szEntName = entry->GetName();
|
||||
for (i = 0; i < m_rdDir.NumberOfNamedEntries; i++) {
|
||||
WCHAR* szName = m_vEntries[i]->GetName();
|
||||
int cmp = wcscmp(szName, szEntName);
|
||||
int cmp = winchar_strcmp(szName, szEntName);
|
||||
delete [] szName;
|
||||
if (cmp == 0) {
|
||||
delete [] szEntName;
|
||||
|
@ -822,14 +822,14 @@ int CResourceDirectory::Find(WCHAR* szName) {
|
|||
return Find((WORD) (DWORD) szName);
|
||||
else
|
||||
if (szName[0] == '#')
|
||||
return Find(WORD(wcstol(szName + 1, NULL, 10)));
|
||||
return Find(WORD(winchar_stoi(szName + 1)));
|
||||
|
||||
for (unsigned int i = 0; i < m_vEntries.size(); i++) {
|
||||
if (!m_vEntries[i]->HasName())
|
||||
continue;
|
||||
|
||||
WCHAR* szEntName = m_vEntries[i]->GetName();
|
||||
int cmp = wcscmp(szName, szEntName);
|
||||
int cmp = winchar_strcmp(szName, szEntName);
|
||||
delete [] szEntName;
|
||||
|
||||
if (!cmp)
|
||||
|
@ -901,8 +901,8 @@ CResourceDirectoryEntry::CResourceDirectoryEntry(WCHAR* szName, CResourceDirecto
|
|||
}
|
||||
else {
|
||||
m_bHasName = true;
|
||||
m_szName = new WCHAR[wcslen(szName)+1];
|
||||
wcscpy(m_szName, szName);
|
||||
m_szName = new WCHAR[winchar_strlen(szName)+1];
|
||||
winchar_strcpy(m_szName, szName);
|
||||
}
|
||||
m_bIsDataDirectory = true;
|
||||
m_rdSubDir = rdSubDir;
|
||||
|
@ -916,8 +916,8 @@ CResourceDirectoryEntry::CResourceDirectoryEntry(WCHAR* szName, CResourceDataEnt
|
|||
}
|
||||
else {
|
||||
m_bHasName = true;
|
||||
m_szName = new WCHAR[wcslen(szName)+1];
|
||||
wcscpy(m_szName, szName);
|
||||
m_szName = new WCHAR[winchar_strlen(szName)+1];
|
||||
winchar_strcpy(m_szName, szName);
|
||||
}
|
||||
m_bIsDataDirectory = false;
|
||||
m_rdeData = rdeData;
|
||||
|
@ -941,13 +941,13 @@ WCHAR* CResourceDirectoryEntry::GetName() {
|
|||
if (!m_bHasName)
|
||||
return 0;
|
||||
WCHAR* szName = 0;
|
||||
szName = new WCHAR[wcslen(m_szName)+1];
|
||||
wcscpy(szName, m_szName);
|
||||
szName = new WCHAR[winchar_strlen(m_szName)+1];
|
||||
winchar_strcpy(szName, m_szName);
|
||||
return szName;
|
||||
}
|
||||
|
||||
int CResourceDirectoryEntry::GetNameLength() {
|
||||
return wcslen(m_szName);
|
||||
return winchar_strlen(m_szName);
|
||||
}
|
||||
|
||||
WORD CResourceDirectoryEntry::GetId() {
|
||||
|
|
|
@ -23,6 +23,7 @@ makensis_files = Split("""
|
|||
strlist.cpp
|
||||
tokens.cpp
|
||||
util.cpp
|
||||
winchar.cpp
|
||||
writer.cpp
|
||||
""")
|
||||
|
||||
|
|
102
Source/winchar.cpp
Normal file
102
Source/winchar.cpp
Normal file
|
@ -0,0 +1,102 @@
|
|||
#include "Platform.h"
|
||||
#include "winchar.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
using std::runtime_error;
|
||||
|
||||
WCHAR *winchar_fromansi(const char* s) {
|
||||
int l = MultiByteToWideChar(CP_ACP, 0, s, -1, 0, 0);
|
||||
if (l == 0)
|
||||
throw runtime_error("Unicode conversion failed");
|
||||
|
||||
WCHAR *ws = new WCHAR[l + 1];
|
||||
|
||||
if (MultiByteToWideChar(CP_ACP, 0, s, -1, ws, l + 1) == 0)
|
||||
throw runtime_error("Unicode conversion failed");
|
||||
|
||||
return ws;
|
||||
}
|
||||
|
||||
char *winchar_toansi(const WCHAR* ws)
|
||||
{
|
||||
int l = WideCharToMultiByte(CP_ACP, 0, ws, -1, 0, 0, 0, 0);
|
||||
if (l == 0)
|
||||
throw runtime_error("Unicode conversion failed");
|
||||
|
||||
char *s = new char[l + 1];
|
||||
|
||||
if (WideCharToMultiByte(CP_ACP, 0, ws, -1, s, l + 1, 0, 0) == 0)
|
||||
throw runtime_error("Unicode conversion failed");
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
WCHAR *winchar_strcpy(WCHAR *ws1, const WCHAR *ws2)
|
||||
{
|
||||
WCHAR *ret = ws1;
|
||||
|
||||
while (*ws2)
|
||||
{
|
||||
*ws1++ = *ws2++;
|
||||
}
|
||||
|
||||
*ws1 = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
WCHAR *winchar_strncpy(WCHAR *ws1, const WCHAR *ws2, size_t n)
|
||||
{
|
||||
WCHAR *ret = ws1;
|
||||
|
||||
while (n && *ws2)
|
||||
{
|
||||
*ws1++ = *ws2++;
|
||||
n--;
|
||||
}
|
||||
|
||||
while (n--)
|
||||
{
|
||||
*ws1++ = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t winchar_strlen(WCHAR *ws)
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
while (*ws++)
|
||||
{
|
||||
len++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int winchar_strcmp(const WCHAR *ws1, const WCHAR *ws2)
|
||||
{
|
||||
WCHAR diff = 0;
|
||||
|
||||
do
|
||||
{
|
||||
diff = *ws1 - *ws2;
|
||||
}
|
||||
while (*ws1++ && *ws2++);
|
||||
|
||||
return static_cast<int>(diff);
|
||||
}
|
||||
|
||||
int winchar_stoi(const WCHAR *ws)
|
||||
{
|
||||
char *s = winchar_toansi(ws);
|
||||
|
||||
int ret = atoi(s);
|
||||
|
||||
delete [] s;
|
||||
|
||||
return ret;
|
||||
}
|
9
Source/winchar.h
Normal file
9
Source/winchar.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include "Platform.h"
|
||||
|
||||
WCHAR *winchar_fromansi(const char* s);
|
||||
char *winchar_toansi(const WCHAR* ws);
|
||||
WCHAR *winchar_strcpy(WCHAR *ws1, const WCHAR *ws2);
|
||||
WCHAR *winchar_strncpy(WCHAR *ws1, const WCHAR *ws2, size_t n);
|
||||
size_t winchar_strlen(WCHAR *ws);
|
||||
int winchar_strcmp(const WCHAR *ws1, const WCHAR *ws2);
|
||||
int winchar_stoi(const WCHAR *ws);
|
Loading…
Add table
Add a link
Reference in a new issue