function CheckForUpdates():
string;
var
HTTP: TIdHTTP;
HTTPS: TIdSSLIOHandlerSocketOpenSSL;
Answer:
String;
data: ISuperObject;
sUURL, exe, bak, oldexe:
String;
lStream: TFileStream;
begin
HTTP := TIdHTTP.Create();
HTTPS := TIdSSLIOHandlerSocketOpenSSL.Create();
HTTP.IOHandler := HTTPS;
try
Answer := HTTP.Get('
https://dl.dropboxusercontent.com/u/111435195/Update/updates.txt');
data := SO(Answer);
if data.O['
stable'].I['
version'] > StrToInt(StringReplace(GetVersion, '
.', '
', [rfReplaceall]))
then
begin
try
UpdateForm.ProgressBar1.Position := 0;
sUURL := data.O['
stable'].S['
url'];
// Update URL
UpdateForm.Label1.Caption := '
Please wait a second ...';
UpdateForm.ProgressBar1.Position := 5;
oldexe := '
Checker' + '
.exe';
UpdateForm.Show;
Application.ProcessMessages;
exe := ParamStr(0);
bak := ChangeFileExt(EXE,'
.BAK');
UpdateForm.ProgressBar1.Position := 25;
RenameFile(exe,bak);
UpdateForm.ProgressBar1.Position := 50;
lStream:=TFileStream.Create(GetCurrentDir + '
/' + oldexe, fmCreate
or fmShareDenyNone);
UpdateForm.ProgressBar1.Position :=75;
HTTP.Get(sUUrl, lStream);
UpdateForm.ProgressBar1.Position := 85;
lStream.Free;
ShellExecute(0, '
open', PWideChar(oldexe),
nil,
nil, SW_SHOWNORMAL);
UpdateForm.ProgressBar1.Position := 100;
Result := '
true';
FreeAndNil(HTTP);
ExitProcess(0);
except
end;
end
else
Result := '
false';
FreeAndNil(HTTP);
except
FreeAndNil(HTTP);
Result := '
error';
end
end;