-
Notifications
You must be signed in to change notification settings - Fork 1
/
frmMain.pas
121 lines (106 loc) · 3.29 KB
/
frmMain.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
unit frmMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, IniFiles, Vcl.Mask, JvExMask,
JvToolEdit, Vcl.ComCtrls;
type
TformMain = class(TForm)
edWorkDir: TJvDirectoryEdit;
edMkvEditDir: TJvDirectoryEdit;
lblWorkDir: TLabel;
lblMkvEditPath: TLabel;
btnStart: TButton;
objStatusBar: TStatusBar;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure edWorkDirChange(Sender: TObject);
procedure edMkvEditDirChange(Sender: TObject);
procedure btnStartClick(Sender: TObject);
private
{ Private declarations }
szBasePath, szWorkPath, szMkvEditPath: String;
iniSource: TIniFile;
procedure ValidateMkvEdit;
public
{ Public declarations }
end;
var
formMain: TformMain;
implementation
uses ShellAPI;
{$R *.dfm}
procedure TformMain.ValidateMkvEdit;
begin
if not FileExists(szMkvEditPath + '\mkvpropedit.exe')
then
begin
btnStart.Enabled := false;
edMkvEditDir.SetFocus();
objStatusBar.SimpleText := 'mkvpropedit.exe not found'
end
else
begin
btnStart.Enabled := true;
btnStart.SetFocus();
objStatusBar.SimpleText := 'Ready'
end;
end;
procedure TformMain.btnStartClick(Sender: TObject);
var
listFiles: TStrings;
SRec: TSearchRec;
i, iErrors: Integer;
begin
iErrors := 0;
listFiles := TStringList.Create();
try
if FindFirst(szWorkPath + '\*.mkv', faNormal, SRec) = 0 then
begin
repeat
listFiles.Add(SRec.Name);
until FindNext(SRec) <> 0;
FindClose(SRec);
end;
if listFiles.Count > 0
then
begin
for i := 0 to listFiles.Count-1 do
begin
objStatusBar.SimpleText := 'Processing ' + listFiles[i];
if ShellExecute(Handle, 'open', PChar(szMkvEditPath + '\mkvpropedit.exe'), PChar('"' + listFiles[i] + '"' + ' --edit info --set "title=' + Copy(listFiles[i], 0, LastDelimiter('.',listFiles[i]) - 1) + '"'), PChar(szWorkPath), SW_HIDE) < 33 then Inc(iErrors);
end;
objStatusBar.SimpleText := IntToStr(listFiles.Count) + ' file(s) processed - ' + IntToStr(iErrors) + ' error(s)';
end
else objStatusBar.SimpleText := 'No files found';
finally
listFiles.Free();
end;
end;
procedure TformMain.edMkvEditDirChange(Sender: TObject);
begin
szMkvEditPath := edMkvEditDir.Directory;
iniSource.WriteString('Paths', 'mkvtoolnix', szMkvEditPath);
ValidateMkvEdit();
end;
procedure TformMain.edWorkDirChange(Sender: TObject);
begin
szWorkPath := edWorkDir.Directory;
iniSource.WriteString('Paths', 'workdir', szWorkPath);
end;
procedure TformMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
iniSource.UpdateFile();
iniSource.Free();
end;
procedure TformMain.FormShow(Sender: TObject);
begin
szBasePath := ExtractFileDir(ParamStr(0));
iniSource := TIniFile.Create(szBasePath + '\mkvtitle.ini');
szWorkPath := iniSource.ReadString('Paths', 'workdir', szBasePath);
szMkvEditPath := iniSource.ReadString('Paths', 'mkvtoolnix', '');
edWorkDir.Directory := szWorkPath;
edMkvEditDir.Directory := szMkvEditPath;
ValidateMkvEdit();
end;
end.