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];
|
||||
int cchRenameLine;
|
||||
char *szRenameSec = "[Rename]\r\n";
|
||||
HANDLE hfile, hfilemap;
|
||||
DWORD dwFileSize, dwRenameLinePos;
|
||||
HANDLE hfile;
|
||||
DWORD dwFileSize;
|
||||
DWORD dwBytes;
|
||||
DWORD dwRenameLinePos;
|
||||
char *pszWinInit;
|
||||
|
||||
int spn;
|
||||
|
||||
|
@ -425,13 +428,11 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew)
|
|||
if (hfile != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
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 (pszWinInit != NULL)
|
||||
if (ReadFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL) && dwFileSize == dwBytes)
|
||||
{
|
||||
LPSTR pszRenameSecInFile = mystrstri(pszWinInit, szRenameSec);
|
||||
if (pszRenameSecInFile == NULL)
|
||||
|
@ -461,18 +462,16 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew)
|
|||
mini_memcpy(&pszWinInit[dwRenameLinePos], szRenameLine, 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);
|
||||
}
|
||||
}
|
||||
//return fOk;
|
||||
|
||||
#ifdef NSIS_SUPPORT_REBOOT
|
||||
g_exec_flags.exec_reboot++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue