void TemporaryPlaylistProvider::Save() { try { Stream::TextFileStream fs(GetTemporaryPlaylistFilename(), Stream::FileStream::modeCreate, Stream::FileStream::accessWrite, Stream::FileStream::shareRead); boost::shared_ptr<IPlaylist> spIPlaylist = GetCurrentPlaylist(); boost::shared_ptr<Playlist> spPlaylist = boost::dynamic_pointer_cast<Playlist>(spIPlaylist); Playlist& playlist = *spPlaylist; for (size_t i=0,iMax=playlist.GetSize(); i<iMax; i++) { const PlaylistEntry& entry = playlist.GetEntry(i); const VideoInfo& info = GetVideoInfo(entry.m_iId); fs.Write(info.Address()); fs.Write(_T(" ")); fs.Write(info.Name()); fs.WriteEndline(); } } catch(...) { } }
void Plugin::ForSelectedTracks(std::function<int(IAIMPPlaylist *, IAIMPPlaylistItem *, int64_t)> callback) { if (!callback) return; if (IAIMPPlaylist *pl = GetCurrentPlaylist()) { pl->BeginUpdate(); std::set<IAIMPPlaylistItem *> to_del; auto delPending = [&] { for (auto x : to_del) { pl->Delete(x); x->Release(); } }; for (int i = 0, n = pl->GetItemCount(); i < n; ++i) { IAIMPPlaylistItem *item = nullptr; if (SUCCEEDED(pl->GetItem(i, IID_IAIMPPlaylistItem, reinterpret_cast<void **>(&item)))) { int isSelected = 0; if (SUCCEEDED(item->GetValueAsInt32(AIMP_PLAYLISTITEM_PROPID_SELECTED, &isSelected))) { if (isSelected) { IAIMPString *url = nullptr; if (SUCCEEDED(item->GetValueAsObject(AIMP_PLAYLISTITEM_PROPID_FILENAME, IID_IAIMPString, reinterpret_cast<void **>(&url)))) { int64_t id = Tools::TrackIdFromUrl(url->GetData()); url->Release(); int result = callback(pl, item, id); if (result & FLAG_DELETE_ITEM) { to_del.insert(item); if (result & FLAG_STOP_LOOP) { delPending(); pl->EndUpdate(); pl->Release(); return; } continue; } if (result & FLAG_STOP_LOOP) { delPending(); item->Release(); pl->EndUpdate(); pl->Release(); return; } } } } item->Release(); } } delPending(); pl->EndUpdate(); pl->Release(); } }