TLama

Untitled

Apr 30th, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.35 KB | None | 0 0
  1. [Code]
  2. function DownloadFile(const AURL: string; var AResponse: string): Boolean;
  3. var
  4.   WinHttpRequest: Variant;
  5. begin
  6.   Result := True;
  7.   try
  8.     WinHttpRequest := CreateOleObject('WinHttp.WinHttpRequest.5.1');
  9.     WinHttpRequest.Open('GET', AURL, False);
  10.     WinHttpRequest.Send;
  11.     AResponse := WinHttpRequest.ResponseText;
  12.   except
  13.     Result := False;
  14.     AResponse := GetExceptionMessage;
  15.   end;
  16. end;
  17.  
  18. procedure DecodeVersion( verstr: String; var verint: array of Integer );
  19. var
  20.   i,p: Integer; s: string;
  21. begin
  22.   verint := [0,0,0,0];
  23.   i := 0;
  24.   while ( (Length(verstr) > 0) and (i < 4) ) do
  25.   begin
  26.     p := pos('.', verstr);
  27.     if p > 0 then
  28.     begin
  29.       if p = 1 then s:= '0' else s:= Copy( verstr, 1, p - 1 );
  30.       verint[i] := StrToInt(s);
  31.       i := i + 1;
  32.       verstr := Copy( verstr, p+1, Length(verstr));
  33.     end
  34.     else
  35.     begin
  36.       verint[i] := StrToInt( verstr );
  37.       verstr := '';
  38.     end;
  39.   end;
  40. end;
  41.  
  42. function CompareVersion( ver1, ver2: String ) : Integer;
  43. var
  44.   verint1, verint2: array of Integer;
  45.   i: integer;
  46. begin
  47.  
  48.   SetArrayLength( verint1, 4 );
  49.   DecodeVersion( ver1, verint1 );
  50.   SetArrayLength( verint2, 4 );
  51.   DecodeVersion( ver2, verint2 );
  52.   Result := 0; i := 0;
  53.   while ( (Result = 0) and ( i < 4 ) ) do
  54.   begin
  55.     if verint1[i] > verint2[i] then
  56.       Result := 1
  57.     else
  58.       if verint1[i] < verint2[i] then
  59.         Result := -1
  60.       else
  61.         Result := 0;
  62.  
  63.     i := i + 1;
  64.   end;
  65. end;
  66.  
  67. function NextButtonClick(PageId: Integer): Boolean;
  68. var
  69.   ErrCode: integer;
  70.   DeXVersion: string;
  71. begin
  72.   // initialize the Result to True to allow the setup to start
  73.   Result := True;
  74.   // if the version file was successfuly downloaded, then...
  75.   if DownloadFile('http://dex.wotanksmods.com/latestver.txt', DeXVersion) then
  76.   begin
  77.     // the version file was downloaded so only now we can compare versions
  78.     if CompareVersion(DeXVersion, '{#MyAppVersion}') > 0 then
  79.     begin
  80.       Result := MsgBox(ExpandConstant('{cm:InfoDeXVersion1} ' + DeXVersion + ExpandConstant('{cm:InfoDeXVersion2}')),
  81.         mbConfirmation, MB_YESNO) = IDNO;
  82.       // hint; do not use 'open' verb; let the Windows Shell decide the default action for HTTP protocol
  83.       if not Result then
  84.         ShellExec('', 'http://goo.gl/uEiRGw', '', '', SW_SHOW, ewNoWait, ErrCode);
  85.     end;
  86.   end;
  87. end;
Advertisement
Add Comment
Please, Sign In to add comment