-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSpecialsForm.pas
591 lines (526 loc) · 21.1 KB
/
SpecialsForm.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
unit SpecialsForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls,
InflatablesList_Manager;
type
TfSpecialsForm = class(TForm)
pnlWarning: TPanel;
leParam_1: TLabeledEdit;
leParam_2: TLabeledEdit;
leParam_3: TLabeledEdit;
lblFunctions: TLabel;
lbFunctions: TListBox;
lblDescription: TLabel;
meDescription: TMemo;
cbCloseWhenDone: TCheckBox;
btnRunSelected: TButton;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure lbFunctionsDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure lbFunctionsClick(Sender: TObject);
procedure btnRunSelectedClick(Sender: TObject);
private
fILManager: TILManager;
fDrawBuffer: TBitmap;
protected
procedure ProcessingDone;
procedure SpecialSelect(Index: Integer);
// special functions implementation
procedure Special_0001;
procedure Special_0002;
procedure Special_0003;
procedure Special_0004;
procedure Special_0005;
procedure Special_0006;
procedure Special_0007;
procedure Special_0008;
procedure Special_0009;
procedure Special_0010;
procedure Special_0011;
procedure Special_0012;
procedure Special_0013;
procedure Special_0014;
procedure Special_0015;
procedure Special_0016;
public
procedure Initialize(ILManager: TILManager);
procedure Finalize;
end;
var
fSpecialsForm: TfSpecialsForm;
implementation
{$R *.dfm}
uses
StrUtils,
InflatablesList_Types,
InflatablesList_Utils;
type
TILSpecialsEntry = record
Title: String;
Details: String;
Description: String;
FunctionIdx: Integer;
end;
const
IL_SPECIALS: array[0..14] of TILSpecialsEntry = (
(Title: 'Clear textual tags';
Details: 'Item.TextTag := ''''';
Description: 'Sets textual tag to an empty string for all items that have accesible data.' + sLineBreak +
sLineBreak +
'Parameters are not used in this function.';
FunctionIdx: 1),
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Title: 'Clear parsing settings';
Details: 'Item.Shop.ParsingSettings.Clear';
Description: 'For all items that have accessible data, the parsing settings in all shops are cleared. ' +
'This means the available and price extraction settings are cleared and all stages in available and price finders are removed.' + sLineBreak +
sLineBreak +
'Parameters are not used in this function.';
FunctionIdx: 2),
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Title: 'Alternative download method for selected shops';
Details: 'Shop.Selected => Shop.AltDownloadMethod := True';
Description: 'For all items that have accessible data, the function traverses all shops and activates alternative download method when ' +
'the shop name matches parameter 1 (case insensitive comparison).' + sLineBreak +
sLineBreak +
'Parameter 1 - item shop name';
FunctionIdx: 3),
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Title: 'Update and flag available count and price';
Details: 'Item.GetAndFlagPriceAndAvail(Price,Available)';
Description: 'Traverses all items and, for those with accessible data, calls method GetAndFlagPriceAndAvail with old price set to current price and old available count set to current count. ' +
'This effectively updates the prices and available count fields from shops and sets appropriate flags ("available change", "price change" and "not available" flags).' + sLineBreak +
sLineBreak +
'Parameters are not used in this function.';
FunctionIdx: 4),
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Title: 'Set material to polyvinylchloride (PVC)';
Details: '(Item.Material = Unknown) => Item.Material := Polyvinylchloride';
Description: 'For all items that have accessible data, if the selected material is unknown, sets material to polyvinylchloride (PVC).' + sLineBreak +
sLineBreak +
'Parameters are not used in this function.';
FunctionIdx: 5),
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Title: 'Clear available change and price change flags';
Details: 'Item.AvailChange := False; Item.PriceChange := False';
Description: 'Traverses all items and, for those with accessible data, clears "available change" and "price change" flags (sets them to false).' + sLineBreak +
sLineBreak +
'Parameters are not used in this function.';
FunctionIdx: 6),
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Title: 'Replace textual tag when it matches';
Details: '(Item.TextTag = P1) => Item.TextTag := P2';
Description: 'Traverses all items and, for those with accessible data, compares (case insensitive) textual tag to a parameter 1. When it matches, it is replaced by a text given in parameter 2.' + sLineBreak +
sLineBreak +
'Parameter 1 - tag to search for' + sLineBreak +
'Parameter 2 - replacement tag';
FunctionIdx: 8),
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Title: 'Remove all shops except the selected one';
Details: 'not Item.Shop.Selected => Item.Remove(Shop)';
Description: 'For all items that have accessible data, removes all shos except the selected one.' + sLineBreak +
sLineBreak +
'Parameters are not used in this function.';
FunctionIdx: 9),
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Title: 'Remove all shops from owned items';
Details: 'Item.Owned => Item.ShopsClear';
Description: 'Removes all shops from all items that have accessible data and have "owned" flag set to true.' + sLineBreak +
sLineBreak +
'Parameters are not used in this function.';
FunctionIdx: 10),
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Title: 'Set wanted level to zero in owned items';
Details: 'Item.Owned => Item.WantedLevel := 0';
Description: 'Sets wanted level to zero for all items that have accessible data and have "owned" flag set to true.' + sLineBreak +
sLineBreak +
'Parameters are not used in this function.';
FunctionIdx: 11),
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Title: 'Generate user ID for owned items';
Details: '(Item.Owned and (Item.UserID = '''')) => Item.GenerateUserID';
Description: 'Generates user ID or all items that has accessible data and the current user ID is empty.' + sLineBreak +
sLineBreak +
'Parameters are not used in this function.';
FunctionIdx: 12),
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Title: 'Uncheck disabling of parsing error for templated shops';
Details: 'Item.Shop.TemplRef => Item.Shop.DisableParsingErrors := False';
Description: 'For all items that have accessible data, unchecks (sets to false) "disable parsing errors" options in ' +
'all shops that have their parsing settings referenced to a template.' + sLineBreak +
sLineBreak +
'Parameters are not used in this function.';
FunctionIdx: 13),
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Title: 'Auto-rename all pictures in all items';
Details: 'Item.Pictures.AutoRename';
Description: 'For all items that have accessible data, auto-rename all pictures. ' + sLineBreak +
sLineBreak +
'Parameters are not used in this function.';
FunctionIdx: 14),
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Title: 'Check existence of all automated picture files';
Details: 'count (not FileExists(Items.Pictures))';
Description: 'For all items that have accessible data, count not existing automated picture files.' + sLineBreak +
sLineBreak +
'Parameters are not used in this function.';
FunctionIdx: 15),
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Title: 'Create compact listing of owned items';
Details: 'Item.Owned => List.Add(Item)';
Description: 'Add all owned items that have accessible data to a compact listing and save it' +
'to a file (in the directory where the main file resides).' + sLineBreak +
sLineBreak +
'Parameter 1 - name of the file, including extension (If not set then name "list.txt" is used)';
FunctionIdx: 16)
);
//==============================================================================
procedure TfSpecialsForm.ProcessingDone;
begin
If cbCloseWhenDone.Checked then
Close;
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.SpecialSelect(Index: Integer);
begin
case Index of
1: Special_0001;
2: Special_0002;
3: Special_0003;
4: Special_0004;
5: Special_0005;
6: Special_0006;
7: Special_0007;
8: Special_0008;
9: Special_0009;
10: Special_0010;
11: Special_0011;
12: Special_0012;
13: Special_0013;
14: Special_0014;
15: Special_0015;
16: Special_0016;
else
MessageDlg(IL_Format('Invalid special function index (%d).',[Index]),mtError,[mbOK],0);
end;
ProcessingDone;
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Special_0001;
var
i: Integer;
begin
For i := fILManager.ItemLowIndex to fILManager.ItemHighIndex do
If fILManager[i].DataAccessible then
fILManager[i].TextTag := '';
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Special_0002;
var
i,j: Integer;
begin
For i := fILManager.ItemLowIndex to fILManager.ItemHighIndex do
If fILManager[i].DataAccessible then
For j := fILManager[i].ShopLowIndex to fILManager[i].ShopHighIndex do
begin
fILManager[i][j].ParsingSettings.AvailExtractionSettingsClear;
fILManager[i][j].ParsingSettings.AvailFinder.StageClear;
fILManager[i][j].ParsingSettings.PriceExtractionSettingsClear;
fILManager[i][j].ParsingSettings.PriceFinder.StageClear;
end;
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Special_0003;
var
i,j: Integer;
begin
For i := fILManager.ItemLowIndex to fILManager.ItemHighIndex do
If fILManager[i].DataAccessible then
For j := fILManager[i].ShopLowIndex to fILManager[i].ShopHighIndex do
If IL_SameText(fILManager[i][j].Name,leParam_1.Text) then
fILManager[i][j].AltDownMethod := True;
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Special_0004;
var
i: Integer;
begin
For i := fILManager.ItemLowIndex to fILManager.ItemHighIndex do
If fILManager[i].DataAccessible then
fILManager[i].GetAndFlagPriceAndAvail(
fILManager[i].UnitPriceSelected,fILManager[i].AvailableSelected);
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Special_0005;
var
i: Integer;
begin
For i := fILManager.ItemLowIndex to fILManager.ItemHighIndex do
If fILManager[i].DataAccessible then
If fILManager[i].Material = ilimtUnknown then
fILManager[i].Material := ilimtPolyvinylchloride;
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Special_0006;
var
i: Integer;
begin
For i := fILManager.ItemLowIndex to fILManager.ItemHighIndex do
If fILManager[i].DataAccessible then
begin
fILManager[i].SetFlagValue(ilifPriceChange,False);
fILManager[i].SetFlagValue(ilifAvailChange,False)
end;
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Special_0007;
begin
// not needed anymore
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Special_0008;
var
i: Integer;
begin
For i := fILManager.ItemLowIndex to fILManager.ItemHighIndex do
If fILManager[i].DataAccessible then
If IL_SameText(fILManager[i].TextTag,leParam_1.Text) then
fILManager[i].TextTag := leParam_2.Text;
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Special_0009;
var
i,j: Integer;
begin
For i := fILManager.ItemLowIndex to fILManager.ItemHighIndex do
If fILManager[i].DataAccessible then
For j := fILManager[i].ShopHighIndex downto fILManager[i].ShopLowIndex do
If not fILManager[i][j].Selected then
fILManager[i].ShopDelete(j);
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Special_0010;
var
i: Integer;
begin
For i := fILManager.ItemLowIndex to fILManager.ItemHighIndex do
If fILManager[i].DataAccessible and (ilifOwned in fILManager[i].Flags) then
fILManager[i].ShopClear;
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Special_0011;
var
i: Integer;
begin
For i := fILManager.ItemLowIndex to fILManager.ItemHighIndex do
If fILManager[i].DataAccessible and (ilifOwned in fILManager[i].Flags) then
fILManager[i].WantedLevel := 0;
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Special_0012;
var
i: Integer;
Temp: String;
begin
For i := fILManager.ItemLowIndex to fILManager.ItemHighIndex do
If fILManager[i].DataAccessible then
If (ilifOwned in fILManager[i].Flags) and (Length(fILManager[i].UserID) <= 0) then
If fILManager.GenerateUserID(Temp) then
fILManager[i].UserID := Temp;
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Special_0013;
var
i,j: Integer;
begin
For i := fILManager.ItemLowIndex to fILManager.ItemHighIndex do
If fILManager[i].DataAccessible then
For j := fILManager[i].ShopLowIndex to fILManager[i].ShopHighIndex do
If Length(fILManager[i][j].ParsingSettings.TemplateReference) > 0 then
fILManager[i][j].ParsingSettings.DisableParsingErrors := False;
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Special_0014;
var
i,j: Integer;
begin
For i := fILManager.ItemLowIndex to fILManager.ItemHighIndex do
If fILManager[i].DataAccessible then
For j := fILManager[i].Pictures.LowIndex to fILManager[i].Pictures.HighIndex do
fILManager[i].Pictures.AutoRenameFile(j);
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Special_0015;
var
i: Integer;
Temp: TStringList;
Cnt: Integer;
begin
Temp := TStringList.Create;
try
Cnt := 0;
For i := fILManager.ItemLowIndex to fILManager.ItemHighIndex do
begin
fILManager[i].Pictures.MissingFiles(Temp);
Inc(Cnt,Temp.Count);
end;
If Cnt > 0 then
MessageDlg(Format('Number of missing picture files: %d.',[Cnt]),mtError,[mbOK],0);
finally
Temp.Free;
end;
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Special_0016;
var
Temp: TStringList;
i: Integer;
Function GetTagStr(Index: Integer): String;
begin
Result := ' ';
If (ilifBoxed in fILManager[i].Flags) then
Result[1] := 'B';
If (ilifDiscarded in fILManager[i].Flags) then
Result[2] := 'E' else
If (ilifRepaired in fILManager[i].Flags) then
Result[2] := 'R' else
If (ilifDamaged in fILManager[i].Flags) then
Result[2] := 'D';
end;
begin
Temp := TStringList.Create;
try
For i := fILManager.ItemLowIndex to fILManager.ItemHighIndex do
If fILManager[i].DataAccessible and (ilifOwned in fILManager[i].Flags) then
begin
// [user id] (flag) TitleStr - TypeStr SizeStr - Variant <VariantTag> [TextTag]
Temp.Add(Format('[%s](%s) %s - %s %s' + sLineBreak + ' %s%s [%s]',[
IfThen(Length(fILManager[i].UserID) <> 0,fILManager[i].UserID,' '),
GetTagStr(i),
fILManager[i].TitleStr,
fILManager[i].TypeStr,
fILManager[i].SizeStr,
fILManager[i].Variant,
IfThen(Length(fILManager[i].VariantTag) <> 0,Format(' <%s>',[fILManager[i].VariantTag]),''),
fILManager[i].TextTag]));
end;
If Length(leParam_1.Text) > 0 then
Temp.SaveToFile(fILManager.StaticSettings.ListPath + leParam_1.Text)
else
Temp.SaveToFile(fILManager.StaticSettings.ListPath + 'list.txt')
finally
Temp.Free;
end;
end;
//==============================================================================
procedure TfSpecialsForm.Initialize(ILManager: TILManager);
var
i: Integer;
begin
fILManager := ILManager;
// fill list of special functions
lbFunctions.Items.BeginUpdate;
try
lbFunctions.Items.Clear;
For i := Low(IL_SPECIALS) to High(IL_SPECIALS) do
lbFunctions.Items.Add(IL_SPECIALS[i].Title);
finally
lbFunctions.Items.EndUpdate;
end;
If lbFunctions.Items.Count > 0 then
lbFunctions.ItemIndex := 0;
lbFunctions.OnClick(nil);
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.Finalize;
begin
// nothing to do here
end;
//==============================================================================
procedure TfSpecialsForm.FormCreate(Sender: TObject);
begin
fDrawBuffer := TBitmap.Create;
fDrawBuffer.PixelFormat := pf24bit;
fDrawBuffer.Canvas.Font.Assign(lbFunctions.Font);
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.FormShow(Sender: TObject);
begin
lbFunctions.SetFocus;
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.FormDestroy(Sender: TObject);
begin
FreeAndNil(fDrawBuffer);
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.lbFunctionsDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
BoundsRect: TRect;
begin
If Assigned(fDrawBuffer) then
begin
// adjust draw buffer size
If fDrawBuffer.Width < (Rect.Right - Rect.Left) then
fDrawBuffer.Width := Rect.Right - Rect.Left;
If fDrawBuffer.Height < (Rect.Bottom - Rect.Top) then
fDrawBuffer.Height := Rect.Bottom - Rect.Top;
BoundsRect := Classes.Rect(0,0,Rect.Right - Rect.Left,Rect.Bottom - Rect.Top);
with fDrawBuffer.Canvas do
begin
// background
Pen.Style := psClear;
Brush.Style := bsSolid;
If odSelected in State then
Brush.Color := $00E5E5E5
else
Brush.Color := clWindow;
Rectangle(BoundsRect.Left,BoundsRect.Top,BoundsRect.Right + 1,BoundsRect.Bottom);
// side strip
Brush.Color := clSilver;
Rectangle(BoundsRect.Left,BoundsRect.Top,BoundsRect.Left + 5,BoundsRect.Bottom);
// separator line
Pen.Style := psSolid;
Pen.Color := clSilver;
MoveTo(BoundsRect.Left,BoundsRect.Bottom - 1);
LineTo(BoundsRect.Right,BoundsRect.Bottom - 1);
// text
Brush.Style := bsClear;
Pen.Style := psClear;
Font.Style := Font.Style + [fsBold];
font.Color := clWindowText;
TextOut(7,2,IL_SPECIALS[Index].Title);
Font.Style := Font.Style - [fsBold];
font.Color := clGray;
TextOut(7,17,IL_SPECIALS[Index].Details);
end;
// move drawbuffer to the canvas
lbFunctions.Canvas.CopyRect(Rect,fDrawBuffer.Canvas,BoundsRect);
end;
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.lbFunctionsClick(Sender: TObject);
begin
If lbFunctions.ItemIndex >= 0 then
meDescription.Text := IL_SPECIALS[lbFunctions.ItemIndex].Description
else
meDescription.Lines.Clear;
end;
//------------------------------------------------------------------------------
procedure TfSpecialsForm.btnRunSelectedClick(Sender: TObject);
begin
If lbFunctions.ItemIndex >= 0 then
begin
If MessageDlg(IL_Format('You are about to execute function "%s".' + sLineBreak +
'There will be no further dialogs, warnings or prompts, even in case of destructive actions' +
sLineBreak + sLineBreak + 'Are you sure you want to continue?',[IL_SPECIALS[lbFunctions.ItemIndex].Title]),
mtWarning,[mbYes,mbNo],0) = mrYes then
SpecialSelect(IL_SPECIALS[lbFunctions.ItemIndex].FunctionIdx);
end
else MessageDlg('No function selected.',mtError,[mbOK],0);
end;
end.