Advertisement
TLama

Untitled

Nov 11th, 2014
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.46 KB | None | 0 0
  1. [Setup]
  2. AppName=My Program
  3. AppVersion=1.5
  4. DefaultDirName={pf}\My Program
  5.  
  6. [Code]
  7. const
  8.   PwdURL = 'https://projects-stackoverflow-tlama.googlecode.com/svn/trunk/18070448/file1.txt';
  9.  
  10. var
  11.   InitialPassword: string;
  12.  
  13. function TryGetTextFile(const URL: string; out Response: string): Boolean;
  14. var
  15.   Request: Variant;
  16. begin
  17.   Result := True;
  18.   try
  19.     Request := CreateOleObject('WinHttp.WinHttpRequest.5.1');
  20.     OleCheck(Request.Open('GET', URL, False));
  21.     OleCheck(Request.Send);
  22.     Response := Request.ResponseText;
  23.   except
  24.     Result := False;
  25.     Response := GetExceptionMessage;
  26.   end;
  27. end;
  28.  
  29. procedure InitializeWizard;
  30. var
  31.   Response: string;
  32. begin
  33.   // if downloading succeeded, assign the response to the InitialPassword
  34.   if TryGetTextFile(PwdURL, Response) then
  35.     InitialPassword := Response
  36.   else
  37.   begin
  38.     // downloading failed, so let's take further actions, like setting up some
  39.     // fallback password, showing error message, or e.g. exiting setup
  40.     InitialPassword := 'Downloading failed, so let''s setup some fixed pwd.';
  41.     MsgBox('Downloading of a password failed. ' + Response, mbError, MB_OK);
  42.   end;
  43. end;
  44.  
  45. function CheckPassword(Password: String): Boolean;
  46. begin
  47.   // continue only if the entered password is not empty and equals to "MasterPassword" or
  48.   // the one downloaded before (if downloading succeeded)
  49.   Result := (Password <> '') and ((Password = 'MasterPassword') or (Password = InitialPassword));
  50. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement