From fcccc8d1476f7e4fb8877a4ac9b79e4c33b06811 Mon Sep 17 00:00:00 2001 From: DarkWyrm Date: Tue, 19 Jul 2005 13:29:54 +0000 Subject: [PATCH] Shouldn't be any more crashes when CDDB lookup fails Lookup now handles inexact matches CDAudioDevice now detects all available CD drives Fixed a minor bug in updating the track list when changing CDs CDDB content files are now stored in R5's location - /boot/home/cd git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13764 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/cdplayer/CDAudioDevice.cpp | 10 ++++-- src/apps/cdplayer/CDDBSupport.cpp | 56 ++++++++++++++++++++--------- src/apps/cdplayer/CDEngine.cpp | 2 +- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/apps/cdplayer/CDAudioDevice.cpp b/src/apps/cdplayer/CDAudioDevice.cpp index eaf5e6d072..9aea159e44 100644 --- a/src/apps/cdplayer/CDAudioDevice.cpp +++ b/src/apps/cdplayer/CDAudioDevice.cpp @@ -331,11 +331,15 @@ int32 CDAudioDevice::FindDrives(const char *path) // ignore floppy -- it is not silent if(strcmp(e.name, "floppy") == 0) continue; + else + if(strcmp(e.name, "ata") == 0) + continue; - int32 count = FindDrives(name); + // Note that if we check for the count here, we could + // just search for one drive. However, we want to find *all* drives + // that are available, so we keep searching even if we've found one + FindDrives(name); - if(count > 0) - return count; } else { diff --git a/src/apps/cdplayer/CDDBSupport.cpp b/src/apps/cdplayer/CDDBSupport.cpp index 07854bc5e2..829abdff1b 100644 --- a/src/apps/cdplayer/CDDBSupport.cpp +++ b/src/apps/cdplayer/CDDBSupport.cpp @@ -24,7 +24,6 @@ #include #include - // #pragma mark - // some glue @@ -349,10 +348,7 @@ CDDBQuery::ReadFromServer(BDataIO *stream) // Format the query BString query; query << "cddb query " << discIDStr << ' ' << numTracks << ' ' - // Add frame offsets - << frameOffsetString << ' ' - // Finish it off with the total CD length. - << discLength << '\n'; + << frameOffsetString << ' ' << discLength << '\n'; if (log) printf(">%s", query.String()); @@ -362,30 +358,56 @@ CDDBQuery::ReadFromServer(BDataIO *stream) BString tmp; ReadLine(tmp); + + BString category; + BString queryDiscID(discIDStr); + if(tmp.FindFirst("200") != 0) { if(tmp.FindFirst("211") == 0) { - while(tmp.CountChars() > 0) - { - printf("%s\n",tmp.String()); - ReadLine(tmp); - } + // A 211 means that the query was not exact. To make sure that we don't + // have a problem with this in the future, we will choose the first entry that + // the server returns. This may or may not be wise, but in my experience, the first + // one has been the right one. + + ReadLine(tmp); + + // Get the category from the what the server returned + GetToken(tmp.String(), category); + + // Now we will get the disc ID for the CD. We will need this when we query for + // the track name list. If we send the track name query with the real discID, nothing + // will be returned. However, if we send the one from the entry, we'll get the names + // and we can take these names attach them to the disc that we have. + GetToken(tmp.String() + category.CountChars(),queryDiscID); + + // This is to suck up any more search results that the server sends us. + BString throwaway; + ReadLine(throwaway); + while(throwaway.ByteAt(0) != '.') + ReadLine(throwaway); } else + { printf("Error: %s\n",tmp.String()); - return; + return; + } } - BString category; - GetToken(tmp.String() + 3, category); + else + { + GetToken(tmp.String() + 3, category); + } + if (!category.Length()) category = "misc"; query = ""; - query << "cddb read " << category << ' ' << discIDStr << '\n' ; + query << "cddb read " << category << ' ' << queryDiscID << '\n' ; ThrowIfNotSize( socket.Send(query.String(), query.Length()) ); - for (;;) { + for (;;) + { BString tmp; ReadLine(tmp); tmp += '\n'; @@ -547,8 +569,8 @@ CDDBQuery::FindOrCreateContentFileForDisk(BFile *file, entry_ref *fileRef, int32 } BPath path; - ThrowOnError( find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) ); - path.Append("CDContentFiles"); + ThrowOnError( find_directory(B_USER_DIRECTORY, &path, true) ); + path.Append("cd"); ThrowOnError( create_directory(path.Path(), 0755) ); BDirectory dir(path.Path()); diff --git a/src/apps/cdplayer/CDEngine.cpp b/src/apps/cdplayer/CDEngine.cpp index af327d3655..0e3dafc88e 100644 --- a/src/apps/cdplayer/CDEngine.cpp +++ b/src/apps/cdplayer/CDEngine.cpp @@ -138,7 +138,7 @@ TrackState::UpdateState() int32 TrackState::GetNumTracks() const { - return sCDDevice.CountTracks(); + return sCDDevice.CountTracks()+1; } bool