-
Notifications
You must be signed in to change notification settings - Fork 3
/
fileHistories.pas
93 lines (84 loc) · 2.56 KB
/
fileHistories.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
93
UNIT fileHistories;
INTERFACE
USES mySys,myGenerics,sysutils,FileUtil,myStringUtil;
PROCEDURE removeNonexistent;
PROCEDURE addToHistory(CONST utfFile1:ansistring; CONST utfFile2:ansistring=''; CONST utfFile3:ansistring=''; CONST utfFile4:ansistring='');
PROCEDURE limitHistory(CONST sizeLimit:longint);
PROCEDURE historyItemRecalled(CONST index:longint);
VAR history:T_arrayOfString;
IMPLEMENTATION
PROCEDURE removeNonexistent;
VAR i,j,i2,j2:longint;
fileSet:T_arrayOfString;
begin
j:=0;
for i:=0 to length(history)-1 do
if fileExists(history[i]) then begin
history[j]:=history[i];
inc(j);
end else if pos('&',history[i])>0 then begin
fileSet:=split(history[i],T_arrayOfString('&'));
j2:=0;
for i2:=0 to length(fileSet)-1 do
if fileExists(fileSet[i2]) then begin
fileSet[j2]:=fileSet[i2];
inc(j2);
end;
setLength(fileSet,j2);
if (j2>0) then begin
history[j]:=join(fileSet,'&');
inc(j);
end;
end;
setLength(history,j);
j:=1;
for i:=1 to length(history)-1 do begin
i2:=0;
while (i2<i) and (history[i2]<>history[i]) do inc(i2);
if i2>=i then begin
history[j]:=history[i];
inc(j);
end;
end;
setLength(history,j);
end;
PROCEDURE addToHistory(CONST utfFile1: ansistring; CONST utfFile2: ansistring; CONST utfFile3: ansistring; CONST utfFile4: ansistring);
VAR historyLine:ansistring;
i,j:longint;
begin
historyLine:=utfFile1;
if utfFile2<>'' then historyLine:=historyLine+'&'+utfFile2;
if utfFile3<>'' then historyLine:=historyLine+'&'+utfFile3;
if utfFile4<>'' then historyLine:=historyLine+'&'+utfFile4;
j:=0;
for i:=0 to length(history)-1 do if history[i]<>historyLine then begin
history[j]:=history[i];
inc(j);
end;
setLength(history,j);
setLength(history,length(history)+1);
for i:=length(history)-1 downto 1 do history[i]:=history[i-1];
history[0]:=historyLine;
removeNonexistent;
end;
PROCEDURE limitHistory(CONST sizeLimit: longint);
begin
if sizeLimit>length(history) then setLength(history,sizeLimit);
end;
PROCEDURE historyItemRecalled(CONST index: longint);
VAR i:longint;
temp:ansistring;
begin
for i:=index-1 downto 0 do begin
temp:=history[i];
history[i]:=history[i+1];
history[i+1]:=temp;
end;
removeNonexistent;
end;
INITIALIZATION
history:=readFile(ChangeFileExt(paramStr(0),'.fileHist'));
removeNonexistent;
FINALIZATION
writeFile(ChangeFileExt(paramStr(0),'.fileHist'),history);
end.