View Issue Details

IDProjectCategoryView StatusLast Update
0035100FPCFCLpublic2019-04-10 17:02
ReporterSerge AnvarovAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformWindowsOSWindowsOS Version
Product Version3.3.1Product Build 
Target Version3.2.0Fixed in Version3.3.1 
Summary0035100: TRegistry. Patch 2. Windows. FileTime
DescriptionTRegistry.GetKeyInfo returns the time of the last key change. But time is taken not local, as most other similar function, but UTC. Added conversion to local time.
TagsNo tags attached.
Fixed in Revision41855
FPCOldBugId
FPCTarget
Attached Files
  • registry2.diff (836 bytes)
    Index: packages/fcl-registry/src/winreg.inc
    ===================================================================
    --- packages/fcl-registry/src/winreg.inc	(revision 41343)
    +++ packages/fcl-registry/src/winreg.inc	(working copy)
    @@ -158,6 +156,7 @@
     var
       winFileTime: Windows.FILETIME;
       sysTime: TSystemTime;
    +  LocalFileTime: Windows.FILETIME;
     begin
       FillChar(Value, SizeOf(Value), 0);
       With Value do
    @@ -167,9 +166,9 @@
                   lpdword(@MaxDataLen),nil,@winFileTime);
         Result:=FLastError=ERROR_SUCCESS;          
         end;          
    -  if Result then
    +  if Result and FileTimeToLocalFileTime(@winFileTime, @LocalFileTime) and
    +    FileTimeToSystemTime(@LocalFileTime, @sysTime) then
       begin
    -    FileTimeToSystemTime(@winFileTime, @sysTime);
         Value.FileTime := SystemTimeToDateTime(sysTime);
       end;
     end;
    
    registry2.diff (836 bytes)

Activities

Serge Anvarov

2019-02-16 19:18

reporter  

registry2.diff (836 bytes)
Index: packages/fcl-registry/src/winreg.inc
===================================================================
--- packages/fcl-registry/src/winreg.inc	(revision 41343)
+++ packages/fcl-registry/src/winreg.inc	(working copy)
@@ -158,6 +156,7 @@
 var
   winFileTime: Windows.FILETIME;
   sysTime: TSystemTime;
+  LocalFileTime: Windows.FILETIME;
 begin
   FillChar(Value, SizeOf(Value), 0);
   With Value do
@@ -167,9 +166,9 @@
               lpdword(@MaxDataLen),nil,@winFileTime);
     Result:=FLastError=ERROR_SUCCESS;          
     end;          
-  if Result then
+  if Result and FileTimeToLocalFileTime(@winFileTime, @LocalFileTime) and
+    FileTimeToSystemTime(@LocalFileTime, @sysTime) then
   begin
-    FileTimeToSystemTime(@winFileTime, @sysTime);
     Value.FileTime := SystemTimeToDateTime(sysTime);
   end;
 end;
registry2.diff (836 bytes)

Joost van der Sluis

2019-02-16 23:54

manager   ~0114205

Could you provide some way to test this?

Serge Anvarov

2019-02-17 05:56

reporter   ~0114208

Create new key and run code to get KeyInfo for this new key. Or modify. With and without patch:

program RegTest;
{$APPTYPE CONSOLE}
{$MODE OBJFPC}
{$LONGSTRINGS ON}

uses SysUtils, Registry;

procedure DoIt;
var
  R: TRegistry;
  Info: TRegKeyInfo;
begin
  Writeln('Now ', DateTimeToStr(Now));
  R := TRegistry.Create;
  try
    if R.OpenKey('Software\{82B71DFA-5B59-400A-B931-D5438A14979C}', True) and R.GetKeyInfo(Info) then
      Writeln('Time from reg ', DateTimeToStr(Info.FileTime));
    Writeln('Wait 10 seconds, please');
    Sleep(10 * MSecsPerSec);
    R.WriteString('', 'Default value');
    if R.GetKeyInfo(Info) then
      Writeln('Time from reg after change ', DateTimeToStr(Info.FileTime));
  finally
    R.Free;
  end;
end;

begin
  DoIt;
  Readln;
end.

Serge Anvarov

2019-04-10 07:11

reporter   ~0115368

Revision 60900. The patch is still actual.

Michael Van Canneyt

2019-04-10 11:18

administrator   ~0115385

Applied, thank you very much!

Issue History

Date Modified Username Field Change
2019-02-16 19:18 Serge Anvarov New Issue
2019-02-16 19:18 Serge Anvarov File Added: registry2.diff
2019-02-16 23:54 Joost van der Sluis Note Added: 0114205
2019-02-17 05:56 Serge Anvarov Note Added: 0114208
2019-04-10 07:11 Serge Anvarov Note Added: 0115368
2019-04-10 11:18 Michael Van Canneyt Fixed in Revision => 41855
2019-04-10 11:18 Michael Van Canneyt Note Added: 0115385
2019-04-10 11:18 Michael Van Canneyt Status new => resolved
2019-04-10 11:18 Michael Van Canneyt Fixed in Version => 3.3.1
2019-04-10 11:18 Michael Van Canneyt Resolution open => fixed
2019-04-10 11:18 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-04-10 11:18 Michael Van Canneyt Target Version => 3.2.0