Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WebUpdate - How?

Status
Not open for further replies.

Tilen

Programmer
Apr 2, 2005
75
SI
Hi

I hope someone can give me some pointers on how to develop a webupdate for my small delphi app.

I have no idea how to do it, but here is my plan:

1. Check for latest version:
I would write an html : which would contain just a number, for example: 20. So I would read this html from delphi and I would get 20 from it and just compare to current installed version.

2. If 20 is more than current then donwload
3. Unzip downloaded file : app.zip -> app.exe

4. Start app.exe

5. Close application so I can copy over the new version.


Now, I don't see any problems with steps 2,4-5.

So, 1. step is the hardest. I have no idea hot to GET html from a specific address.

And step 2. download specific file... how?

I can't have any asp or php on so just html.

If anybody thinks this is completely wrong :) ... Please advise.



Thanx

Tilen
 
To get the HTML code of a specific URL:

1) Drop a TRichEdit, a TButton and a TIdHTTP (found in the Indy Clients tab of the Delphi 6 component palette) onto a form.

2) Write a procedure such as the following, where HTTP1 is your TIdHTTP component and reHTML is your TRichEdit:
Code:
procedure TForm1.GetHTMLContent(URL: String);
var
  PostDataStream : TStringStream;
begin
  PostDataStream := TStringStream.Create('');
  try
    HTTP1.Get(URL, PostDataStream);
    reHTML.Text := PostDataStream.DataString;
  finally
    PostDataStream.Free;
  end;
end;
3) Then call your function passing the appropriate URL, for example from a TButton OnClick event:
Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
  GetHTMLContent('[URL unfurl="true"]http://www.abc.com/latestversion.html');[/URL]
end;

Obviously, this is just the bare bones - but it should give you a starting point.

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Thanx for quick response.

Your sample is exactly what I need.

And here is a code that downloads the file:

function GetInetFile(const fileURL, FileName: String): boolean;
const BufferSize = 1024;
var
hSession, hURL: HInternet;
Buffer: array[1..BufferSize] of Byte;
BufferLen: DWORD;
f: File;
sAppName: string;
begin
Result:=False;
sAppName := ExtractFileName(Application.ExeName);
hSession := InternetOpen(PChar(sAppName),
INTERNET_OPEN_TYPE_PRECONFIG,
nil, nil, 0);
stevec:=0;
try
hURL := InternetOpenURL(hSession,
PChar(fileURL),
nil,0,0,0);
try
AssignFile(f, FileName);
Rewrite(f,1);
repeat
InternetReadFile(hURL, @Buffer,
SizeOf(Buffer), BufferLen);
BlockWrite(f, Buffer, BufferLen);
until BufferLen = 0;
CloseFile(f);
Result:=True;
finally
InternetCloseHandle(hURL)
end
finally
InternetCloseHandle(hSession)
end
end;


Thanx again

Tilen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top