-
Notifications
You must be signed in to change notification settings - Fork 2
/
FixEdidLengths.pas
92 lines (80 loc) · 2.35 KB
/
FixEdidLengths.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{
Ensures the EditorIDs of the forms it's run on are <= 87 characters.
87, because the CK might still add DUPLICATE000 to the EditorID.
}
unit userscript;
const
maxEdidLength = 87; // 99-12, because 12 is the length of DUPLICATE000
{
Calculates a string's CRC32
To output as string, use IntToHex(foo, 8)
Function by zilav
}
function StringCRC32(s: string): Cardinal;
var
ms: TMemoryStream;
bw: TBinaryWriter;
br: TBinaryReader;
begin
ms := TMemoryStream.Create;
bw := TBinaryWriter.Create(ms);
bw.Write(s);
bw.Free;
ms.Position := 0;
br := TBinaryReader.Create(ms);
Result := wbCRC32Data(br.ReadBytes(ms.Size));
br.Free;
ms.Free;
end;
function shortenWithCrc32(input: string): string;
var
part: string;
begin
if(length(input) > maxEdidLength) then begin
part := copy(input, 1, maxEdidLength-9);
Result := part + '_' + IntToHex(StringCRC32(input), 8);
exit;
end;
Result := input;
end;
function fixEditorID(form: IInterface): boolean;
var
curEdid, newEdid: string;
begin
Result := false;
curEdid := EditorID(form);
newEdid := shortenWithCrc32(curEdid);
if(curEdid <> newEdid) then begin
SetElementEditValues(form, 'EDID', newEdid);
Result := true;
end;
end;
// Called before processing
// You can remove it if script doesn't require initialization code
function Initialize: integer;
begin
Result := 0;
end;
// called for every record selected in xEdit
function Process(e: IInterface): integer;
var
edid: string;
begin
Result := 0;
// comment this out if you don't want those messages
edid := EditorID(e);
if(edid = '') then begin
exit;
end;
if(fixEditorID(e)) then begin
AddMessage('FOUND: '+IntToStr(length(edid)) + ' -> '+EditorID(e));
end;
// processing code goes here
end;
// Called after processing
// You can remove it if script doesn't require finalization code
function Finalize: integer;
begin
Result := 0;
end;
end.