Unicode port: adding UTF-16LE file functions

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6089 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
wizou 2010-05-17 15:11:29 +00:00
parent 7a99fafa68
commit 24c02b97d0
6 changed files with 101 additions and 12 deletions

View file

@ -30,10 +30,10 @@
#include "toolbar.h"
#include "update.h"
#ifdef _countof
#define COUNTOF _countof
#else
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#ifdef _countof
#define COUNTOF _countof
#else
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#endif
NSCRIPTDATA g_sdata;
@ -706,8 +706,8 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
}
DWORD WINAPI MakeNSISProc(LPVOID p) {
TCHAR buf[1024];
char iobuf[1024]; //i/o buffer
TCHAR buf[1024];
char iobuf[1024]; //i/o buffer
STARTUPINFO si={sizeof(si),};
SECURITY_ATTRIBUTES sa={sizeof(sa),};
SECURITY_DESCRIPTOR sd={0,};

View file

@ -1362,26 +1362,43 @@ static int NSISCALL ExecuteEntry(entry *entry_)
}
break;
case EW_FPUTS:
#ifdef _UNICODE
case EW_FPUTWS:
// 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
{
DWORD dw;
int l;
int l; // number of bytes to write
TCHAR *t=var0;
if (parm2)
if (parm2) // FileWriteByte or FileWriteWord
{
((_TUCHAR *)buf1)[0]=(_TUCHAR) GetIntFromParm(1);
l=1;
// Note: In Unicode version, we put a WORD in buf1[0] and will write 1 or 2 bytes, depending on FileWriteByte/Word.
((_TUCHAR *)buf1)[0]=(_TUCHAR) GetIntFromParm(1); // FIX_ENDIAN_INT16 needed?
l=(which==EW_FPUTS)?1:sizeof(TCHAR); // Note: This is optimized by the compiler into l=1 for ANSI compilation
}
#ifdef _UNICODE
else if (which==EW_FPUTS)
{
GetStringFromParm(0x21); // load string in buf2, convert it to ANSI in buf1
WideCharToMultiByte(CP_ACP, 0, buf2, -1, (LPSTR) buf1, NSIS_MAX_STRLEN, NULL, NULL);
l=lstrlenA((LPCSTR)buf1);
}
#endif
else
{
l=mystrlen(GetStringFromParm(0x11));
l=mystrlen(GetStringFromParm(0x11))*sizeof(TCHAR);
}
if (!*t || !WriteFile((HANDLE)myatoi(t),buf1,l*sizeof(TCHAR),&dw,NULL))
if (!*t || !WriteFile((HANDLE)myatoi(t),buf1,l,&dw,NULL))
{
exec_error++;
}
}
break;
case EW_FGETS:
#ifdef _UNICODE
case EW_FGETWS:
// Jim Park/Wizou: in Unicode version of NSIS, EW_FGETS still deals with ANSI files (conversion is done). We add EW_FGETWS to deal with Unicode files.
#endif
{
TCHAR *textout=var1;
DWORD dw;
@ -1397,6 +1414,15 @@ static int NSISCALL ExecuteEntry(entry *entry_)
while (rpos<maxlen)
{
TCHAR c;
#ifdef _UNICODE
if (which==EW_FGETS)
{
char tmpc;
if (!ReadFile(h,&tmpc,1,&dw,NULL) || dw != 1) break;
MultiByteToWideChar(CP_ACP, 0, &tmpc, 1, &c, 1);
}
else
#endif
if (!ReadFile(h,&c,sizeof(c),&dw,NULL) || dw != sizeof(c)) break;
if (parm3)
{

View file

@ -167,6 +167,10 @@ enum
EW_FOPEN, // FileOpen: 4 [name, openmode, createmode, outputhandle]
EW_FPUTS, // FileWrite: 3 [handle, string, ?int:string]
EW_FGETS, // FileRead: 4 [handle, output, maxlen, ?getchar:gets]
#ifdef _UNICODE
EW_FPUTWS, // FileWriteUTF16LE: 3 [handle, string, ?int:string]
EW_FGETWS, // FileReadUTF16LE: 4 [handle, output, maxlen, ?getchar:gets]
#endif
EW_FSEEK, // FileSeek: 4 [handle, offset, mode, >=0?positionoutput]
#endif//NSIS_SUPPORT_FILEFUNCTIONS

View file

@ -12,6 +12,8 @@
*
* This software is provided 'as-is', without any express or implied
* warranty.
*
* Unicode support by Jim Park -- 08/09/2007
*/
#include "Platform.h"
@ -5494,6 +5496,43 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
if (ent.offsets[0]<0) PRINTHELP()
SCRIPT_MSG(_T("FileWriteByte: %s->%s\n"),line.gettoken_str(2),line.gettoken_str(1));
return add_entry(&ent);
#ifdef _UNICODE
case TOK_FILEREADUTF16LE:
ent.which=EW_FGETWS;
ent.offsets[0]=GetUserVarIndex(line, 1); // file handle
ent.offsets[1]=GetUserVarIndex(line, 2); // output string
if (line.gettoken_str(3)[0])
ent.offsets[2]=add_string(line.gettoken_str(3));
else
ent.offsets[2]=add_intstring(NSIS_MAX_STRLEN-1);
if (ent.offsets[0]<0 || ent.offsets[1]<0) PRINTHELP()
SCRIPT_MSG(_T("FileReadUTF16LE: %s->%s (max:%s)\n"),line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3));
return add_entry(&ent);
case TOK_FILEWRITEUTF16LE:
ent.which=EW_FPUTWS;
ent.offsets[0]=GetUserVarIndex(line, 1); // file handle
ent.offsets[1]=add_string(line.gettoken_str(2));
if (ent.offsets[0]<0) PRINTHELP()
SCRIPT_MSG(_T("FileWriteUTF16LE: %s->%s\n"),line.gettoken_str(2),line.gettoken_str(1));
return add_entry(&ent);
case TOK_FILEREADWORD:
ent.which=EW_FGETWS;
ent.offsets[0]=GetUserVarIndex(line, 1); // file handle
ent.offsets[1]=GetUserVarIndex(line, 2); // output string
ent.offsets[2]=add_string(_T("1"));
ent.offsets[3]=1;
if (ent.offsets[0]<0 || ent.offsets[1]<0) PRINTHELP()
SCRIPT_MSG(_T("FileReadWord: %s->%s\n"),line.gettoken_str(1),line.gettoken_str(2));
return add_entry(&ent);
case TOK_FILEWRITEWORD:
ent.which=EW_FPUTWS;
ent.offsets[0]=GetUserVarIndex(line, 1); // file handle
ent.offsets[1]=add_string(line.gettoken_str(2));
ent.offsets[2]=1;
if (ent.offsets[0]<0) PRINTHELP()
SCRIPT_MSG(_T("FileWriteWord: %s->%s\n"),line.gettoken_str(2),line.gettoken_str(1));
return add_entry(&ent);
#endif
case TOK_FILESEEK:
{
const TCHAR *modestr;
@ -5529,6 +5568,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
case TOK_FILEWRITE:
case TOK_FILEREADBYTE:
case TOK_FILEWRITEBYTE:
#ifdef _UNICODE
case TOK_FILEREADUTF16LE:
case TOK_FILEWRITEUTF16LE:
case TOK_FILEREADWORD:
case TOK_FILEWRITEWORD:
#endif
ERROR_MSG(_T("Error: %s specified, NSIS_SUPPORT_FILEFUNCTIONS not defined.\n"), line.gettoken_str(0));
return PS_ERROR;

View file

@ -97,6 +97,12 @@ static tokenType tokenlist[TOK__LAST] =
{TOK_FILEWRITE,_T("FileWrite"),2,0,_T("$(user_var: handle input) text"),TP_CODE},
{TOK_FILEREADBYTE,_T("FileReadByte"),2,0,_T("$(user_var: handle input) $(user_var: bytevalue output)"),TP_CODE},
{TOK_FILEWRITEBYTE,_T("FileWriteByte"),2,0,_T("$(user_var: handle input) bytevalue"),TP_CODE},
#ifdef _UNICODE
{TOK_FILEREADUTF16LE,_T("FileReadUTF16LE"),2,1,_T("$(user_var: handle input) $(user_var: text output) [maxlen]"),TP_CODE},
{TOK_FILEWRITEUTF16LE,_T("FileWriteUTF16LE"),2,0,_T("$(user_var: handle input) text"),TP_CODE},
{TOK_FILEREADWORD,_T("FileReadWord"),2,0,_T("$(user_var: handle input) $(user_var: wordvalue output)"),TP_CODE},
{TOK_FILEWRITEWORD,_T("FileWriteWord"),2,0,_T("$(user_var: handle input) wordvalue"),TP_CODE},
#endif
{TOK_FILESEEK,_T("FileSeek"),2,2,_T("$(user_var: handle input) offset [mode] [$(user_var: new position output)]\n mode=SET|CUR|END"),TP_CODE},
{TOK_FUNCTION,_T("Function"),1,0,_T("function_name"),TP_GLOBAL},
{TOK_FUNCTIONEND,_T("FunctionEnd"),0,0,_T(""),TP_FUNC},

View file

@ -12,6 +12,8 @@
*
* This software is provided 'as-is', without any express or implied
* warranty.
*
* Added commands for Unicode support by Jim Park -- 08/21/2007
*/
#ifndef _TOKENS_H_
@ -236,6 +238,12 @@ enum
TOK_FILEWRITE,
TOK_FILEREADBYTE,
TOK_FILEWRITEBYTE,
#ifdef _UNICODE
TOK_FILEREADUTF16LE,
TOK_FILEWRITEUTF16LE,
TOK_FILEREADWORD,
TOK_FILEWRITEWORD,
#endif
TOK_FILESEEK,
TOK_GETFULLPATHNAME,
TOK_REBOOT,