-
Notifications
You must be signed in to change notification settings - Fork 1
/
untConfiguracoes.pas
242 lines (214 loc) · 7.59 KB
/
untConfiguracoes.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
unit untConfiguracoes;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.CheckLst,
Vcl.Samples.Spin, Vcl.Mask, Vcl.ExtCtrls, Winapi.ShellAPI, Vcl.Buttons,
PngBitBtn, Vcl.WinXCtrls, System.IniFiles, Vcl.Themes;
type
TfrmConfiguracoes = class(TForm)
gpbArquivos: TGroupBox;
cklFileTypes: TCheckListBox;
gbOpcoes: TGroupBox;
Label1: TLabel;
edtHandBreakPath: TEdit;
btnOpenCLI: TButton;
btnHandBreakHelp: TButton;
edtHandBreakParams: TLabeledEdit;
btnExtraFlagsHelp: TButton;
GroupBox1: TGroupBox;
cbPreset: TComboBox;
GroupBox2: TGroupBox;
cbSemLegenda: TComboBox;
GroupBox3: TGroupBox;
spinProcessos: TSpinEdit;
GroupBox4: TGroupBox;
cbSoftware: TComboBox;
GroupBox5: TGroupBox;
Label2: TLabel;
edtFFMpegPath: TEdit;
Button1: TButton;
Button2: TButton;
edtFFMpegParams: TLabeledEdit;
Button3: TButton;
hbDialog: TOpenDialog;
ffmpegDialog: TOpenDialog;
memParams: TMemo;
btnOK: TPngBitBtn;
VisualSwitch: TToggleSwitch;
btnRestore: TPngBitBtn;
gbVisProcessos: TGroupBox;
cbVisualizar: TComboBox;
procedure Button1Click(Sender: TObject);
procedure btnOpenCLIClick(Sender: TObject);
procedure btnExtraFlagsHelpClick(Sender: TObject);
procedure btnHandBreakHelpClick(Sender: TObject);
procedure btnOKClick(Sender: TObject);
procedure SetStyle();
procedure VisualSwitchClick(Sender: TObject);
procedure LoadIni();
procedure SaveIni();
procedure btnRestoreClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure ApplyConfig;
procedure CheckSoftwareExists;
procedure FormCreate(Sender: TObject);
procedure cbSoftwareChange(Sender: TObject);
private
{ Private declarations }
public
Loaded: Boolean;
{ Public declarations }
end;
var
frmConfiguracoes: TfrmConfiguracoes;
implementation
{$R *.dfm}
uses untPrincipal;
procedure TfrmConfiguracoes.ApplyConfig;
begin
with frmPrincipal do begin
if cbSoftware.ItemIndex = 0 then begin
CLIPath := edtHandBreakPath.Text;
BaseParams := edtHandBreakParams.Text;
end else begin
CLIPath := edtFFmpegPath.Text;
BaseParams := edtFFMpegParams.Text;
end;
MaxProcesses := spinProcessos.Value;
NoSubtitle := cbSemLegenda.ItemIndex;
Preset := cbPreset.Items[cbPreset.ItemIndex];
Software := cbSoftware.ItemIndex;
VisualizarProcessos := (cbVisualizar.ItemIndex = 1);
end;
end;
procedure TfrmConfiguracoes.btnExtraFlagsHelpClick(Sender: TObject);
begin
ShellExecute(0, 'open', PChar('https://handbrake.fr/docs/en/latest/cli/command-line-reference.html'), nil, nil, SW_SHOWNORMAL);
end;
procedure TfrmConfiguracoes.btnHandBreakHelpClick(Sender: TObject);
begin
ShellExecute(0, 'open', PChar('https://handbrake.fr/downloads2.php'), nil, nil, SW_SHOWNORMAL);
end;
procedure TfrmConfiguracoes.btnOKClick(Sender: TObject);
begin
SaveIni;
ApplyConfig;
Close;
end;
procedure TfrmConfiguracoes.btnOpenCLIClick(Sender: TObject);
begin
if hbDialog.Execute then
edtHandBreakPath.Text := hbDialog.FileName;
end;
procedure TfrmConfiguracoes.Button1Click(Sender: TObject);
begin
if ffmpegDialog.Execute then
edtFFmpegPath.Text := ffmpegDialog.FileName;
end;
procedure TfrmConfiguracoes.Button2Click(Sender: TObject);
begin
ShellExecute(0, 'open', PChar('https://github.com/BtbN/FFmpeg-Builds/releases'), nil, nil, SW_SHOWNORMAL);
end;
procedure TfrmConfiguracoes.Button3Click(Sender: TObject);
begin
ShellExecute(0, 'open', PChar('https://ffmpeg.org/ffmpeg.html'), nil, nil, SW_SHOWNORMAL);
end;
procedure TfrmConfiguracoes.cbSoftwareChange(Sender: TObject);
begin
cbPreset.Enabled := (cbSoftware.ItemIndex = 0);
end;
procedure TfrmConfiguracoes.CheckSoftwareExists;
begin
if cbSoftware.ItemIndex = 0 then
if not FileExists(edtHandBreakPath.Text) then
edtHandBreakPath.Text := '';
if cbSoftware.ItemIndex = 1 then
if not FileExists(edtFFMpegPath.Text) then
edtFFMpegPath.Text := '';
end;
procedure TfrmConfiguracoes.FormCreate(Sender: TObject);
begin
Loaded := False;
LoadIni;
ApplyConfig;
frmPrincipal.CheckConfig();
end;
procedure TfrmConfiguracoes.LoadIni;
var
Ini: TIniFile;
i: Integer;
begin
Ini := TIniFile.Create( ChangeFileExt( Application.ExeName, '.ini' ) );
try
for i := 0 to cklFileTypes.Count-1 do
cklFileTypes.Checked[i] := Ini.ReadBool('FileTypes', cklFileTypes.Items[i], True);
cbPreset.ItemIndex := Ini.ReadInteger('Opções', 'Preset', 5);
cbSemLegenda.ItemIndex := Ini.ReadInteger('Opções', 'SemLegendas', 0);
cbSoftware.ItemIndex := Ini.ReadInteger('Opções', 'Software', 0);
cbPreset.Enabled := (cbSoftware.ItemIndex = 0);
spinProcessos.Value := Ini.ReadInteger('Opções', 'MaximoProcessos', 4);
edtHandBreakPath.Text := Ini.ReadString('HandBreak', 'Path', ExtractFilePath(Application.ExeName) + 'HandBrakeCLI.exe');
edtHandBreakParams.Text := Ini.ReadString('HandBreak', 'Params', '-i "#inputfile#" -Z "#preset#" --srt-codeset utf-8 --srt-file "#subtitlefile#" --srt-burn "1" -o "#outputfile#"');
edtFFMpegPath.Text := Ini.ReadString('FFMPEG', 'Path', ExtractFilePath(Application.ExeName) + 'ffmpeg.exe');
edtFFMpegParams.Text := Ini.ReadString('FFMPEG', 'Params', '-i "#inputfile#" -c:v libx264 -crf 20 -movflags +faststart -vf subtitles="#subtitlefile#" -c:a aac -b:a 160k -y "#outputfile#"');
cbVisualizar.ItemIndex := Ini.ReadInteger('Opções', 'VisualizarP', 0);
if Ini.ReadString('Opções', 'Visual', 'Windows') = 'Windows' then
VisualSwitch.State := tssOff
else
VisualSwitch.State := tssOn;
Loaded:= True;
finally
Ini.Free;
end;
end;
procedure TfrmConfiguracoes.btnRestoreClick(Sender: TObject);
begin
cbPreset.ItemIndex := 5;
cbSemLegenda.ItemIndex := 0;
cbSoftware.ItemIndex := 0;
spinProcessos.Value := 4;
edtHandBreakPath.Text := '';
edtHandBreakParams.Text := '-i "#inputfile#" -Z "#preset#" --srt-codeset utf-8 --srt-file "#subtitlefile#" --srt-burn "1" -o "#outputfile#"';
edtFFMpegPath.Text := '';
edtFFMpegParams.Text := '-i "#inputfile#" -c:v libx264 -crf 20 -movflags +faststart -vf subtitles="#subtitlefile#" -c:a aac -b:a 160k -y "#outputfile#"';
end;
procedure TfrmConfiguracoes.SaveIni;
var
Ini: TIniFile;
i: Integer;
begin
Ini := TIniFile.Create( ChangeFileExt( Application.ExeName, '.ini' ) );
try
for i := 0 to cklFileTypes.Count-1 do
Ini.WriteBool('FileTypes', cklFileTypes.Items[i], cklFileTypes.Checked[i]);
Ini.WriteInteger('Opções', 'Preset', cbPreset.ItemIndex);
Ini.WriteInteger('Opções', 'SemLegendas', cbSemLegenda.ItemIndex);
Ini.WriteInteger('Opções', 'Software', cbSoftware.ItemIndex);
Ini.WriteInteger('Opções', 'MaximoProcessos', spinProcessos.Value);
Ini.WriteInteger('Opções', 'VisualizarP', cbVisualizar.ItemIndex);
Ini.WriteString('HandBreak', 'Path', edtHandBreakPath.Text);
Ini.WriteString('HandBreak', 'Params', edtHandBreakParams.Text);
Ini.WriteString('FFMPEG', 'Path', edtFFMpegPath.Text);
Ini.WriteString('FFMPEG', 'Params', edtFFMpegParams.Text);
if VisualSwitch.State = tssOff then
Ini.WriteString('Opções', 'Visual', 'Windows')
else
Ini.WriteString('Opções', 'Visual', 'Onyx Blue');
finally
Ini.Free;
end;
end;
procedure TfrmConfiguracoes.SetStyle;
begin
SaveIni;
ShellExecute(Handle, nil, PChar(Application.ExeName), nil, nil, SW_SHOWNORMAL);
Application.Terminate;
end;
procedure TfrmConfiguracoes.VisualSwitchClick(Sender: TObject);
begin
if Loaded then
SetStyle;
end;
end.