Skip to content

Commit 901b89d

Browse files
committed
Detect z88dk corrupt DSKs
1 parent 7e1c4f6 commit 901b89d

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

Source/DiskImageManager.res

0 Bytes
Binary file not shown.

Source/DskImage.pas

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,14 @@ constructor TDSKImage.CreateFromStream(Stream: TStream);
430430
if CompareBlock(DSKInfoBlock.DiskInfoBlock, 'MV - CPC') then
431431
FileFormat := diStandardDSK;
432432
if CompareBlock(DSKInfoBlock.DiskInfoBlock, 'EXTENDED CPC DSK File') then
433+
FileFormat := diExtendedDSK
434+
else
435+
if CompareBlockInsensitive(DSKInfoBlock.DiskInfoBlock, 'EXTENDED CPC DSK FILE') then
436+
begin
433437
FileFormat := diExtendedDSK;
438+
Corrupt := True;
439+
Messages.Add('File signature has incorrect case.');
440+
end;
434441

435442
if FileFormat <> diInvalid then
436443
begin

Source/Utils.pas

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function StrBufPos(ByteArray: array of byte; SubString: string): integer;
3333

3434
function CompareBlock(A: array of char; B: string): boolean;
3535
function CompareBlockStart(A: array of char; B: string; Start: integer): boolean;
36+
function CompareBlockInsensitive(A: array of char; B: string): boolean;
3637

3738
function FontToDescription(ThisFont: TFont): string;
3839
function FontFromDescription(Description: string): TFont;
@@ -84,9 +85,9 @@ function CompareBlock(A: array of char; B: string): boolean;
8485
begin
8586
Result := True;
8687
Idx := 0;
87-
while (Result and (Idx < Length(B) - 1)) do
88+
while Result and (Idx < Length(B) - 1) do
8889
begin
89-
if (A[Idx] <> B[Idx + 1]) then
90+
if A[Idx] <> B[Idx + 1] then
9091
Result := False;
9192
Inc(Idx);
9293
end;
@@ -99,9 +100,27 @@ function CompareBlockStart(A: array of char; B: string; Start: integer): boolean
99100
begin
100101
Result := True;
101102
Idx := 0;
102-
while (Result and (Idx < Length(B) - 1)) do
103+
while Result and (Idx < Length(B) - 1) do
103104
begin
104-
if (A[Idx + Start] <> B[Idx + 1]) then
105+
if A[Idx + Start] <> B[Idx + 1] then
106+
Result := False;
107+
Inc(Idx);
108+
end;
109+
end;
110+
111+
// Compare two char arrays case insensitively
112+
function CompareBlockInsensitive(A: array of char; B: string): boolean;
113+
var
114+
Idx: integer;
115+
AChar, BChar: Char;
116+
begin
117+
Result := True;
118+
Idx := 0;
119+
while Result and (Idx < Length(B) - 1) do
120+
begin
121+
AChar := UpCase(A[Idx]);
122+
BChar := UpCase(B[Idx + 1]);
123+
if AChar <> BChar then
105124
Result := False;
106125
Inc(Idx);
107126
end;

0 commit comments

Comments
 (0)