use normal file functions for wininit.ini modification
- according to msdn, mmap operations can raise an exception which wasn't handled - free up a lot of bytes from .data section (no mmap API functions) - mmap size is, like allocation of a buffer, limited by available memory git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4462 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
1b8a44584d
commit
3f18dc0b75
1 changed files with 12 additions and 13 deletions
|
@ -396,8 +396,11 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew)
|
||||||
static char tmpbuf[1024];
|
static char tmpbuf[1024];
|
||||||
int cchRenameLine;
|
int cchRenameLine;
|
||||||
char *szRenameSec = "[Rename]\r\n";
|
char *szRenameSec = "[Rename]\r\n";
|
||||||
HANDLE hfile, hfilemap;
|
HANDLE hfile;
|
||||||
DWORD dwFileSize, dwRenameLinePos;
|
DWORD dwFileSize;
|
||||||
|
DWORD dwBytes;
|
||||||
|
DWORD dwRenameLinePos;
|
||||||
|
char *pszWinInit;
|
||||||
|
|
||||||
int spn;
|
int spn;
|
||||||
|
|
||||||
|
@ -425,13 +428,11 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew)
|
||||||
if (hfile != INVALID_HANDLE_VALUE)
|
if (hfile != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
dwFileSize = GetFileSize(hfile, NULL);
|
dwFileSize = GetFileSize(hfile, NULL);
|
||||||
hfilemap = CreateFileMapping(hfile, NULL, PAGE_READWRITE, 0, dwFileSize + cchRenameLine + 10, NULL);
|
pszWinInit = GlobalAlloc(GPTR, dwFileSize + cchRenameLine + 10);
|
||||||
|
|
||||||
if (hfilemap != NULL)
|
if (pszWinInit != NULL)
|
||||||
{
|
{
|
||||||
LPSTR pszWinInit = (LPSTR) MapViewOfFile(hfilemap, FILE_MAP_WRITE, 0, 0, 0);
|
if (ReadFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL) && dwFileSize == dwBytes)
|
||||||
|
|
||||||
if (pszWinInit != NULL)
|
|
||||||
{
|
{
|
||||||
LPSTR pszRenameSecInFile = mystrstri(pszWinInit, szRenameSec);
|
LPSTR pszRenameSecInFile = mystrstri(pszWinInit, szRenameSec);
|
||||||
if (pszRenameSecInFile == NULL)
|
if (pszRenameSecInFile == NULL)
|
||||||
|
@ -461,18 +462,16 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew)
|
||||||
mini_memcpy(&pszWinInit[dwRenameLinePos], szRenameLine, cchRenameLine);
|
mini_memcpy(&pszWinInit[dwRenameLinePos], szRenameLine, cchRenameLine);
|
||||||
dwFileSize += cchRenameLine;
|
dwFileSize += cchRenameLine;
|
||||||
|
|
||||||
UnmapViewOfFile(pszWinInit);
|
SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
|
||||||
|
WriteFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL);
|
||||||
|
|
||||||
//fOk++;
|
GlobalFree(pszWinInit);
|
||||||
}
|
}
|
||||||
CloseHandle(hfilemap);
|
|
||||||
}
|
}
|
||||||
SetFilePointer(hfile, dwFileSize, NULL, FILE_BEGIN);
|
|
||||||
SetEndOfFile(hfile);
|
|
||||||
CloseHandle(hfile);
|
CloseHandle(hfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//return fOk;
|
|
||||||
|
|
||||||
#ifdef NSIS_SUPPORT_REBOOT
|
#ifdef NSIS_SUPPORT_REBOOT
|
||||||
g_exec_flags.exec_reboot++;
|
g_exec_flags.exec_reboot++;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue