ADD: MultiArc - cleaning chars in size string w/o additional helpers (#1883)

This commit is contained in:
j2969719 2024-10-28 09:08:53 +03:00 committed by GitHub
commit ab42674559
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 43 additions and 7 deletions

View file

@ -72,6 +72,7 @@ type
Comment: string;
procedure ClearStore; virtual;
function CheckValues: Boolean; virtual;
function CheckSizeChar(Chr: AnsiChar): Boolean; virtual;
procedure FillRecord(const Value: TArchiveItem); virtual;
function ParseByMask(Value, NextValue, Mask: ansistring): Integer; virtual;
public
@ -227,7 +228,7 @@ begin
begin
while IValue <= Length(Value) do
begin
if not(Value[Ivalue] in ['0'..'9']) then
if CheckSizeChar(Value[Ivalue]) = False then
break;
s := s + Value[Ivalue];
Inc(Ivalue);
@ -304,6 +305,21 @@ begin
end;
end;
function TMultiArchiveDynamicParser.CheckSizeChar(Chr: AnsiChar): Boolean;
var
I: Integer;
begin
Result:= False;
if not (Chr in ['0'..'9']) then
begin
with FMultiArcItem do
if (FSizeStripChars <> EmptyStr) and ContainsOneOf(Chr, FSizeStripChars) then
Result:= True;
end
else
Result:= True;
end;
function TMultiArchiveDynamicParser.CheckValues: Boolean;
var
x, n: integer;
@ -356,7 +372,7 @@ begin
begin
Size := Trim(Size);
for n := 1 to Length(Size) do
if not (Size[n] in ['0'..'9']) then
if CheckSizeChar(Size[n]) = False then
Exit;
end;
if ThreeMonth <> '' then
@ -400,8 +416,8 @@ var
begin
Value.FileName:= FGetFileName(FileName);
Value.FileExt:= FGetFileName(FileExt);
Value.PackSize:= StrToInt64Def(PackSize, -1);
Value.UnpSize:= StrToInt64Def(Size, -1);
Value.PackSize:= StrToInt64Def(CleanSize(PackSize), -1);
Value.UnpSize:= StrToInt64Def(CleanSize(Size), -1);
Value.Year:= YearShortToLong(StrToIntDef(Year, 0));
Value.Month:= StrToIntDef(Month, 0);
Value.Day:= StrToIntDef(Day, 0);

View file

@ -41,6 +41,7 @@ type
procedure Prepare; virtual; abstract;
procedure ParseLines; virtual; abstract;
procedure AddLine(const Str: String); virtual; abstract;
function CleanSize(Str: String): String;
property OnGetArchiveItem: TOnGetArchiveItem write FOnGetArchiveItem;
end;
@ -247,6 +248,20 @@ begin
end;
function TMultiArchiveParser.CleanSize(Str: String): String;
var
I: Integer;
Size: String;
begin
Size:= Trim(Str);
if FMultiArcItem.FSizeStripChars <> EmptyStr then
begin
for I:= 1 to Length(FMultiArcItem.FSizeStripChars) do
Size:= Size.Replace(FMultiArcItem.FSizeStripChars[I], '');
end;
Result:= Size;
end;
procedure TMultiArchiveStaticParser.AddLine(const Str: String);
begin
// if next item
@ -262,9 +277,9 @@ begin
if FNamePos.Index = FFormatIndex then
FArchiveItem.FileName := FGetFileName(Trim(GetKeyValue(str, FNamePos)));
if FUnpSizePos.Index = FFormatIndex then
FArchiveItem.UnpSize := StrToInt64Def(Trim(GetKeyValue(str, FUnpSizePos)), -1);
FArchiveItem.UnpSize := StrToInt64Def(CleanSize(GetKeyValue(str, FUnpSizePos)), -1);
if FPackSizePos.Index = FFormatIndex then
FArchiveItem.PackSize := StrToInt64Def(Trim(GetKeyValue(str, FPackSizePos)), -1);
FArchiveItem.PackSize := StrToInt64Def(CleanSize(GetKeyValue(str, FPackSizePos)), -1);
if FYearPos.Index = FFormatIndex then
FArchiveItem.Year := YearShortToLong(StrToIntDef(Trim(GetKeyValue(str, FYearPos)), 0));
if FMonthPos.Index = FFormatIndex then

View file

@ -130,7 +130,8 @@ type
FDelete,
FAdd,
FAddSelfExtract,
FPasswordQuery: String;
FPasswordQuery,
FSizeStripChars: String;
FFormMode: Integer;
FFlags: TMultiArcFlags;
FIgnoreString: TStringList;
@ -352,6 +353,7 @@ begin
Break;
end;
FFlags:= TMultiArcFlags(IniFile.ReadInteger(Section, 'Flags', 0));
FSizeStripChars:= Trim(IniFile.ReadString(Section, 'SizeStripChars', EmptyStr));
FFormMode:= IniFile.ReadInteger(Section, 'FormMode', 0);
FEnabled:= IniFile.ReadBool(Section, 'Enabled', True);
FOutput:= IniFile.ReadBool(Section, 'Output', False);
@ -416,6 +418,7 @@ begin
IniFile.WriteString(Section, 'AskHistory' + IntToStr(J), FAskHistory[J]);
end;
IniFile.WriteInteger(Section, 'Flags', Integer(FFlags));
IniFile.WriteString(Section, 'SizeStripChars', FSizeStripChars);
IniFile.WriteInteger(Section, 'FormMode', FFormMode);
IniFile.WriteBool(Section, 'Enabled', FEnabled);
IniFile.WriteBool(Section, 'Output', FOutput);
@ -495,6 +498,7 @@ begin
UpdateSignature(Self.Items[Index].FID);
UpdateSignature(Self.Items[Index].FIDPos);
UpdateSignature(Self.Items[Index].FIDSeekRange);
UpdateSignature(Self.Items[Index].FSizeStripChars);
Result := crc32(Result, @Self.Items[Index].FFlags, sizeof(Self.Items[Index].FFlags));
Result := crc32(Result, @Self.Items[Index].FFormMode, sizeof(Self.Items[Index].FFormMode));
Result := crc32(Result, @Self.Items[Index].FEnabled, sizeof(Self.Items[Index].FEnabled));
@ -723,6 +727,7 @@ begin
Result.FEnabled := Self.FEnabled;
Result.FOutput := Self.FOutput;
Result.FDebug := Self.FDebug;
Result.FSizeStripChars := Self.FSizeStripChars;
Result.FIgnoreString.Assign(Self.FIgnoreString);
Result.FAskHistory.Assign(Self.FAskHistory);
end;