Translatable NSISdl
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1883 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
928a37800f
commit
415c1a00c6
4 changed files with 219 additions and 186 deletions
|
@ -40,3 +40,19 @@ then, check $0 for errors:
|
|||
StrCmp $0 "success" yay
|
||||
Abort "Error downloading file
|
||||
yay:
|
||||
|
||||
To translate NSISdl add:
|
||||
/TRANSLATE downloading connecting second minute hour plural progress remianing
|
||||
to the call line.
|
||||
|
||||
Default values are:
|
||||
downloading - "Downloading %s"
|
||||
connecting - "Connecting ..."
|
||||
second - "second"
|
||||
minute - "minute"
|
||||
hour - "hour"
|
||||
plural - "s"
|
||||
progress - "%dkB (%d%%) of %dkB @ %d.%01dkB/s"
|
||||
remaining - "(%d %s%s remaining)"
|
||||
|
||||
/TRANSLATE must come before /TIMEOUT.
|
|
@ -96,11 +96,122 @@ static void progress_callback(char *msg, int read_bytes)
|
|||
extern char *_strstr(char *i, char *s);
|
||||
#define strstr _strstr
|
||||
|
||||
static
|
||||
void downloadFile(char *url,
|
||||
HANDLE hFile,
|
||||
char **error)
|
||||
RECT r, cr;
|
||||
void AdjustSize(int id)
|
||||
{
|
||||
GetWindowRect(GetDlgItem(g_dialog,id),&cr);
|
||||
ScreenToClient(g_dialog,(LPPOINT)&cr);
|
||||
ScreenToClient(g_dialog,((LPPOINT)&cr)+1);
|
||||
SetWindowPos(GetDlgItem(g_dialog,id),0,0,0,r.right-r.left,cr.bottom-cr.top,SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
__declspec(dllexport) void download (HWND parent,
|
||||
int string_size,
|
||||
char *variables,
|
||||
stack_t **stacktop)
|
||||
{
|
||||
static char buf[1024];
|
||||
static char url[1024];
|
||||
static char filename[1024];
|
||||
int wasen=0;
|
||||
HWND hwndL=0;
|
||||
HWND hwndB=0;
|
||||
|
||||
static char szDownloading[32];//= "Downloading %s";
|
||||
static char szConnecting[32];//= "Connecting ...";
|
||||
static char szSecond[32];//= "second";
|
||||
static char szMinute[32];//= "minute";
|
||||
static char szHour[32];//= "hour";
|
||||
static char szPlural[32];//= "s";
|
||||
static char szProgress[128];//= "%dkB (%d%%) of %dkB @ %d.%01dkB/s";
|
||||
static char szRemaining[128];//= " (%d %s%s remaining)";
|
||||
|
||||
g_parent = parent;
|
||||
EXDLL_INIT();
|
||||
|
||||
popstring(url);
|
||||
if (!lstrcmpi(url, "/TRANSLATE")) {
|
||||
popstring(szDownloading);
|
||||
popstring(szConnecting);
|
||||
popstring(szSecond);
|
||||
popstring(szMinute);
|
||||
popstring(szHour);
|
||||
popstring(szPlural);
|
||||
popstring(szProgress);
|
||||
popstring(szRemaining);
|
||||
popstring(url);
|
||||
}
|
||||
else {
|
||||
lstrcpy(szDownloading, "Downloading %s");
|
||||
lstrcpy(szConnecting, "Connecting ...");
|
||||
lstrcpy(szSecond, "second");
|
||||
lstrcpy(szMinute, "minute");
|
||||
lstrcpy(szHour, "hour");
|
||||
lstrcpy(szPlural, "s");
|
||||
lstrcpy(szProgress, "%dkB (%d%%) of %dkB @ %d.%01dkB/s");
|
||||
lstrcpy(szRemaining, " (%d %s%s remaining)");
|
||||
}
|
||||
lstrcpyn(buf, url, 10);
|
||||
if (!lstrcmpi(buf, "/TIMEOUT=")) {
|
||||
g_timeout_ms=my_atoi(url+9);
|
||||
popstring(url);
|
||||
}
|
||||
popstring(filename);
|
||||
|
||||
HANDLE hFile = CreateFile(filename,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL);
|
||||
|
||||
if (hFile == INVALID_HANDLE_VALUE) {
|
||||
wsprintf (buf, "Unable to open %s", filename);
|
||||
setuservariable(INST_0, buf);
|
||||
} else {
|
||||
if (g_parent)
|
||||
{
|
||||
g_childwnd=FindWindowEx(g_parent,NULL,"#32770",NULL);
|
||||
hwndL=GetDlgItem(g_childwnd,1016);
|
||||
hwndB=GetDlgItem(g_childwnd,1027);
|
||||
if (hwndL && IsWindowVisible(hwndL)) ShowWindow(hwndL,SW_HIDE);
|
||||
else hwndL=NULL;
|
||||
if (hwndB && IsWindowVisible(hwndB)) ShowWindow(hwndB,SW_HIDE);
|
||||
else hwndB=NULL;
|
||||
|
||||
wasen=EnableWindow(GetDlgItem(g_parent,IDCANCEL),1);
|
||||
lpWndProcOld = (void *) GetWindowLong(g_parent,GWL_WNDPROC);
|
||||
SetWindowLong(g_parent,GWL_WNDPROC,(long)ParentWndProc);
|
||||
|
||||
g_dialog = CreateDialog((HINSTANCE)hModule,
|
||||
MAKEINTRESOURCE(IDD_DIALOG1),
|
||||
g_childwnd,
|
||||
DownloadDialogProc);
|
||||
if (g_dialog)
|
||||
{
|
||||
GetWindowRect(g_dialog,&cr);
|
||||
ScreenToClient(g_dialog,(LPPOINT)&cr);
|
||||
ScreenToClient(g_dialog,((LPPOINT)&cr)+1);
|
||||
GetWindowRect(GetDlgItem(g_childwnd,1016),&r);
|
||||
ScreenToClient(g_childwnd,(LPPOINT)&r);
|
||||
ScreenToClient(g_childwnd,((LPPOINT)&r)+1);
|
||||
SetWindowPos(g_dialog,0,r.left,r.top,r.right-r.left,cr.bottom-cr.top,SWP_NOACTIVATE|SWP_NOZORDER);
|
||||
AdjustSize(IDC_STATIC2);
|
||||
AdjustSize(IDC_PROGRESS1);
|
||||
ShowWindow(g_dialog,SW_SHOWNA);
|
||||
char *p=filename;
|
||||
while (*p) p++;
|
||||
while (*p != '\\' && p != filename) p=CharPrev(filename,p);
|
||||
wsprintf(buf,szDownloading, p+1);
|
||||
SetDlgItemText(g_childwnd,1006,buf);
|
||||
|
||||
SetDlgItemText (g_dialog, IDC_STATIC2, szConnecting);
|
||||
}
|
||||
}
|
||||
|
||||
g_hwndProgressBar = GetDlgItem (g_dialog, IDC_PROGRESS1);
|
||||
|
||||
char *error=NULL;
|
||||
|
||||
{
|
||||
WSADATA wsaData;
|
||||
WSAStartup(MAKEWORD(1, 1), &wsaData);
|
||||
|
||||
|
@ -165,11 +276,11 @@ void downloadFile(char *url,
|
|||
st = get->run ();
|
||||
|
||||
if (st == -1) {
|
||||
*error=get->geterrorstr();
|
||||
error=get->geterrorstr();
|
||||
break;
|
||||
} else if (st == 1) {
|
||||
if (sofar < cl)
|
||||
*error="download incomplete";
|
||||
error="download incomplete";
|
||||
break;
|
||||
} else {
|
||||
|
||||
|
@ -177,7 +288,7 @@ void downloadFile(char *url,
|
|||
// progressFunc ("Connecting ...", 0);
|
||||
if (last_recv_time+g_timeout_ms < GetTickCount())
|
||||
{
|
||||
*error = "Timed out on connecting.";
|
||||
error = "Timed out on connecting.";
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -186,7 +297,7 @@ void downloadFile(char *url,
|
|||
progress_callback("Reading headers", 0);
|
||||
if (last_recv_time+g_timeout_ms < GetTickCount())
|
||||
{
|
||||
*error = "Timed out on getting headers.";
|
||||
error = "Timed out on getting headers.";
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -198,7 +309,7 @@ void downloadFile(char *url,
|
|||
|
||||
cl = get->content_length ();
|
||||
if (cl == 0) {
|
||||
*error = "Server did not specify content length.";
|
||||
error = "Server did not specify content length.";
|
||||
break;
|
||||
} else if (g_dialog) {
|
||||
SendMessage(g_hwndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0,30000));
|
||||
|
@ -218,149 +329,55 @@ void downloadFile(char *url,
|
|||
int time_sofar=(GetTickCount()-start_time)/1000;
|
||||
int bps=sofar/(time_sofar?time_sofar:1);
|
||||
int remain=MulDiv(time_sofar,cl,sofar) - time_sofar;
|
||||
char *rtext="second";
|
||||
char *rtext=szSecond;
|
||||
if (remain >= 60)
|
||||
{
|
||||
remain/=60;
|
||||
rtext="minute";
|
||||
rtext=szMinute;
|
||||
if (remain >= 60)
|
||||
{
|
||||
remain/=60;
|
||||
rtext="hour";
|
||||
rtext=szHour;
|
||||
}
|
||||
}
|
||||
wsprintf (buf,
|
||||
"%dkB (%d%%) of %dkB @ %d.%01dkB/s",
|
||||
szProgress,
|
||||
sofar/1024,
|
||||
MulDiv(100,sofar,cl),
|
||||
cl/1024,
|
||||
bps/1024,((bps*10)/1024)%10
|
||||
);
|
||||
if (remain) wsprintf(buf+lstrlen(buf)," (%d %s%s remaining)",
|
||||
if (remain) wsprintf(buf+lstrlen(buf),szRemaining,
|
||||
remain,
|
||||
rtext,
|
||||
remain==1?"":"s"
|
||||
remain==1?"":szPlural
|
||||
);
|
||||
progress_callback(buf, sofar);
|
||||
} else {
|
||||
if (sofar < cl)
|
||||
*error = "Server aborted.";
|
||||
error = "Server aborted.";
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (GetTickCount() > last_recv_time+g_timeout_ms)
|
||||
{
|
||||
*error = "Downloading timed out.";
|
||||
error = "Downloading timed out.";
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
*error = "Bad response status.";
|
||||
error = "Bad response status.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (*error)
|
||||
{
|
||||
char *t=*error;
|
||||
*error = new char[lstrlen(t)+1];
|
||||
lstrcpy(*error,t);
|
||||
}
|
||||
delete get;
|
||||
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
RECT r, cr;
|
||||
void AdjustSize(int id)
|
||||
{
|
||||
GetWindowRect(GetDlgItem(g_dialog,id),&cr);
|
||||
ScreenToClient(g_dialog,(LPPOINT)&cr);
|
||||
ScreenToClient(g_dialog,((LPPOINT)&cr)+1);
|
||||
SetWindowPos(GetDlgItem(g_dialog,id),0,0,0,r.right-r.left,cr.bottom-cr.top,SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
__declspec(dllexport) void download (HWND parent,
|
||||
int string_size,
|
||||
char *variables,
|
||||
stack_t **stacktop)
|
||||
{
|
||||
static char buf[1024];
|
||||
static char url[1024];
|
||||
static char filename[1024];
|
||||
int wasen=0;
|
||||
HWND hwndL=0;
|
||||
HWND hwndB=0;
|
||||
|
||||
g_parent = parent;
|
||||
EXDLL_INIT();
|
||||
|
||||
popstring(url);
|
||||
lstrcpyn(buf, url, 10);
|
||||
if (!lstrcmp(buf, "/TIMEOUT=")) {
|
||||
g_timeout_ms=my_atoi(url+9);
|
||||
popstring(url);
|
||||
}
|
||||
popstring(filename);
|
||||
|
||||
HANDLE hFile = CreateFile(filename,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL);
|
||||
|
||||
if (hFile == INVALID_HANDLE_VALUE) {
|
||||
wsprintf (buf, "Unable to open %s", filename);
|
||||
setuservariable(INST_0, buf);
|
||||
} else {
|
||||
if (g_parent)
|
||||
{
|
||||
g_childwnd=FindWindowEx(g_parent,NULL,"#32770",NULL);
|
||||
hwndL=GetDlgItem(g_childwnd,1016);
|
||||
hwndB=GetDlgItem(g_childwnd,1027);
|
||||
if (hwndL && IsWindowVisible(hwndL)) ShowWindow(hwndL,SW_HIDE);
|
||||
else hwndL=NULL;
|
||||
if (hwndB && IsWindowVisible(hwndB)) ShowWindow(hwndB,SW_HIDE);
|
||||
else hwndB=NULL;
|
||||
|
||||
wasen=EnableWindow(GetDlgItem(g_parent,IDCANCEL),1);
|
||||
lpWndProcOld = (void *) GetWindowLong(g_parent,GWL_WNDPROC);
|
||||
SetWindowLong(g_parent,GWL_WNDPROC,(long)ParentWndProc);
|
||||
|
||||
g_dialog = CreateDialog((HINSTANCE)hModule,
|
||||
MAKEINTRESOURCE(IDD_DIALOG1),
|
||||
g_childwnd,
|
||||
DownloadDialogProc);
|
||||
if (g_dialog)
|
||||
{
|
||||
GetWindowRect(g_dialog,&cr);
|
||||
ScreenToClient(g_dialog,(LPPOINT)&cr);
|
||||
ScreenToClient(g_dialog,((LPPOINT)&cr)+1);
|
||||
GetWindowRect(GetDlgItem(g_childwnd,1016),&r);
|
||||
ScreenToClient(g_childwnd,(LPPOINT)&r);
|
||||
ScreenToClient(g_childwnd,((LPPOINT)&r)+1);
|
||||
SetWindowPos(g_dialog,0,r.left,r.top,r.right-r.left,cr.bottom-cr.top,SWP_NOACTIVATE|SWP_NOZORDER);
|
||||
AdjustSize(IDC_STATIC2);
|
||||
AdjustSize(IDC_PROGRESS1);
|
||||
ShowWindow(g_dialog,SW_SHOWNA);
|
||||
char *p=filename;
|
||||
while (*p) p++;
|
||||
while (*p != '\\' && p != filename) p=CharPrev(filename,p);
|
||||
wsprintf(buf,"Downloading %s", p+1);
|
||||
SetDlgItemText(g_childwnd,1006,buf);
|
||||
|
||||
wsprintf(buf,"Connecting ...");
|
||||
SetDlgItemText (g_dialog, IDC_STATIC2, buf);
|
||||
}
|
||||
}
|
||||
|
||||
g_hwndProgressBar = GetDlgItem (g_dialog, IDC_PROGRESS1);
|
||||
|
||||
char *error=NULL;
|
||||
|
||||
downloadFile(url, hFile, &error);
|
||||
|
||||
CloseHandle(hFile);
|
||||
if (g_parent)
|
||||
|
|
|
@ -53,7 +53,7 @@ BSC32=bscmake.exe
|
|||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /entry:"DllMain" /dll /machine:I386 /nodefaultlib /out:"../../Plugins/nsisdl.dll" /opt:nowin98
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /entry:"DllMain" /dll /map /machine:I386 /nodefaultlib /out:"../../Plugins/nsisdl.dll" /opt:nowin98
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "nsisdl - Win32 Debug"
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue