-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMainUnit.pas
More file actions
186 lines (153 loc) · 5.07 KB
/
MainUnit.pas
File metadata and controls
186 lines (153 loc) · 5.07 KB
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
unit MainUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, FolderBrowser, StdCtrls, TntStdCtrls, ExtCtrls, TntExtCtrls,
ComCtrls, tntclasses, tntsysutils, XPMan;
type
TMainForm = class(TForm)
FolderList: TTntListBox;
AddFolderButton: TTntButton;
FolderBrowser: TFolderBrowser;
ClearButton: TTntButton;
LabeOutput: TTntLabel;
OutputFormatCB: TTntComboBox;
HashButton: TTntButton;
LabelTip: TTntLabel;
ProgressBar: TProgressBar;
PanelStatus: TTntPanel;
XPManifest: TXPManifest;
procedure AddFolderButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ClearButtonClick(Sender: TObject);
procedure HashButtonClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
uses
misc_utils_unit, MediaInfoDLL;
var
MediaInfoLoaded : Boolean = False;
procedure TMainForm.AddFolderButtonClick(Sender: TObject);
var
S : WideString;
begin
If FolderBrowser.Execute('') = True then
Begin
S := FolderBrowser.Directory;
If S[Length(S)] <> '\' then S := S+'\';
FolderList.Items.Add(S);
End;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
LabelTip.Caption := 'TIPS:'#10'1. Folders are scanned recursively.'#10#10'2. Each listed folder is designated as a root folder where an output file is saved.';
PanelStatus.Caption := HashStatus[HashIdle];
MediaInfoLoaded := MediaInfoDLL_Load('MediaInfo.dll');
If MediaInfoLoaded = True then
Begin
MediaInfo_Option(0, 'Internet', 'No');
MediaInfo_Option(0, 'ParseSpeed', '0');
MediaInfo_Option(0, 'ReadByHuman', '0');
End;
end;
procedure TMainForm.ClearButtonClick(Sender: TObject);
begin
FolderList.Clear;
PanelStatus.Caption := HashStatus[HashIdle];
ProgressBar.Position := 0;
end;
procedure TMainForm.HashButtonClick(Sender: TObject);
var
I,I1 : Integer;
fList : TTNTStringList;
oList : TList;
sPath : WideString;
fHash1 : Int64;
fHash2 : Int64;
nEntry : PHashRecord;
begin
If FolderList.Count > 0 then
Begin
HashButton.Enabled := False;
fList := TTNTStringList.Create;
oList := TList.Create;
For I := 0 to FolderList.Count-1 do
Begin
ProgressBar.Position := 0;
PanelStatus.Caption := HashStatus[HashScanning]+' '+FolderList.Items[I];
Application.ProcessMessages;
ScanForAudioFiles(FolderList.Items[I],fList);
If fList.Count > 0 then
Begin
ProgressBar.Max := fList.Count-1;
PanelStatus.Caption := HashStatus[HashProcessing]+' '+FolderList.Items[I];
Application.ProcessMessages;
For I1 := 0 to fList.Count-1 do
Begin
ProgressBar.Position := I1;
Application.ProcessMessages;
New(nEntry);
ResetHashRecord(nEntry);
// Calculate Hashes
CalcGabestHash(fList[I1],nEntry^.hrHash1,nEntry^.hrHash2);
// Validate successful hashing
If nEntry^.hrHash1 <> 0 then
Begin
// Get File Path
nEntry^.hrFilePath := WideExtractFilePath(fList[I1]);
// Get File Name
nEntry^.hrFileName := WideExtractFileName(fList[I1]);
// Get File Size
nEntry^.hrFileSize := GetFileSize(fList[I1]);
// Get file Extension
nEntry^.hrFileExt := Lowercase(ExtractFileExt(nEntry^.hrFileName));
If Length(nEntry^.hrFileExt) > 0 then If nEntry^.hrFileExt[1] = '.' then Delete(nEntry^.hrFileExt,1,1);
// Get TAG/ID3 data
If MediaInfoLoaded = True then MediaInfo_ProccessTAGdata(fList[I1],nEntry);
oList.Add(nEntry);
End
Else Dispose(nEntry);
End;
SaveHashOutput(oList,FolderList.Items[I],OutputFormatCB.ItemIndex);
ProgressBar.Position := ProgressBar.Max;
For I1 := 0 to oList.Count-1 do Dispose(PHashRecord(oList[I1]));
oList.Clear;
fList.Clear;
End;
End;
oList.Free;
fList.Free;
HashButton.Enabled := True;
End;
PanelStatus.Caption := HashStatus[HashComplete];
ProgressBar.Position := 0;
end;
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
If MediaInfoLoaded = True then
Begin
MediaInfoDLL_UnLoad;
End;
end;
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := HashButton.Enabled;
end;
procedure TMainForm.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
SendMessage(MainForm.Handle,WM_SYSCOMMAND,$F012,0);
end;
end.