Skip to content
⌘ NSIS Forum Archive

http + ftp download plug-in

545 posts

klopfdreh#
I tried various settings now in
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings

ReceiveTimeout (REG_DWORD) = 300000
KeepAliveTimeout (REG_DWORD) = 300000
ServerInfoTimeout (REG_DWORD) = 300000

But I had no success, because I received the error message every ~3000 Milliseconds and not as expected ~5 minutes.

So I had a deeper look into the source code.

Please correct me if I'm wrong, but you are using a thread which is waiting if there is a transfer and if not it will abort after 3000 milliseconds, right?

Line: WaitForSingleObject(hThread, 3000) == WAIT_TIMEOUT

Could it be that the timeout which is going to be set via RECEIVE_TIMEOUT and CONNECT_TIMEOUT should influence this timeout, because the thread would exit to early?

In my opinion the changes of the RECEIVE_TIMEOUT would be only a little (~5 lines -> cmd line parsing and call in the function itself), so I would add it to the next version, to set it as needed.

P.S.: A few options are not mentioned in the wiki (for example: nocookies).
Yathosho#
could it be the plugin ignores the default font rendering settings when used in /BANNER mode? it seems to ignore the fact i have cleartype enabled.
Takhir#
Originally Posted by klopfdreh View Post
Please correct me if I'm wrong, but you are using a thread which is waiting if there is a transfer and if not it will abort after 3000 milliseconds, right?

Line: WaitForSingleObject(hThread, 3000) == WAIT_TIMEOUT
No, in this line plug-in waits transfer thread termination after Cancel button was pressed. On server termination DATA_RECEIVE_TIMEOUT probably defines time. If you tested InternetSetOption(hSession, INTERNET_OPTION_DATA_RECEIVE_TIMEOUT, &timeout,
sizeof(DWORD)); and this work as expected please let me know (or I'll test this when I'll have time - a lot of job now 🙁 ). Both options - connection and receive timeouts have sence, so let's test and add new feature 🙂.

> P.S.: A few options are not mentioned in the wiki (for example: nocookies).
Thanks!

> could it be the plugin ignores the default font rendering settings when used in /BANNER mode? it seems to ignore the fact i have cleartype enabled.

Yathosho, please send me minimum size sample script and I'll test this. Only english/russian/italian systems are available now for me 🙂.
klopfdreh#edited
@Takhir: Thank a lot for the fast answer again. Well I don't have the environment to compile the source 🙁 . Would you please so kind and test it?

The way I did was simply to limit the transfer rate of the http server and shut it down, before the download was finished. The response always appears after ~3 Seconds, thats why I was supposing it could be the line I worte. And in the case of the virus scanner it also appears in ~3 Seconds, because the file is beeing scanned.

It would be really really nice, because we are using your lib to update clients automatically in an environment with ~1500 users. 🙂

I think it should be only a little change, just those lines that get the parameter out of the call and if the parameter contains the receive timeout the call of the internetSetOption.
klopfdreh#edited
Now I tried to compile it with cygwin by myself and I got some errors during the compilation (picture)

@Takhir: Because I can't compile it easily - would you be so kind and add/change the following lines to inetc.cpp and recompile it? I think it should work that way:

line 208:
timeout,
receivetimeout = 0;
line 799:
if(receivetimeout > 0)
InternetSetOption(hSes, INTERNET_OPTION_DATA_RECEIVE_TIMEOUT, &receivetimeout, sizeof(receivetimeout));
line 1374:
else if(lstrcmpi(url, _T("/receivetimeout")) == 0)
{
popstring(url);
receivetimeout = _tcstol(url, NULL, 10);
}
That would be very very nice of you. If you could do this and post a new build in here I would check if that will solve our problem!

Edit: I was able to solve the error with the exdll by using the exdll.h and the api.h of the current source of nsis but the error in inetc.cpp on line 648 still appears.
Afrow UK#
You don't need to use strtol (you don't want a dependency on CRT). NSIS exposes popint() and myatoi() that you can use.

Stu
klopfdreh#
Ok, I solved it for my environment. I used dev-c (g++) within cygwin:

g++ -c inetc.cpp -I/usr/include/mingw -lwininet -lcomctl32
g++ -shared -o inetc.dll inetc.o -I/usr/include/mingw -lwininet -lcomctl32

and I used the exdll.h and api.h attached to the post.

