Fixed bug and Unicode support in RenameViaWininit function

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6057 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
wizou 2010-04-15 08:51:35 +00:00
parent 36f6645935
commit e438c2092b
2 changed files with 24 additions and 10 deletions

View file

@ -1,3 +1,5 @@
// Unicode support by Jim Park & Olivier Marcoux
#include <windows.h> #include <windows.h>
#include <tchar.h> #include <tchar.h>
@ -299,7 +301,11 @@ void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName)
spn = GetShortPathName(prevName,wininit,1024); spn = GetShortPathName(prevName,wininit,1024);
if (!spn || spn > 1024) if (!spn || spn > 1024)
return; return;
#ifdef _UNICODE
cchRenameLine = wsprintfA(szRenameLine, "%ls=l%s\r\n", tmpbuf, wininit);
#else
cchRenameLine = wsprintfA(szRenameLine, "%s=%s\r\n", tmpbuf, wininit); cchRenameLine = wsprintfA(szRenameLine, "%s=%s\r\n", tmpbuf, wininit);
#endif
// Get the path to the wininit.ini file. // Get the path to the wininit.ini file.
GetWindowsDirectory(wininit, 1024-16); GetWindowsDirectory(wininit, 1024-16);
lstrcat(wininit, _T("\\wininit.ini")); lstrcat(wininit, _T("\\wininit.ini"));
@ -332,13 +338,15 @@ void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName)
char *pszNextSec = mystrstriA(pszFirstRenameLine,"\n["); char *pszNextSec = mystrstriA(pszFirstRenameLine,"\n[");
if (pszNextSec) if (pszNextSec)
{ {
char *p = ++pszNextSec; char *p = pszWinInit + dwFileSize;
while (p < pszWinInit + dwFileSize) { char *pEnd = pszWinInit + dwFileSize + cchRenameLine;
p[cchRenameLine] = *p;
p++; while (p > pszNextSec)
{
*pEnd-- = *p--;
} }
dwRenameLinePos = pszNextSec - pszWinInit; dwRenameLinePos = pszNextSec - pszWinInit + 1; // +1 for the \n
} }
// rename section is last, stick item at end of file // rename section is last, stick item at end of file
else dwRenameLinePos = dwFileSize; else dwRenameLinePos = dwFileSize;

View file

@ -460,7 +460,11 @@ void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName)
spn = GetShortPathName(prevName,wininit,1024); spn = GetShortPathName(prevName,wininit,1024);
if (!spn || spn > 1024) if (!spn || spn > 1024)
return; return;
#ifdef _UNICODE
cchRenameLine = wsprintfA(szRenameLine, "%ls=%ls\r\n", tmpbuf, wininit);
#else
cchRenameLine = wsprintfA(szRenameLine, "%s=%s\r\n", tmpbuf, wininit); cchRenameLine = wsprintfA(szRenameLine, "%s=%s\r\n", tmpbuf, wininit);
#endif
// Get the path to the wininit.ini file. // Get the path to the wininit.ini file.
GetNSISString(wininit, g_header->str_wininit); GetNSISString(wininit, g_header->str_wininit);
@ -492,13 +496,15 @@ void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName)
char *pszNextSec = mystrstriA(pszFirstRenameLine,"\n["); char *pszNextSec = mystrstriA(pszFirstRenameLine,"\n[");
if (pszNextSec) if (pszNextSec)
{ {
char *p = ++pszNextSec; char *p = pszWinInit + dwFileSize;
while (p < pszWinInit + dwFileSize) { char *pEnd = pszWinInit + dwFileSize + cchRenameLine;
p[cchRenameLine] = *p;
p++; while (p > pszNextSec)
{
*pEnd-- = *p--;
} }
dwRenameLinePos = pszNextSec - pszWinInit; dwRenameLinePos = pszNextSec - pszWinInit + 1; // +1 for the \n
} }
// rename section is last, stick item at end of file // rename section is last, stick item at end of file
else dwRenameLinePos = dwFileSize; else dwRenameLinePos = dwFileSize;