diff options
Diffstat (limited to 'UChecksumDruid.pas')
| -rw-r--r-- | UChecksumDruid.pas | 103 |
1 files changed, 64 insertions, 39 deletions
diff --git a/UChecksumDruid.pas b/UChecksumDruid.pas index 7745fad..fb62775 100644 --- a/UChecksumDruid.pas +++ b/UChecksumDruid.pas @@ -76,7 +76,7 @@ var implementation -uses ULocale, UCoreUtils, ULibc, UCore, DateUtils, UConfig, StrUtils, md5, crc; +uses ULocale, UCoreUtils, ULibc, UCore, DateUtils, UConfig, UError, StrUtils, md5, crc; procedure TFChecksumDruid.FormCreate(Sender: TObject); @@ -306,19 +306,22 @@ procedure TFChecksumDruid.SetCurrentPage(const Num: integer; const GoingForward: const Ext: array[boolean] of string = ('.md5', '.sfv'); var s: string; i: TEngineFileDes; - Error: integer; + Error: PGError; begin // A simple test before we can continue if (CurrentPage = 3) and (not SeparateFileCheckBox.Checked) and GoingForward then begin - s := UTF8ToStr(FileNameEntry.Text); - i := Engine.OpenFile(s, omWrite, Error); - if Error <> 0 then begin - Application.MessageBox(PGtkWindow(FWidget), Format(LANGCCHKSUMAnErrorOccuredWhileOpeningFileSS, [StrToUTF8(ExtractFileName(s)), GetErrorString(Error)]), - [mbOK], mbError, mbNone, mbOK); + s := ProcessPattern(Engine, StrToUTF8(FileNameEntry.Text), IncludeTrailingPathDelimiter(ExtractFilePath(FileNames[0])), '', False); + Error := nil; + i := Engine.OpenFile(s, omWrite, @Error); + if i = nil then begin + if Error <> nil then begin + ShowError(Self, Format('An error occured while opening file ''%s''', [StrToUTF8(ExtractFileName(s))]), Error); + g_error_free(Error); + end; Exit; end; - Engine.CloseFile(i); - Engine.Remove(s); + Engine.CloseFile(i, nil); + Engine.Remove(s, nil); end; DebugMsg(['TFChecksumDruid.SetCurrentPage: CurrentPage = ', CurrentPage, ', new = ', Num]); @@ -443,7 +446,7 @@ begin // Compute maximal size of selected files MaxSize := 0; for i := 0 to FileNames.Count - 1 do begin - Stat := Engine.GetFileInfo(FileNames[i], True, True); + Stat := Engine.GetFileInfo(FileNames[i], True, True, nil); if Assigned(Stat) then begin Inc(MaxSize, Stat.Size); FreeDataItem(Stat); @@ -458,7 +461,7 @@ begin for i := 0 to FileNames.Count - 1 do begin ProcessingLabel.Caption := Format(LANGCCHKSUMNowProcessingFileS, [StrToUTF8(ExtractFileName(FileNames[i]))]); LastValue := Progress.Value; - Stat := Engine.GetFileInfo(FileNames[i], True, True); + Stat := Engine.GetFileInfo(FileNames[i], True, True, nil); Application.ProcessMessages; try if ProcessFile(FileNames[i], SFVRadioButton.Checked, s) then begin @@ -490,11 +493,12 @@ end; function TFChecksumDruid.ProcessFile(const FName: string; const IsItSFV: boolean; var HashString: string): boolean; const ChksumBlockSize = 65536*4; var FD: TEngineFileDes; - Error, Count: integer; + Count: integer; Buffer: Pointer; CRC: LongWord; MDContext: TMDContext; MDDigest: TMDDigest; + Error: PGError; begin HashString := ''; Result := False; @@ -508,16 +512,21 @@ begin CRC := 0; if not IsItSFV then MDInit(MDContext, MD_VERSION_5); - FD := Engine.OpenFile(FName, omRead, Error); - if Error <> 0 then begin - ErrorLabel.Caption := ErrorLabel.Caption + Format(LANGCCHKSUMAnErrorOccuredWhileOpeningFileSS, [StrToUTF8(ExtractFileName(FName)), GetErrorString(Error)]); + Error := nil; + FD := Engine.OpenFile(FName, omRead, @Error); + if FD = nil then begin + if Error <> nil then begin + ErrorLabel.Caption := ErrorLabel.Caption + Format(LANGCCHKSUMAnErrorOccuredWhileOpeningFileSS, [StrToUTF8(ExtractFileName(FName)), Error^.message]); + g_error_free(Error); + end; Exit; end; repeat - Count := Engine.ReadFile(FD, Buffer, ChksumBlockSize, Error); - if Error <> 0 then begin - ErrorLabel.Caption := ErrorLabel.Caption + Format(LANGCCHKSUMAnErrorOccuredWhileReadingFileSS, [StrToUTF8(ExtractFileName(FName)), GetErrorString(Error)]); - Engine.CloseFile(FD); + Count := Engine.ReadFile(FD, Buffer, ChksumBlockSize, @Error); + if Error <> nil then begin + ErrorLabel.Caption := ErrorLabel.Caption + Format(LANGCCHKSUMAnErrorOccuredWhileReadingFileSS, [StrToUTF8(ExtractFileName(FName)), Error^.message]); + g_error_free(Error); + Engine.CloseFile(FD, nil); Exit; end; if IsItSFV then CRC := CRC32(CRC, Buffer, Count) @@ -527,7 +536,7 @@ begin Application.ProcessMessages; CheckStop; until (Count < ChksumBlockSize) or Stop; - Engine.CloseFile(FD); + Engine.CloseFile(FD, nil); libc_free(Buffer); if IsItSFV then HashString := IntToHex(CRC, 8) else @@ -541,13 +550,18 @@ end; const ChksumBlockSize = 32768; // Maximum of PByteArray procedure TFChecksumDruid.WriteLine(const FName, CheckedFName, HashString: string; const IsItSFV, CreateFile, CloseFile: boolean); -var i, Error, Count: integer; +var i, Count: integer; s: string; + Error: PGError; begin if CreateFile then begin - FileDes := Engine.OpenFile(FName, omWrite, Error); - if Error <> 0 then begin - ErrorLabel.Caption := ErrorLabel.Caption + Format(LANGCCHKSUMAnErrorOccuredWhileOpeningFileSS, [StrToUTF8(ExtractFileName(FName)), GetErrorString(Error)]); + Error := nil; + FileDes := Engine.OpenFile(FName, omWrite, @Error); + if FileDes = nil then begin + if Error <> nil then begin + ErrorLabel.Caption := ErrorLabel.Caption + Format(LANGCCHKSUMAnErrorOccuredWhileOpeningFileSS, [StrToUTF8(ExtractFileName(FName)), Error^.message]); + g_error_free(Error); + end; Exit; end; try @@ -565,10 +579,12 @@ begin else s := Format('%s %s'#10, [Trim(AnsiLowerCase(HashString)), ExtractFileName(CheckedFName)]); for i := 1 to Length(s) do begin if BufferPos + 1 >= ChksumBlockSize then begin - Count := Engine.WriteFile(FileDes, Buffer, ChksumBlockSize, Error); + Error := nil; + Count := Engine.WriteFile(FileDes, Buffer, ChksumBlockSize, @Error); BufferPos := -1; - if (Error <> 0) or (Count <> ChksumBlockSize) then begin - ErrorLabel.Caption := ErrorLabel.Caption + Format(LANGCCHKSUMAnErrorOccuredWhileWritingFileSS, [StrToUTF8(ExtractFileName(FName)), GetErrorString(Error)]); + if (Error <> nil) { or (Count <> ChksumBlockSize) } then begin + ErrorLabel.Caption := ErrorLabel.Caption + Format(LANGCCHKSUMAnErrorOccuredWhileWritingFileSS, [StrToUTF8(ExtractFileName(FName)), Error^.message]); + g_error_free(Error); Exit; end; end; @@ -578,25 +594,32 @@ begin if CloseFile then begin Inc(BufferPos); // Counting with zero-starting element - Count := Engine.WriteFile(FileDes, Buffer, BufferPos, Error); - if (Error <> 0) or (Count <> BufferPos) then begin - ErrorLabel.Caption := ErrorLabel.Caption + Format(LANGCCHKSUMAnErrorOccuredWhileWritingFileSS, [StrToUTF8(ExtractFileName(FName)), GetErrorString(Error)]); + Error := nil; + Count := Engine.WriteFile(FileDes, Buffer, BufferPos, @Error); + if (Error <> nil) { or (Count <> BufferPos) } then begin + ErrorLabel.Caption := ErrorLabel.Caption + Format(LANGCCHKSUMAnErrorOccuredWhileWritingFileSS, [StrToUTF8(ExtractFileName(FName)), Error^.message]); + g_error_free(Error); Exit; end; BufferPos := -1; - Engine.CloseFile(FileDes); + Engine.CloseFile(FileDes, nil); libc_free(Buffer); end; end; procedure TFChecksumDruid.WriteSFVComment(const FName: string); -var i, Error, Count: integer; +var i, Count: integer; Stat: PDataItem; s: string; + Error: PGError; begin - FileDes := Engine.OpenFile(FName, omWrite, Error); - if Error <> 0 then begin - ErrorLabel.Caption := ErrorLabel.Caption + Format(LANGCCHKSUMAnErrorOccuredWhileOpeningFileSS, [StrToUTF8(ExtractFileName(FName)), GetErrorString(Error)]); + Error := nil; + FileDes := Engine.OpenFile(FName, omWrite, @Error); + if FileDes = nil then begin + if Error <> nil then begin + ErrorLabel.Caption := ErrorLabel.Caption + Format(LANGCCHKSUMAnErrorOccuredWhileOpeningFileSS, [StrToUTF8(ExtractFileName(FName)), Error^.message]); + g_error_free(Error); + end; Exit; end; try @@ -613,7 +636,7 @@ begin '; http://tuxcmd.sourceforge.net/'#13#10'; '#13#10'; /----'#13#10, [ConstAboutVersion, ConstAboutBuildDate, SysUtils.FormatDateTime('mm.dd.yyyy "at" hh:nn:ss', Now)]); for i := 0 to FileNames.Count - 1 do begin - Stat := Engine.GetFileInfo(FileNames[i], True, True); + Stat := Engine.GetFileInfo(FileNames[i], True, True, nil); if Assigned(Stat) then begin s := s + Format('; %s %s %s'#13#10, [PadRightStr(IntToStr(Stat^.Size), 11), FormatDate(Stat^.mtime, True, True, 999, 999, 1, '%Y-%m-%d', '%k:%M.%S'), ExtractFileName(FileNames[i])]); @@ -624,10 +647,12 @@ begin for i := 1 to Length(s) do begin if BufferPos + 1 >= ChksumBlockSize then begin - Count := Engine.WriteFile(FileDes, Buffer, ChksumBlockSize, Error); + Error := nil; + Count := Engine.WriteFile(FileDes, Buffer, ChksumBlockSize, @Error); BufferPos := -1; - if (Error <> 0) or (Count <> ChksumBlockSize) then begin - ErrorLabel.Caption := ErrorLabel.Caption + Format(LANGCCHKSUMAnErrorOccuredWhileWritingFileSS, [StrToUTF8(ExtractFileName(FName)), GetErrorString(Error)]); + if (Error <> nil) { or (Count <> ChksumBlockSize) } then begin + ErrorLabel.Caption := ErrorLabel.Caption + Format(LANGCCHKSUMAnErrorOccuredWhileWritingFileSS, [StrToUTF8(ExtractFileName(FName)), Error^.message]); + g_error_free(Error); Exit; end; end; |