@ Afrow UK: It is not my code. I only want to recompile and test the changes posted above.

Edit: Well my dll doesn't work! 😁 I hope I will get it running today.

Edit2: Mmhhh I don't know why it is not working for me, the result if I compile the dll is, that the return value is not "OK". Example:

inetc::get /NOCOOKIES /TIMEOUT 300000 /NOCANCEL /CAPTION "$(^Name)" /RESUME "..."

Pop $R0

MessageBox MB_OK $R0

$R0 is always the first paramter I give into the dll call....
Takhir#
I am sorry... and thank for your efforts!
I am attaching build with your changes, please send me info if you need something else and I'll try to do this tonight.
klopfdreh#edited
@Takhir: Thank you very very much! Maybe you are able to tell me what I did wrong with the compilation?

I don't know why it doesn't worked for me - even NSIS was compiling fine...

Edit: I tried the new version with the internetreceive timeout and if I have the kaspersky virus scanner installed, it trys to check the download after the tranfer and then aborts. 😢 I've tested it on a vmware box already...

Edit2: BUUUUUTTTT!!! I tested the ReceiveTimeout in the registry again and then the download worked for me. Seems that the internetSetOption with INTERNET_OPTION_DATA_RECEIVE_TIMEOUT doesn't apply it to the current connection.

Brrrr.... this smells like an ugly sh* but I'm going to set the dword previously:

WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Internet Settings\" 'ReceiveTimeout' 0x001b7740
Takhir#
Thanks, klopfdreh

Attached plug-in worked as expected (for me ).
Finally: INTERNET_OPTION_RECEIVE_TIMEOUT sets what we need. Interesting information from MSDN 2005: INTERNET_OPTION_DATA_RECEIVE_TIMEOUT 8 Not implemented.
Now Inetc options are /connecttimeout and /receivetimeout, both in seconds (not milliseconds!). I.e. 60 sec timeout will be /receivetimeout 60

And ... this not took many time after I understood how to test timeout - simple php script with sleep() . Included to zip. please let me know if big files problem resolved.
klopfdreh#
Great! Thanks a lot! I'm going to test it without the reg key and with this new version, now!

Edit: It is working like a charm, even without the registry entry - thank you very very much! 😁

I think we should add those changes to the wiki, too. It is a great change and really usefull!
Yathosho#
Originally Posted by Takhir View Post
Yathosho, please send me minimum size sample script and I'll test this. Only english/russian/italian systems are available now for me 🙂.
(screenshot based on your cameron diaz example)

is the banner using the system font? it should be antialiased according to my windows settings, but it's not.
Yathosho#
btw, i have tried to use InetLoad with three switches (/TIMEOUT 5000 /RESUME /BANNER) but the download only works when using just one of these. the documentation and examples don't deal with multiple switches, is it even possible to chain these?
zenpoy#
Hi all - I've noticed that when using embedded progress bar the text above the main progress bar is always printf("Downloading %s",filename), ignoring the caption switch. so I've changed the code a bit to make the text printf("%s",caption) if the caption switch exists.

If you think the this is really a bug you can merge it. Anyway, this is what the I thought the expected behavior would be.

Thanks,

J
ManoKum80#
Feature Add Request -
- If download file already exists, check hash, if OK do not re-download
- Resume download even if user Cancels it, something like /NODELETE option on nsisdl v1.4
- on resume prompt, window title is 'Inetc plugin', it should be either removed completely or changeable via some option

Currently both above are available nsisdl v1.4 but it does not have authentication/proxy handling features that inetc can do.

PS - let me know if above features are already available and i am missing something.
Great thanks to all!
MSG#
Originally Posted by ManoKum80 View Post
- If download file already exists, check hash, if OK do not re-download
This is actually trivial to implement in NSIS code. Use the md5dll plugin.
zenpoy#
Bug?

I think I found a bug in Inetc but I'm not sure - for some reason it clears the stack after cancelling. Does anyone see this behavior also?

