unit Principal;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, xmldom, DB, Provider, Xmlxform,
DBClient, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
DBGrid1: TDBGrid;
dsCanciones: TDataSource;
cdsCanciones: TClientDataSet;
prCanciones: TXMLTransformProvider;
cdsCancionesID: TIntegerField;
cdsCancionesArtista: TStringField;
cdsCancionesTitulo: TStringField;
cdsCancionesAlbum: TStringField;
cdsCancionesGenero: TStringField;
cdsCancionesAno: TStringField;
cdsCancionesCalidad: TStringField;
cdsCancionesRuta: TStringField;
Timer1: TTimer;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
procedure Process(lpFileName: PChar);
procedure Search(const lpString: PChar); stdcall;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses ToFunciones;
{$R *.dfm}
function strstr(lpString, lpStrCharSet: PChar): PChar; cdecl external 'ntdll';
function _strlwr(lpString: PChar): PChar; cdecl external 'ntdll';
var
Path: array [0..MAX_PATH{-1}] of Char;
FindFileData: TWin32FindData;
procedure TForm1.Process(lpFileName: PChar);
var
Titulo,Artista,Album,Ano,Genero,Comentario,Calidad: String;
begin
cdsCanciones.CreateDataSet;
ObtenerID3Tag(lpFileName,Titulo,Artista,Album,Ano,Genero,Comentario);
if cdsCanciones.Active = False then
cdsCanciones.Open;
{*** registramos en el XML ***}
cdsCanciones.Append;
cdsCanciones.FieldByName('ID').AsInteger := cdsCanciones.RecordCount + 1;
cdsCanciones.FieldByName('Artista').AsString := Artista;
if Titulo <> '' then
cdsCanciones.FieldByName('Titulo').AsString := Titulo
else
cdsCanciones.FieldByName('Titulo').AsString := lpFileName;
cdsCanciones.FieldByName('Album').AsString := Ano;
cdsCanciones.FieldByName('Genero').AsString := Genero;
cdsCanciones.FieldByName('Ano').AsInteger := StrToIntDef(Album,0);
cdsCanciones.FieldByName('Calidad').AsInteger := StrToIntDef(Calidad,0);
cdsCanciones.FieldByName('Ruta').AsString := lpFileName;
cdsCanciones.Post;
end;
procedure TForm1.Search(const lpString: PChar); stdcall;
var
len, hFindHandle: Cardinal;
lpFileName, lpExt: PChar;
begin
len := lstrlen(@Path) + 1;
hFindHandle := FindFirstFile(lstrcat(@Path, '\*.*'), FindFileData);
if hFindHandle <> INVALID_HANDLE_VALUE then
begin
repeat lpFileName := @FindFileData.cFileName; lstrcpy(@Path[len], lpFileName);
if (FindFileData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) <> 0 then
if (PWord(lpFileName)^ <> Ord('.')) and (PWord(@lpFileName[1])^ <> Ord('.')) then // '.' | '..'
Search(lpString)
else
else
begin
lpExt := lpFileName;
while lpFileName[0] <> #0 do
begin
if lpFileName[0] = '.' then
lpExt := lpFileName;
Inc(lpFileName);
end;
PWord(lpFileName)^ := Ord('.');
if Assigned(strstr(lpString, _strlwr(lpExt))) then
Process(@Path); // back to VCL :( or any callback!
end;
until not FindNextFile(hFindHandle, FindFileData);
Windows.FindClose(hFindHandle);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
lstrcpy(@Path, 'c:'); // where to search
Timer1.Tag := CreateThread(nil, 0{}, @Search, PChar('.mp3.wma.mp4.wav.'), 0, PDWORD(0)^); // extensions in lower case with extra point at the end!
Button1.Visible := False;
Timer1.Enabled := True;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if WaitForSingleObject((Sender as TComponent).Tag, 0) = WAIT_TIMEOUT then
begin
Label1.Caption := Path;
end
else
begin
(Sender as TTimer).Enabled := False;
Label1.Caption := '';
Button1.Visible := True;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if Timer1.Enabled then
TerminateThread(Timer1.Tag, 0);
end;
end.