Просмотр исходного кода

ADD: Capability to choose hash file format (fixes #1183)

Alexander Koblov 1 год назад
Родитель
Сommit
cc19b745ae

+ 44 - 4
src/fchecksumcalc.lfm

@@ -58,21 +58,21 @@ inherited frmCheckSumCalc: TfrmCheckSumCalc
     end
     object lbHashAlgorithm: TListBox[3]
       AnchorSideLeft.Control = edtSaveTo
-      AnchorSideTop.Control = cbOpenAfterJobIsComplete
+      AnchorSideTop.Control = rbWindows
       AnchorSideTop.Side = asrBottom
       AnchorSideRight.Control = edtSaveTo
       AnchorSideRight.Side = asrBottom
       AnchorSideBottom.Side = asrBottom
       Left = 0
-      Height = 244
-      Top = 100
+      Height = 219
+      Top = 125
       Width = 384
       Anchors = [akTop, akLeft, akRight, akBottom]
       BorderSpacing.Top = 6
       ItemHeight = 0
       OnSelectionChange = lbHashAlgorithmSelectionChange
       ScrollWidth = 150
-      TabOrder = 3
+      TabOrder = 5
     end
     object cbOpenAfterJobIsComplete: TCheckBox[4]
       AnchorSideLeft.Control = edtSaveTo
@@ -87,6 +87,46 @@ inherited frmCheckSumCalc: TfrmCheckSumCalc
       OnChange = cbSeparateFileChange
       TabOrder = 2
     end
+    object lblFileFormat: TLabel[5]
+      AnchorSideLeft.Control = cbOpenAfterJobIsComplete
+      AnchorSideTop.Control = rbWindows
+      AnchorSideTop.Side = asrCenter
+      Left = 0
+      Height = 15
+      Top = 102
+      Width = 57
+      BorderSpacing.Top = 6
+      Caption = 'File &format'
+      FocusControl = rbWindows
+      ParentColor = False
+    end
+    object rbWindows: TRadioButton[6]
+      AnchorSideLeft.Control = lblFileFormat
+      AnchorSideLeft.Side = asrBottom
+      AnchorSideTop.Control = cbOpenAfterJobIsComplete
+      AnchorSideTop.Side = asrBottom
+      Left = 69
+      Height = 19
+      Top = 100
+      Width = 69
+      BorderSpacing.Left = 12
+      BorderSpacing.Top = 6
+      Caption = 'Windows'
+      TabOrder = 3
+    end
+    object rbUnix: TRadioButton[7]
+      AnchorSideLeft.Control = rbWindows
+      AnchorSideLeft.Side = asrBottom
+      AnchorSideTop.Control = rbWindows
+      AnchorSideTop.Side = asrCenter
+      Left = 144
+      Height = 19
+      Top = 100
+      Width = 44
+      BorderSpacing.Left = 6
+      Caption = 'Unix'
+      TabOrder = 4
+    end
   end
   inherited pnlButtons: TPanel
     Top = 358

+ 4 - 1
src/fchecksumcalc.lrj

@@ -2,5 +2,8 @@
 {"hash":124685262,"name":"tfrmchecksumcalc.caption","sourcebytes":[67,97,108,99,117,108,97,116,101,32,99,104,101,99,107,115,117,109,46,46,46],"value":"Calculate checksum..."},
 {"hash":117557194,"name":"tfrmchecksumcalc.lblsaveto.caption","sourcebytes":[38,83,97,118,101,32,99,104,101,99,107,115,117,109,32,102,105,108,101,40,115,41,32,116,111,58],"value":"&Save checksum file(s) to:"},
 {"hash":222079109,"name":"tfrmchecksumcalc.cbseparatefile.caption","sourcebytes":[67,38,114,101,97,116,101,32,115,101,112,97,114,97,116,101,32,99,104,101,99,107,115,117,109,32,102,105,108,101,32,102,111,114,32,101,97,99,104,32,102,105,108,101],"value":"C&reate separate checksum file for each file"},
-{"hash":20936404,"name":"tfrmchecksumcalc.cbopenafterjobiscomplete.caption","sourcebytes":[79,112,101,110,32,99,104,101,99,107,115,117,109,32,102,105,108,101,32,97,102,116,101,114,32,106,111,98,32,105,115,32,99,111,109,112,108,101,116,101,100],"value":"Open checksum file after job is completed"}
+{"hash":20936404,"name":"tfrmchecksumcalc.cbopenafterjobiscomplete.caption","sourcebytes":[79,112,101,110,32,99,104,101,99,107,115,117,109,32,102,105,108,101,32,97,102,116,101,114,32,106,111,98,32,105,115,32,99,111,109,112,108,101,116,101,100],"value":"Open checksum file after job is completed"},
+{"hash":136754340,"name":"tfrmchecksumcalc.lblfileformat.caption","sourcebytes":[70,105,108,101,32,38,102,111,114,109,97,116],"value":"File &format"},
+{"hash":235189939,"name":"tfrmchecksumcalc.rbwindows.caption","sourcebytes":[87,105,110,100,111,119,115],"value":"Windows"},
+{"hash":378120,"name":"tfrmchecksumcalc.rbunix.caption","sourcebytes":[85,110,105,120],"value":"Unix"}
 ]}