EDIT: It clears the stack when clicking cancel and then it pops up an are you sure dialog - while it continues to download - if it finishes to download while the dialog is still open and then I press "Yes" (which means - yes, I'm sure I want to cancel) It clears the stack. If everyone see this behavior - I think it's pretty critical...
Takhir#
Originally Posted by zenpoy View Post
I think I found a bug in Inetc but I'm not sure - for some reason it clears the stack after cancelling. Does anyone see this behavior also?
inetc can download few files, so stack can include few pairs of URL/file, on termination plug-in should remove tail from stack. Best of all is to use /end paramater in your command line.
zenpoy#
the command line I'm using is:

Inetc::get /NOPROXY /QUESTION "" /CAPTION "Installing $TITLE" $IS_PROXY_ALLOWED $URL $R3 /END
zenpoy#
Anyway - I think I fixed it I've changed dlgProc, case IDCANCEL to be:

case IDCANCEL:
if(nocancel) break;
if(szQuestion) {
msgboxAnswer = MessageBox(hDlg, szQuestion, szCaption, MB_ICONWARNING|MB_YESNO);
if (msgboxAnswer == IDNO)
break;
else if (status == ST_DOWNLOAD)
status = ST_CANCELLED;
}
zenpoy#
ok... now I've fixed it

Sorry for spamming the thread... The former solution wasn't a solution - it did not clear the stack but it returned a wrong status. So please ignore the last fix.

There's a function called inetTransfer which pops pairs of url and file name and downloads them. what I did was to add two lines right after the loop that does that:

if (lstrcmpi(url, _T("/end"))==0)
pushstring(url);

And in cleanup section I removed the status check - so now I always clean the stack.

Hope it makes sense to anyone. If you want the fixed version, tell me.

J.
Takhir#
Originally Posted by zenpoy View Post
Hope it makes sense to anyone. If you want the fixed version, tell me.
J.
Thanks, zenpoy!
If you can send me PM with updated source, I'll merge changes and build new release for wiki.
Unfortunatelly I am overloaded with business tasks and had not time to dig into proble, sorry 🙁.
Takhir
zenpoy#
What do you use to compile inetc?

When I'm using the inetc.dll out of the box (that is, out of the zip) it works fine in winxp sp2. When I use my x64 (win7) pc with both vs2008 and vs2010 to compile the source code it produces a dll that works in win7 but is not working in winxp sp2 (without any updates/vc++ packs or anything, completely fresh install).

When I try to call inetc:

 
strcpy $R0 "http://www.google.com/intl/en_com/images/srpr/logo2w.png"
Inetc::get /SILENT /CONNECTTIMEOUT 10000 $R0 "image.png" /END
dumpstate::debug
it leaves the args on the stack ( /SILENT /CONNECTTIMEOUT 10000 $R0 "image.png" /END)

So how do you compile it to be compatible for xp sp2??

Thanks
Takhir#
I compile it in VS 6 on XP or Vista. Resulting DLL depends on msvctr.dll but this is OK. You can change settings in later VS to multithreaded DLL, this case module size should increase, but without dependencies to runtimes. IMHO targetver.h should not produce any conflicts.
zenpoy#
Thanks! that helped... I tried to change to multithreasded DLL but still, it didn't work. So I used VS6 and it works like a charm.
Takhir#
Oups... Sorry, 'multithreaded' only. No 'DLL' and no dependencies to runtimes this case. But any case VS 6 is better way.
zenpoy#
I have now another issue with winxp32 sp2. In win7/vista and others I can redirect from https to http. but in winxp32sp2 I get error Redirection (302). I thought I should add something like:



InternetQueryOption (hFile, INTERNET_OPTION_SECURITY_FLAGS,
(LPVOID)&rslt, &(err = sizeof(rslt)));
rslt |= SECURITY_FLAG_IGNORE_REDIRECT_TO_HTTP;
InternetSetOption (hFile, INTERNET_OPTION_SECURITY_FLAGS,
&rslt, sizeof(rslt) );

but it didn't work - I'm not that familiar with the code, can you give me some guidance?
Takhir#
Inetc already has

#define MY_REDIR_FLAGS INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP | INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS

for primary https URL. 'SECURITY_' flags are the same

#define SECURITY_FLAG_IGNORE_REDIRECT_TO_HTTPS INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
#define SECURITY_FLAG_IGNORE_REDIRECT_TO_HTTP INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP

So I guess problem is in this XP settings or in WinInet.dll version supplied with this OS/SP.

I am attaching test version with merged code for 'Cancel' issue (because it's not possible to send link in PM 🙁 ). BTW I am not sure if anybody use this 'multiple download' mode. May be has sence to remove this option and download one file per Inetc call? For me this even simpler then long-long-long strings with name-URL pairs...