diff --git a/components/heidisql/include/const.inc b/components/heidisql/include/const.inc index 0a570268..8a04b54b 100644 --- a/components/heidisql/include/const.inc +++ b/components/heidisql/include/const.inc @@ -169,6 +169,11 @@ const REGNAME_COPYTABLE_ALLFIELDS = 'CopyTable_Option_WithAllFields'; REGNAME_DEFAULTVIEW = 'DefaultView'; REGNAME_FILTERS = 'RecentFilters'; + REGNAME_SERVERVERSION = 'ServerVersion'; + REGNAME_LASTCONNECT = 'LastConnect'; + REGNAME_DO_STATISTICS = 'DoUsageStatistics'; + DEFAULT_DO_STATISTICS = False; + REGNAME_LAST_STATSCALL = 'LastUsageStatisticCall'; REGNAME_FIELDCOLOR_NUMERIC = 'FieldColor_Numeric'; REGNAME_FIELDCOLOR_TEXT = 'FieldColor_Text'; diff --git a/source/main.pas b/source/main.pas index ac65cbf0..3028105d 100644 --- a/source/main.pas +++ b/source/main.pas @@ -1406,17 +1406,20 @@ var sValue, parHost, parPort, parUser, parPass, parDatabase, parTimeout, parCompress, parDescription : String; - LastUpdatecheck : TDateTime; - UpdatecheckInterval : Integer; - DefaultLastrunDate, LastSession: String; + LastUpdatecheck, LastStatsCall, LastConnect: TDateTime; + UpdatecheckInterval, i: Integer; + DefaultLastrunDate, LastSession, StatsURL: String; frm : TfrmUpdateCheck; dlgResult: Integer; Connected, CommandLineMode: Boolean; ConnForm: TConnForm; + StatsCall: TDownloadUrl2; + SessionNames: TStringlist; begin + DefaultLastrunDate := '2000-01-01'; + // Do an updatecheck if checked in settings if GetRegValue(REGNAME_DO_UPDATECHECK, DEFAULT_DO_UPDATECHECK) then begin - DefaultLastrunDate := '2000-01-01'; try LastUpdatecheck := StrToDateTime( GetRegValue(REGNAME_LAST_UPDATECHECK, DefaultLastrunDate) ); except @@ -1432,6 +1435,44 @@ begin end; end; + // Call user statistics if checked in settings + if GetRegValue(REGNAME_DO_STATISTICS, DEFAULT_DO_STATISTICS) then begin + try + LastStatsCall := StrToDateTime( GetRegValue(REGNAME_LAST_STATSCALL, DefaultLastrunDate) ); + except + LastStatsCall := StrToDateTime( DefaultLastrunDate ); + end; + if DaysBetween(Now, LastStatsCall) >= 30 then begin + // Report used SVN revision + StatsURL := APPDOMAIN + 'savestats.php?c=' + AppRevision; + // Enumerate actively used server versions + SessionNames := TStringlist.Create; + if MainReg.OpenKey(REGPATH + REGKEY_SESSIONS, true) then + MainReg.GetKeyNames(SessionNames); + for i:=0 to SessionNames.Count-1 do begin + try + LastConnect := StrToDateTime(GetRegValue(REGNAME_LASTCONNECT, DefaultLastrunDate, SessionNames[i])); + except + LastConnect := StrToDateTime(DefaultLastrunDate); + end; + if LastConnect > LastStatsCall then begin + StatsURL := StatsURL + '&s[]=' + IntToStr(GetRegValue(REGNAME_SERVERVERSION, 0, SessionNames[i])); + end; + end; + StatsCall := TDownloadUrl2.Create(Self); + StatsCall.URL := StatsURL; + StatsCall.SetUserAgent(APPNAME + ' ' + FullAppVersion); + try + StatsCall.ExecuteTarget(nil); + OpenRegistry; + MainReg.WriteString(REGNAME_LAST_STATSCALL, DateTimeToStr(Now)); + except + // Silently ignore it when the url could not be called over the network. + end; + FreeAndNil(StatsCall); + end; + end; + Connected := False; // Check commandline if parameters were passed. Otherwise show connections windows @@ -1573,6 +1614,11 @@ begin tabHost.Caption := 'Host: '+MySQLConn.Connection.HostName; showstatus('MySQL '+v1+'.'+v2+'.'+v3, 3); + // Save server version + OpenRegistry(SessionName); + Mainreg.WriteInteger(REGNAME_SERVERVERSION, mysql_version); + Mainreg.WriteString(REGNAME_LASTCONNECT, DateTimeToStr(Now)); + DatabasesWanted := explode(';', FConn.DatabaseList); if FConn.DatabaseListSort then DatabasesWanted.Sort; diff --git a/source/options.dfm b/source/options.dfm index e890f537..87332805 100644 --- a/source/options.dfm +++ b/source/options.dfm @@ -185,6 +185,19 @@ object optionsform: Toptionsform TabOrder = 11 OnClick = Modified end + object chkDoStatistics: TCheckBox + Left = 16 + Top = 233 + Width = 379 + Height = 48 + Caption = + 'Count in usage statistics. This option, if enabled, will cause H' + + 'eidiSQL to ping heidisql.com at most once every month. This is ' + + 'used to count the used HeidiSQL and MySQL versions.' + TabOrder = 12 + WordWrap = True + OnClick = Modified + end end object tabSQL: TTabSheet BorderWidth = 5 diff --git a/source/options.pas b/source/options.pas index cfccaecb..79a219f5 100644 --- a/source/options.pas +++ b/source/options.pas @@ -100,6 +100,7 @@ type btnRestoreDefaults: TButton; lblMaxTotalRows: TLabel; editMaxTotalRows: TEdit; + chkDoStatistics: TCheckBox; procedure FormShow(Sender: TObject); procedure Modified(Sender: TObject); procedure Apply(Sender: TObject); @@ -196,6 +197,7 @@ begin MainReg.WriteBool(REGNAME_DO_UPDATECHECK, chkUpdatecheck.Checked); MainReg.WriteBool(REGNAME_DO_UPDATECHECK_BUILDS, chkUpdatecheckBuilds.Checked); MainReg.WriteInteger(REGNAME_UPDATECHECK_INTERVAL, updownUpdatecheckInterval.Position); + MainReg.WriteBool(REGNAME_DO_STATISTICS, chkDoStatistics.Checked); // Save color settings MainReg.WriteInteger(REGNAME_FIELDCOLOR_NUMERIC, cboxNumeric.Selected); MainReg.WriteInteger(REGNAME_FIELDCOLOR_TEXT, cboxText.Selected); @@ -313,6 +315,7 @@ begin chkUpdatecheckBuilds.Checked := GetRegValue(REGNAME_DO_UPDATECHECK_BUILDS, DEFAULT_DO_UPDATECHECK_BUILDS); updownUpdatecheckInterval.Position := GetRegValue(REGNAME_UPDATECHECK_INTERVAL, DEFAULT_UPDATECHECK_INTERVAL); chkUpdatecheckClick(Sender); + chkDoStatistics.Checked := GetRegValue(REGNAME_DO_STATISTICS, DEFAULT_DO_STATISTICS); // Default Column-Width in DBGrids: updownMaxColWidth.Position := GetRegValue(REGNAME_MAXCOLWIDTH, DEFAULT_MAXCOLWIDTH);