From ff7ead47bc1decfcd5f32ec4347ab181268d659c Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Tue, 17 Sep 2013 18:11:15 +0000 Subject: [PATCH] Issue #3334: * Decrease connect timeout for donation state check from 30s down to 3s, so especially on application start noone has to wait too long only because heidisql.com is down again. * Return TThreeStateBoolean in HasDonated(), so we can display an appropriate warning when the HTTP check was unsuccessful --- out/locale/en/LC_MESSAGES/default.po | 6 +++++- source/about.pas | 21 ++++++++++++++------- source/helpers.pas | 11 +++++++++-- source/main.pas | 10 +++++----- source/updatecheck.pas | 2 +- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/out/locale/en/LC_MESSAGES/default.po b/out/locale/en/LC_MESSAGES/default.po index 071dc706..947de477 100644 --- a/out/locale/en/LC_MESSAGES/default.po +++ b/out/locale/en/LC_MESSAGES/default.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: HeidiSQL\n" "POT-Creation-Date: 2012-11-05 21:40\n" -"PO-Revision-Date: 2013-09-14 06:56+0100\n" +"PO-Revision-Date: 2013-09-17 20:06+0100\n" "Last-Translator: Ansgar Becker \n" "Language-Team: English (http://www.transifex.com/projects/p/heidisql/" "language/en/)\n" @@ -49,6 +49,10 @@ msgstr "Thanks for donating!" msgid "Not a valid donators email address" msgstr "Not a valid donators email address" +#. About dialog +msgid "Could not check donation state, gracefully assuming you have donated." +msgstr "Could not check donation state, gracefully assuming you have donated." + #. frmBinEditor..Caption #: bineditor.dfm:4 msgid "Binary editor" diff --git a/source/about.pas b/source/about.pas index 936b7fa5..832a2217 100644 --- a/source/about.pas +++ b/source/about.pas @@ -63,15 +63,22 @@ end; procedure TAboutBox.btnDonatedOKClick(Sender: TObject); +var + Check: TThreeStateBoolean; begin AppSettings.WriteString(asDonatedEmail, editDonated.Text); - if MainForm.HasDonated(True) then - MessageDialog(_('Thanks for donating!'), mtInformation, [mbOK]) - else - ErrorDialog(_('Not a valid donators email address')); - imgDonate.Visible := not MainForm.HasDonated(False); + Check := MainForm.HasDonated(True); + case Check of + nbUnset: + MessageDialog(_('Could not check donation state, gracefully assuming you have donated.'), mtWarning, [mbOK]); + nbFalse: + ErrorDialog(_('Not a valid donators email address')); + nbTrue: + MessageDialog(_('Thanks for donating!'), mtInformation, [mbOK]); + end; + imgDonate.Visible := Check = nbFalse; MainForm.imgDonate.Width := 122; - MainForm.imgDonate.Visible := not MainForm.HasDonated(False); + MainForm.imgDonate.Visible := imgDonate.Visible; end; @@ -99,7 +106,7 @@ begin lblAppName.Font.Size := 14; InheritFont(lblAppWebpage.Font); imgDonate.Hint := APPDOMAIN + imgDonate.Hint; - imgDonate.Visible := not MainForm.HasDonated(False); + imgDonate.Visible := MainForm.HasDonated(False) = nbFalse; editDonated.Text := AppSettings.ReadString(asDonatedEmail); // Assign text diff --git a/source/helpers.pas b/source/helpers.pas index 2553e7af..50824f8b 100644 --- a/source/helpers.pas +++ b/source/helpers.pas @@ -80,12 +80,14 @@ type FURL: String; FBytesRead: Integer; FContentLength: Integer; + FTimeOut: Cardinal; FOnProgress: TNotifyEvent; public constructor Create(Owner: TComponent); procedure SendRequest(Filename: String); property OnProgress: TNotifyEvent read FOnProgress write FOnProgress; property URL: String read FURL write FURL; + property TimeOut: Cardinal read FTimeOut write FTimeOut; property BytesRead: Integer read FBytesRead; property ContentLength: Integer read FContentLength; end; @@ -3026,6 +3028,7 @@ begin FBytesRead := -1; FContentLength := -1; FOwner := Owner; + FTimeOut := 10; end; @@ -3035,7 +3038,7 @@ var UrlHandle: HINTERNET; Buffer: array[1..4096] of Byte; Head: array[1..1024] of Char; - BytesInChunk, HeadSize, Reserved: Cardinal; + BytesInChunk, HeadSize, Reserved, TimeOutSeconds: Cardinal; LocalFile: File; DoStore: Boolean; UserAgent, OS: String; @@ -3048,8 +3051,12 @@ begin OS := 'Windows NT '+IntToStr(Win32MajorVersion)+'.'+IntToStr(Win32MinorVersion); UserAgent := APPNAME+'/'+MainForm.AppVersion+' ('+OS+'; '+ExtractFilename(Application.ExeName)+'; '+FOwner.Name+')'; NetHandle := InternetOpen(PChar(UserAgent), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); - UrlHandle := nil; + // Do not let the user wait 30s + TimeOutSeconds := FTimeOut * 1000; + InternetSetOption(NetHandle, INTERNET_OPTION_CONNECT_TIMEOUT, @TimeOutSeconds, SizeOf(TimeOutSeconds)); + + UrlHandle := nil; try UrlHandle := InternetOpenURL(NetHandle, PChar(FURL), nil, 0, INTERNET_FLAG_RELOAD, 0); if not Assigned(UrlHandle) then diff --git a/source/main.pas b/source/main.pas index bacb89a2..da5b3a5e 100644 --- a/source/main.pas +++ b/source/main.pas @@ -1071,7 +1071,7 @@ type procedure ProgressStep; procedure SetProgressState(State: TProgressbarState); procedure TaskDialogHyperLinkClicked(Sender: TObject); - function HasDonated(ForceCheck: Boolean): Boolean; + function HasDonated(ForceCheck: Boolean): TThreeStateBoolean; end; @@ -1683,7 +1683,7 @@ begin imgDonate.Width := 122; imgDonate.Height := 22; imgDonate.Hint := APPDOMAIN + imgDonate.Hint; - imgDonate.Visible := not HasDonated(True); + imgDonate.Visible := HasDonated(True) = nbFalse; FileEncodings := Explode(',', _('Auto detect (may fail)')+',ANSI,ASCII,Unicode,Unicode Big Endian,UTF-8,UTF-7'); @@ -11297,7 +11297,7 @@ begin end; -function TMainForm.HasDonated(ForceCheck: Boolean): Boolean; +function TMainForm.HasDonated(ForceCheck: Boolean): TThreeStateBoolean; var Email, TempFileName, CheckResult: String; rx: TRegExpr; @@ -11318,6 +11318,7 @@ begin rx := TRegExpr.Create; CheckWebpage := THttpDownload.Create(MainForm); CheckWebpage.URL := APPDOMAIN + 'hasdonated.php?email='+EncodeURLElementUnicode(Email); + CheckWebpage.TimeOut := 3; TempFileName := GetTempDir + '\' + APPNAME + '_hasdonated_check.tmp'; try CheckWebpage.SendRequest(TempFileName); @@ -11340,8 +11341,7 @@ begin rx.Free; end; end; - // Gracefully return true if webpage access was not successful - Result := FHasDonatedDatabaseCheck in [nbUnset, nbTrue]; + Result := FHasDonatedDatabaseCheck; Screen.Cursor := crDefault; end; diff --git a/source/updatecheck.pas b/source/updatecheck.pas index e5938b0a..c50b39da 100644 --- a/source/updatecheck.pas +++ b/source/updatecheck.pas @@ -59,7 +59,7 @@ begin InheritFont(Font); TranslateComponent(Self); imgDonate.Hint := APPDOMAIN + imgDonate.Hint; - imgDonate.Visible := not MainForm.HasDonated(False); + imgDonate.Visible := MainForm.HasDonated(False) = nbFalse; end; {**