-
Notifications
You must be signed in to change notification settings - Fork 2
/
DelEQPrUnit.pas
executable file
·189 lines (174 loc) · 3.92 KB
/
DelEQPrUnit.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
unit DelEQPrUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TDelEQPrForm = class(TForm)
PresetsBox: TListBox;
DelBtn: TButton;
CancelBtn: TButton;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure DelBtnClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure PresetsBoxKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
procedure LoadPresets;
procedure DelCurPreset;
end;
var DelEQPrForm: TDelEQPrForm;
procedure DelPreset;
implementation uses Main, IO;
{$R *.DFM}
procedure DelPreset;
begin
with TDelEQPrForm.Create(Application) do
try
ShowModal;
finally
Free;
end;
end;
procedure TDelEQPrForm.DelCurPreset;
var f : file;
s,t,st,stu : string;
hdr : array[0..30] of char;
eqd : array[0..267] of byte;
nr,i,ior : integer;
begin
{$I-}
s := BasePath + 'mp3nav.q1';
i := PresetsBox.ItemIndex;
if i < 0 then exit;
st := trim(PresetsBox.Items[i]);
PresetsBox.Items.Delete(i);
stu := AnsiUpperCase(st);
if length(st) > 267 - 12 then st := copy(st,1,267 - 12);
if FileExists(s) then
begin
FileMode := fmOpenReadWrite;
AssignFile(f,s); reset(f,1);
blockread(f,hdr,sizeof(hdr));
ior := IOResult;
if not FatalIOError(ior) then
begin
while not eof(f) do
begin
blockread(f,eqd,sizeof(eqd));
i := 0; t := '';
while (i < 267 - 11) do
begin
if eqd[i] = 0 then break else t := t + char(eqd[i]);
inc(i);
end;
t := ansiuppercase(trim(t));
if t = stu then
begin
i := filepos(f);
if eof(f) then
begin
i := i - sizeof(eqd);
end else
begin
while not eof(f) do
begin
seek(f,i);
blockread(f,eqd,sizeof(eqd),nr);
if nr > 0 then
begin
seek(f,i - sizeof(eqd));
blockwrite(f,eqd,nr);
inc(i,nr);
if i > filesize(f) then break;
end;
if nr <> sizeof(eqd) then break;
end;
i := i - sizeof(eqd);
end;
seek(f,i);
// ior := IOResult;
Truncate(f);
// ior := IOResult;
break;
end;
end;
end;
end;
CloseFile(f);
LoadPresets;
{$I+}
end;
procedure TDelEQPrForm.LoadPresets;
var f : file;
s : string;
hdr : array[0..30] of char;
eqd : array[0..267] of byte;
i,ior : integer;
begin
PresetsBox.Items.BeginUpdate;
PresetsBox.Items.Clear;
s := BasePath + 'mp3nav.q1';
{$I-}
if FileExists(s) then
begin
assignfile(f,s); reset(f,1);
blockread(f,hdr,sizeof(hdr));
ior := IOResult;
if not FatalIOError(ior) then
begin
while not eof(f) do
begin
blockread(f,eqd,sizeof(eqd));
i := 0; s := '';
while (i < 267 - 11) do
begin
if eqd[i] = 0 then break else s := s + char(eqd[i]);
inc(i);
end;
s := trim(s);
if s <> '' then
begin
PresetsBox.Items.Add(s);
end;
ior := IOResult;
if FatalIOError(IOR) then
begin
{ syserrormessage(ior);{}
break;
end;
end;
end else
begin
{ syserrormessage(ior);{}
end;
closefile(f);
end;
{$I+}
PresetsBox.Items.EndUpdate;
end;
procedure TDelEQPrForm.Button1Click(Sender: TObject);
begin
LoadPresets;
end;
procedure TDelEQPrForm.DelBtnClick(Sender: TObject);
begin
DelCurPreset;
end;
procedure TDelEQPrForm.FormCreate(Sender: TObject);
begin
LoadPresets;
end;
procedure TDelEQPrForm.PresetsBoxKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = VK_DELETE) then
begin
DelCurPreset;
end;
end;
end.