When deleting tab backup file, delete it to recycle bin, for cases where the user did that by accident. Same for snippet file and overwritten export/zip file. See https://www.heidisql.com/forum.php?t=39355

This commit is contained in:
Ansgar Becker
2022-06-08 19:25:33 +02:00
parent 7a20e6eb16
commit 9ec40f0703
3 changed files with 16 additions and 3 deletions

View File

@@ -293,6 +293,7 @@ type
function EncodeURLParam(const Value: String): String;
procedure StreamWrite(S: TStream; Text: String = '');
function _GetFileSize(Filename: String): Int64;
function DeleteFileWithUndo(sFileName: String): Boolean;
function MakeInt(Str: String) : Int64;
function MakeFloat(Str: String): Extended;
function CleanupNumber(Str: String): String;
@@ -606,6 +607,18 @@ begin
end;
function DeleteFileWithUndo(sFileName: string): Boolean;
var
fos: TSHFileOpStruct;
begin
FillChar(fos, SizeOf(fos), 0);
fos.wFunc := FO_DELETE;
fos.pFrom := PChar(sFileName);
fos.fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION or FOF_SILENT;
Result := (0 = ShFileOperation(fos));
end;
{***
Convert a string-number to an integer-number

View File

@@ -8317,7 +8317,7 @@ begin
if MessageDialog(_('Delete snippet file?'), snippetfile, mtConfirmation, [mbOk, mbCancel]) = mrOk then
begin
Screen.Cursor := crHourGlass;
if DeleteFile(snippetfile) then begin
if DeleteFileWithUndo(snippetfile) then begin
// Refresh list with snippets
SetSnippetFilenames;
end else begin
@@ -12571,7 +12571,7 @@ begin
end else begin
// Delete backup file if tab is closed by user, intentionally
if (not Tab.MemoBackupFilename.IsEmpty) and FileExists(Tab.MemoBackupFilename) then begin
if not DeleteFile(Tab.MemoBackupFilename) then begin
if not DeleteFileWithUndo(Tab.MemoBackupFilename) then begin
ErrorDialog(f_('Backup file could not be deleted: %s', [Tab.MemoBackupFilename]));
end;
end;

View File

@@ -893,7 +893,7 @@ begin
StartTime := GetTickCount;
FileNameZip := FExportFileName;
if FileExists(FileNameZip) then
DeleteFile(FileNameZip);
DeleteFileWithUndo(FileNameZip);
Zip := TZipFile.Create;
Zip.Open(FileNameZip, zmWrite);
FileNameInZip := ExtractFileName(ChangeFileExt(FileNameZip, '.sql'));