void CSaveSlotState::Save() { CGamePlayState* pGamePlay = CGamePlayState::GetInstance(); SetCurrLevel(pGamePlay->GetCurrentLevel()); //save settings ofstream out; char filename[255] = {0}; int nLevel = GetCurrLevel(); sprintf_s(filename, "resource/Game Saves/Slot%d.dat", m_nCurrSaveSlot); out.open(filename, ios_base::out | ios_base::trunc | ios_base::binary); if (out.is_open()) { if (out.good()) out.write(((const char *)&nLevel), 4); out.close(); } }
//mutators void CSaveSlotState::SetCurrLevel(const int nLevel) { CGamePlayState* pGamePlay = CGamePlayState::GetInstance(); m_nCurrLoadedLevel = nLevel; pGamePlay->SetCurrentLevel(GetCurrLevel()); }
bool CDAAPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CURL url(strPath); CStdString strRoot = strPath; URIUtils::AddSlashAtEnd(strRoot); CStdString host = url.GetHostName(); if (url.HasPort()) host.Format("%s:%i",url.GetHostName(),url.GetPort()); m_thisHost = g_DaapClient.GetHost(host); if (!m_thisHost) return false; // find out where we are in the folder hierarchy m_currLevel = GetCurrLevel(strRoot); CLog::Log(LOGDEBUG, "DAAPDirectory: Current Level is %i", m_currLevel); // if we have at least one database we should show it's contents if (m_thisHost->nDatabases) { CLog::Log(LOGDEBUG, "Have %i databases", m_thisHost->nDatabases); //Store the first database g_DaapClient.m_iDatabase = m_thisHost->databases[0].id; m_currentSongItems = m_thisHost->dbitems[0].items; m_currentSongItemCount = m_thisHost->dbitems[0].nItems; // Get the songs from the database if we haven't already if (!m_artisthead && (m_currLevel >= 0 && m_currLevel < 2)) { CLog::Log(LOGDEBUG, "Getting songs from the database. Have %i", m_currentSongItemCount); // Add each artist and album to an array for (int c = 0; c < m_currentSongItemCount; c++) { AddToArtistAlbum(m_currentSongItems[c].songartist, m_currentSongItems[c].songalbum); } } if (m_currLevel < 0) // root, so show playlists { for (int c = 0; c < m_thisHost->dbplaylists->nPlaylists; c++) { CStdString strFile; //size_t strLen; // we use UTF-8 internally, so no need to convert strFile = m_thisHost->dbplaylists->playlists[c].itemname; // Add item to directory list CLog::Log(LOGDEBUG, "DAAPDirectory: Adding item %s", strFile.c_str()); CFileItemPtr pItem(new CFileItem(strFile)); pItem->SetPath(strRoot + m_thisHost->dbplaylists->playlists[c].itemname + "/"); pItem->m_bIsFolder = true; items.Add(pItem); } } else if (m_currLevel == 0) // playlists, so show albums { // find the playlist bool bFoundMatch = false; int c; for (c = 0; c < m_thisHost->dbplaylists->nPlaylists; c++) { if (m_thisHost->dbplaylists->playlists[c].itemname == m_selectedPlaylist) { bFoundMatch = true; break; } } // if we found it show the songs contained ... if (bFoundMatch) { // if selected playlist name == d/b name then show in artist/album/song formation if (strcmp(m_thisHost->databases[0].name, m_thisHost->dbplaylists->playlists[c].itemname) == 0) { CStdString strBuffer; artistPTR *cur = m_artisthead; while (cur) { strBuffer = cur->artist; CLog::Log(LOGDEBUG, "DAAPDirectory: Adding item %s", strBuffer.c_str()); CFileItemPtr pItem(new CFileItem(strBuffer)); pItem->SetPath(strRoot + cur->artist + "/"); pItem->m_bIsFolder = true; items.Add(pItem); cur = cur->next; } } else { // no support for playlist items in libOpenDAAP yet? - there is now :) int j; for (j = 0; j < m_thisHost->dbplaylists->playlists[c].count; j++) { // the playlist id is the song id, these do not directly match the array // position so we've no choice but to cycle through all the songs until // we find the one we want. int i, idx; idx = -1; for (i = 0; i < m_currentSongItemCount; i ++) { if (m_currentSongItems[i].id == m_thisHost->dbplaylists->playlists[c].items[j].songid) { idx = i; break; } } if (idx > -1) { CLog::Log(LOGDEBUG, "DAAPDirectory: Adding item %s", m_currentSongItems[idx].itemname); CFileItemPtr pItem(new CFileItem(m_currentSongItems[idx].itemname)); CStdString path; if( m_thisHost->version_major != 3 ) { path.Format(REQUEST42, m_thisHost->host, g_DaapClient.m_iDatabase, m_currentSongItems[idx].id, m_currentSongItems[idx].songformat, m_thisHost->sessionid, m_thisHost->revision_number); } else { path.Format(REQUEST45, m_thisHost->host, g_DaapClient.m_iDatabase, m_currentSongItems[idx].id, m_currentSongItems[idx].songformat, m_thisHost->sessionid); } pItem->SetPath(path); pItem->m_bIsFolder = false; pItem->m_dwSize = m_currentSongItems[idx].songsize; pItem->GetMusicInfoTag()->SetURL(pItem->GetPath()); pItem->GetMusicInfoTag()->SetTitle(m_currentSongItems[idx].itemname); pItem->GetMusicInfoTag()->SetArtist(m_currentSongItems[idx].songartist); pItem->GetMusicInfoTag()->SetAlbum(m_currentSongItems[idx].songalbum); //pItem->m_musicInfoTag.SetTrackNumber(m_currentSongItems[idx].songtracknumber); pItem->GetMusicInfoTag()->SetTrackNumber(m_thisHost->dbplaylists->playlists[c].items[j].songid); //pItem->m_musicInfoTag.SetTrackNumber(j+1); //pItem->m_musicInfoTag.SetPartOfSet(m_currentSongItems[idx].songdiscnumber); pItem->GetMusicInfoTag()->SetDuration((int) (m_currentSongItems[idx].songtime / 1000)); pItem->GetMusicInfoTag()->SetLoaded(true); items.Add(pItem); } } } } } else if (m_currLevel == 1) // artists, so show albums { // Find the artist ... artistPTR *cur = m_artisthead; while (cur) { if (cur->artist == m_selectedArtist) break; cur = cur->next; } // if we find it, then show albums for this artist if (cur) { albumPTR *curAlbum = cur->albumhead; while (curAlbum) { CLog::Log(LOGDEBUG, "DAAPDirectory: Adding item %s", curAlbum->album); CFileItemPtr pItem(new CFileItem(curAlbum->album)); pItem->SetPath(strRoot + curAlbum->album + "/"); pItem->m_bIsFolder = true; items.Add(pItem); curAlbum = curAlbum->next; } } } else if (m_currLevel == 2) // albums, so show songs { int c; for (c = 0; c < m_currentSongItemCount; c++) { // mt-daapd will sometimes give us null artist and album names if (m_currentSongItems[c].songartist && m_currentSongItems[c].songalbum) { char *artist = m_currentSongItems[c].songartist; char *album = m_currentSongItems[c].songalbum; if (!strlen(artist)) artist = (char *)unknownArtistAlbum; if (!strlen(album)) album = (char *)unknownArtistAlbum; // if this song is for the current artist & album add it to the file list if (artist == m_selectedArtist && album == m_selectedAlbum) { CLog::Log(LOGDEBUG, "DAAPDirectory: Adding item %s", m_currentSongItems[c].itemname); CFileItemPtr pItem(new CFileItem(m_currentSongItems[c].itemname)); CStdString path; if( m_thisHost->version_major != 3 ) { path.Format(REQUEST42, m_thisHost->host, g_DaapClient.m_iDatabase, m_currentSongItems[c].id, m_currentSongItems[c].songformat, m_thisHost->sessionid, m_thisHost->revision_number); } else { path.Format(REQUEST45, m_thisHost->host, g_DaapClient.m_iDatabase, m_currentSongItems[c].id, m_currentSongItems[c].songformat, m_thisHost->sessionid); } pItem->SetPath(path); pItem->m_bIsFolder = false; pItem->m_dwSize = m_currentSongItems[c].songsize; pItem->GetMusicInfoTag()->SetURL(pItem->GetPath()); pItem->GetMusicInfoTag()->SetTitle(m_currentSongItems[c].itemname); pItem->GetMusicInfoTag()->SetArtist(m_selectedArtist); pItem->GetMusicInfoTag()->SetAlbum(m_selectedAlbum); pItem->GetMusicInfoTag()->SetTrackNumber(m_currentSongItems[c].songtracknumber); pItem->GetMusicInfoTag()->SetPartOfSet(m_currentSongItems[c].songdiscnumber); pItem->GetMusicInfoTag()->SetDuration((int) (m_currentSongItems[c].songtime / 1000)); pItem->GetMusicInfoTag()->SetLoaded(true); items.Add(pItem); } } } } } return true; }