Issue #140: make auto-backup/restore feature stable against running multiple application instances:

* use unique date/time with milliseconds as ini sections
* open ini file for each read + write, separately, don't keep it open all the time
This commit is contained in:
Ansgar Becker
2019-04-10 12:19:40 +02:00
parent f43c37a65f
commit 430ea3bde6
4 changed files with 132 additions and 50 deletions

View File

@ -346,6 +346,7 @@ type
procedure Help(Sender: TObject; Anchor: String);
function PortOpen(Port: Word): Boolean;
function IsValidFilePath(FilePath: String): Boolean;
function FileIsWritable(FilePath: String): Boolean;
function GetProductInfo(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion: DWORD; out pdwReturnedProductType: DWORD): BOOL stdcall; external kernel32 delayed;
function RunningOnWindows10S: Boolean;
function GetCurrentPackageFullName(out Len: Cardinal; Name: PWideChar): Integer; stdcall; external kernel32 delayed;
@ -2936,6 +2937,22 @@ begin
end;
function FileIsWritable(FilePath: String): Boolean;
var
hFile: DWORD;
begin
// Check if file is writable
if not FileExists(FilePath) then begin
// Return true if file does not exist
Result := True;
end else begin
hFile := CreateFile(PChar(FilePath), GENERIC_WRITE, 0, nil, OPEN_EXISTING, 0, 0);
Result := hFile <> INVALID_HANDLE_VALUE;
CloseHandle(hFile);
end;
end;
function RunningOnWindows10S: Boolean;
const
PRODUCT_CLOUD = $000000B2; //* Windows 10 S