diff options
author | mogguh <mogguh@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2008-02-13 19:58:44 +0000 |
---|---|---|
committer | mogguh <mogguh@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2008-02-13 19:58:44 +0000 |
commit | 949fea202f6c963ad6c8a40040e1e9e6f909161b (patch) | |
tree | 9f6f683d203d55e41e5b7483b4038103d471ce76 /ScoreConverter/USongs.pas | |
parent | 1a7da68ae6e1368dae25821b15318bd1d2d9f88e (diff) | |
parent | efe5b06fd5715f550334692d28c2218896b62ce1 (diff) | |
download | usdx-949fea202f6c963ad6c8a40040e1e9e6f909161b.tar.gz usdx-949fea202f6c963ad6c8a40040e1e9e6f909161b.tar.xz usdx-949fea202f6c963ad6c8a40040e1e9e6f909161b.zip |
First multi platform version, works on Linux and Windows
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/1.1@855 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to '')
-rw-r--r-- | ScoreConverter/USongs.pas | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/ScoreConverter/USongs.pas b/ScoreConverter/USongs.pas new file mode 100644 index 00000000..a43ea61e --- /dev/null +++ b/ScoreConverter/USongs.pas @@ -0,0 +1,160 @@ +unit USongs;
+
+interface
+
+type
+ TScore = record
+ Name: string;
+ Score: integer;
+ Length: string;
+ end;
+
+ TSong = record
+ Path: string;
+ FileName: string;
+
+ Title: string;
+ Artist: string;
+
+ Score: array[0..2] of array of TScore;
+ end;
+
+ TSongs = class
+ LastCount: Integer;
+ Song: array of TSong; // array of songs
+
+ function ReadHeader(var rSong: TSong): boolean;
+ procedure BrowseDir(Dir: string); // Browse a dir + subdirs for songfiles
+ end;
+
+ var Songs: TSongs;
+
+implementation
+uses Sysutils, UMainForm, Dialogs;
+
+function TSongs.ReadHeader(var rSong: TSong): boolean;
+var
+ Line, Identifier, Value: String;
+ Temp: word;
+ Done: byte;
+ SongFile: Textfile;
+begin
+ Result := False;
+
+
+ //Open File and set File Pointer to the beginning
+ AssignFile(SongFile, rSong.Path + rSong.FileName);
+ Reset(SongFile);
+
+ //Read Header
+ Result := true;
+
+ //Read first Line
+ ReadLn (SongFile, Line);
+
+ if (Length(Line)<=0) then
+ begin
+ Result := False;
+ Exit;
+ end;
+ Done := 0;
+ //Read Lines while Line starts with #
+ While (Line[1] = '#') do
+ begin
+ Temp := Pos(':', Line);
+
+ //Line has a Seperator-> Headerline
+ if (Temp <> 0) then
+ begin
+ //Read Identifier and Value
+ Identifier := Uppercase(Trim(Copy(Line, 2, Temp - 2))); //Uppercase is for Case Insensitive Checks
+ Value := Trim(Copy(Line, Temp + 1,Length(Line) - Temp));
+
+ //Check the Identifier (If Value is given)
+ if (Length(Value) <> 0) then
+ begin
+
+ //-----------
+ //Required Attributes
+ //-----------
+
+ //Title
+ if (Identifier = 'TITLE') then
+ begin
+ rSong.Title := Value;
+
+ //Add Title Flag to Done
+ Done := Done or 1;
+ end
+
+ //Artist
+ else if (Identifier = 'ARTIST') then
+ begin
+ rSong.Artist := Value;
+
+ //Add Artist Flag to Done
+ Done := Done or 2;
+ end;
+
+ end;
+ end;
+
+ if not EOf(SongFile) then
+ ReadLn (SongFile, Line)
+ else
+ begin
+ Result := False;
+ break;
+ end;
+
+ //End on first empty Line
+ if (Length(Line) = 0) then
+ break;
+ end;
+
+ //Check if all Required Values are given
+ if (Done <> 3) then
+ begin
+ Result := False;
+ end;
+
+ //And Close File
+ CloseFile(SongFile);
+end;
+
+procedure TSongs.BrowseDir(Dir: string);
+var
+ SR: TSearchRec; // for parsing Songs Directory
+ SLen: integer;
+begin
+ if FindFirst(Dir + '*', faDirectory, SR) = 0 then begin
+ repeat
+ if (SR.Name <> '.') and (SR.Name <> '..') then
+ BrowseDir(Dir + Sr.Name + '\');
+ until FindNext(SR) <> 0;
+ end;
+ FindClose(SR);
+
+ if FindFirst(Dir + '*.txt', 0, SR) = 0 then begin
+ repeat
+ SLen := Length(Song);
+ SetLength(Song, SLen + 1);
+
+ Song[SLen].Path := Dir;
+ Song[SLen].FileName := SR.Name;
+
+ if (ReadHeader(Song[SLen]) = false) then SetLength(Song, SLen);
+
+ //update Songs Label
+ if LastCount <> SLen div 30 then
+ begin
+ LastCount := SLen div 30;
+ MainForm.UpdateLoadedSongs(Dir, SLen);
+ end;
+
+ until FindNext(SR) <> 0;
+ end; // if FindFirst
+ FindClose(SR);
+end;
+
+end.
|