-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unit1.pas
119 lines (101 loc) · 2.45 KB
/
Unit1.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
unit Unit1;
interface
uses
Windows,
Messages,
SysUtils,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
StdCtrls,
Buttons,
ComCtrls,
functions;
type
TForm1 = class(TForm)
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
PBar: TProgressBar;
GroupBox1: TGroupBox;
Button1: TButton;
BitBtn1: TBitBtn;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
CheckBox1: TCheckBox;
procedure BitBtn1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
end;
var Form1: TForm1;
filePath: string;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var OpenDialog: TOpenDialog;
begin
OpenDialog := TOpenDialog.Create(nil);
if OpenDialog.Execute then
begin
filePath := OpenDialog.FileName;
Edit1.Text := filePath;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
StringList: TStringList;
i, c, linenum:integer;
T1, T2, Offset: TSrt;
T: TArrayOfString;
begin
Offset := StrToSrt(Edit3.Text+':'+Edit4.Text+':'+Edit5.Text+','+Edit6.Text);
if Offset = 0 then
begin
MessageDlg('Please specify a higher offset!'#13'No files were processed', mtError, [mbOk], 0);
exit;
end;
StringList := TStringList.Create;
SetLength(T, 0);
c := 0;
if FileExists(filePath) then
begin
StringList.LoadFromFile(filePath);
linenum := StringList.Count-1;
PBar.Max := linenum;
for i:=0 to linenum do
begin
if Pos('-->', StringList[i]) <> 0 then
begin
if Length(StringList[i]) <> 29 then continue;
T := Explode(StringList[i], ' --> ');
T1 := StrToSrt(T[0]);
T2 := StrToSrt(T[1]);
if not RadioButton1.Checked then
begin
T1 := T1 - Offset;
T2 := T2 - Offset;
end else
begin
T1 := T1 + Offset;
T2 := T2 + Offset;
end;
StringList[i] := SrtToStr(T1) +' --> '+ SrtToStr(T2);
Inc(c);
end;
PBar.Position := i;
end;
PBar.Position := 0;
MessageDlg('All done, did '+IntToStr(c)+' modifications...', mtInformation, [mbOk], 0);
if CheckBox1.Checked then CopyFile(PChar(filePath), PChar(filePath+'.bak'), False);
StringList.SaveToFile(filePath);
StringList.Free;
end else
if filepath = '' then MessageDlg('Please specify a valid filename to scan!', mtError, [mbOk], 0);
end;
end.