Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Code]
- function DownloadFile(const AURL: string; var AResponse: string): Boolean;
- var
- WinHttpRequest: Variant;
- begin
- Result := True;
- try
- WinHttpRequest := CreateOleObject('WinHttp.WinHttpRequest.5.1');
- WinHttpRequest.Open('GET', AURL, False);
- WinHttpRequest.Send;
- AResponse := WinHttpRequest.ResponseText;
- except
- Result := False;
- AResponse := GetExceptionMessage;
- end;
- end;
- procedure DecodeVersion( verstr: String; var verint: array of Integer );
- var
- i,p: Integer; s: string;
- begin
- verint := [0,0,0,0];
- i := 0;
- while ( (Length(verstr) > 0) and (i < 4) ) do
- begin
- p := pos('.', verstr);
- if p > 0 then
- begin
- if p = 1 then s:= '0' else s:= Copy( verstr, 1, p - 1 );
- verint[i] := StrToInt(s);
- i := i + 1;
- verstr := Copy( verstr, p+1, Length(verstr));
- end
- else
- begin
- verint[i] := StrToInt( verstr );
- verstr := '';
- end;
- end;
- end;
- function CompareVersion( ver1, ver2: String ) : Integer;
- var
- verint1, verint2: array of Integer;
- i: integer;
- begin
- SetArrayLength( verint1, 4 );
- DecodeVersion( ver1, verint1 );
- SetArrayLength( verint2, 4 );
- DecodeVersion( ver2, verint2 );
- Result := 0; i := 0;
- while ( (Result = 0) and ( i < 4 ) ) do
- begin
- if verint1[i] > verint2[i] then
- Result := 1
- else
- if verint1[i] < verint2[i] then
- Result := -1
- else
- Result := 0;
- i := i + 1;
- end;
- end;
- function NextButtonClick(PageId: Integer): Boolean;
- var
- ErrCode: integer;
- DeXVersion: string;
- begin
- // initialize the Result to True to allow the setup to start
- Result := True;
- // if the version file was successfuly downloaded, then...
- if DownloadFile('http://dex.wotanksmods.com/latestver.txt', DeXVersion) then
- begin
- // the version file was downloaded so only now we can compare versions
- if CompareVersion(DeXVersion, '{#MyAppVersion}') > 0 then
- begin
- Result := MsgBox(ExpandConstant('{cm:InfoDeXVersion1} ' + DeXVersion + ExpandConstant('{cm:InfoDeXVersion2}')),
- mbConfirmation, MB_YESNO) = IDNO;
- // hint; do not use 'open' verb; let the Windows Shell decide the default action for HTTP protocol
- if not Result then
- ShellExec('', 'http://goo.gl/uEiRGw', '', '', SW_SHOW, ewNoWait, ErrCode);
- end;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment