bool CMusicLibrary::SaveMedia(CMedia* pMedia) { CSong* pSong = static_cast<CSong*>(pMedia); long ID = pSong->GetID(); // save the song to the device wxString Path = this->GetLibraryPath(); bool OK = true; OK = OK | m_pDevice->AddFolder(cms::ReplaceIllegalPathCharsWithUnderscore(pSong->GetArtist() ), Path); OK = OK | m_pDevice->AddFolder(cms::ReplaceIllegalPathCharsWithUnderscore(pSong->GetAlbum() ), Path); Path << cms::ReplaceIllegalPathCharsWithUnderscore(pSong->GetTitle() ) << "."; Path << CMedia::GetFileTypeStr(pSong->GetFullPath() ); if (!OK) { return false; } if (!m_pDevice->SaveMedia(pSong, Path) ) { return false; } // add song to library database wxString str; if (pSong->GetID() < 0) { str << "INSERT INTO main." << m_pDevice->GetDeviceName() << " (col_Artist,col_Album,col_Title,col_Genre," << "col_Time,col_Track,col_Year,col_Type,col_BitRate,col_SampleRate," << "col_Channels,col_Comment,col_FullPath) VALUES (" << "'" << cms::sqlEscapeQuotes(pSong->GetArtist() ) << "'," << "'" << cms::sqlEscapeQuotes(pSong->GetAlbum() ) << "'," << "'" << cms::sqlEscapeQuotes(pSong->GetTitle() ) << "'," << "'" << cms::sqlEscapeQuotes(pSong->GetGenre() ) << "'," << "'" << pSong->GetTimeString() << "'," << "'" << pSong->GetTrack() << "'," << "'" << pSong->GetYear() << "'," << "'" << pSong->GetType() << "'," << "'" << pSong->GetBitRate() << "'," << "'" << pSong->GetSampleRate() << "'," << "'" << pSong->GetChannels() << "'," << "'" << cms::sqlEscapeQuotes(pSong->GetComment() ) << "'," << "'" << cms::sqlEscapeQuotes(pSong->GetFullPath() ) << "')"; } else { str << "UPDATE main." << m_pDevice->GetDeviceName() << " SET " << "col_Artist=" << cms::sqlEscapeQuotes(pSong->GetArtist() ) << "," << "col_Album=" << cms::sqlEscapeQuotes(pSong->GetAlbum() ) << "," << "col_Title=" << cms::sqlEscapeQuotes(pSong->GetTitle() ) << "," << "col_Genre=" << cms::sqlEscapeQuotes(pSong->GetGenre() ) << "," << "col_Time=" << pSong->GetTimeString() << "," << "col_Track=" << pSong->GetTrack() << "," << "col_Year=" << pSong->GetYear() << "," << "col_Type=" << pSong->GetType() << "," << "col_BitRate=" << pSong->GetBitRate() << "," << "col_SampleRate=" << pSong->GetSampleRate() << "," << "col_Channels=" << pSong->GetChannels() << "," << "col_Comment=" << cms::sqlEscapeQuotes(pSong->GetComment() ) << "," << "col_FullPath=" << cms::sqlEscapeQuotes(pSong->GetFullPath() ) << " WHERE ROWID=" << pSong->GetID(); } if (!m_pDatabase->ProcessStatement(str) ) { return false; } return true; }