Implement optional usage statistics call:

* Disabled by default, can be checked in preferences dialog
* If enabled, reports HeidiSQL revision and versions of recently used servers
This commit is contained in:
Ansgar Becker
2009-06-20 22:10:08 +00:00
parent 0ab2599a17
commit ddbee4c536
4 changed files with 71 additions and 4 deletions

View File

@ -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';

View File

@ -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;

View File

@ -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

View File

@ -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);