Цитата:
Сообщение от Alegun
Или вы хотите чтоб кто-то все за вас собрал - кому только это надо даже догадок нет
|
Я же писал "Программа рабочая, но, написана она мною очень криво.".
Мне бы хотелось бы получить советы, что и где исправить , изменить-
Код:
procedure TForm1.GetAllFiles(Path: string);
var
sRec: TSearchRec;
isFound: boolean;
begin
Panel1.Caption := 'Создание списка адресов';
isFound := FindFirst( Path + '\*.*', faAnyFile, sRec ) = 0;
while isFound do
begin
if ( sRec.Name <> '.' ) and ( sRec.Name <> '..' ) then
begin
if ( sRec.Attr and faDirectory ) = faDirectory then
GetAllFiles(Path + '\' + sRec.Name);
if CheckFileExt(sRec.Name) then
begin
IdTag.LoadFile(Path + '\' + sRec.Name);
if IdTag.Loaded and IdTag.TagExists and (IdTag.tag.Genre <> '') and (IdTag.tag.Genre <> ' ') then
LbItogGanre.Add(AnsiUpperCase(IdTag.tag.Genre)); //добавляет все найденные на диске жанры
if IdTag.Loaded and IdTag.TagExists then //добавляет имена исполнителей
LBArtist.Add(AnsiUpperCase(IdTag.tag.Artist));
LBAdressTrack.Add(Path + '\' + sRec.Name); //добавляет адреса
end;
Gauge1.MaxValue := Gauge1.Width + LBAdressTrack.Count;
Gauge1.Progress := LBAdressTrack.Count;
end;
isFound := FindNext( sRec ) = 0;
end;
FindClose( sRec );
end;
Код:
procedure TForm1.Button1Click(Sender: TObject);
var
b, n, i : Integer;
st : string;
begin
Button1.Enabled := False;
LBArtist.Clear;
LbNoArt.Clear;
LBAdressTrack.Clear;
lbnotag.Clear;
LbItogGanre.Clear;
LBArtistAlfavit.Clear;
GetAllFiles('E:\Music');
TreeView2.Items.BeginUpdate;
TreeView2.Items.Clear;
Panel1.Caption := 'Создание списка "Исполнители"';
TreeView2.Items.Add(nil,'Исполнители');
for b := 0 to LBArtist.Count - 1 do //извлекаем первые буквы исполнителя
begin // и создаем список
st := LBArtist[b];
LBArtistAlfavit.Add(st[1]);
end;
Gauge1.MaxValue := LBArtist.Count + LBArtistAlfavit.Count + LBAdressTrack.Count;
for b := 0 to LBArtistAlfavit.Count - 1 do //а здесь заполняем treeview
begin
Gauge1.Progress := b;
TreeView2.Items.AddChild(TreeView2.Items[0], LBArtistAlfavit[b]) ;
end;
for b := 0 to LBArtist.Count - 1 do //здесь сравниваем первую букву исполнителя
begin
Gauge1.Progress := LBArtistAlfavit.Count + b;
st := LBArtist[b];
for i := 0 to LBArtistAlfavit.Count - 1 do
if st[1] = LBArtistAlfavit[i] then //и если совпало, добавляем в нужную
TreeView2.Items.AddChild(TreeView2.Items[0].Item[i], LBArtist[b]);
end;
// вот здесь и хотелось бы узнать, можно ли упростить?
for n := 0 to LBAdressTrack.Count - 1 do //здесь бегаем по адресам файлов
begin
Gauge1.Progress := LBArtistAlfavit.Count + LBArtist.Count + n;
IdTag.LoadFile(LBAdressTrack.Strings[n]); //и читаем теги
for b := 0 to TreeView2.Items[0].Count - 1 do
for I := 0 to TreeView2.Items[0].Item[b].Count - 1 do
if IdTag.Loaded and (AnsiUpperCase(IdTag.tag.Artist) = TreeView2.Items[0].Item[b].Item[i].Text) then
TreeView2.Items.AddChild(TreeView2.Items[0].Item[b].Item[i], LBAdressTrack.Strings[n])
else
if not IdTag.Loaded or not idtag.TagExists then
LbNoArt.Add(LBAdressTrack.Strings[n]);
end;
if LbNoArt.Count <> 0 then
begin
Gauge1.MaxValue := LBArtist.Count + LBArtistAlfavit.Count + LBAdressTrack.Count + LbNoArt.Count - 1;
TreeView2.Items.AddChild(TreeView2.Items[0], 'Не определены (Без "Исполнителя")');
for n := 0 to LbNoArt.Count - 1 do
begin
Gauge1.Progress := LBAdressTrack.Count + LBArtist.Count + LBArtistAlfavit.Count + n;
TreeView2.Items.AddChild(TreeView2.Items[0].Item[TreeView2.Items.Item[0].Count-1], LbNoArt.Strings[n]);
end;
end;
TreeView2.Items.EndUpdate;
Gauge1.MaxValue := 0;
Gauge1.Progress := 0;
Panel1.Caption := '';
Button1.Enabled := True;
end;
Если никто не хочет помочь, прошу удалить тему.