more simple TCHARs fixes
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6047 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
a92fad7347
commit
64a0f32e52
38 changed files with 1831 additions and 1961 deletions
|
@ -292,7 +292,7 @@ void CDialogTemplate::SetFont(TCHAR* szFaceName, WORD wFontSize) {
|
|||
m_bCharset = DEFAULT_CHARSET;
|
||||
m_dwStyle |= DS_SETFONT;
|
||||
if (m_szFont) delete [] m_szFont;
|
||||
m_szFont = winchar_fromansi(szFaceName, m_uCodePage);
|
||||
m_szFont = winchar_fromTchar(szFaceName, m_uCodePage);
|
||||
m_sFontSize = wFontSize;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ void Plugins::FindCommands(const tstring &path, bool displayInfo)
|
|||
|
||||
struct NSISException : public std::runtime_error
|
||||
{
|
||||
NSISException(const string& msg) : std::runtime_error(msg) {}
|
||||
NSISException(const tstring& msg) : std::runtime_error(string(TtoCString(msg))) {}
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
@ -82,7 +82,7 @@ void read_file(const tstring& filename, vector<unsigned char>& data) {
|
|||
ifstream file(filename.c_str(), ios::binary);
|
||||
|
||||
if (!file) {
|
||||
throw NSISException("Can't open file '" + filename + "'");
|
||||
throw NSISException(_T("Can't open file '") + filename + _T("'"));
|
||||
}
|
||||
|
||||
// get the file size
|
||||
|
@ -93,7 +93,7 @@ void read_file(const tstring& filename, vector<unsigned char>& data) {
|
|||
file.read(reinterpret_cast<char*>(&data[0]), filesize);
|
||||
|
||||
if (size_t(file.tellg()) != filesize) { // ifstream::eof doesn't return true here
|
||||
throw NSISException("Couldn't read entire file '" + filename + "'");
|
||||
throw NSISException(_T("Couldn't read entire file '") + filename + _T("'"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ void Plugins::GetExports(const tstring &pathToDll, bool displayInfo)
|
|||
for (DWORD j = 0; j < FIX_ENDIAN_INT32(exports->NumberOfNames); j++)
|
||||
{
|
||||
const string name = string((char*)exports + FIX_ENDIAN_INT32(names[j]) - ExportDirVA);
|
||||
const tstring signature = dllName + _T("::") + name;
|
||||
const tstring signature = dllName + _T("::") + tstring(CtoTString(name));
|
||||
const tstring lcsig = lowercase(signature);
|
||||
m_command_to_path[lcsig] = pathToDll;
|
||||
m_command_lowercase_to_command[lcsig] = signature;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -114,19 +114,10 @@ public:
|
|||
CResourceEditor(BYTE* pbPE, int iSize, bool bKeepData = true);
|
||||
virtual ~CResourceEditor();
|
||||
|
||||
bool UpdateResource(WORD szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
|
||||
bool UpdateResourceW(WCHAR* szType, WCHAR* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
|
||||
bool UpdateResourceW(WORD szType, WCHAR* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
|
||||
bool UpdateResourceW(WCHAR* szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
|
||||
bool UpdateResourceA(char* szType, char* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
|
||||
bool UpdateResourceA(WORD szType, char* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
|
||||
bool UpdateResourceA(char* szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
|
||||
BYTE* GetResourceW(WCHAR* szType, WCHAR* szName, LANGID wLanguage);
|
||||
BYTE* GetResourceA(char* szType, char* szName, LANGID wLanguage);
|
||||
int GetResourceSizeW(WCHAR* szType, WCHAR* szName, LANGID wLanguage);
|
||||
int GetResourceSizeA(char* szType, char* szName, LANGID wLanguage);
|
||||
DWORD GetResourceOffsetW(WCHAR* szType, WCHAR* szName, LANGID wLanguage);
|
||||
DWORD GetResourceOffsetA(char* szType, char* szName, LANGID wLanguage);
|
||||
bool UpdateResource (TCHAR* szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
|
||||
BYTE* GetResource (TCHAR* szType, WORD szName, LANGID wLanguage);
|
||||
int GetResourceSize (TCHAR* szType, WORD szName, LANGID wLanguage);
|
||||
DWORD GetResourceOffset(TCHAR* szType, WORD szName, LANGID wLanguage);
|
||||
void FreeResource(BYTE* pbResource);
|
||||
|
||||
// The section name must be in ASCII.
|
||||
|
@ -143,6 +134,11 @@ public:
|
|||
DWORD *pdwResSecVA = NULL,
|
||||
DWORD *pdwSectionIndex = NULL
|
||||
);
|
||||
private:
|
||||
bool UpdateResourceW(WCHAR* szType, WCHAR* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
|
||||
BYTE* GetResourceW(WCHAR* szType, WCHAR* szName, LANGID wLanguage);
|
||||
int GetResourceSizeW(WCHAR* szType, WCHAR* szName, LANGID wLanguage);
|
||||
DWORD GetResourceOffsetW(WCHAR* szType, WCHAR* szName, LANGID wLanguage);
|
||||
|
||||
private:
|
||||
BYTE* m_pbPE;
|
||||
|
|
|
@ -57,7 +57,7 @@ CVersionStrigList::~CVersionStrigList()
|
|||
int CVersionStrigList::add(LANGID langid, int codepage)
|
||||
{
|
||||
TCHAR Buff[10];
|
||||
sprintf(Buff, _T("%04x"), langid);
|
||||
_stprintf(Buff, _T("%04x"), langid);
|
||||
int pos = SortedStringListND<struct version_string_list>::add(Buff);
|
||||
if (pos == -1) return false;
|
||||
((struct version_string_list*)gr.get())[pos].pChildStrings = new DefineList;
|
||||
|
@ -87,7 +87,7 @@ DefineList* CVersionStrigList::get_strings(int idx)
|
|||
int CVersionStrigList::find(LANGID lang_id, int codepage)
|
||||
{
|
||||
TCHAR Buff[10];
|
||||
sprintf(Buff, _T("%04x"), lang_id);
|
||||
_stprintf(Buff, _T("%04x"), lang_id);
|
||||
return SortedStringListND<struct version_string_list>::find(Buff);
|
||||
}
|
||||
|
||||
|
@ -218,8 +218,8 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index)
|
|||
PadStream (stringInfoStream);
|
||||
|
||||
p = stringInfoStream.getlen();
|
||||
KeyName = winchar_fromansi(pChildStrings->getname(i), codepage);
|
||||
KeyValue = winchar_fromansi(pChildStrings->getvalue(i), codepage);
|
||||
KeyName = winchar_fromTchar(pChildStrings->getname(i), codepage);
|
||||
KeyValue = winchar_fromTchar(pChildStrings->getvalue(i), codepage);
|
||||
SaveVersionHeader (stringInfoStream, 0, WORD(winchar_strlen(KeyValue) + 1), 1, KeyName, (void*)KeyValue);
|
||||
delete [] KeyName;
|
||||
delete [] KeyValue;
|
||||
|
|
|
@ -11,35 +11,24 @@
|
|||
class WinCharTest : public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE( WinCharTest );
|
||||
CPPUNIT_TEST( testFromAnsi );
|
||||
CPPUNIT_TEST( testToAnsi );
|
||||
CPPUNIT_TEST( testFromTchar );
|
||||
CPPUNIT_TEST( testStrCpy );
|
||||
CPPUNIT_TEST( testStrNCpy );
|
||||
CPPUNIT_TEST( testStrLen );
|
||||
CPPUNIT_TEST( testStrCmp );
|
||||
CPPUNIT_TEST( testStrDup );
|
||||
CPPUNIT_TEST( testStoi );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
void testFromAnsi() {
|
||||
void testFromTchar() {
|
||||
WCHAR test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
|
||||
WCHAR *dyn = winchar_fromansi("test");
|
||||
WCHAR *dyn = winchar_fromTchar("test");
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 0, memcmp(test, dyn, 5) );
|
||||
|
||||
delete [] dyn;
|
||||
}
|
||||
|
||||
void testToAnsi() {
|
||||
WCHAR test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
|
||||
char *dyn = winchar_toansi(test);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 0, strcmp("test", dyn) );
|
||||
|
||||
delete [] dyn;
|
||||
}
|
||||
|
||||
void testStrCpy() {
|
||||
WCHAR a[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
|
||||
WCHAR b[5];
|
||||
|
@ -111,20 +100,6 @@ public:
|
|||
delete [] b;
|
||||
}
|
||||
|
||||
void testStoi() {
|
||||
srand(time(0));
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
int r = rand();
|
||||
char s[128];
|
||||
sprintf(s, "%d", r);
|
||||
WCHAR *ws = winchar_fromansi(s);
|
||||
CPPUNIT_ASSERT_EQUAL( r, winchar_stoi(ws) );
|
||||
delete [] ws;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( WinCharTest );
|
||||
|
|
|
@ -1733,7 +1733,7 @@ int CEXEBuild::AddVersionInfo()
|
|||
warning(_T("Generating version information for language \"%04d-%s\" without standard key \"LegalCopyright\""), lang_id, lang_name);
|
||||
|
||||
rVersionInfo.ExportToStream(VerInfoStream, i);
|
||||
res_editor->UpdateResourceA(RT_VERSION, 1, lang_id, (BYTE*)VerInfoStream.get(), VerInfoStream.getlen());
|
||||
res_editor->UpdateResource(RT_VERSION, 1, lang_id, (BYTE*)VerInfoStream.get(), VerInfoStream.getlen());
|
||||
}
|
||||
}
|
||||
catch (exception& err) {
|
||||
|
@ -2073,7 +2073,7 @@ again:
|
|||
SCRIPT_MSG(_T("Done!\n"));
|
||||
|
||||
#define REMOVE_ICON(id) if (disable_window_icon) { \
|
||||
BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); \
|
||||
BYTE* dlg = res_editor->GetResource(RT_DIALOG, id, NSIS_DEFAULT_LANG); \
|
||||
if (dlg) { \
|
||||
CDialogTemplate dt(dlg,uDefCodePage); \
|
||||
res_editor->FreeResource(dlg); \
|
||||
|
@ -2091,7 +2091,7 @@ again:
|
|||
\
|
||||
DWORD dwSize; \
|
||||
dlg = dt.Save(dwSize); \
|
||||
res_editor->UpdateResourceA(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG, dlg, dwSize); \
|
||||
res_editor->UpdateResource(RT_DIALOG, id, NSIS_DEFAULT_LANG, dlg, dwSize); \
|
||||
delete [] dlg; \
|
||||
} \
|
||||
} \
|
||||
|
@ -2102,43 +2102,43 @@ again:
|
|||
init_res_editor();
|
||||
#ifdef NSIS_CONFIG_LICENSEPAGE
|
||||
if (!license_normal) {
|
||||
res_editor->UpdateResourceA(RT_DIALOG, IDD_LICENSE, NSIS_DEFAULT_LANG, 0, 0);
|
||||
res_editor->UpdateResource(RT_DIALOG, IDD_LICENSE, NSIS_DEFAULT_LANG, 0, 0);
|
||||
}
|
||||
else REMOVE_ICON(IDD_LICENSE);
|
||||
if (!license_fsrb) {
|
||||
res_editor->UpdateResourceA(RT_DIALOG, IDD_LICENSE_FSRB, NSIS_DEFAULT_LANG, 0, 0);
|
||||
res_editor->UpdateResource(RT_DIALOG, IDD_LICENSE_FSRB, NSIS_DEFAULT_LANG, 0, 0);
|
||||
}
|
||||
else REMOVE_ICON(IDD_LICENSE_FSRB);
|
||||
if (!license_fscb) {
|
||||
res_editor->UpdateResourceA(RT_DIALOG, IDD_LICENSE_FSCB, NSIS_DEFAULT_LANG, 0, 0);
|
||||
res_editor->UpdateResource(RT_DIALOG, IDD_LICENSE_FSCB, NSIS_DEFAULT_LANG, 0, 0);
|
||||
}
|
||||
else REMOVE_ICON(IDD_LICENSE_FSCB);
|
||||
#endif // NSIS_CONFIG_LICENSEPAGE
|
||||
#ifdef NSIS_CONFIG_COMPONENTPAGE
|
||||
if (!selcom) {
|
||||
res_editor->UpdateResourceA(RT_DIALOG, IDD_SELCOM, NSIS_DEFAULT_LANG, 0, 0);
|
||||
res_editor->UpdateResourceA(RT_BITMAP, IDB_BITMAP1, NSIS_DEFAULT_LANG, 0, 0);
|
||||
res_editor->UpdateResource(RT_DIALOG, IDD_SELCOM, NSIS_DEFAULT_LANG, 0, 0);
|
||||
res_editor->UpdateResource(RT_BITMAP, IDB_BITMAP1, NSIS_DEFAULT_LANG, 0, 0);
|
||||
}
|
||||
else REMOVE_ICON(IDD_SELCOM);
|
||||
#endif // NSIS_CONFIG_COMPONENTPAGE
|
||||
if (!dir) {
|
||||
res_editor->UpdateResourceA(RT_DIALOG, IDD_DIR, NSIS_DEFAULT_LANG, 0, 0);
|
||||
res_editor->UpdateResource(RT_DIALOG, IDD_DIR, NSIS_DEFAULT_LANG, 0, 0);
|
||||
}
|
||||
else REMOVE_ICON(IDD_DIR);
|
||||
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
|
||||
if (!uninstconfirm) {
|
||||
res_editor->UpdateResourceA(RT_DIALOG, IDD_UNINST, NSIS_DEFAULT_LANG, 0, 0);
|
||||
res_editor->UpdateResource(RT_DIALOG, IDD_UNINST, NSIS_DEFAULT_LANG, 0, 0);
|
||||
}
|
||||
else REMOVE_ICON(IDD_UNINST);
|
||||
#endif // NSIS_CONFIG_UNINSTALL_SUPPORT
|
||||
if (!instlog) {
|
||||
res_editor->UpdateResourceA(RT_DIALOG, IDD_INSTFILES, NSIS_DEFAULT_LANG, 0, 0);
|
||||
res_editor->UpdateResource(RT_DIALOG, IDD_INSTFILES, NSIS_DEFAULT_LANG, 0, 0);
|
||||
}
|
||||
else REMOVE_ICON(IDD_INSTFILES);
|
||||
if (!main) {
|
||||
res_editor->UpdateResourceA(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, 0, 0);
|
||||
res_editor->UpdateResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, 0, 0);
|
||||
if (!build_compress_whole && !build_crcchk)
|
||||
res_editor->UpdateResourceA(RT_DIALOG, IDD_VERIFY, NSIS_DEFAULT_LANG, 0, 0);
|
||||
res_editor->UpdateResource(RT_DIALOG, IDD_VERIFY, NSIS_DEFAULT_LANG, 0, 0);
|
||||
}
|
||||
|
||||
SCRIPT_MSG(_T("Done!\n"));
|
||||
|
@ -2279,7 +2279,7 @@ int CEXEBuild::SetManifest()
|
|||
return PS_OK;
|
||||
|
||||
// Saved directly as binary into the exe.
|
||||
res_editor->UpdateResourceA(MAKEINTRESOURCE(24), MAKEINTRESOURCE(1), NSIS_DEFAULT_LANG, (LPBYTE) manifest.c_str(), manifest.length());
|
||||
res_editor->UpdateResource(MAKEINTRESOURCE(24), 1, NSIS_DEFAULT_LANG, (LPBYTE) manifest.c_str(), manifest.length());
|
||||
}
|
||||
catch (exception& err) {
|
||||
ERROR_MSG(_T("Error setting manifest: %s\n"), CtoTString(err.what()));
|
||||
|
|
|
@ -1174,13 +1174,13 @@ static int NSISCALL ExecuteEntry(entry *entry_)
|
|||
break;
|
||||
case EW_READINISTR:
|
||||
{
|
||||
DWORD errstr = CHAR4_TO_DWORD(_T('!'), _T('N'), _T('~'), 0);
|
||||
TCHAR errstr[] = _T("!N~");
|
||||
TCHAR *p=var0;
|
||||
TCHAR *buf0=GetStringFromParm(0x01);
|
||||
TCHAR *buf1=GetStringFromParm(0x12);
|
||||
TCHAR *buf2=GetStringFromParm(-0x23);
|
||||
GetPrivateProfileString(buf0,buf1,(LPCTSTR)&errstr,p,NSIS_MAX_STRLEN-1,buf2);
|
||||
if (*(DWORD*)p == errstr)
|
||||
GetPrivateProfileString(buf0,buf1,errstr,p,NSIS_MAX_STRLEN-1,buf2);
|
||||
if (lstrcmp(p, errstr) == 0)
|
||||
{
|
||||
exec_error++;
|
||||
p[0]=0;
|
||||
|
|
|
@ -272,7 +272,6 @@ enum {
|
|||
};
|
||||
|
||||
// nsis strings
|
||||
|
||||
typedef TCHAR NSIS_STRING[NSIS_MAX_STRLEN];
|
||||
|
||||
// Settings common to both installers and uninstallers
|
||||
|
|
|
@ -49,8 +49,8 @@ IconGroup load_icon_res(CResourceEditor* re, WORD id)
|
|||
IconGroupHeader* header;
|
||||
IconGroup result;
|
||||
|
||||
LPBYTE group = re->GetResourceA(
|
||||
RT_GROUP_ICON, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG);
|
||||
LPBYTE group = re->GetResource(
|
||||
RT_GROUP_ICON, id, NSIS_DEFAULT_LANG);
|
||||
|
||||
if (!group)
|
||||
throw runtime_error("can't find icon group");
|
||||
|
@ -69,7 +69,7 @@ IconGroup load_icon_res(CResourceEditor* re, WORD id)
|
|||
|
||||
WORD rsrc_id = FIX_ENDIAN_INT16(entry->wRsrcId);
|
||||
|
||||
icon.data = re->GetResourceA(RT_ICON, MAKEINTRESOURCE(rsrc_id), NSIS_DEFAULT_LANG);
|
||||
icon.data = re->GetResource(RT_ICON, rsrc_id, NSIS_DEFAULT_LANG);
|
||||
|
||||
if (!icon.data)
|
||||
{
|
||||
|
@ -276,17 +276,17 @@ void set_icon(CResourceEditor* re, WORD wIconId, IconGroup icon1, IconGroup icon
|
|||
size_t group_size = sizeof(IconGroupHeader) // header
|
||||
+ order.size() * SIZEOF_RSRC_ICON_GROUP_ENTRY; // entries
|
||||
|
||||
re->UpdateResourceA(RT_GROUP_ICON, MAKEINTRESOURCE(wIconId), NSIS_DEFAULT_LANG, group1, group_size);
|
||||
re->UpdateResource(RT_GROUP_ICON, wIconId, NSIS_DEFAULT_LANG, group1, group_size);
|
||||
|
||||
// delete old icons
|
||||
unsigned i = 1;
|
||||
while (re->UpdateResourceA(RT_ICON, MAKEINTRESOURCE(i++), NSIS_DEFAULT_LANG, 0, 0));
|
||||
while (re->UpdateResource(RT_ICON, i++, NSIS_DEFAULT_LANG, 0, 0));
|
||||
|
||||
// set new icons
|
||||
IconGroup::size_type order_index;
|
||||
for (order_index = 0; order_index < order.size(); order_index++)
|
||||
{
|
||||
DWORD size_index = order[order_index].size_index;
|
||||
WORD size_index = order[order_index].size_index;
|
||||
DWORD size = order[order_index].size;
|
||||
LPBYTE data = new BYTE[size];
|
||||
memset(data, 0, size);
|
||||
|
@ -297,7 +297,7 @@ void set_icon(CResourceEditor* re, WORD wIconId, IconGroup icon1, IconGroup icon
|
|||
memcpy(data, icon->data, FIX_ENDIAN_INT32(icon->meta.dwRawSize));
|
||||
}
|
||||
|
||||
re->UpdateResourceA(RT_ICON, MAKEINTRESOURCE(size_index + 1), NSIS_DEFAULT_LANG, data, size);
|
||||
re->UpdateResource(RT_ICON, size_index + 1, NSIS_DEFAULT_LANG, data, size);
|
||||
|
||||
delete [] data;
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ int generate_unicons_offsets(LPBYTE exeHeader, size_t exeHeaderSize, LPBYTE unin
|
|||
|
||||
LPBYTE seeker = uninstIconData;
|
||||
|
||||
offset = re.GetResourceOffsetA(RT_GROUP_ICON, MAKEINTRESOURCE(wIconId), NSIS_DEFAULT_LANG);
|
||||
offset = re.GetResourceOffset(RT_GROUP_ICON, wIconId, NSIS_DEFAULT_LANG);
|
||||
|
||||
size = FIX_ENDIAN_INT32(*(LPDWORD)seeker);
|
||||
seeker += sizeof(DWORD);
|
||||
|
@ -388,14 +388,14 @@ int generate_unicons_offsets(LPBYTE exeHeader, size_t exeHeaderSize, LPBYTE unin
|
|||
|
||||
while (*(LPDWORD)seeker)
|
||||
{
|
||||
offset = re.GetResourceOffsetA(RT_ICON, MAKEINTRESOURCE(icon_index), NSIS_DEFAULT_LANG);
|
||||
offset = re.GetResourceOffset(RT_ICON, icon_index, NSIS_DEFAULT_LANG);
|
||||
|
||||
if (offset > exeHeaderSize)
|
||||
{
|
||||
throw runtime_error(_T("invalid icon offset (possibly compressed icon)"));
|
||||
throw runtime_error("invalid icon offset (possibly compressed icon)");
|
||||
}
|
||||
|
||||
DWORD real_size = re.GetResourceSizeA(RT_ICON, MAKEINTRESOURCE(icon_index), NSIS_DEFAULT_LANG);
|
||||
DWORD real_size = re.GetResourceSize(RT_ICON, icon_index, NSIS_DEFAULT_LANG);
|
||||
|
||||
size = FIX_ENDIAN_INT32(*(LPDWORD)seeker);
|
||||
seeker += sizeof(DWORD);
|
||||
|
|
|
@ -286,7 +286,7 @@ int StringsArray::set(int idx, const TCHAR *str)
|
|||
|
||||
int old = ((int*)offsets.get())[idx];
|
||||
|
||||
((int*)offsets.get())[idx] = strings.add(str, strlen(str) + 1);
|
||||
((int*)offsets.get())[idx] = strings.add(str, (_tcsclen(str)+1)*sizeof(TCHAR))/sizeof(TCHAR);
|
||||
|
||||
return old;
|
||||
}
|
||||
|
@ -696,14 +696,14 @@ int CEXEBuild::GenerateLangTables() {
|
|||
init_res_editor();
|
||||
|
||||
#define ADD_FONT(id) { \
|
||||
BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); \
|
||||
BYTE* dlg = res_editor->GetResource(RT_DIALOG, id, NSIS_DEFAULT_LANG); \
|
||||
if (dlg) { \
|
||||
CDialogTemplate td(dlg); \
|
||||
res_editor->FreeResource(dlg); \
|
||||
td.SetFont(build_font, (WORD) build_font_size); \
|
||||
DWORD dwSize; \
|
||||
dlg = td.Save(dwSize); \
|
||||
res_editor->UpdateResourceA(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG, dlg, dwSize); \
|
||||
res_editor->UpdateResource(RT_DIALOG, id, NSIS_DEFAULT_LANG, dlg, dwSize); \
|
||||
delete [] dlg; \
|
||||
} \
|
||||
}
|
||||
|
@ -751,7 +751,7 @@ int CEXEBuild::GenerateLangTables() {
|
|||
init_res_editor();
|
||||
|
||||
#define ADD_FONT(id) { \
|
||||
BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG); \
|
||||
BYTE* dlg = res_editor->GetResource(RT_DIALOG, id, NSIS_DEFAULT_LANG); \
|
||||
if (dlg) { \
|
||||
CDialogTemplate td(dlg,lt[i].nlf.m_uCodePage); \
|
||||
res_editor->FreeResource(dlg); \
|
||||
|
@ -766,7 +766,7 @@ int CEXEBuild::GenerateLangTables() {
|
|||
} \
|
||||
DWORD dwSize; \
|
||||
dlg = td.Save(dwSize); \
|
||||
res_editor->UpdateResourceA(RT_DIALOG, MAKEINTRESOURCE(id+cur_offset), NSIS_DEFAULT_LANG, dlg, dwSize); \
|
||||
res_editor->UpdateResource(RT_DIALOG, id+cur_offset, NSIS_DEFAULT_LANG, dlg, dwSize); \
|
||||
delete [] dlg; \
|
||||
} \
|
||||
}
|
||||
|
|
|
@ -2157,7 +2157,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
try {
|
||||
init_res_editor();
|
||||
|
||||
BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(IDD_INSTFILES), NSIS_DEFAULT_LANG);
|
||||
BYTE* dlg = res_editor->GetResource(RT_DIALOG, IDD_INSTFILES, NSIS_DEFAULT_LANG);
|
||||
if (!dlg) throw runtime_error("IDD_INSTFILES doesn't exist!");
|
||||
CDialogTemplate dt(dlg,uDefCodePage);
|
||||
free(dlg);
|
||||
|
@ -2173,7 +2173,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
|
||||
DWORD dwSize;
|
||||
dlg = dt.Save(dwSize);
|
||||
res_editor->UpdateResourceA(RT_DIALOG, MAKEINTRESOURCE(IDD_INSTFILES), NSIS_DEFAULT_LANG, dlg, dwSize);
|
||||
res_editor->UpdateResource(RT_DIALOG, IDD_INSTFILES, NSIS_DEFAULT_LANG, dlg, dwSize);
|
||||
delete [] dlg;
|
||||
}
|
||||
catch (exception& err) {
|
||||
|
@ -2452,9 +2452,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
init_res_editor();
|
||||
|
||||
// Search for required items
|
||||
#define GET(x) dlg = uire->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(x), 0); if (!dlg) return PS_ERROR; CDialogTemplate UIDlg(dlg, uDefCodePage);
|
||||
#define SEARCH(x) if (!UIDlg.GetItem(x)) {ERROR_MSG("Error: Can't find %s (%u) in the custom UI!\n", #x, x);delete [] dlg;delete uire;return PS_ERROR;}
|
||||
#define SAVE(x) dwSize = UIDlg.GetSize(); res_editor->UpdateResourceA(RT_DIALOG, x, NSIS_DEFAULT_LANG, dlg, dwSize); delete [] dlg;
|
||||
#define GET(x) dlg = uire->GetResource(RT_DIALOG, x, 0); if (!dlg) return PS_ERROR; CDialogTemplate UIDlg(dlg, uDefCodePage);
|
||||
#define SEARCH(x) if (!UIDlg.GetItem(x)) {ERROR_MSG(_T("Error: Can't find %s (%u) in the custom UI!\n"), _T(#x), x);delete [] dlg;delete uire;return PS_ERROR;}
|
||||
#define SAVE(x) dwSize = UIDlg.GetSize(); res_editor->UpdateResource(RT_DIALOG, x, NSIS_DEFAULT_LANG, dlg, dwSize); delete [] dlg;
|
||||
|
||||
LPBYTE dlg = NULL;
|
||||
|
||||
|
@ -2570,7 +2570,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
padding = line.gettoken_int(3);
|
||||
|
||||
init_res_editor();
|
||||
BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), NSIS_DEFAULT_LANG);
|
||||
BYTE* dlg = res_editor->GetResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG);
|
||||
|
||||
CDialogTemplate dt(dlg, uDefCodePage);
|
||||
|
||||
|
@ -2618,7 +2618,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
DWORD dwDlgSize;
|
||||
dlg = dt.Save(dwDlgSize);
|
||||
|
||||
res_editor->UpdateResourceA(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, dlg, dwDlgSize);
|
||||
res_editor->UpdateResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, dlg, dwDlgSize);
|
||||
|
||||
delete [] dlg;
|
||||
|
||||
|
@ -2846,7 +2846,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
for (;;) {
|
||||
TCHAR *p=str;
|
||||
*p=0;
|
||||
fgets(str,MAX_LINELENGTH,fp);
|
||||
_fgetts(str,MAX_LINELENGTH,fp);
|
||||
linecnt++;
|
||||
if (feof(fp)&&!str[0]) break;
|
||||
|
||||
|
@ -3668,7 +3668,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
if (trim) try {
|
||||
init_res_editor();
|
||||
|
||||
BYTE* dlg = res_editor->GetResourceA(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), NSIS_DEFAULT_LANG);
|
||||
BYTE* dlg = res_editor->GetResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG);
|
||||
CDialogTemplate td(dlg,uDefCodePage);
|
||||
free(dlg);
|
||||
|
||||
|
@ -3695,7 +3695,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
|
||||
DWORD dwSize;
|
||||
dlg = td.Save(dwSize);
|
||||
res_editor->UpdateResourceA(RT_DIALOG, MAKEINTRESOURCE(IDD_INST), NSIS_DEFAULT_LANG, dlg, dwSize);
|
||||
res_editor->UpdateResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, dlg, dwSize);
|
||||
res_editor->FreeResource(dlg);
|
||||
}
|
||||
catch (exception& err) {
|
||||
|
|
|
@ -1,204 +1,205 @@
|
|||
/*
|
||||
* strlist.cpp: Implementation of the StringList class.
|
||||
*
|
||||
* This file is a part of NSIS.
|
||||
*
|
||||
* Copyright (C) 1999-2009 Nullsoft and Contributors
|
||||
*
|
||||
* Licensed under the zlib/libpng license (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
*
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty.
|
||||
*/
|
||||
|
||||
#include "strlist.h"
|
||||
|
||||
int StringList::add(const TCHAR *str, int case_sensitive)
|
||||
{
|
||||
int a=find(str,case_sensitive);
|
||||
if (a >= 0 && case_sensitive!=-1) return a;
|
||||
return gr.add(str,strlen(str)+1);
|
||||
}
|
||||
|
||||
// use 2 for case sensitive end-of-string matches too
|
||||
int StringList::find(const TCHAR *str, int case_sensitive, int *idx/*=NULL*/) const // returns -1 if not found
|
||||
{
|
||||
const TCHAR *s=get();
|
||||
int ml=getlen();
|
||||
int offs=0;
|
||||
if (idx) *idx=0;
|
||||
while (offs < ml)
|
||||
{
|
||||
if ((case_sensitive && !strcmp(s+offs,str)) ||
|
||||
(!case_sensitive && !stricmp(s+offs,str)))
|
||||
{
|
||||
return offs;
|
||||
}
|
||||
if (case_sensitive==2 &&
|
||||
strlen(str) < strlen(s+offs) && // check for end of string
|
||||
!strcmp(s+offs+strlen(s+offs)-strlen(str),str))
|
||||
{
|
||||
return offs+strlen(s+offs)-strlen(str);
|
||||
}
|
||||
offs+=strlen(s+offs)+1;
|
||||
if (idx) (*idx)++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void StringList::delbypos(int pos)
|
||||
{
|
||||
TCHAR *s=(TCHAR*)gr.get();
|
||||
int len=strlen(s+pos)+1;
|
||||
if (pos+len < gr.getlen()) memcpy(s+pos,s+pos+len,gr.getlen()-(pos+len));
|
||||
gr.resize(gr.getlen()-len);
|
||||
}
|
||||
|
||||
int StringList::idx2pos(int idx) const
|
||||
{
|
||||
TCHAR *s=(TCHAR*)gr.get();
|
||||
int offs=0;
|
||||
int cnt=0;
|
||||
if (idx>=0) while (offs < gr.getlen())
|
||||
{
|
||||
if (cnt++ == idx) return offs;
|
||||
offs+=strlen(s+offs)+1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int StringList::getnum() const
|
||||
{
|
||||
TCHAR *s=(TCHAR*)gr.get();
|
||||
int ml=gr.getlen();
|
||||
int offs=0;
|
||||
int idx=0;
|
||||
while (offs < ml)
|
||||
{
|
||||
offs+=strlen(s+offs)+1;
|
||||
idx++;
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
const TCHAR *StringList::get() const
|
||||
{
|
||||
return (const TCHAR*)gr.get();
|
||||
}
|
||||
|
||||
int StringList::getlen() const
|
||||
{
|
||||
return gr.getlen();
|
||||
}
|
||||
|
||||
// ==========
|
||||
// DefineList
|
||||
// ==========
|
||||
|
||||
DefineList::~DefineList()
|
||||
{
|
||||
struct define *s=(struct define*)gr.get();
|
||||
int num=gr.getlen()/sizeof(struct define);
|
||||
|
||||
for (int i=0; i<num; i++) {
|
||||
free(s[i].value);
|
||||
}
|
||||
}
|
||||
|
||||
int DefineList::add(const TCHAR *name, const TCHAR *value/*=_T("")*/)
|
||||
{
|
||||
int pos=SortedStringList<struct define>::add(name);
|
||||
if (pos == -1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
TCHAR **newvalue=&(((struct define*)gr.get())[pos].value);
|
||||
*newvalue=(TCHAR*)malloc(strlen(value)+1);
|
||||
if (!(*newvalue))
|
||||
{
|
||||
extern FILE *g_output;
|
||||
extern int g_display_errors;
|
||||
extern void quit();
|
||||
if (g_display_errors)
|
||||
{
|
||||
fprintf(g_output,_T("\nInternal compiler error #12345: GrowBuf realloc/malloc(%lu) failed.\n"),(unsigned long)strlen(value)+1);
|
||||
fflush(g_output);
|
||||
}
|
||||
quit();
|
||||
}
|
||||
strcpy(*newvalue,value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
TCHAR *DefineList::find(const TCHAR *name)
|
||||
{
|
||||
int v=SortedStringList<struct define>::find(name);
|
||||
if (v==-1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return ((struct define*)gr.get())[v].value;
|
||||
}
|
||||
|
||||
// returns 0 on success, 1 otherwise
|
||||
int DefineList::del(const TCHAR *str)
|
||||
{
|
||||
int pos=SortedStringList<struct define>::find(str);
|
||||
if (pos==-1) return 1;
|
||||
|
||||
struct define *db=(struct define *)gr.get();
|
||||
free(db[pos].value);
|
||||
delbypos(pos);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DefineList::getnum()
|
||||
{
|
||||
return gr.getlen()/sizeof(define);
|
||||
}
|
||||
|
||||
TCHAR *DefineList::getname(int num)
|
||||
{
|
||||
if ((unsigned int)getnum() <= (unsigned int)num)
|
||||
return 0;
|
||||
return ((struct define*)gr.get())[num].name;
|
||||
}
|
||||
|
||||
TCHAR *DefineList::getvalue(int num)
|
||||
{
|
||||
if ((unsigned int)getnum() <= (unsigned int)num)
|
||||
return 0;
|
||||
return ((struct define*)gr.get())[num].value;
|
||||
}
|
||||
|
||||
// ==============
|
||||
// FastStringList
|
||||
// ==============
|
||||
|
||||
int FastStringList::add(const TCHAR *name, int case_sensitive/*=0*/)
|
||||
{
|
||||
int pos = SortedStringListND<struct string_t>::add(name, case_sensitive);
|
||||
if (pos == -1) return -1;
|
||||
return ((struct string_t*)gr.get())[pos].name;
|
||||
}
|
||||
|
||||
TCHAR *FastStringList::get() const
|
||||
{
|
||||
return (TCHAR*)strings.get();
|
||||
}
|
||||
|
||||
int FastStringList::getlen() const
|
||||
{
|
||||
return strings.getlen();
|
||||
}
|
||||
|
||||
int FastStringList::getnum() const
|
||||
{
|
||||
return gr.getlen()/sizeof(struct string_t);
|
||||
}
|
||||
|
||||
/*
|
||||
* strlist.cpp: Implementation of the StringList class.
|
||||
*
|
||||
* This file is a part of NSIS.
|
||||
*
|
||||
* Copyright (C) 1999-2009 Nullsoft and Contributors
|
||||
*
|
||||
* Licensed under the zlib/libpng license (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
*
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty.
|
||||
*/
|
||||
|
||||
#include "strlist.h"
|
||||
|
||||
int StringList::add(const TCHAR *str, int case_sensitive)
|
||||
{
|
||||
int a=find(str,case_sensitive);
|
||||
if (a >= 0 && case_sensitive!=-1) return a;
|
||||
return gr.add(str,(_tcsclen(str)+1)*sizeof(TCHAR))/sizeof(TCHAR);
|
||||
}
|
||||
|
||||
// use 2 for case sensitive end-of-string matches too
|
||||
int StringList::find(const TCHAR *str, int case_sensitive, int *idx/*=NULL*/) const // returns -1 if not found
|
||||
{
|
||||
const TCHAR *s=get();
|
||||
int ml=getlen();
|
||||
int offs=0;
|
||||
if (idx) *idx=0;
|
||||
while (offs < ml)
|
||||
{
|
||||
if ((case_sensitive && !_tcscmp(s+offs,str)) ||
|
||||
(!case_sensitive && !_tcsicmp(s+offs,str)))
|
||||
{
|
||||
return offs;
|
||||
}
|
||||
if (case_sensitive==2 &&
|
||||
_tcslen(str) < _tcslen(s+offs) && // check for end of string
|
||||
!_tcscmp(s+offs+_tcslen(s+offs)-_tcslen(str),str))
|
||||
{
|
||||
return offs+_tcslen(s+offs)-_tcslen(str);
|
||||
}
|
||||
offs+=_tcslen(s+offs)+1;
|
||||
if (idx) (*idx)++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void StringList::delbypos(int pos)
|
||||
{
|
||||
TCHAR *s=(TCHAR*)gr.get();
|
||||
int len=_tcslen(s+pos)+1;
|
||||
if (pos+len < gr.getlen()) memcpy(s+pos,s+pos+len,gr.getlen()-(pos+len));
|
||||
gr.resize(gr.getlen()-len);
|
||||
}
|
||||
|
||||
int StringList::idx2pos(int idx) const
|
||||
{
|
||||
TCHAR *s=(TCHAR*)gr.get();
|
||||
int offs=0;
|
||||
int cnt=0;
|
||||
if (idx>=0) while (offs < gr.getlen())
|
||||
{
|
||||
if (cnt++ == idx) return offs;
|
||||
offs+=_tcslen(s+offs)+1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int StringList::getnum() const
|
||||
{
|
||||
TCHAR *s=(TCHAR*)gr.get();
|
||||
int ml=gr.getlen();
|
||||
int offs=0;
|
||||
int idx=0;
|
||||
while (offs < ml)
|
||||
{
|
||||
offs+=_tcslen(s+offs)+1;
|
||||
idx++;
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
const TCHAR *StringList::get() const
|
||||
{
|
||||
return (const TCHAR*)gr.get();
|
||||
}
|
||||
|
||||
int StringList::getlen() const
|
||||
{
|
||||
return gr.getlen();
|
||||
}
|
||||
|
||||
// ==========
|
||||
// DefineList
|
||||
// ==========
|
||||
|
||||
DefineList::~DefineList()
|
||||
{
|
||||
struct define *s=(struct define*)gr.get();
|
||||
int num=gr.getlen()/sizeof(struct define);
|
||||
|
||||
for (int i=0; i<num; i++) {
|
||||
free(s[i].value);
|
||||
}
|
||||
}
|
||||
|
||||
int DefineList::add(const TCHAR *name, const TCHAR *value/*=_T("")*/)
|
||||
{
|
||||
int pos=SortedStringList<struct define>::add(name);
|
||||
if (pos == -1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
TCHAR **newvalue=&(((struct define*)gr.get())[pos].value);
|
||||
size_t size_in_bytes = (_tcslen(value) + 1) * sizeof(TCHAR);
|
||||
*newvalue=(TCHAR*)malloc(size_in_bytes);
|
||||
if (!(*newvalue))
|
||||
{
|
||||
extern FILE *g_output;
|
||||
extern int g_display_errors;
|
||||
extern void quit();
|
||||
if (g_display_errors)
|
||||
{
|
||||
_ftprintf(g_output,_T("\nInternal compiler error #12345: GrowBuf realloc/malloc(%lu) failed.\n"), (unsigned long) size_in_bytes);
|
||||
fflush(g_output);
|
||||
}
|
||||
quit();
|
||||
}
|
||||
_tcscpy(*newvalue,value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
TCHAR *DefineList::find(const TCHAR *name)
|
||||
{
|
||||
int v=SortedStringList<struct define>::find(name);
|
||||
if (v==-1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return ((struct define*)gr.get())[v].value;
|
||||
}
|
||||
|
||||
// returns 0 on success, 1 otherwise
|
||||
int DefineList::del(const TCHAR *str)
|
||||
{
|
||||
int pos=SortedStringList<struct define>::find(str);
|
||||
if (pos==-1) return 1;
|
||||
|
||||
struct define *db=(struct define *)gr.get();
|
||||
free(db[pos].value);
|
||||
delbypos(pos);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DefineList::getnum()
|
||||
{
|
||||
return gr.getlen()/sizeof(define);
|
||||
}
|
||||
|
||||
TCHAR *DefineList::getname(int num)
|
||||
{
|
||||
if ((unsigned int)getnum() <= (unsigned int)num)
|
||||
return 0;
|
||||
return ((struct define*)gr.get())[num].name;
|
||||
}
|
||||
|
||||
TCHAR *DefineList::getvalue(int num)
|
||||
{
|
||||
if ((unsigned int)getnum() <= (unsigned int)num)
|
||||
return 0;
|
||||
return ((struct define*)gr.get())[num].value;
|
||||
}
|
||||
|
||||
// ==============
|
||||
// FastStringList
|
||||
// ==============
|
||||
|
||||
int FastStringList::add(const TCHAR *name, int case_sensitive/*=0*/)
|
||||
{
|
||||
int pos = SortedStringListND<struct string_t>::add(name, case_sensitive);
|
||||
if (pos == -1) return -1;
|
||||
return ((struct string_t*)gr.get())[pos].name;
|
||||
}
|
||||
|
||||
TCHAR *FastStringList::get() const
|
||||
{
|
||||
return (TCHAR*)strings.get();
|
||||
}
|
||||
|
||||
int FastStringList::getlen() const
|
||||
{
|
||||
return strings.getlen();
|
||||
}
|
||||
|
||||
int FastStringList::getnum() const
|
||||
{
|
||||
return gr.getlen()/sizeof(struct string_t);
|
||||
}
|
||||
|
||||
|
|
|
@ -210,7 +210,7 @@ class SortedStringList
|
|||
if (case_sensitive)
|
||||
res=_tcscmp(str, data[nextpos].name);
|
||||
else
|
||||
res=stricmp(str, data[nextpos].name);
|
||||
res=_tcsicmp(str, data[nextpos].name);
|
||||
if (res==0) return returnbestpos ? -1 : nextpos;
|
||||
if (res<0) ul=nextpos;
|
||||
else ll=nextpos+1;
|
||||
|
@ -302,7 +302,7 @@ class SortedStringListND // no delete - can be placed in GrowBuf
|
|||
if (pos==-1) return alwaysreturnpos ? where : -1;
|
||||
|
||||
// Note that .name is set with the TCHAR* offset into m_strings.
|
||||
newstruct.name=strings.add(name,strlen(name)+1);
|
||||
newstruct.name=strings.add(name,(_tcsclen(name)+1)*sizeof(TCHAR))/sizeof(TCHAR);
|
||||
|
||||
gr.add(&newstruct,sizeof(T));
|
||||
T *s=(T*)gr.get();
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#ifndef _TSTRING_
|
||||
#define _TSTRING_
|
||||
|
||||
#include "Platform.h"
|
||||
#include "tchar.h"
|
||||
#include <string>
|
||||
|
||||
|
@ -28,9 +29,7 @@ typedef std::wstring tstring;
|
|||
typedef std::wofstream tofstream;
|
||||
typedef std::wifstream tifstream;
|
||||
// Use the following macros to open text files.
|
||||
// #define FOPENTEXT(file, mode) _wfopen(file, mode ## L", ccs=Unicode")
|
||||
FILE* FileOpenUnicodeText(const TCHAR* file, const TCHAR* mode);
|
||||
#define FOPENTEXT(file, mode) FileOpenUnicodeText(file, mode)
|
||||
#define FOPENTEXT(file, mode) _wfopen(file, mode)
|
||||
#else
|
||||
typedef std::string tstring;
|
||||
typedef std::ofstream tofstream;
|
||||
|
@ -56,10 +55,16 @@ public:
|
|||
m_wStr = (wchar_t*) GlobalAlloc(GPTR, len*sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_ACP, 0, str, -1, m_wStr, len);
|
||||
}
|
||||
CtoTString(const std::string& str)
|
||||
{
|
||||
int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length()+1, NULL, 0);
|
||||
m_wStr = (wchar_t*) GlobalAlloc(GPTR, len*sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length()+1, m_wStr, len);
|
||||
}
|
||||
|
||||
~CtoTString() { GlobalFree(m_wStr); m_wStr = 0; }
|
||||
|
||||
operator const wchar_t* tstr() { return m_wStr; }
|
||||
operator const wchar_t*() { return m_wStr; }
|
||||
|
||||
private:
|
||||
wchar_t* m_wStr;
|
||||
|
@ -76,6 +81,12 @@ public:
|
|||
m_cStr = (char*) GlobalAlloc(GPTR, len);
|
||||
WideCharToMultiByte(CP_ACP, 0, wStr, -1, m_cStr, len, 0, 0);
|
||||
}
|
||||
TtoCString(const tstring& wStr)
|
||||
{
|
||||
int len = WideCharToMultiByte(CP_ACP, 0, wStr.c_str(), wStr.length()+1, NULL, 0, 0, 0);
|
||||
m_cStr = (char*) GlobalAlloc(GPTR, len);
|
||||
WideCharToMultiByte(CP_ACP, 0, wStr.c_str(), wStr.length()+1, m_cStr, len, 0, 0);
|
||||
}
|
||||
|
||||
~TtoCString() { GlobalFree(m_cStr); m_cStr = 0; }
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ int update_bitmap(CResourceEditor* re, WORD id, const TCHAR* filename, int width
|
|||
}
|
||||
fclose(f);
|
||||
|
||||
re->UpdateResourceA(RT_BITMAP, MAKEINTRESOURCE(id), NSIS_DEFAULT_LANG, bitmap, dwSize);
|
||||
re->UpdateResource(RT_BITMAP, id, NSIS_DEFAULT_LANG, bitmap, dwSize);
|
||||
|
||||
free(bitmap);
|
||||
|
||||
|
@ -537,8 +537,8 @@ static bool GetDLLVersionUsingRE(const tstring& filepath, DWORD& high, DWORD & l
|
|||
try
|
||||
{
|
||||
CResourceEditor *dllre = new CResourceEditor(dll, len);
|
||||
LPBYTE ver = dllre->GetResourceA(VS_FILE_INFO, MAKEINTRESOURCE(VS_VERSION_INFO), 0);
|
||||
int versize = dllre->GetResourceSizeA(VS_FILE_INFO, MAKEINTRESOURCE(VS_VERSION_INFO), 0);
|
||||
LPBYTE ver = dllre->GetResource(VS_FILE_INFO, VS_VERSION_INFO, 0);
|
||||
int versize = dllre->GetResourceSize(VS_FILE_INFO, VS_VERSION_INFO, 0);
|
||||
|
||||
if (ver)
|
||||
{
|
||||
|
|
|
@ -24,8 +24,11 @@
|
|||
|
||||
using std::runtime_error;
|
||||
|
||||
WCHAR *winchar_fromansi(const char* s, unsigned int codepage/*=CP_ACP*/)
|
||||
WCHAR *winchar_fromTchar(const TCHAR* s, unsigned int codepage/*=CP_ACP*/)
|
||||
{
|
||||
#ifdef _UNICODE
|
||||
return _wcsdup(s); // codepage is not used in this mode
|
||||
#else
|
||||
int l = MultiByteToWideChar(codepage, 0, s, -1, 0, 0);
|
||||
if (l == 0)
|
||||
throw runtime_error("Unicode conversion failed");
|
||||
|
@ -36,20 +39,7 @@ WCHAR *winchar_fromansi(const char* s, unsigned int codepage/*=CP_ACP*/)
|
|||
throw runtime_error("Unicode conversion failed");
|
||||
|
||||
return ws;
|
||||
}
|
||||
|
||||
char *winchar_toansi(const WCHAR* ws, unsigned int codepage/*=CP_ACP*/)
|
||||
{
|
||||
int l = WideCharToMultiByte(codepage, 0, ws, -1, 0, 0, 0, 0);
|
||||
if (l == 0)
|
||||
throw runtime_error("Unicode conversion failed");
|
||||
|
||||
char *s = new char[l + 1];
|
||||
|
||||
if (WideCharToMultiByte(codepage, 0, ws, -1, s, l + 1, 0, 0) == 0)
|
||||
throw runtime_error("Unicode conversion failed");
|
||||
|
||||
return s;
|
||||
#endif
|
||||
}
|
||||
|
||||
WCHAR *winchar_strcpy(WCHAR *ws1, const WCHAR *ws2)
|
||||
|
@ -115,14 +105,3 @@ int winchar_strcmp(const WCHAR *ws1, const WCHAR *ws2)
|
|||
|
||||
return diff;
|
||||
}
|
||||
|
||||
int winchar_stoi(const WCHAR *ws)
|
||||
{
|
||||
char *s = winchar_toansi(ws);
|
||||
|
||||
int ret = atoi(s);
|
||||
|
||||
delete [] s;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -18,11 +18,9 @@
|
|||
|
||||
#include "Platform.h"
|
||||
|
||||
WCHAR *winchar_fromansi(const char* s, unsigned int codepage = CP_ACP);
|
||||
char *winchar_toansi(const WCHAR* ws, unsigned int codepage = CP_ACP);
|
||||
WCHAR *winchar_fromTchar(const TCHAR* s, unsigned int codepage = CP_ACP);
|
||||
WCHAR *winchar_strcpy(WCHAR *ws1, const WCHAR *ws2);
|
||||
WCHAR *winchar_strncpy(WCHAR *ws1, const WCHAR *ws2, size_t n);
|
||||
size_t winchar_strlen(const WCHAR *ws);
|
||||
WCHAR *winchar_strdup(const WCHAR *ws);
|
||||
int winchar_strcmp(const WCHAR *ws1, const WCHAR *ws2);
|
||||
int winchar_stoi(const WCHAR *ws);
|
||||
|
|
|
@ -50,19 +50,29 @@ void writer_sink::write_int_array(const int i[], const size_t len)
|
|||
}
|
||||
}
|
||||
|
||||
void writer_sink::write_string(const char *s)
|
||||
{
|
||||
write_data(s, strlen(s) + 1);
|
||||
}
|
||||
|
||||
// size in this case is the length of the string to write.
|
||||
void writer_sink::write_string(const char *s, const size_t size)
|
||||
void writer_sink::write_string(const TCHAR *s, size_t size)
|
||||
{
|
||||
#ifdef _UNICODE
|
||||
bool strEnd = false;
|
||||
TCHAR ch;
|
||||
for (; size ; size--)
|
||||
{
|
||||
if (!strEnd)
|
||||
{
|
||||
ch = *s++;
|
||||
if (ch == _T('\0'))
|
||||
strEnd = true;
|
||||
}
|
||||
write_short(ch);
|
||||
}
|
||||
#else
|
||||
char *wb = new char[size];
|
||||
memset(wb, 0, size);
|
||||
strncpy(wb, s, size);
|
||||
write_data(wb, size);
|
||||
delete [] wb;
|
||||
#endif
|
||||
}
|
||||
|
||||
void writer_sink::write_growbuf(const IGrowBuf *b)
|
||||
|
|
|
@ -34,8 +34,7 @@ public:
|
|||
virtual void write_short(const short s);
|
||||
virtual void write_int(const int i);
|
||||
virtual void write_int_array(const int i[], const size_t len);
|
||||
virtual void write_string(const TCHAR *s);
|
||||
virtual void write_string(const TCHAR *s, const size_t size);
|
||||
virtual void write_string(const TCHAR *s, size_t size);
|
||||
virtual void write_growbuf(const IGrowBuf *b);
|
||||
|
||||
virtual void write_data(const void *data, const size_t size) = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue