Skip to content

Commit

Permalink
Merge pull request #160 from HeidiSQL/master
Browse files Browse the repository at this point in the history
Migrate files from old default snippets directory. Closes #159
  • Loading branch information
CodehunterWorks committed Feb 25, 2018
2 parents aa00379 + 424b9f9 commit 3ed6d95
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
11 changes: 10 additions & 1 deletion out/locale/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)"
30 changes: 29 additions & 1 deletion source/main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,6 @@ procedure TMainForm.FormDestroy(Sender: TObject);
procedure TMainForm.FormCreate(Sender: TObject);
var
i, j, MonitorIndex: Integer;
ToolButton: TToolButton;
QueryTab: TQueryTab;
Action: TAction;
dwInfoSize, // Size of VERSIONINFO structure
Expand All @@ -1600,6 +1599,8 @@ procedure TMainForm.FormCreate(Sender: TObject);
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;

Expand Down Expand Up @@ -1661,6 +1662,33 @@ procedure TMainForm.FormCreate(Sender: TObject);
// 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;

Expand Down

0 comments on commit 3ed6d95

Please sign in to comment.