Skip to content

Commit 971d56b

Browse files
committed
fix: do not auto-create c:\users\mike\AppData\Roaming\HeidiSQL\ in portable mode, through the default value of asLogFilePath
This makes DirnameUserAppData and DirnameUserDocuments the only ones being aware of portable mode Refs #2450
1 parent 35e43df commit 971d56b

File tree

2 files changed

+21
-30
lines changed

2 files changed

+21
-30
lines changed

source/apphelpers.pas

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3780,7 +3780,6 @@ constructor TAppSettings.Create;
37803780
var
37813781
rx: TRegExpr;
37823782
i: Integer;
3783-
DefaultSnippetsDirectory: String;
37843783
PortableLockFile: String;
37853784
NewFileHandle: THandle;
37863785
begin
@@ -4058,14 +4057,7 @@ constructor TAppSettings.Create;
40584057
InitSetting(asDisplayReverseForeignKeys, 'DisplayReverseForeignKeys', 0, False);
40594058
InitSetting(asGenerateDataNumRows, 'GenerateDataNumRows', 1000);
40604059
InitSetting(asGenerateDataNullAmount, 'GenerateDataNullAmount', 10);
4061-
4062-
// Default folder for snippets
4063-
if FPortableMode then
4064-
DefaultSnippetsDirectory := GetAppDir
4065-
else
4066-
DefaultSnippetsDirectory := DirnameUserDocuments;
4067-
DefaultSnippetsDirectory := DefaultSnippetsDirectory + 'Snippets\';
4068-
InitSetting(asCustomSnippetsDirectory, 'CustomSnippetsDirectory', 0, False, DefaultSnippetsDirectory);
4060+
InitSetting(asCustomSnippetsDirectory, 'CustomSnippetsDirectory', 0, False, DirnameUserDocuments + 'Snippets\');
40694061
InitSetting(asPromptSaveFileOnTabClose, 'PromptSaveFileOnTabClose', 0, True);
40704062
// Restore tabs feature crashes often on old XP systems, see https://www.heidisql.com/forum.php?t=34044
40714063
InitSetting(asRestoreTabs, 'RestoreTabs', 0, Win32MajorVersion >= 6);
@@ -4723,19 +4715,29 @@ function TAppSettings.ExportSettings: Boolean;
47234715

47244716
function TAppSettings.DirnameUserAppData: String;
47254717
begin
4726-
// User folder for HeidiSQL's data (<user name>\Application Data)
4727-
Result := GetShellFolder(FOLDERID_RoamingAppData) + '\' + APPNAME + '\';
4728-
if not DirectoryExists(Result) then begin
4729-
ForceDirectories(Result);
4718+
// C:\Users\mike\AppData\Roaming\HeidiSQL\
4719+
if PortableMode then begin
4720+
Result := GetAppDir;
4721+
end
4722+
else begin
4723+
Result := GetShellFolder(FOLDERID_RoamingAppData) + '\' + APPNAME + '\';
4724+
if not DirectoryExists(Result) then begin
4725+
ForceDirectories(Result);
4726+
end;
47304727
end;
47314728
end;
47324729

47334730

47344731
function TAppSettings.DirnameUserDocuments: String;
47354732
begin
4736-
// "HeidiSQL" folder under user's documents folder, e.g. c:\Users\Mike\Documents\HeidiSQL\
4737-
Result := GetShellFolder(FOLDERID_Documents) + '\' + APPNAME + '\';
4738-
// Do not auto-create it, as we only use it for snippets which can also have a custom path.
4733+
// C:\Users\mike\Documents\HeidiSQL\
4734+
if PortableMode then begin
4735+
Result := GetAppDir;
4736+
end
4737+
else begin
4738+
Result := GetShellFolder(FOLDERID_Documents) + '\' + APPNAME + '\';
4739+
// Do not auto-create it, as we only use it for snippets which can also have a custom path.
4740+
end;
47394741
end;
47404742

47414743

@@ -4755,11 +4757,7 @@ function TAppSettings.DirnameSnippets: String;
47554757
function TAppSettings.DirnameBackups: String;
47564758
begin
47574759
// Create backup folder if it does not exist and return it
4758-
if PortableMode then begin
4759-
Result := GetAppDir + 'Backups\'
4760-
end else begin
4761-
Result := DirnameUserAppData + 'Backups\';
4762-
end;
4760+
Result := DirnameUserAppData + 'Backups\';
47634761
if not DirectoryExists(Result) then begin
47644762
ForceDirectories(Result);
47654763
end;
@@ -4768,11 +4766,7 @@ function TAppSettings.DirnameBackups: String;
47684766

47694767
function TAppSettings.DirnameHighlighters: string;
47704768
begin
4771-
if PortableMode then begin
4772-
Result := GetAppDir + 'Highlighters\'
4773-
end else begin
4774-
Result := DirnameUserAppData + 'Highlighters\';
4775-
end;
4769+
Result := DirnameUserAppData + 'Highlighters\';
47764770
if not DirectoryExists(Result) then begin
47774771
ForceDirectories(Result);
47784772
end;

source/main.pas

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,10 +2369,7 @@ function TMainForm.InitTabsIniFile: TIniFile;
23692369
begin
23702370
// Try to open tabs.ini for writing or reading
23712371
// Taking multiple application instances into account
2372-
if AppSettings.PortableMode then
2373-
TabsIniFilename := GetAppDir + 'tabs.ini'
2374-
else
2375-
TabsIniFilename := AppSettings.DirnameUserAppData + 'tabs.ini';
2372+
TabsIniFilename := AppSettings.DirnameUserAppData + 'tabs.ini';
23762373
WaitingSince := GetTickCount64;
23772374
Attempts := 0;
23782375
while not FileIsWritable(TabsIniFilename) do begin

0 commit comments

Comments
 (0)