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
|
unit Umainform;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, UDataBase, ShellAPI, ShlObj, USongs;
type
Tmainform = class(TForm)
Label1: TLabel;
lFolder: TLabel;
bFLoad: TButton;
Label2: TLabel;
lDatabase: TLabel;
bDLoad: TButton;
lDatabase2: TLabel;
lFolder2: TLabel;
bToDB: TButton;
bFromDB: TButton;
pProgress: TProgressBar;
oDatabase: TOpenDialog;
lStatus: TLabel;
procedure FormCreate(Sender: TObject);
procedure bDLoadClick(Sender: TObject);
function BrowseDialog (const Title: string; const Flag: integer): string;
procedure bFLoadClick(Sender: TObject);
procedure UpdateLoadedSongs(Path: String; Count: integer);
procedure bToDBClick(Sender: TObject);
procedure bFromDBClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
mainform: Tmainform;
DBLoaded: Boolean;
SFLoaded: Boolean;
implementation
uses UScores;
{$R *.dfm}
function Tmainform.BrowseDialog
(const Title: string; const Flag: integer): string;
var
lpItemID : PItemIDList;
BrowseInfo : TBrowseInfo;
DisplayName : array[0..MAX_PATH] of char;
TempPath : array[0..MAX_PATH] of char;
begin
Result:='';
FillChar(BrowseInfo, sizeof(TBrowseInfo), #0);
with BrowseInfo do begin
hwndOwner := Application.Handle;
pszDisplayName := @DisplayName;
lpszTitle := PChar(Title);
ulFlags := Flag;
end;
lpItemID := SHBrowseForFolder(BrowseInfo);
if lpItemId <> nil then begin
SHGetPathFromIDList(lpItemID, TempPath);
Result := TempPath;
GlobalFreePtr(lpItemID);
end;
end;
procedure Tmainform.FormCreate(Sender: TObject);
begin
Database := TDataBaseSystem.Create;
Songs := TSongs.Create;
lStatus.Caption := 'Welcome to USD Score Converter';
lFolder2.Caption := 'No Songs loaded';
lFolder.Caption := '';
lDataBase2.Caption := 'No Database loaded';
lDataBase.Caption := '';
end;
procedure Tmainform.bDLoadClick(Sender: TObject);
begin
if oDatabase.Execute then
begin
try
Database.Init(oDataBase.FileName);
lDataBase2.Caption := 'Database loaded';
lDataBase.Caption := oDataBase.FileName;
DBLoaded := True;
except
lDataBase2.Caption := 'No Database loaded';
lDataBase.Caption := '';
DBLoaded := False;
end;
end;
bToDB.Enabled := DBLoaded and SFLoaded;
bFromDB.Enabled := bToDB.Enabled;
end;
procedure Tmainform.bFLoadClick(Sender: TObject);
var
Path: String;
begin
Path := BrowseDialog('Select UltraStar SongFolder', BIF_RETURNONLYFSDIRS);
if Path <> '' then
begin
SetLength(Songs.Song, 0);
try
Songs.BrowseDir(Path + '\');
lFolder2.Caption := Inttostr(Length(Songs.Song)) + ' Songs loaded';
lFolder.Caption := Path;
SFLoaded := True;
except
lFolder2.Caption := 'No Songs loaded';
lFolder.Caption := '';
SFLoaded := False;
end;
end;
bToDB.Enabled := DBLoaded and SFLoaded;
bFromDB.Enabled := bToDB.Enabled;
end;
procedure Tmainform.UpdateLoadedSongs(Path: String; Count: integer);
begin
lFolder2.Caption := Inttostr(Count) + ' Songs loaded';
lFolder.Caption := Path;
Application.ProcessMessages;
end;
procedure Tmainform.bToDBClick(Sender: TObject);
var
I, J, K: Integer;
LastI: integer;
begin
if (Messagebox(0, PChar('If the same directory is added more than one time the Score-File will be useless. Cont�nue ?'), PChar(Mainform.Caption), MB_ICONWARNING or MB_YESNO) = IDYes) then
begin
pProgress.Max := high(Songs.Song);
pProgress.Position := 0;
// Go through all Songs
For I := 0 to high(Songs.Song) do
begin
try
//Read Scores from .SCO File
ReadScore (Songs.Song[I]);
//Go from Easy to Difficult
For J := 0 to 2 do
begin
//Go through all Score Entrys with Difficulty J
For K := 0 to high(Songs.Song[I].Score[J]) do
begin
//Add to DataBase
DataBase.AddScore(Songs.Song[I], J, Songs.Song[I].Score[J][K].Name, Songs.Song[I].Score[J][K].Score);
end;
end;
except
showmessage ('Error Converting Score From Song: ' + Songs.Song[I].Path + Songs.Song[I].FileName);
end;
//Update ProgressBar
J := I div 30;
if (LastI <> J) then
begin
LastI := J;
pProgress.Position := I;
lStatus.Caption := 'Adding Songscore: ' + Songs.Song[I].Artist + ' - ' + Songs.Song[I].Title;
Application.ProcessMessages;
end;
end;
pProgress.Position := pProgress.Max;
lStatus.Caption := 'Finished';
end;
end;
procedure Tmainform.bFromDBClick(Sender: TObject);
var
I, J: Integer;
LastI: integer;
anyScoreinthere: boolean;
begin
if (Messagebox(0, PChar('All Score Entrys in the Song Directory having an equivalent will be Overwritten. Cont�nue ?'), PChar(Mainform.Caption), MB_ICONWARNING or MB_YESNO) = IDYes) then
begin
pProgress.Max := high(Songs.Song);
pProgress.Position := 0;
// Go through all Songs
For I := 0 to high(Songs.Song) do
begin
try
//Not Write ScoreFile when there are no Scores for this File
anyScoreinthere := false;
//Read Scores from DB File
Database.ReadScore (Songs.Song[I]);
//Go from Easy to Difficult
For J := 0 to 2 do
begin
anyScoreinthere := anyScoreinthere or (Length(Songs.Song[I].Score[J]) > 0);
end;
if AnyScoreinThere then
WriteScore(Songs.Song[I]);
except
showmessage ('Error Converting Score From Song: ' + Songs.Song[I].Path + Songs.Song[I].FileName);
end;
//Update ProgressBar
J := I div 30;
if (LastI <> J) then
begin
LastI := J;
pProgress.Position := I;
lStatus.Caption := 'Writing ScoreFile: ' + Songs.Song[I].Artist + ' - ' + Songs.Song[I].Title;
Application.ProcessMessages;
end;
end;
pProgress.Position := pProgress.Max;
lStatus.Caption := 'Finished';
end;
end;
end.
|