Old 21st January 2009, 16:14   #1
ThiWeb
Junior Member
 
Join Date: Jan 2009
Location: Paris
Posts: 5
[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 :
code:
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
ThiWeb is offline   Reply With Quote
Old 21st January 2009, 17:26   #2
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
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.
Animaether is offline   Reply With Quote
Old 21st January 2009, 20:11   #3
ThiWeb
Junior Member
 
Join Date: Jan 2009
Location: Paris
Posts: 5
Quote:
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" :
code:
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 ?

Here is my code :
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
ThiWeb is offline   Reply With Quote
Old 21st January 2009, 20:19   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,449
HTTP/1.1 200 = ok, 404 is file not found etc

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 21st January 2009, 20:56   #5
ThiWeb
Junior Member
 
Join Date: Jan 2009
Location: Paris
Posts: 5
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
ThiWeb is offline   Reply With Quote
Old 21st January 2009, 21:06   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,449
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

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 21st January 2009, 21:11   #7
ThiWeb
Junior Member
 
Join Date: Jan 2009
Location: Paris
Posts: 5
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
ThiWeb is offline   Reply With Quote
Old 21st January 2009, 22:23   #8
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
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.
Animaether is offline   Reply With Quote
Old 22nd January 2009, 09:06   #9
Takhir
Major Dude
 
Join Date: Feb 2004
Location: Moscow, Russia
Posts: 1,222
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.
Takhir is offline   Reply With Quote
Old 23rd January 2009, 00:04   #10
ThiWeb
Junior Member
 
Join Date: Jan 2009
Location: Paris
Posts: 5
Hi,

I found something interesting,
I try to use an XML to check the version of my installation. Here is the code :
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 :

And here is my XML :
code:
<?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
ThiWeb is offline   Reply With Quote
Old 23rd January 2009, 11:49   #11
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
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...
code:

${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.
Animaether is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump