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
|
unit UCatCovers;
/////////////////////////////////////////////////////////////////////////
// UCatCovers by Whiteshark //
// Class for listing and managing the Category Covers //
/////////////////////////////////////////////////////////////////////////
interface
uses UIni;
type
TCatCovers = class
protected
cNames: array [low(ISorting)..high(ISorting)] of array of string;
cFiles: array [low(ISorting)..high(ISorting)] of array of string;
public
constructor Create;
procedure Load; //Load Cover aus Cover.ini and Cover Folder
procedure Add(Sorting: integer; Name, Filename: string); //Add a Cover
function CoverExists(Sorting: integer; Name: string): boolean; //Returns True when a cover with the given Name exists
function GetCover(Sorting: integer; Name: string): string; //Returns the Filename of a Cover
end;
var
CatCovers: TCatCovers;
implementation
uses IniFiles,
SysUtils,
Classes,
// UFiles,
UMain,
ULog;
constructor TCatCovers.Create;
begin
Load;
end;
//Load Cover aus Cover.ini and Cover Folder
procedure TCatCovers.Load;
var
Ini: TMemIniFile;
SR: TSearchRec;
List: TStringlist;
I, J: Integer;
Name, Filename, Temp: string;
begin
try
Ini := TMemIniFile.Create(CoversPath + 'covers.ini');
List := TStringlist.Create;
//Add every Cover in Covers Ini for Every Sorting option
for I := low(ISorting) to high(ISorting) do
begin
Ini.ReadSection(ISorting[I], List);
for J := 0 to List.Count - 1 do
Add(I, List.Strings[J], CoversPath + Ini.ReadString(ISorting[I], List.Strings[J], 'NoCover.jpg'));
end;
finally
Ini.Free;
List.Free;
end;
try
//Add Covers from Folder
if (FindFirst (CoversPath + '*.jpg', faAnyFile, SR) = 0) then
repeat
//Add Cover if it doesn't exist for every Section
Name := SR.Name;
Filename := CoversPath + Name;
Delete (Name, length(Name) - 3, 4);
for I := low(ISorting) to high(ISorting) do
begin
Temp := Name;
if ((I = sTitle) or (I = sTitle2)) and (Pos ('Title', Temp) <> 0) then
Delete (Temp, Pos ('Title', Temp), 5)
else if (I = sArtist) or (I = sArtist2) and (Pos ('Artist', Temp) <> 0) then
Delete (Temp, Pos ('Artist', Temp), 6);
if not CoverExists(I, Temp) then
Add (I, Temp, Filename);
end;
until FindNext (SR) <> 0;
finally
FindClose (SR);
end;
end;
//Add a Cover
procedure TCatCovers.Add(Sorting: integer; Name, Filename: string);
begin
if FileExists (Filename) then //If Exists -> Add
begin
SetLength (CNames[Sorting], Length(CNames[Sorting]) + 1);
SetLength (CFiles[Sorting], Length(CNames[Sorting]) + 1);
CNames[Sorting][high(cNames[Sorting])] := Uppercase(Name);
CFiles[Sorting][high(cNames[Sorting])] := FileName;
end;
end;
//Returns True when a cover with the given Name exists
function TCatCovers.CoverExists(Sorting: integer; Name: string): boolean;
var
I: Integer;
begin
Result := False;
Name := Uppercase(Name); //Case Insensitiv
for I := low(cNames[Sorting]) to high(cNames[Sorting]) do
begin
if (cNames[Sorting][I] = Name) then //Found Name
begin
Result := true;
break; //Break For Loop
end;
end;
end;
//Returns the Filename of a Cover
function TCatCovers.GetCover(Sorting: integer; Name: string): string;
var
I: Integer;
begin
Result := '';
Name := Uppercase(Name);
for I := low(cNames[Sorting]) to high(cNames[Sorting]) do
begin
if cNames[Sorting][I] = Name then
begin
Result := cFiles[Sorting][I];
Break;
end;
end;
//No Cover
if (Result = '') AND (FileExists(CoversPath + 'NoCover.jpg')) then
Result := CoversPath + 'NoCover.jpg';
end;
end.
|