[Delphi][Tut][ENG] Update System

03/04/2010 21:14 CappieW#1
How many tags u.u
Well, let's start with the tutorial.

Well, it's a simple system, it downloads an program/file/something from your FTP.

in Uses put urlmon,shellapi;

Add the function:
Code:
function DownloadFile(Source, Dest: string): Boolean;
begin
try
Result:= UrlDownloadToFile(nil, PChar(source),PChar(Dest), 0, nil) = 0;
except
Result:= False;
end;
end;
Add the component IdHTTP1 in the Indy Clients pallet.
Add a TMemo in the standard pallet.

Now, do an archive ".txt" called "Verify" inside it, write the name of your form.
Example: CappieWilliams Likes Chocolate v1.0.

Upload it in an FTP folder, now make a button in your program and add the code below:
Code:
//Gets the Verify.txt and write in the memo
Memo1.Lines.text:=IdHTTP1.Get('http://www.elitepvpers.com/Verify.txt');

//If it's written the same name of the form on the memo, it will say that is already updated
if Memo1.Lines.Text = LoaderForm.caption then begin
MessageBeep(MB_ICONERROR);
showmessage('You already have the newest version!');
end else

//If it's not written in the .txt archive it will update
if messagedlg('There's a new version, want to update?',mtconfirmation,[mbyes,mbno],0)=mryes then
begin

//Download the archive and save in the archive folder with the "CappieWilliams" name XD
if DownloadFile ('http://www.elitepvpers.com/CappieWilliams.exe','CappieWilliams.exe') then

//Make an OK! sound
MessageBeep(MB_OK);

//If the archive exists, appear a succes message
if fileexists('CappieWilliams.exe') then begin

//Give a message telling that it's updated and close the program and open again!
showmessage('Update complete, click on OK to restart the application!');
application.terminate;
shellexecute (handle, 'open', 'CappieWilliams.exe', '', nil, sw_shownormal);
end;
end;
Conclusion: It'll see if it's written CappieWilliams Likes Chocolate v1.0 in the archive, and see if the form is also written as CappieWilliams Likes Chocolate v1.0, if they're the same, a message box will appear telling you that is already updated and won't do anything. But if you write "Cappie'sAwesome" in the .txt archive, it'll update (:

But, in the place of writting "Cappie'sAwesome" you write CappieWilliams Likes Chocolate v2.0 and in the v2.0 you edit from 1.0 to 2.0 to read on the archive, got it?

Credits: Cappie Williams (CappieW), made only for elitepvpers.com.
If you have some question, just ask here or send an PM.

Cya.
03/19/2010 20:52 CappieW#2
62 Views, 0 Comments D:
03/19/2010 21:00 HardCore.1337#3
take the Indy Components

Edit: Linking the Website about the Indy Components, because the Indy Components available are only in D7 and higher