+ 12 - 3
src/fchecksumcalc.pas

@@ -37,8 +37,11 @@ type
     cbSeparateFile: TCheckBox;
     cbOpenAfterJobIsComplete: TCheckBox;
     edtSaveTo: TEdit;
+    lblFileFormat: TLabel;
     lblSaveTo: TLabel;
     lbHashAlgorithm: TListBox;
+    rbWindows: TRadioButton;
+    rbUnix: TRadioButton;
     procedure cbSeparateFileChange(Sender: TObject);
     procedure edtSaveToChange(Sender: TObject);
     procedure FormCreate(Sender: TObject);
@@ -53,6 +56,7 @@ type
 
 function ShowCalcCheckSum(var sFileName: String; out SeparateFile: Boolean;
                           out HashAlgorithm: THashAlgorithm; out OpenFileAfterJobCompleted: Boolean;
+                          out TextLineBreakStyle: TTextLineBreakStyle;
                           out QueueId: TOperationsManagerQueueIdentifier): Boolean;
 
 function ShowCalcVerifyCheckSum(out Hash: String; out HashAlgorithm: THashAlgorithm;
@@ -65,19 +69,24 @@ implementation
 uses
   uGlobs, uLng;
 
-function ShowCalcCheckSum(var sFileName: String; out SeparateFile: Boolean;
-  out HashAlgorithm: THashAlgorithm; out OpenFileAfterJobCompleted: Boolean;
-  out QueueId: TOperationsManagerQueueIdentifier): Boolean;
+function ShowCalcCheckSum(var sFileName: String; out SeparateFile: Boolean; out
+  HashAlgorithm: THashAlgorithm; out OpenFileAfterJobCompleted: Boolean; out
+  TextLineBreakStyle: TTextLineBreakStyle; out
+  QueueId: TOperationsManagerQueueIdentifier): Boolean;
+const
+  TextLineBreak: array[Boolean] of TTextLineBreakStyle = (tlbsLF, tlbsCRLF);
 begin
   with TfrmCheckSumCalc.Create(Application) do
   try
     FFileName:= sFileName;
+    rbWindows.Checked:= (DefaultTextLineBreakStyle = tlbsCRLF);
 
     Result:= (ShowModal = mrOK);
     if Result then
       begin
         sFileName:= edtSaveTo.Text;
         SeparateFile:= cbSeparateFile.Checked;
+        TextLineBreakStyle:= TextLineBreak[rbWindows.Checked];
         OpenFileAfterJobCompleted:=(cbOpenAfterJobIsComplete.Checked AND cbOpenAfterJobIsComplete.Enabled);
         HashAlgorithm:= FAlgorithm;
         QueueId:= QueueIdentifier

+ 13 - 4
src/filesources/filesystem/ufilesystemcalcchecksumoperation.pas

@@ -121,6 +121,8 @@ begin
                      FStatistics.TotalFiles,
                      FStatistics.TotalBytes);     // gets full list of files (recursive)
 
