Jim Park's Unicode NSIS merging - Step 4 : merging more TCHAR stuff that shouldn't have any impact
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6041 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
8ab72b9ece
commit
acf9a8c21f
41 changed files with 937 additions and 586 deletions
|
@ -146,8 +146,7 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPTSTR lpszCmdPara
|
|||
{
|
||||
cmdline++;
|
||||
|
||||
// this only works with spaces because they have just one bit on
|
||||
#define END_OF_ARG(c) (((c)|_T(' '))==_T(' '))
|
||||
#define END_OF_ARG(c) (c == _T(' ') || c == _T('\0'))
|
||||
|
||||
#if defined(NSIS_CONFIG_VISIBLE_SUPPORT) && defined(NSIS_CONFIG_SILENT_SUPPORT)
|
||||
if (cmdline[0] == _T('S') && END_OF_ARG(cmdline[1]))
|
||||
|
|
|
@ -249,7 +249,9 @@ FORCE_INLINE int NSISCALL ui_doinstall(void)
|
|||
static const TCHAR reg_nt_locale_key[] = _T(".DEFAULT\\Control Panel\\International");
|
||||
const TCHAR *reg_nt_locale_val = ®_9x_locale[30]; // = _T("Locale") with opt
|
||||
|
||||
*(DWORD*)state_language = CHAR4_TO_DWORD(_T('0'), _T('x'), 0, 0);
|
||||
state_language[0] = _T('0');
|
||||
state_language[1] = _T('x');
|
||||
state_language[2] = 0;
|
||||
|
||||
{
|
||||
// Windows 9x
|
||||
|
@ -318,7 +320,6 @@ FORCE_INLINE int NSISCALL ui_doinstall(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
mystrcpy(state_install_directory,addtrailingslash(p));
|
||||
}
|
||||
}
|
||||
|
@ -343,20 +344,20 @@ FORCE_INLINE int NSISCALL ui_doinstall(void)
|
|||
#ifdef NSIS_SUPPORT_BGBG
|
||||
if (header->bg_color1 != -1)
|
||||
{
|
||||
DWORD cn = CHAR4_TO_DWORD(_T('_'), _T('N'), _T('b'), 0);
|
||||
LPCTSTR cn = _T("_Nb");
|
||||
RECT vp;
|
||||
extern LRESULT CALLBACK BG_WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||
wc.lpfnWndProc = BG_WndProc;
|
||||
wc.hInstance = g_hInstance;
|
||||
wc.hIcon = g_hIcon;
|
||||
//wc.hCursor = LoadCursor(NULL,IDC_ARROW);
|
||||
wc.lpszClassName = (LPCTSTR)&cn;
|
||||
wc.lpszClassName = cn;
|
||||
|
||||
if (!RegisterClass(&wc)) return 0;
|
||||
|
||||
SystemParametersInfo(SPI_GETWORKAREA, 0, &vp, 0);
|
||||
|
||||
m_bgwnd = CreateWindowEx(WS_EX_TOOLWINDOW,(LPCTSTR)&cn,0,WS_POPUP,
|
||||
m_bgwnd = CreateWindowEx(WS_EX_TOOLWINDOW,cn,0,WS_POPUP,
|
||||
vp.left,vp.top,vp.right-vp.left,vp.bottom-vp.top,0,NULL,g_hInstance,NULL);
|
||||
}
|
||||
|
||||
|
@ -399,6 +400,7 @@ FORCE_INLINE int NSISCALL ui_doinstall(void)
|
|||
RegisterClass(&wc);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
|
@ -434,7 +436,6 @@ FORCE_INLINE int NSISCALL ui_doinstall(void)
|
|||
#endif//NSIS_CONFIG_SILENT_SUPPORT
|
||||
}
|
||||
|
||||
|
||||
#ifdef NSIS_CONFIG_VISIBLE_SUPPORT
|
||||
static int CALLBACK WINAPI BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
|
||||
{
|
||||
|
@ -894,6 +895,7 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
|
|||
page *thispage = g_this_page;
|
||||
TCHAR *dir = g_usrvars[thispage->parms[4]];
|
||||
int browse_text = thispage->parms[3];
|
||||
|
||||
if (uMsg == WM_NOTIFY_INIGO_MONTOYA)
|
||||
{
|
||||
GetUIText(IDC_DIR,dir);
|
||||
|
@ -1026,7 +1028,6 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
|
|||
* 6. `dir' is never modified.
|
||||
*
|
||||
*/
|
||||
|
||||
mystrcpy(s,dir);
|
||||
|
||||
// Test for and use the GetDiskFreeSpaceEx API
|
||||
|
@ -1038,8 +1039,8 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
|
|||
ULARGE_INTEGER available64;
|
||||
ULARGE_INTEGER a, b;
|
||||
TCHAR *p;
|
||||
WORD *pw = NULL;
|
||||
while ((TCHAR *) pw != s) // trimslashtoend() cut the entire string
|
||||
TCHAR *pw = NULL;
|
||||
while (pw != s) // trimslashtoend() cut the entire string
|
||||
{
|
||||
if (GDFSE(s, &available64, &a, &b))
|
||||
{
|
||||
|
@ -1057,8 +1058,11 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
|
|||
*pw = 0;
|
||||
|
||||
p = trimslashtoend(s); // trim last backslash
|
||||
pw = (LPWORD) (p - 1);
|
||||
*pw = CHAR2_TO_WORD(_T('\\'), 0); // bring it back, but make the next TCHAR null
|
||||
// bring it back, but make the next char null
|
||||
pw = p;
|
||||
*pw = 0;
|
||||
--pw;
|
||||
*pw = _T('\\');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1730,12 +1734,16 @@ static BOOL CALLBACK InstProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|
|||
do {
|
||||
item.pszText = ptr;
|
||||
ptr += SendMessage(linsthwnd,LVM_GETITEMTEXT,i,(LPARAM)&item);
|
||||
*(WORD*)ptr = CHAR2_TO_WORD(_T('\r'),_T('\n'));
|
||||
ptr+=2;
|
||||
*ptr++ = _T('\r');
|
||||
*ptr++ = _T('\n');
|
||||
} while (++i < count);
|
||||
// memory is auto zeroed when allocated with GHND - *ptr = 0;
|
||||
GlobalUnlock(memory);
|
||||
#ifdef _UNICODE
|
||||
SetClipboardData(CF_UNICODETEXT,memory);
|
||||
#else
|
||||
SetClipboardData(CF_TEXT,memory);
|
||||
#endif
|
||||
CloseClipboard();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1067,10 +1067,14 @@ static int NSISCALL ExecuteEntry(entry *entry_)
|
|||
|
||||
if (SUCCEEDED(hres))
|
||||
{
|
||||
static WCHAR wsz[1024];
|
||||
hres=E_FAIL;
|
||||
if (MultiByteToWideChar(CP_ACP, 0, buf1, -1, wsz, 1024))
|
||||
hres=ppf->lpVtbl->Save(ppf,(const WCHAR*)wsz,TRUE);
|
||||
#ifdef _UNICODE
|
||||
hres=ppf->lpVtbl->Save(ppf,(const WCHAR*)buf1,TRUE);
|
||||
#else
|
||||
static WCHAR wsz[1024];
|
||||
hres=E_FAIL;
|
||||
if (MultiByteToWideChar(CP_ACP, 0, buf1, -1, wsz, 1024))
|
||||
hres=ppf->lpVtbl->Save(ppf,(const WCHAR*)wsz,TRUE);
|
||||
#endif
|
||||
}
|
||||
ppf->lpVtbl->Release(ppf);
|
||||
}
|
||||
|
|
|
@ -483,6 +483,7 @@ typedef struct {
|
|||
#define NS_SHELL_CODE 254
|
||||
#define NS_LANG_CODE 255
|
||||
#define NS_CODES_START NS_SKIP_CODE
|
||||
#define NS_IS_CODE(x) ((x) >= NS_SKIP_CODE)
|
||||
|
||||
// We are doing this to store an integer value into a char string and we
|
||||
// don't want false end of string values so we shift then OR with 0x8080
|
||||
|
|
|
@ -285,7 +285,8 @@ TCHAR * NSISCALL trimslashtoend(TCHAR *buf)
|
|||
int NSISCALL validpathspec(TCHAR *ubuf)
|
||||
{
|
||||
TCHAR dl = ubuf[0] | 0x20; // convert alleged drive letter to lower case
|
||||
return ((*(WORD*)ubuf==CHAR2_TO_WORD(_T('\\'),_T('\\'))) || (dl >= _T('a') && dl <= _T('z') && ubuf[1]==_T(':')));
|
||||
return ((ubuf[0] == _T('\\') && ubuf[1] == _T('\\')) ||
|
||||
(dl >= _T('a') && dl <= _T('z') && ubuf[1] == _T(':')));
|
||||
}
|
||||
|
||||
TCHAR * NSISCALL skip_root(TCHAR *path)
|
||||
|
@ -293,11 +294,11 @@ TCHAR * NSISCALL skip_root(TCHAR *path)
|
|||
TCHAR *p = CharNext(path);
|
||||
TCHAR *p2 = CharNext(p);
|
||||
|
||||
if (*path && *(WORD*)p == CHAR2_TO_WORD(_T(':'), _T('\\')))
|
||||
if (*path && p[0] == _T(':') && p[1] == _T('\\'))
|
||||
{
|
||||
return CharNext(p2);
|
||||
}
|
||||
else if (*(WORD*)path == CHAR2_TO_WORD(_T('\\'),_T('\\')))
|
||||
else if (path[0] == _T('\\') && path[1] == _T('\\'))
|
||||
{
|
||||
// skip host and share name
|
||||
int x = 2;
|
||||
|
@ -357,20 +358,21 @@ int NSISCALL is_valid_instpath(TCHAR *s)
|
|||
return 1;
|
||||
}
|
||||
|
||||
TCHAR * NSISCALL mystrstri(TCHAR *a, const TCHAR *b)
|
||||
// Used strictly for the wininit.ini file which is an ASCII file.
|
||||
char * NSISCALL mystrstriA(char *a, const char *b)
|
||||
{
|
||||
int l = mystrlen(b);
|
||||
while (mystrlen(a) >= l)
|
||||
int l = lstrlenA(b);
|
||||
while (lstrlenA(a) >= l)
|
||||
{
|
||||
TCHAR c = a[l];
|
||||
char c = a[l];
|
||||
a[l] = 0;
|
||||
if (!lstrcmpi(a, b))
|
||||
if (!lstrcmpiA(a, b))
|
||||
{
|
||||
a[l] = c;
|
||||
return a;
|
||||
}
|
||||
a[l] = c;
|
||||
a = CharNext(a);
|
||||
a = CharNextA(a);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -413,8 +415,7 @@ TCHAR * NSISCALL my_GetTempFileName(TCHAR *buf, const TCHAR *dir)
|
|||
int n = 100;
|
||||
while (n--)
|
||||
{
|
||||
TCHAR prefix[4];
|
||||
*(LPDWORD)prefix = CHAR4_TO_DWORD(_T('n'), _T('s'), _T('a'), 0);
|
||||
TCHAR prefix[4] = _T("nsa");
|
||||
prefix[2] += (TCHAR)(GetTickCount() % 26);
|
||||
if (GetTempFileName(dir, prefix, 0, buf))
|
||||
return buf;
|
||||
|
@ -424,6 +425,106 @@ TCHAR * NSISCALL my_GetTempFileName(TCHAR *buf, const TCHAR *dir)
|
|||
}
|
||||
|
||||
#ifdef NSIS_SUPPORT_MOVEONREBOOT
|
||||
/** Modifies the wininit.ini file to rename / delete a file.
|
||||
*
|
||||
* @param prevName The previous / current name of the file.
|
||||
* @param newName The new name to move the file to. If NULL, the current file
|
||||
* will be deleted.
|
||||
*/
|
||||
void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName)
|
||||
{
|
||||
static char szRenameLine[1024];
|
||||
static TCHAR wininit[1024];
|
||||
static TCHAR tmpbuf[1024];
|
||||
|
||||
int cchRenameLine;
|
||||
LPCSTR szRenameSec = "[Rename]\r\n"; // rename section marker
|
||||
HANDLE hfile;
|
||||
DWORD dwFileSize;
|
||||
DWORD dwBytes;
|
||||
DWORD dwRenameLinePos;
|
||||
char *pszWinInit; // Contains the file contents of wininit.ini
|
||||
|
||||
int spn; // length of the short path name in TCHARs.
|
||||
|
||||
lstrcpy(tmpbuf, _T("NUL"));
|
||||
|
||||
if (newName) {
|
||||
// create the file if it's not already there to prevent GetShortPathName from failing
|
||||
CloseHandle(myOpenFile(newName,0,CREATE_NEW));
|
||||
spn = GetShortPathName(newName,tmpbuf,1024);
|
||||
if (!spn || spn > 1024)
|
||||
return;
|
||||
}
|
||||
// wininit is used as a temporary here
|
||||
spn = GetShortPathName(prevName,wininit,1024);
|
||||
if (!spn || spn > 1024)
|
||||
return;
|
||||
cchRenameLine = wsprintfA(szRenameLine, "%s=%s\r\n", tmpbuf, wininit);
|
||||
// Get the path to the wininit.ini file.
|
||||
GetNSISString(wininit, g_header->str_wininit);
|
||||
|
||||
hfile = myOpenFile(wininit, GENERIC_READ | GENERIC_WRITE, OPEN_ALWAYS);
|
||||
|
||||
if (hfile != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
// We are now working on the Windows wininit file
|
||||
dwFileSize = GetFileSize(hfile, NULL);
|
||||
pszWinInit = (char*) GlobalAlloc(GPTR, dwFileSize + cchRenameLine + 10);
|
||||
|
||||
if (pszWinInit != NULL)
|
||||
{
|
||||
if (ReadFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL) && dwFileSize == dwBytes)
|
||||
{
|
||||
// Look for the rename section in the current file.
|
||||
LPSTR pszRenameSecInFile = mystrstriA(pszWinInit, szRenameSec);
|
||||
if (pszRenameSecInFile == NULL)
|
||||
{
|
||||
// No rename section. So we add it to the end of file.
|
||||
lstrcpyA(pszWinInit+dwFileSize, szRenameSec);
|
||||
dwFileSize += 10;
|
||||
dwRenameLinePos = dwFileSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
// There is a rename section, but is there another section after it?
|
||||
char *pszFirstRenameLine = pszRenameSecInFile+10;
|
||||
char *pszNextSec = mystrstriA(pszFirstRenameLine,"\n[");
|
||||
if (pszNextSec)
|
||||
{
|
||||
TCHAR *p = ++pszNextSec;
|
||||
while (p < pszWinInit + dwFileSize) {
|
||||
p[cchRenameLine] = *p;
|
||||
p++;
|
||||
}
|
||||
|
||||
dwRenameLinePos = pszNextSec - pszWinInit;
|
||||
}
|
||||
// rename section is last, stick item at end of file
|
||||
else dwRenameLinePos = dwFileSize;
|
||||
}
|
||||
|
||||
mini_memcpy(&pszWinInit[dwRenameLinePos], szRenameLine, cchRenameLine);
|
||||
dwFileSize += cchRenameLine;
|
||||
|
||||
SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
|
||||
WriteFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL);
|
||||
|
||||
GlobalFree(pszWinInit);
|
||||
}
|
||||
}
|
||||
|
||||
CloseHandle(hfile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MoveFileOnReboot tries to move a file by the name of pszExisting to the
|
||||
* name pszNew.
|
||||
*
|
||||
* @param pszExisting The old name of the file.
|
||||
* @param pszNew The new name of the file.
|
||||
*/
|
||||
void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew)
|
||||
{
|
||||
BOOL fOk = 0;
|
||||
|
@ -434,86 +535,10 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew)
|
|||
{
|
||||
fOk=mfea(pszExisting, pszNew, MOVEFILE_DELAY_UNTIL_REBOOT|MOVEFILE_REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
|
||||
if (!fOk)
|
||||
{
|
||||
static TCHAR szRenameLine[1024];
|
||||
static TCHAR wininit[1024];
|
||||
static TCHAR tmpbuf[1024];
|
||||
int cchRenameLine;
|
||||
static const TCHAR szRenameSec[] = _T("[Rename]\r\n");
|
||||
HANDLE hfile;
|
||||
DWORD dwFileSize;
|
||||
DWORD dwBytes;
|
||||
DWORD dwRenameLinePos;
|
||||
TCHAR *pszWinInit;
|
||||
|
||||
int spn;
|
||||
|
||||
*(DWORD*)tmpbuf = CHAR4_TO_DWORD(_T('N'), _T('U'), _T('L'), 0);
|
||||
|
||||
if (pszNew) {
|
||||
// create the file if it's not already there to prevent GetShortPathName from failing
|
||||
CloseHandle(myOpenFile(pszNew,0,CREATE_NEW));
|
||||
spn = GetShortPathName(pszNew,tmpbuf,1024);
|
||||
if (!spn || spn > 1024)
|
||||
return;
|
||||
}
|
||||
// wininit is used as a temporary here
|
||||
spn = GetShortPathName(pszExisting,wininit,1024);
|
||||
if (!spn || spn > 1024)
|
||||
return;
|
||||
cchRenameLine = wsprintf(szRenameLine,_T("%s=%s\r\n"),tmpbuf,wininit);
|
||||
|
||||
GetNSISString(wininit, g_header->str_wininit);
|
||||
hfile = myOpenFile(wininit, GENERIC_READ | GENERIC_WRITE, OPEN_ALWAYS);
|
||||
|
||||
if (hfile != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
dwFileSize = GetFileSize(hfile, NULL);
|
||||
pszWinInit = GlobalAlloc(GPTR, dwFileSize + cchRenameLine + 10);
|
||||
|
||||
if (pszWinInit != NULL)
|
||||
{
|
||||
if (ReadFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL) && dwFileSize == dwBytes)
|
||||
{
|
||||
LPTSTR pszRenameSecInFile = mystrstri(pszWinInit, szRenameSec);
|
||||
if (pszRenameSecInFile == NULL)
|
||||
{
|
||||
mystrcpy(pszWinInit+dwFileSize, szRenameSec);
|
||||
dwFileSize += 10;
|
||||
dwRenameLinePos = dwFileSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
TCHAR *pszFirstRenameLine = pszRenameSecInFile+10;
|
||||
TCHAR *pszNextSec = mystrstri(pszFirstRenameLine,_T("\n["));
|
||||
if (pszNextSec)
|
||||
{
|
||||
TCHAR *p = ++pszNextSec;
|
||||
while (p < pszWinInit + dwFileSize) {
|
||||
p[cchRenameLine] = *p;
|
||||
p++;
|
||||
}
|
||||
|
||||
dwRenameLinePos = pszNextSec - pszWinInit;
|
||||
}
|
||||
// rename section is last, stick item at end of file
|
||||
else dwRenameLinePos = dwFileSize;
|
||||
}
|
||||
|
||||
mini_memcpy(&pszWinInit[dwRenameLinePos], szRenameLine, cchRenameLine);
|
||||
dwFileSize += cchRenameLine;
|
||||
|
||||
SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
|
||||
WriteFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL);
|
||||
|
||||
GlobalFree(pszWinInit);
|
||||
}
|
||||
}
|
||||
|
||||
CloseHandle(hfile);
|
||||
}
|
||||
RenameViaWininit(pszExisting, pszNew);
|
||||
}
|
||||
|
||||
#ifdef NSIS_SUPPORT_REBOOT
|
||||
|
@ -622,11 +647,16 @@ TCHAR * NSISCALL GetNSISString(TCHAR *outbuf, int strtab)
|
|||
// indexes into the language
|
||||
TCHAR *in = (TCHAR*)GetNSISStringNP(GetNSISTab(strtab));
|
||||
TCHAR *out = ps_tmpbuf;
|
||||
if ((unsigned int) (outbuf - ps_tmpbuf) < sizeof(ps_tmpbuf))
|
||||
|
||||
// Still working within ps_tmpbuf, so set out to the
|
||||
// current position that is passed in.
|
||||
if (outbuf >= ps_tmpbuf &&
|
||||
(size_t) (outbuf - ps_tmpbuf) < _countof(ps_tmpbuf))
|
||||
{
|
||||
out = outbuf;
|
||||
outbuf = 0;
|
||||
}
|
||||
|
||||
while (*in && out - ps_tmpbuf < NSIS_MAX_STRLEN)
|
||||
{
|
||||
_TUCHAR nVarIdx = (_TUCHAR)*in++;
|
||||
|
@ -949,6 +979,19 @@ struct MGA_FUNC
|
|||
const char *func;
|
||||
};
|
||||
|
||||
#ifdef _UNICODE
|
||||
struct MGA_FUNC MGA_FUNCS[] = {
|
||||
{"KERNEL32", "GetDiskFreeSpaceExW"},
|
||||
{"KERNEL32", "MoveFileExW"},
|
||||
{"ADVAPI32", "RegDeleteKeyExW"},
|
||||
{"ADVAPI32", "OpenProcessToken"},
|
||||
{"ADVAPI32", "LookupPrivilegeValueW"},
|
||||
{"ADVAPI32", "AdjustTokenPrivileges"},
|
||||
{"KERNEL32", "GetUserDefaultUILanguage"},
|
||||
{"SHLWAPI", "SHAutoComplete"},
|
||||
{"SHFOLDER", "SHGetFolderPathW"}
|
||||
};
|
||||
#else
|
||||
struct MGA_FUNC MGA_FUNCS[] = {
|
||||
{"KERNEL32", "GetDiskFreeSpaceExA"},
|
||||
{"KERNEL32", "MoveFileExA"},
|
||||
|
@ -960,6 +1003,7 @@ struct MGA_FUNC MGA_FUNCS[] = {
|
|||
{"SHLWAPI", "SHAutoComplete"},
|
||||
{"SHFOLDER", "SHGetFolderPathA"}
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Given a function enum, it will load the appropriate DLL and get the
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue