- NSIS Discussion
- [PROBLEM] How To Check URL ?
Archive: [PROBLEM] How To Check URL ?
ThiWeb
21st January 2009 17:14 UTC
[PROBLEM] How To Check URL ?
Hi,
I'm trying to check an URL like http://mysite.com/program1.6.exe
If URL exist, the program is up to date.
But if not, the installation have to close and launch the URL.
I don't want a special download way...
An IE download will be enough for me.
Now, how can I realise that ? :$
I'm already checking if the program is installed or not with :
Function .onInit
ClearErrors
readregstr $1 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName"
IfErrors done
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Already installed, uninstall ?" IDNO +2
ExecShell Open "$INSTDIR\uninst.exe"
SetAutoClose true
Abort
done:
FunctionEnd
But how can I do the same with an simple URL ?
Thanks !
ThiWeb
Animaether
21st January 2009 18:26 UTC
could try the Inetc plugin (or others like it)
http://nsis.sourceforge.net/Inetc_plug-in
It has an option to grab just the headers of an HTTP file request. Then just check if the headers say that the file is there, or whether the file doesn't exist. easypeasy.
ThiWeb
21st January 2009 21:11 UTC
It has an option to grab just the headers of an HTTP file request. Then just check if the headers say that the file is there, or whether the file doesn't exist.
Ok thank you so much ! But when I try to use the script, it download my file...
I've try to put "HEAD" in the script but where is the "title" of my file.
My file is : test.zip
And after launching the programme he wrote that in the "TXT" :
HTTP/1.1 200 OK
Date: Wed, 21 Jan 2009 21:08:38 GMT
Server: Apache/2.2.10 (Unix) mod_ssl/2.2.10 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
Last-Modified: Wed, 21 Jan 2009 20:49:10 GMT
ETag: "967003d-12172-4610449a29d80"
Accept-Ranges: bytes
Content-Length: 74098
Keep-Alive: timeout=2, max=15
Connection: Keep-Alive
Content-Type: application/zip
What can I do with that ? :rolleyes:
Here is my code :
inetc::head "http://mywebsite.com/test.zip" "test.txt"
Pop $0 # return value = exit code, "OK" if OK
MessageBox MB_OK "Download Status: $0"
ThiWeb
Anders
21st January 2009 21:19 UTC
HTTP/1.1 200 = ok, 404 is file not found etc
ThiWeb
21st January 2009 21:56 UTC
Ahhh ok ok ! Thank you again !
I begin to understand lol !
So if the file exist on the serveur : "TEST.TXT" contain : HTTP/1.1 200 OK
If not, there's no file ? No way to have one TXT with 404 in it ?
My idee is to check this file and tell : "You are up to date / Or not".
If OK => Up to date
If 404 => An udate is available
Any idee for that ?
ThiWeb
Anders
21st January 2009 22:06 UTC
no, if its not 200, it could be file not found, server down, or any kind of error
you are better off storing a .ini file on the server, and put the version info in the .ini, just download and use the nsis ini functions to check the version
ThiWeb
21st January 2009 22:11 UTC
Yes... I think you'r right.
INI file on the server is better.
I will try this and try also INI Function.
Thanks again.
I'll surly come back :)
ThiWeb
Animaether
21st January 2009 23:23 UTC
there's pros and cons to both methods
We use an ini, ourselves, because it allows us to add a summary line of text that we can display in the installer and a URL that we can then hook up to a hyperlink control so the user can browse for more information.
However, it does mean that the URL for that ini -must- exist for some time to come - you don't want older installers to suddenly go nuts just because the file can no longer be found - expect, say, 6 months to a year that you should -at least- keep that URL, with valid content, alive. Anybody running an installer that's over a year old should - if the ini file doesn't exist anymore - get a message that their version is possibly horribly outdated, with a link to the main site page.
Takhir
22nd January 2009 10:06 UTC
inetc puts to NSIS stack "OK" if file or http headers were downloaded successfully, "File Not Found (404)" if no such file on server. Please note that a lot of other situations may have place on customer comp (like no internet connection at all). Plug-in auto-removes local file on '404' situation. So the best way is to check what you have after "Pop $0". Ini file tracking is another good approach.
ThiWeb
23rd January 2009 01:04 UTC
Hi,
I found something interesting,
I try to use an XML to check the version of my installation. Here is the code :
Name "OnlineUpdate"
OutFile "OnlineUpdate.exe"
ShowInstDetails show
!include "WordFunc.nsh" ; only for UpdatePad
!insertmacro "VersionCompare" ; only for UpdatePad
!include "XML.nsh"
!include "OnlineUpdate.nsh"
!insertmacro "UpdateXml"
!insertmacro "UpdatePad"
Page Components
Page InstFiles
Section "Read Version from XML"
${UpdateXml} "http://198.63.208.118/padinfo/padgen.xml" "/XML_DIZ_INFO/Program_Info/Program_Version" "$0"
DetailPrint "The latest version is $0"
SectionEnd
Section "Read Version from PAD and Download"
${UpdatePad} "http://198.63.208.118/padinfo/padgen.xml" "1.0" $0
StrCmp $0 "" 0 +3
DetailPrint "No updates available"
Goto +2
DetailPrint "You can download a newer version @ $0"
SectionEnd
I've change the adress with mine, but he say everytime the same thing :
http://light.zone-dl.fr/4UMEQ/nsis.jpg
And here is my XML :
<?xml version="1.0" encoding="utf-8"?>
<Test>
<ver>1.2</ver>
</Test>
Why he don't me : "Hey ! There's an update available !" ?
Maybe it's simple to use an INI file, but I'm a beginner with NSIS...
Can someone show me how use my script to do what I want ?
Or I'm open to try INI way.
Thank you so much.
ThiWeb
Animaether
23rd January 2009 12:49 UTC
I think you'd have to check the documentation for UpdateXml / UpdatePad (wherever those are from - google's proving fruitless on either term in combination with nsis), but if I'd have to perform guesswork...
${UpdateXml} "http://198.63.208.118/padinfo/padgen.xml" "/XML_DIZ_INFO/Program_Info/Program_Version" "$0"
...I'd say that line means "from the padgen.xml, read the value for the XML path /XML_DIZ_INFO/Program_Info/Program_Version and stick the result in $0".
However, your XML does not have that path. Apparently, it's supposed to look more like - say - this:
http://www.asp-shareware.org/padinfo/padgen.xml
Now, that one has a ton of fields and only a few of them are actually required, but you should be able to tell that the /XML_DIZ_INFO/Program_Info/Program_Version path at least exists in that file.
So, again, my guess would be that your XML does not conform to the PAD specification, and thus the PAD scripts fail to work with it.