+        FCheckSumFile.TextLineBreakStyle:= TextLineBreakStyle;
+
         if (Algorithm = HASH_SFV) and OneFile then
         begin
           FCheckSumFile.Add(SFV_HEADER);
@@ -419,6 +421,8 @@ begin
 end;
 
 function TFileSystemCalcChecksumOperation.CalcChecksumProcessFile(aFile: TFile): Boolean;
+const
+  TextLineBreak: array[TTextLineBreakStyle] of String = ('/', '\', PathDelim);
 var
   FileName: String;
   sCheckSum: String;
@@ -444,14 +448,19 @@ begin
 
   if not CheckSumCalc(aFile, sCheckSum) then Exit;
 
+  FileName:= ExtractDirLevel(FFullFilesTree.Path, aFile.Path) + aFile.Name;
+
+  if (TextLineBreak[TextLineBreakStyle] <> PathDelim) then
+  begin
+    FileName:= StringReplace(FileName, PathDelim, TextLineBreak[TextLineBreakStyle], [rfReplaceAll]);
+  end;
+
   if Algorithm = HASH_SFV then
   begin
-    FCheckSumFile.Add(ExtractDirLevel(FFullFilesTree.Path,
-                                      aFile.Path) + aFile.Name + ' ' + sCheckSum);
+    FCheckSumFile.Add(FileName + ' ' + sCheckSum);
   end
   else begin
-    FCheckSumFile.Add(sCheckSum + ' *' + ExtractDirLevel(FFullFilesTree.Path,
-                                                         aFile.Path) + aFile.Name);
+    FCheckSumFile.Add(sCheckSum + ' *' + FileName);
   end;
 
   if not OneFile then

+ 2 - 0
src/filesources/ufilesourcecalcchecksumoperation.pas

@@ -59,6 +59,7 @@ type
 
   protected
     FResult: TVerifyChecksumResult;
+    FTextLineBreakStyle: TTextLineBreakStyle;
 
     function GetID: TFileSourceOperationType; override;
 
@@ -85,6 +86,7 @@ type
     property Mode: TCalcCheckSumOperationMode read FMode write FMode;
     property Algorithm: THashAlgorithm read FAlgorithm write FAlgorithm;
     property OneFile: Boolean read FOneFile write FOneFile;
+    property TextLineBreakStyle: TTextLineBreakStyle read FTextLineBreakStyle write FTextLineBreakStyle;
     property OpenFileAfterOperationCompleted: Boolean  read FOpenFileAfterOperationCompleted write FOpenFileAfterOperationCompleted;
     property Result: TVerifyChecksumResult read FResult;
   end;

+ 3 - 1
src/umaincommands.pas

@@ -2641,6 +2641,7 @@ var
   sFileName: String;
   SelectedFiles: TFiles;
   HashAlgorithm: THashAlgorithm;
+  TextLineBreakStyle: TTextLineBreakStyle;
   QueueId: TOperationsManagerQueueIdentifier;
   Operation: TFileSourceCalcChecksumOperation;
   bSeparateFile, bOpenFileAfterJobCompleted: Boolean;
@@ -2681,7 +2682,7 @@ begin
       else
         sFileName:= ActiveFrame.CurrentPath + SelectedFiles[0].Name;
 
-      if ShowCalcCheckSum(sFileName, bSeparateFile, HashAlgorithm, bOpenFileAfterJobCompleted, QueueId) then
+      if ShowCalcCheckSum(sFileName, bSeparateFile, HashAlgorithm, bOpenFileAfterJobCompleted, TextLineBreakStyle, QueueId) then
       begin
         Operation := ActiveFrame.FileSource.CreateCalcChecksumOperation(
                        SelectedFiles, ActiveFrame.CurrentPath, sFileName) as TFileSourceCalcChecksumOperation;
@@ -2690,6 +2691,7 @@ begin
         begin
           Operation.Mode := checksum_calc;
           Operation.OneFile := not bSeparateFile;
+          Operation.TextLineBreakStyle:= TextLineBreakStyle;
           Operation.OpenFileAfterOperationCompleted := bOpenFileAfterJobCompleted;
           Operation.Algorithm := HashAlgorithm;