From 7ab04b52548a1e04d996c32860ec2a7ca01a1bf0 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sun, 26 Apr 2015 13:31:08 +0000 Subject: [PATCH] Periodically store portable settings file, each 60 seconds. In case of a crash, the user does not loose dialog settings and whatever was customized. See http://www.heidisql.com/forum.php?t=18144#p18243 --- out/locale/en/LC_MESSAGES/default.po | 6 +++++- source/helpers.pas | 9 ++++++++- source/main.pas | 17 ++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/out/locale/en/LC_MESSAGES/default.po b/out/locale/en/LC_MESSAGES/default.po index f723b94a..a966bea0 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: 2015-04-03 22:00+0100\n" +"PO-Revision-Date: 2015-04-26 15:27+0100\n" "Last-Translator: Ansgar Becker \n" "Language-Team: English (http://www.transifex.com/projects/p/heidisql/" "language/en/)\n" @@ -4347,6 +4347,10 @@ msgstr "Registry dump, deprecated" msgid "Settings successfully restored from %s" msgstr "Settings successfully restored from %s" +#. Automatic export of portable settings +msgid "Portable settings file written, with %d changes." +msgstr "Portable settings file written, with %d changes." + #: main.pas:2142 msgid "Splitting SQL queries ..." msgstr "Splitting SQL queries ..." diff --git a/source/helpers.pas b/source/helpers.pas index 7eb52e59..46e35698 100644 --- a/source/helpers.pas +++ b/source/helpers.pas @@ -226,8 +226,10 @@ type procedure ResetPath; property SessionPath: String read FSessionPath write SetSessionPath; property PortableMode: Boolean read FPortableMode; + property Writes: Integer read FWrites; procedure ImportSettings(Filename: String); - procedure ExportSettings(Filename: String); + procedure ExportSettings(Filename: String); overload; + procedure ExportSettings; overload; end; @@ -3792,6 +3794,11 @@ begin end; +procedure TAppSettings.ExportSettings; +begin + ExportSettings(FSettingsFile); +end; + end. diff --git a/source/main.pas b/source/main.pas index 1f3fd0f4..2ce218a7 100644 --- a/source/main.pas +++ b/source/main.pas @@ -1023,6 +1023,8 @@ type FCaptions: TStringList; FLastCaptionChange: Cardinal; FListTablesSorted: Boolean; + FLastPortableSettingsSave: Cardinal; + FLastAppSettingsWrites: Integer; // Host subtabs backend structures FHostListResults: TDBQueryList; @@ -1783,6 +1785,10 @@ begin FJumpList := TJumpList.Create; FJumpList.ApplicationId := APPNAME + IntToStr(GetExecutableBits); end; + + FLastCaptionChange := 0; + FLastPortableSettingsSave := 0; + FLastAppSettingsWrites := 0; end; @@ -11615,15 +11621,24 @@ begin btnDonate.Caption := FCaptions[i]; FLastCaptionChange := GetTickCount; end; + if AppSettings.PortableMode and (FLastPortableSettingsSave < GetTickCount-60000) then begin + if AppSettings.Writes > FLastAppSettingsWrites then begin + AppSettings.ExportSettings; + LogSQL(f_('Portable settings file written, with %d changes.', [AppSettings.Writes-FLastAppSettingsWrites]), lcDebug); + end; + FLastAppSettingsWrites := AppSettings.Writes; + FLastPortableSettingsSave := GetTickCount; + end; + // Sort list tables in idle time, so ListTables.TreeOptions.AutoSort does not crash the list // when dropping a right-clicked database if (PageControlMain.ActivePage = tabDatabase) and (not FListTablesSorted) then begin ListTables.SortTree(ListTables.Header.SortColumn, ListTables.Header.SortDirection); FListTablesSorted := True; end; - end; + procedure TMainForm.ApplicationDeActivate(Sender: TObject); begin // Prevent completion window from showing up after Alt-Tab. See issue #2640