From e438c2092bc1adf25684b0b994084f5f1efe1eca Mon Sep 17 00:00:00 2001 From: wizou Date: Thu, 15 Apr 2010 08:51:35 +0000 Subject: [PATCH] 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 --- Contrib/Library/RegTool/RegTool.c | 18 +++++++++++++----- Source/exehead/util.c | 16 +++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Contrib/Library/RegTool/RegTool.c b/Contrib/Library/RegTool/RegTool.c index 69b90080..d01e21b0 100644 --- a/Contrib/Library/RegTool/RegTool.c +++ b/Contrib/Library/RegTool/RegTool.c @@ -1,3 +1,5 @@ +// Unicode support by Jim Park & Olivier Marcoux + #include #include @@ -299,7 +301,11 @@ void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName) spn = GetShortPathName(prevName,wininit,1024); if (!spn || spn > 1024) return; +#ifdef _UNICODE + cchRenameLine = wsprintfA(szRenameLine, "%ls=l%s\r\n", tmpbuf, wininit); +#else cchRenameLine = wsprintfA(szRenameLine, "%s=%s\r\n", tmpbuf, wininit); +#endif // Get the path to the wininit.ini file. GetWindowsDirectory(wininit, 1024-16); lstrcat(wininit, _T("\\wininit.ini")); @@ -332,13 +338,15 @@ void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName) char *pszNextSec = mystrstriA(pszFirstRenameLine,"\n["); if (pszNextSec) { - char *p = ++pszNextSec; - while (p < pszWinInit + dwFileSize) { - p[cchRenameLine] = *p; - p++; + char *p = pszWinInit + dwFileSize; + char *pEnd = pszWinInit + dwFileSize + cchRenameLine; + + 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 else dwRenameLinePos = dwFileSize; diff --git a/Source/exehead/util.c b/Source/exehead/util.c index 3d786635..729b14a4 100644 --- a/Source/exehead/util.c +++ b/Source/exehead/util.c @@ -460,7 +460,11 @@ void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName) spn = GetShortPathName(prevName,wininit,1024); if (!spn || spn > 1024) return; +#ifdef _UNICODE + cchRenameLine = wsprintfA(szRenameLine, "%ls=%ls\r\n", tmpbuf, wininit); +#else cchRenameLine = wsprintfA(szRenameLine, "%s=%s\r\n", tmpbuf, wininit); +#endif // Get the path to the wininit.ini file. GetNSISString(wininit, g_header->str_wininit); @@ -492,13 +496,15 @@ void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName) char *pszNextSec = mystrstriA(pszFirstRenameLine,"\n["); if (pszNextSec) { - char *p = ++pszNextSec; - while (p < pszWinInit + dwFileSize) { - p[cchRenameLine] = *p; - p++; + char *p = pszWinInit + dwFileSize; + char *pEnd = pszWinInit + dwFileSize + cchRenameLine; + + 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 else dwRenameLinePos = dwFileSize;