Use myWriteFile helper function in exehead
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6628 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
1c1d1d5e12
commit
252adb2f39
4 changed files with 27 additions and 28 deletions
|
@ -1367,7 +1367,6 @@ static int NSISCALL ExecuteEntry(entry *entry_)
|
||||||
// Jim Park/Wizou: in Unicode version of NSIS, EW_FPUTS still deals with ANSI files (conversion is done). We add EW_FPUTWS to deal with Unicode files.
|
// Jim Park/Wizou: in Unicode version of NSIS, EW_FPUTS still deals with ANSI files (conversion is done). We add EW_FPUTWS to deal with Unicode files.
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
DWORD dw;
|
|
||||||
int l; // number of bytes to write
|
int l; // number of bytes to write
|
||||||
TCHAR *t=var0;
|
TCHAR *t=var0;
|
||||||
const int writeCodPt = parm2, ansi = EW_FPUTS == which;
|
const int writeCodPt = parm2, ansi = EW_FPUTS == which;
|
||||||
|
@ -1395,7 +1394,7 @@ static int NSISCALL ExecuteEntry(entry *entry_)
|
||||||
#ifdef _UNICODE
|
#ifdef _UNICODE
|
||||||
if ((ansi | writeCodPt) || !parm3 || SUCCEEDED(UTF16LEBOM(hFile,(INT_PTR)hFile)))
|
if ((ansi | writeCodPt) || !parm3 || SUCCEEDED(UTF16LEBOM(hFile,(INT_PTR)hFile)))
|
||||||
#endif
|
#endif
|
||||||
if (WriteFile(hFile,buf1,l,&dw,NULL))
|
if (myWriteFile(hFile,buf1,l))
|
||||||
break; // Success
|
break; // Success
|
||||||
}
|
}
|
||||||
exec_error++;
|
exec_error++;
|
||||||
|
@ -1549,7 +1548,6 @@ static int NSISCALL ExecuteEntry(entry *entry_)
|
||||||
filebuf=(unsigned char *)GlobalAlloc(GPTR,filehdrsize);
|
filebuf=(unsigned char *)GlobalAlloc(GPTR,filehdrsize);
|
||||||
if (filebuf)
|
if (filebuf)
|
||||||
{
|
{
|
||||||
DWORD lout;
|
|
||||||
SetSelfFilePointer(0);
|
SetSelfFilePointer(0);
|
||||||
ReadSelfFile((char*)filebuf,filehdrsize);
|
ReadSelfFile((char*)filebuf,filehdrsize);
|
||||||
{
|
{
|
||||||
|
@ -1571,7 +1569,7 @@ static int NSISCALL ExecuteEntry(entry *entry_)
|
||||||
GlobalFree(unicon_data);
|
GlobalFree(unicon_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WriteFile(hFile,(char*)filebuf,filehdrsize,&lout,NULL);
|
myWriteFile(hFile,(char*)filebuf,filehdrsize);
|
||||||
GlobalFree(filebuf);
|
GlobalFree(filebuf);
|
||||||
ret=GetCompressedDataFromDataBlock(-1,hFile);
|
ret=GetCompressedDataFromDataBlock(-1,hFile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -430,8 +430,7 @@ int NSISCALL _dodecomp(int offset, HANDLE hFileOut, unsigned char *outbuf, int o
|
||||||
|
|
||||||
if (!outbuf)
|
if (!outbuf)
|
||||||
{
|
{
|
||||||
DWORD r;
|
if (!myWriteFile(hFileOut,outbuffer,u)) return -2;
|
||||||
if (!WriteFile(hFileOut,outbuffer,u,&r,NULL) || (int)r != u) return -2;
|
|
||||||
retval+=u;
|
retval+=u;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -452,9 +451,8 @@ int NSISCALL _dodecomp(int offset, HANDLE hFileOut, unsigned char *outbuf, int o
|
||||||
while (input_len > 0)
|
while (input_len > 0)
|
||||||
{
|
{
|
||||||
DWORD l=min(input_len,outbuffer_len);
|
DWORD l=min(input_len,outbuffer_len);
|
||||||
DWORD t;
|
|
||||||
if (!ReadSelfFile((LPVOID)inbuffer,l)) return -3;
|
if (!ReadSelfFile((LPVOID)inbuffer,l)) return -3;
|
||||||
if (!WriteFile(hFileOut,inbuffer,l,&t,NULL) || l!=t) return -2;
|
if (!myWriteFile(hFileOut,inbuffer,l)) return -2;
|
||||||
retval+=l;
|
retval+=l;
|
||||||
input_len-=l;
|
input_len-=l;
|
||||||
}
|
}
|
||||||
|
@ -498,7 +496,7 @@ static int NSISCALL __ensuredata(int amount)
|
||||||
g_inflate_stream.avail_in=l;
|
g_inflate_stream.avail_in=l;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
DWORD r,t;
|
DWORD r;
|
||||||
#ifdef NSIS_CONFIG_VISIBLE_SUPPORT
|
#ifdef NSIS_CONFIG_VISIBLE_SUPPORT
|
||||||
if (g_header)
|
if (g_header)
|
||||||
#ifdef NSIS_CONFIG_SILENT_SUPPORT
|
#ifdef NSIS_CONFIG_SILENT_SUPPORT
|
||||||
|
@ -520,7 +518,7 @@ static int NSISCALL __ensuredata(int amount)
|
||||||
r=BUGBUG64TRUNCATE(DWORD,(UINT_PTR)g_inflate_stream.next_out)-BUGBUG64TRUNCATE(DWORD,(UINT_PTR)_outbuffer);
|
r=BUGBUG64TRUNCATE(DWORD,(UINT_PTR)g_inflate_stream.next_out)-BUGBUG64TRUNCATE(DWORD,(UINT_PTR)_outbuffer);
|
||||||
if (r)
|
if (r)
|
||||||
{
|
{
|
||||||
if (!WriteFile(dbd_hFile,_outbuffer,r,&t,NULL) || r != t)
|
if (!myWriteFile(dbd_hFile,_outbuffer,r))
|
||||||
{
|
{
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
@ -568,10 +566,9 @@ int NSISCALL _dodecomp(int offset, HANDLE hFileOut, unsigned char *outbuf, int o
|
||||||
{
|
{
|
||||||
while (input_len > 0)
|
while (input_len > 0)
|
||||||
{
|
{
|
||||||
DWORD t;
|
|
||||||
DWORD l=min(input_len,IBUFSIZE);
|
DWORD l=min(input_len,IBUFSIZE);
|
||||||
if (!myReadFile(dbd_hFile,(LPVOID)_inbuffer,r=l)) return -3;
|
if (!myReadFile(dbd_hFile,(LPVOID)_inbuffer,r=l)) return -3;
|
||||||
if (!WriteFile(hFileOut,_inbuffer,r,&t,NULL) || t != l) return -2;
|
if (!myWriteFile(hFileOut,_inbuffer,r)) return -2;
|
||||||
retval+=r;
|
retval+=r;
|
||||||
input_len-=r;
|
input_len-=r;
|
||||||
dbd_pos+=r;
|
dbd_pos+=r;
|
||||||
|
|
|
@ -452,14 +452,19 @@ TCHAR * NSISCALL my_GetTempFileName(TCHAR *buf, const TCHAR *dir)
|
||||||
BOOL NSISCALL myReadFile(HANDLE h, LPVOID buf, DWORD cb)
|
BOOL NSISCALL myReadFile(HANDLE h, LPVOID buf, DWORD cb)
|
||||||
{
|
{
|
||||||
DWORD cbio;
|
DWORD cbio;
|
||||||
BOOL r = ReadFile(h, buf, cb, &cbio, NULL);
|
return ReadFile(h, buf, cb, &cbio, NULL) && cb == cbio;
|
||||||
return r && cb == cbio;
|
}
|
||||||
|
|
||||||
|
BOOL NSISCALL myWriteFile(HANDLE h, const void*buf, DWORD cb)
|
||||||
|
{
|
||||||
|
DWORD cbio;
|
||||||
|
return WriteFile(h, buf, cb, &cbio, NULL) && cb == cbio;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reading skips the BOM if present, writing writes it to a empty file
|
// Reading skips the BOM if present, writing writes it to a empty file
|
||||||
HRESULT NSISCALL UTF16LEBOM(HANDLE h, INT_PTR ForWrite)
|
HRESULT NSISCALL UTF16LEBOM(HANDLE h, INT_PTR ForWrite)
|
||||||
{
|
{
|
||||||
DWORD orgpos = SetFilePointer(h, 0, NULL, FILE_CURRENT), cbio;
|
DWORD orgpos = SetFilePointer(h, 0, NULL, FILE_CURRENT);
|
||||||
if (0 == orgpos)
|
if (0 == orgpos)
|
||||||
{
|
{
|
||||||
BYTE bom[2];
|
BYTE bom[2];
|
||||||
|
@ -472,11 +477,10 @@ HRESULT NSISCALL UTF16LEBOM(HANDLE h, INT_PTR ForWrite)
|
||||||
if (0 == SetFilePointer(h, 0, NULL, FILE_CURRENT)) // Is the file empty?
|
if (0 == SetFilePointer(h, 0, NULL, FILE_CURRENT)) // Is the file empty?
|
||||||
{
|
{
|
||||||
static const BYTE bom16le[] = { 0xff, 0xfe };
|
static const BYTE bom16le[] = { 0xff, 0xfe };
|
||||||
return (WriteFile(h, bom16le, 2, &cbio, NULL) && 2 == cbio)
|
return myWriteFile(h, bom16le, 2) ? S_OK : E_FAIL;
|
||||||
? S_OK : E_FAIL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetFilePointer(h, 0, NULL, FILE_BEGIN); // The file may have starting with something that was not a BOM, undo the read
|
SetFilePointer(h, 0, NULL, FILE_BEGIN); // The file may have started with something that was not a BOM, undo the read
|
||||||
}
|
}
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -498,9 +502,7 @@ void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName)
|
||||||
int cchRenameLine;
|
int cchRenameLine;
|
||||||
LPCSTR szRenameSec = "[Rename]\r\n"; // rename section marker
|
LPCSTR szRenameSec = "[Rename]\r\n"; // rename section marker
|
||||||
HANDLE hfile;
|
HANDLE hfile;
|
||||||
DWORD dwFileSize;
|
DWORD dwFileSize, dwRenameLinePos;
|
||||||
DWORD dwBytes;
|
|
||||||
DWORD dwRenameLinePos;
|
|
||||||
char *pszWinInit; // Contains the file contents of wininit.ini
|
char *pszWinInit; // Contains the file contents of wininit.ini
|
||||||
|
|
||||||
int spn; // length of the short path name in TCHARs.
|
int spn; // length of the short path name in TCHARs.
|
||||||
|
@ -572,7 +574,7 @@ void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName)
|
||||||
dwFileSize += cchRenameLine;
|
dwFileSize += cchRenameLine;
|
||||||
|
|
||||||
SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
|
SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
|
||||||
WriteFile(hfile, pszWinInit, dwFileSize, &dwBytes, NULL);
|
myWriteFile(hfile, pszWinInit, dwFileSize);
|
||||||
|
|
||||||
GlobalFree(pszWinInit);
|
GlobalFree(pszWinInit);
|
||||||
}
|
}
|
||||||
|
@ -952,9 +954,8 @@ void NSISCALL log_write(int close)
|
||||||
}
|
}
|
||||||
if (fp!=INVALID_HANDLE_VALUE)
|
if (fp!=INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
DWORD d;
|
|
||||||
mystrcat(log_text,_T("\r\n"));
|
mystrcat(log_text,_T("\r\n"));
|
||||||
WriteFile(fp,log_text,mystrlen(log_text)*sizeof(TCHAR),&d,NULL);
|
myWriteFile(fp,log_text,mystrlen(log_text)*sizeof(TCHAR));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1013,6 +1014,9 @@ void log_timestamp(TCHAR *buf)
|
||||||
|
|
||||||
void log_printf(TCHAR *format, ...)
|
void log_printf(TCHAR *format, ...)
|
||||||
{
|
{
|
||||||
|
#ifdef NSIS_CONFIG_LOG_STDOUT
|
||||||
|
HANDLE hStdOut;
|
||||||
|
#endif
|
||||||
va_list val;
|
va_list val;
|
||||||
va_start(val,format);
|
va_start(val,format);
|
||||||
|
|
||||||
|
@ -1026,11 +1030,10 @@ void log_printf(TCHAR *format, ...)
|
||||||
OutputDebugString(log_text);
|
OutputDebugString(log_text);
|
||||||
#endif
|
#endif
|
||||||
#ifdef NSIS_CONFIG_LOG_STDOUT
|
#ifdef NSIS_CONFIG_LOG_STDOUT
|
||||||
if (log_dolog && GetStdHandle(STD_OUTPUT_HANDLE) != INVALID_HANDLE_VALUE)
|
if (log_dolog && (hStdOut = GetStdHandle(STD_OUTPUT_HANDLE)) != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
DWORD dwBytes;
|
myWriteFile(hStdOut, log_text, lstrlen(log_text)); // BUGBUG: Should this be lstrlen*sizeof(TCHAR)?
|
||||||
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), log_text, lstrlen(log_text), &dwBytes, NULL);
|
myWriteFile(hStdOut, _T("\n"), 1); // BUGBUG: sizeof(TCHAR)?
|
||||||
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), _T("\n"), 1, &dwBytes, NULL);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if !defined(NSIS_CONFIG_LOG_ODS) && !defined(NSIS_CONFIG_LOG_STDOUT)
|
#if !defined(NSIS_CONFIG_LOG_ODS) && !defined(NSIS_CONFIG_LOG_STDOUT)
|
||||||
|
|
|
@ -44,6 +44,7 @@ TCHAR * NSISCALL mystrstr(TCHAR *a, TCHAR *b);
|
||||||
WIN32_FIND_DATA * NSISCALL file_exists(TCHAR *buf);
|
WIN32_FIND_DATA * NSISCALL file_exists(TCHAR *buf);
|
||||||
TCHAR * NSISCALL my_GetTempFileName(TCHAR *buf, const TCHAR *dir);
|
TCHAR * NSISCALL my_GetTempFileName(TCHAR *buf, const TCHAR *dir);
|
||||||
BOOL NSISCALL myReadFile(HANDLE h, LPVOID buf, DWORD cb);
|
BOOL NSISCALL myReadFile(HANDLE h, LPVOID buf, DWORD cb);
|
||||||
|
BOOL NSISCALL myWriteFile(HANDLE h, const void*buf, DWORD cb);
|
||||||
HRESULT NSISCALL UTF16LEBOM(HANDLE h, INT_PTR ForWrite);
|
HRESULT NSISCALL UTF16LEBOM(HANDLE h, INT_PTR ForWrite);
|
||||||
|
|
||||||
//BOOL NSISCALL my_SetWindowText(HWND hWnd, const TCHAR *val);
|
//BOOL NSISCALL my_SetWindowText(HWND hWnd, const TCHAR *val);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue