mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2026-03-13 09:24:25 +08:00
fix: delete CLI-created session settings from registry after disconnect
Refs #2162
This commit is contained in:
@@ -2703,9 +2703,13 @@ begin
|
||||
ConnectionParams.SSHTimeout := StrToIntDef(SshTimeout, ConnectionParams.SSHTimeout);
|
||||
end;
|
||||
|
||||
// Ensure we have a session name to pass to InitConnection
|
||||
if (ConnectionParams.SessionPath = '') and (ConnectionParams.Hostname <> '') then
|
||||
ConnectionParams.SessionPath := ConnectionParams.Hostname;
|
||||
if ConnectionParams.SessionPath.IsEmpty then begin
|
||||
// Ensure we have a (random) session name to pass to InitConnection
|
||||
ConnectionParams.SessionPath := IfEmpty(ConnectionParams.Hostname, 'temp')+'-'+GeneratePassword(4);
|
||||
end;
|
||||
|
||||
// Delete stored session in Destroy:
|
||||
ConnectionParams.DeleteAfterUse := True;
|
||||
end;
|
||||
|
||||
// Check for valid filename(s) in parameters.
|
||||
|
||||
@@ -310,6 +310,8 @@ type
|
||||
|
||||
TConnectionParameters = class(TObject)
|
||||
strict private
|
||||
FDeleteAfterUse: Boolean;
|
||||
FLoadedFromSettings: Boolean;
|
||||
FNetType: TNetType;
|
||||
FHostname, FUsername, FPassword, FAllDatabases, FLibraryOrProvider, FComment, FStartupScriptFilename,
|
||||
FSessionPath, FSSLPrivateKey, FSSLCertificate, FSSLCACertificate, FSSLCipher, FServerVersion,
|
||||
@@ -330,7 +332,9 @@ type
|
||||
public
|
||||
constructor Create; overload;
|
||||
constructor Create(SessionRegPath: String); overload;
|
||||
destructor Destroy; override;
|
||||
procedure SaveToRegistry;
|
||||
property DeleteAfterUse: Boolean read FDeleteAfterUse write FDeleteAfterUse;
|
||||
function CreateConnection(AOwner: TComponent): TDBConnection;
|
||||
function CreateQuery(Connection: TDbConnection): TDBQuery;
|
||||
function NetTypeName(LongFormat: Boolean): String;
|
||||
@@ -1281,6 +1285,8 @@ constructor TConnectionParameters.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
FIsFolder := False;
|
||||
FDeleteAfterUse := False;
|
||||
FLoadedFromSettings := False;
|
||||
|
||||
FNetType := TNetType(AppSettings.GetDefaultInt(asNetType));
|
||||
FHostname := DefaultHost;
|
||||
@@ -1354,6 +1360,7 @@ begin
|
||||
);
|
||||
FNetType := ntMySQL_TCPIP;
|
||||
end;
|
||||
FLoadedFromSettings := True;
|
||||
FHostname := AppSettings.ReadString(asHost);
|
||||
FUsername := AppSettings.ReadString(asUser);
|
||||
FPassword := decrypt(AppSettings.ReadString(asPassword));
|
||||
@@ -1410,6 +1417,16 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
destructor TConnectionParameters.Destroy;
|
||||
begin
|
||||
if FDeleteAfterUse and (not FLoadedFromSettings) and (not FSessionPath.IsEmpty) then begin
|
||||
if AppSettings.SessionPathExists(FSessionPath) then begin
|
||||
AppSettings.SessionPath := FSessionPath;
|
||||
AppSettings.DeleteCurrentKey;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TConnectionParameters.SaveToRegistry;
|
||||
var
|
||||
@@ -2130,6 +2147,7 @@ begin
|
||||
FKeepAliveTimer.Free;
|
||||
FFavorites.Free;
|
||||
FInformationSchemaObjects.Free;
|
||||
FParameters.Free;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user