Migrate files from old default snippets directory. Closes #159

This commit is contained in:
Ansgar Becker
2018-02-25 15:33:54 +01:00
parent 25717dc222
commit 424b9f9ab4
2 changed files with 39 additions and 2 deletions

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: HeidiSQL\n"
"POT-Creation-Date: 2012-11-05 21:40\n"
"PO-Revision-Date: 2018-02-03 15:54+0100\n"
"PO-Revision-Date: 2018-02-25 15:32+0100\n"
"Last-Translator: Ansgar Becker <anse@heidisql.com>\n"
"Language-Team: English (http://www.transifex.com/projects/p/heidisql/language/en/)\n"
"MIME-Version: 1.0\n"
@ -6233,3 +6233,12 @@ msgstr "Please update %s through the Microsoft Store."
# Text in parentheses for detected linebreak style in popup text editor
msgid "detected"
msgstr "detected"
msgid "Migrating snippet files to new folder: %s"
msgstr "Migrating snippet files to new folder: %s"
msgid "Successfully moved \"%s\" to \"%s\""
msgstr "Successfully moved \"%s\" to \"%s\""
msgid "Error: Could not move \"%s\" to \"%s\" (Error: %s)"
msgstr "Error: Could not move \"%s\" to \"%s\" (Error: %s)"

View File

@ -1581,7 +1581,6 @@ end;
procedure TMainForm.FormCreate(Sender: TObject);
var
i, j, MonitorIndex: Integer;
ToolButton: TToolButton;
QueryTab: TQueryTab;
Action: TAction;
dwInfoSize, // Size of VERSIONINFO structure
@ -1597,6 +1596,8 @@ var
wine_nt_to_unix_file_name: procedure(p1:pointer; p2:pointer); stdcall;
CoolBand: TCoolBand;
DonateCaptions: TStringList;
OldSnippetsDir, CurrentSnippetsDir, TargetSnippet: String;
Files: TStringDynArray;
begin
caption := APPNAME;
@ -1658,6 +1659,33 @@ begin
// Ensure directory exists
ForceDirectories(DirnameUserAppData);
// Move files from old default snippets directory, see issue #159
if not AppSettings.PortableMode then begin
// This was the default folder up to r5244 / 8b2966c52efb685b00189037a0507157ed03a368
OldSnippetsDir := GetShellFolder(CSIDL_COMMON_APPDATA) + '\' + APPNAME + '\Snippets\';
CurrentSnippetsDir := DirnameSnippets;
if not DirectoryExists(CurrentSnippetsDir) then
ForceDirectories(CurrentSnippetsDir);
//showmessage('1:'+crlf+OldSnippetsDir+crlf+CurrentSnippetsDir);
if (not OldSnippetsDir.IsEmpty) and (not CurrentSnippetsDir.IsEmpty)
and DirectoryExists(OldSnippetsDir) and DirectoryExists(CurrentSnippetsDir)
and (CompareText(OldSnippetsDir, CurrentSnippetsDir) <> 0)
then begin
Files := TDirectory.GetFiles(OldSnippetsDir, '*.sql');
if Length(Files) > 0 then begin
LogSQL(f_('Migrating snippet files to new folder: %s', [CurrentSnippetsDir]));
for i:=Low(Files) to High(Files) do begin
TargetSnippet := CurrentSnippetsDir + ExtractFileName(Files[i]);
if MoveFile(PChar(Files[i]), PChar(TargetSnippet)) then begin
LogSQL(f_('Successfully moved "%s" to "%s"', [Files[i], TargetSnippet]));
end else begin
LogSQL(f_('Error: Could not move "%s" to "%s" (Error: %s)', [Files[i], TargetSnippet, SysErrorMessage(GetLastError())]), lcError);
end;
end;
end;
end;
end;
// Load snippet filenames
SetSnippetFilenames;