Преглед изворни кода

UPD: Use one compare time function

Alexander Koblov пре 11 година
родитељ
комит
ffef58e98d
2 измењених фајлова са 13 додато и 19 уклоњено
  1. 6 8
      src/fsyncdirsdlg.pas
  2. 7 11
      src/umaincommands.pas

+ 6 - 8
src/fsyncdirsdlg.pas

@@ -129,7 +129,7 @@ implementation
 
 uses
   fMain, uDebug, fDiffer, fSyncDirsPerformDlg, uGlobs, LCLType, LazUTF8,
-  DCClassesUtf8, uFileSystemFileSource, uFileSourceOperationOptions,
+  DCClassesUtf8, uFileSystemFileSource, uFileSourceOperationOptions, DCDateTimeUtils,
   uFileSourceOperation, uDCUtils, uFileSourceUtil, uFileSourceOperationTypes;
 
 {$R *.lfm}
@@ -287,10 +287,8 @@ begin
 end;
 
 procedure TFileSyncRec.UpdateState(ignoreDate: Boolean);
-const
-  TimeDiff = 3100 / MSecsPerDay;
 var
-  FileTimeDiff: TDateTime;
+  FileTimeDiff: Integer;
 begin
   FState := srsNotEq;
   if Assigned(FFileR) and not Assigned(FFileL) then
@@ -299,15 +297,15 @@ begin
   if not Assigned(FFileR) and Assigned(FFileL) then
     FState := srsCopyRight
   else begin
-    FileTimeDiff := FFileL.ModificationTime - FFileR.ModificationTime;
-    if (((FileTimeDiff > -TimeDiff) and (FileTimeDiff < TimeDiff)) or ignoreDate) and (FFileL.Size = FFileR.Size) then
+    FileTimeDiff := FileTimeCompare(FFileL.ModificationTime, FFileR.ModificationTime, False);
+    if ((FileTimeDiff = 0) or ignoreDate) and (FFileL.Size = FFileR.Size) then
       FState := srsEqual
     else
     if not ignoreDate then
-      if FFileR.ModificationTime < FFileL.ModificationTime then
+      if FileTimeDiff > 0 then
         FState := srsCopyRight
       else
-      if FFileR.ModificationTime > FFileL.ModificationTime then
+      if FileTimeDiff < 0 then
         FState := srsCopyLeft;
   end;
   FAction := FState;

+ 7 - 11
src/umaincommands.pas

@@ -228,7 +228,7 @@ type
 implementation
 
 uses Forms, Controls, Dialogs, Clipbrd, strutils, LCLProc, HelpIntfs, StringHashList,
-     dmHelpManager, typinfo, fMain, fPackDlg, fMkDir, fFileAssoc,
+     dmHelpManager, typinfo, fMain, fPackDlg, fMkDir, fFileAssoc, DCDateTimeUtils,
      fExtractDlg, fAbout, fOptions, fDiffer, fFindDlg, fSymLink, fHardLink, fMultiRename,
      fLinker, fSplitter, fDescrEdit, fCheckSumVerify, fCheckSumCalc, fSetFileProperties,
      uGlobs, uLng, uLog, uShowMsg, uOSForms, uOSUtils, uDCUtils, uBriefFileView,
@@ -3006,8 +3006,6 @@ begin
 end;
 
 procedure TMainCommands.cm_CompareDirectories(const Params: array of string);
-const
-  TimeDiff = 3100 / MSecsPerDay;
 var
   I: LongWord;
   SourceFile: TDisplayFile;
@@ -3015,7 +3013,6 @@ var
   SourceList: TStringHashList;
   SourceFiles: TDisplayFiles = nil;
   TargetFiles: TDisplayFiles = nil;
-  FileTimeDiff: TDateTime;
 begin
   SourceList:= TStringHashList.Create(FileNameCaseSensitive);
   with frmMain do
@@ -3039,13 +3036,12 @@ begin
       if (SourceFile = nil) then
         NotActiveFrame.MarkFile(TargetFile, True)
       else
-        begin
-          FileTimeDiff:= SourceFile.FSFile.ModificationTime - TargetFile.FSFile.ModificationTime;
-          if (FileTimeDiff > -TimeDiff) and (FileTimeDiff < TimeDiff) then
-            ActiveFrame.MarkFile(SourceFile, False)
-          else if FileTimeDiff > 0 then
-            NotActiveFrame.MarkFile(TargetFile, False)
-          else if FileTimeDiff < 0 then
+        case FileTimeCompare(SourceFile.FSFile.ModificationTime, TargetFile.FSFile.ModificationTime, False) of
+          0:
+            ActiveFrame.MarkFile(SourceFile, False);
+          +1:
+            NotActiveFrame.MarkFile(TargetFile, False);
+          -1:
             begin
               ActiveFrame.MarkFile(SourceFile, False);
               NotActiveFrame.MarkFile(TargetFile, True);