CMediaSource *CGUIDialogContextMenu::GetShare(const std::string &type, const CFileItem *item) { VECSOURCES *shares = CMediaSourceSettings::GetInstance().GetSources(type); if (!shares || !item) return nullptr; for (unsigned int i = 0; i < shares->size(); i++) { CMediaSource &testShare = shares->at(i); if (URIUtils::IsDVD(testShare.strPath)) { if (!item->IsDVD()) continue; } else { if (!URIUtils::CompareWithoutSlashAtEnd(testShare.strPath, item->GetPath())) continue; } // paths match, what about share name - only match the leftmost // characters as the label may contain other info (status for instance) if (StringUtils::StartsWithNoCase(item->GetLabel(), testShare.strName)) { return &testShare; } } return nullptr; }
/*! \brief Is the share \e strPath in the virtual directory. \param strPath Share to test \return Returns \e true, if share is in the virtual directory. \note The parameter \e strPath can not be a share with directory. Eg. "iso9660://dir" will return \e false. It must be "iso9660://". */ bool CVirtualDirectory::IsSource(const CStdString& strPath, VECSOURCES *sources, CStdString *name) const { CStdString strPathCpy = strPath; strPathCpy.TrimRight("/"); strPathCpy.TrimRight("\\"); // just to make sure there's no mixed slashing in share/default defines // ie. f:/video and f:\video was not be recognised as the same directory, // resulting in navigation to a lower directory then the share. if(URIUtils::IsDOSPath(strPathCpy)) strPathCpy.Replace("/", "\\"); VECSOURCES shares; if (sources) shares = *sources; else GetSources(shares); for (int i = 0; i < (int)shares.size(); ++i) { const CMediaSource& share = shares.at(i); CStdString strShare = share.strPath; strShare.TrimRight("/"); strShare.TrimRight("\\"); if(URIUtils::IsDOSPath(strShare)) strShare.Replace("/", "\\"); if (strShare == strPathCpy) { if (name) *name = share.strName; return true; } } return false; }
CMediaSource *CGUIDialogContextMenu::GetShare(const CStdString &type, const CFileItem *item) { VECSOURCES *shares = g_settings.GetSourcesFromType(type); if (!shares) return NULL; for (unsigned int i = 0; i < shares->size(); i++) { CMediaSource &testShare = shares->at(i); if (CUtil::IsDVD(testShare.strPath)) { if (!item->IsDVD()) continue; } else { if (!testShare.strPath.Equals(item->m_strPath)) continue; } // paths match, what about share name - only match the leftmost // characters as the label may contain other info (status for instance) if (item->GetLabel().Left(testShare.strName.size()).Equals(testShare.strName)) { return &testShare; } } return NULL; }
JSON_STATUS CFileOperations::GetRootDirectory(const CStdString &method, ITransportLayer *transport, IClient *client, const Value ¶meterObject, Value &result) { CStdString media = parameterObject["media"].asString(); media = media.ToLower(); VECSOURCES *sources = g_settings.GetSourcesFromType(media); if (sources) { CFileItemList items; for (unsigned int i = 0; i < (unsigned int)sources->size(); i++) items.Add(CFileItemPtr(new CFileItem(sources->at(i)))); for (unsigned int i = 0; i < (unsigned int)items.Size(); i++) { if (items[i]->IsSmb()) { CURI url(items[i]->m_strPath); items[i]->m_strPath = url.GetWithoutUserDetails(); } } HandleFileItemList(NULL, true, "shares", items, parameterObject, result); } result["success"] = true; return OK; }
/*---------------------------------------------------------------------- | CUPnPVirtualPathDirectory::GetMatchingSource +---------------------------------------------------------------------*/ bool CUPnPVirtualPathDirectory::GetMatchingSource(const CStdString &strPath, CMediaSource& share, vector<CStdString>& paths) { unsigned int index; paths.clear(); CStdString strType, strSource; if (!GetTypeAndSource(strPath, strType, strSource)) return false; VECSOURCES *vecSources = g_settings.GetSourcesFromType(strType); if (!vecSources) return false; // look for share for (index = 0; index < vecSources->size(); ++index) { CMediaSource share = vecSources->at(index); CStdString strName = share.strName; if (strSource.Equals(strName)) break; } if (index == vecSources->size()) return false; share = (*vecSources)[index]; // filter out non local shares for (unsigned int j = 0; j < share.vecPaths.size(); j++) { if (!CUtil::IsRemote(share.vecPaths[j])) { paths.push_back(share.vecPaths[j]); } } return true; }
JSON_STATUS CFileOperations::GetRootDirectory(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { CStdString media = parameterObject["media"].asString(); media = media.ToLower(); VECSOURCES *sources = g_settings.GetSourcesFromType(media); if (sources) { CFileItemList items; for (unsigned int i = 0; i < (unsigned int)sources->size(); i++) items.Add(CFileItemPtr(new CFileItem(sources->at(i)))); for (unsigned int i = 0; i < (unsigned int)items.Size(); i++) { if (items[i]->IsSmb()) { CURL url(items[i]->GetPath()); items[i]->SetPath(url.GetWithoutUserDetails()); } } CVariant param = parameterObject["fields"]; param["fields"] = CVariant(CVariant::VariantTypeArray); param["fields"].append("file"); HandleFileItemList(NULL, true, "shares", items, param, result); } return OK; }
bool CFileUtils::RemoteAccessAllowed(const std::string &strPath) { const unsigned int SourcesSize = 5; std::string SourceNames[] = { "programs", "files", "video", "music", "pictures" }; std::string realPath = URIUtils::GetRealPath(strPath); // for rar:// and zip:// paths we need to extract the path to the archive // instead of using the VFS path while (URIUtils::IsInArchive(realPath)) realPath = CURL(realPath).GetHostName(); if (StringUtils::StartsWithNoCase(realPath, "virtualpath://upnproot/")) return true; else if (StringUtils::StartsWithNoCase(realPath, "musicdb://")) return true; else if (StringUtils::StartsWithNoCase(realPath, "videodb://")) return true; else if (StringUtils::StartsWithNoCase(realPath, "library://video")) return true; else if (StringUtils::StartsWithNoCase(realPath, "library://music")) return true; else if (StringUtils::StartsWithNoCase(realPath, "sources://video")) return true; else if (StringUtils::StartsWithNoCase(realPath, "special://musicplaylists")) return true; else if (StringUtils::StartsWithNoCase(realPath, "special://profile/playlists")) return true; else if (StringUtils::StartsWithNoCase(realPath, "special://videoplaylists")) return true; else if (StringUtils::StartsWithNoCase(realPath, "special://skin")) return true; else if (StringUtils::StartsWithNoCase(realPath, "special://profile/addon_data")) return true; else if (StringUtils::StartsWithNoCase(realPath, "addons://sources")) return true; else if (StringUtils::StartsWithNoCase(realPath, "upnp://")) return true; else if (StringUtils::StartsWithNoCase(realPath, "plugin://")) return true; else { std::string strPlaylistsPath = CServiceBroker::GetSettings().GetString(CSettings::SETTING_SYSTEM_PLAYLISTSPATH); URIUtils::RemoveSlashAtEnd(strPlaylistsPath); if (StringUtils::StartsWithNoCase(realPath, strPlaylistsPath)) return true; } bool isSource; for (unsigned int index = 0; index < SourcesSize; index++) { VECSOURCES* sources = CMediaSourceSettings::GetInstance().GetSources(SourceNames[index]); int sourceIndex = CUtil::GetMatchingSource(realPath, *sources, isSource); if (sourceIndex >= 0 && sourceIndex < (int)sources->size() && sources->at(sourceIndex).m_iHasLock != 2 && sources->at(sourceIndex).m_allowSharing) return true; } return false; }
void CGUIViewStateWindowMusicNav::AddOnlineShares() { if (!g_advancedSettings.m_bVirtualShares) return; VECSOURCES *musicSources = CMediaSourceSettings::GetInstance().GetSources("music"); for (int i = 0; i < (int)musicSources->size(); ++i) { CMediaSource share = musicSources->at(i); } }
std::string CGUIDialogContextMenu::GetDefaultShareNameByType(const std::string &strType) { VECSOURCES *pShares = CMediaSourceSettings::GetInstance().GetSources(strType); std::string strDefault = CMediaSourceSettings::GetInstance().GetDefaultSource(strType); if (!pShares) return ""; bool bIsSourceName(false); int iIndex = CUtil::GetMatchingSource(strDefault, *pShares, bIsSourceName); if (iIndex < 0 || iIndex >= (int)pShares->size()) return ""; return pShares->at(iIndex).strName; }
CStdString CGUIDialogContextMenu::GetDefaultShareNameByType(const CStdString &strType) { VECSOURCES *pShares = g_settings.GetSourcesFromType(strType); CStdString strDefault = g_settings.GetDefaultSourceFromType(strType); if (!pShares) return ""; bool bIsSourceName(false); int iIndex = CUtil::GetMatchingSource(strDefault, *pShares, bIsSourceName); if (iIndex < 0 || iIndex >= (int)pShares->size()) return ""; return pShares->at(iIndex).strName; }
JSONRPC_STATUS CFileOperations::GetRootDirectory(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { CStdString media = parameterObject["media"].asString(); StringUtils::ToLower(media); VECSOURCES *sources = CMediaSourceSettings::Get().GetSources(media); if (sources) { CFileItemList items; for (unsigned int i = 0; i < (unsigned int)sources->size(); i++) { // Do not show sources which are locked if (sources->at(i).m_iHasLock == 2) continue; items.Add(CFileItemPtr(new CFileItem(sources->at(i)))); } for (unsigned int i = 0; i < (unsigned int)items.Size(); i++) { if (items[i]->IsSmb()) { CURL url(items[i]->GetPath()); items[i]->SetPath(url.GetWithoutUserDetails()); } } CVariant param = parameterObject; param["properties"] = CVariant(CVariant::VariantTypeArray); param["properties"].append("file"); HandleFileItemList(NULL, true, "sources", items, param, result); } return OK; }
JSONRPC_STATUS CFileOperations::GetDirectory(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { CStdString media = parameterObject["media"].asString(); media = media.ToLower(); CFileItemList items; CStdString strPath = parameterObject["directory"].asString(); // Check if this directory is part of a source and whether it's locked VECSOURCES *sources; bool isSource; for (unsigned int index = 0; index < SourcesSize; index++) { sources = g_settings.GetSourcesFromType(SourceNames[index]); int sourceIndex = CUtil::GetMatchingSource(strPath, *sources, isSource); if (sourceIndex >= 0 && sourceIndex < (int)sources->size() && sources->at(sourceIndex).m_iHasLock == 2) return InvalidParams; } CStdStringArray regexps; CStdString extensions = ""; if (media.Equals("video")) { regexps = g_advancedSettings.m_videoExcludeFromListingRegExps; extensions = g_settings.m_videoExtensions; } else if (media.Equals("music")) { regexps = g_advancedSettings.m_audioExcludeFromListingRegExps; extensions = g_settings.m_musicExtensions; } else if (media.Equals("pictures")) { regexps = g_advancedSettings.m_pictureExcludeFromListingRegExps; extensions = g_settings.m_pictureExtensions; } if (CDirectory::GetDirectory(strPath, items, extensions)) { CFileItemList filteredDirectories, filteredFiles; for (unsigned int i = 0; i < (unsigned int)items.Size(); i++) { if (CUtil::ExcludeFileOrFolder(items[i]->GetPath(), regexps)) continue; if (items[i]->IsSmb()) { CURL url(items[i]->GetPath()); items[i]->SetPath(url.GetWithoutUserDetails()); } if ((media == "video" && items[i]->HasVideoInfoTag()) || (media == "music" && items[i]->HasMusicInfoTag()) || (media == "picture" && items[i]->HasPictureInfoTag()) || media == "files") { if (items[i]->m_bIsFolder) filteredDirectories.Add(items[i]); else filteredFiles.Add(items[i]); } else { CFileItem fileItem; if (FillFileItem(items[i], fileItem, media)) { if (items[i]->m_bIsFolder) filteredDirectories.Add(CFileItemPtr(new CFileItem(fileItem))); else filteredFiles.Add(CFileItemPtr(new CFileItem(fileItem))); } else { if (items[i]->m_bIsFolder) filteredDirectories.Add(items[i]); else filteredFiles.Add(items[i]); } } } // Check if the "properties" list exists // and make sure it contains the "file" // field CVariant param = parameterObject; if (!param.isMember("properties")) param["properties"] = CVariant(CVariant::VariantTypeArray); bool hasFileField = false; for (CVariant::const_iterator_array itr = param["properties"].begin_array(); itr != param["properties"].end_array(); itr++) { if (itr->asString().compare("file") == 0) { hasFileField = true; break; } } if (!hasFileField) param["properties"].append("file"); HandleFileItemList("id", true, "files", filteredDirectories, param, result); for (unsigned int index = 0; index < result["files"].size(); index++) { result["files"][index]["filetype"] = "directory"; } int count = (int)result["limits"]["total"].asInteger(); HandleFileItemList("id", true, "files", filteredFiles, param, result); for (unsigned int index = count; index < result["files"].size(); index++) { result["files"][index]["filetype"] = "file"; } count += (int)result["limits"]["total"].asInteger(); result["limits"]["end"] = count; result["limits"]["total"] = count; return OK; } return InvalidParams; }
/*---------------------------------------------------------------------- | CUPnPVirtualPathDirectory::GetDirectory +---------------------------------------------------------------------*/ bool CUPnPVirtualPathDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { NPT_String path = strPath.c_str(); CMediaSource share; CFileItemPtr item; vector<CStdString> paths; path.TrimRight("/"); if (path == "virtualpath://upnproot") { // music item.reset(new CFileItem("virtualpath://upnpmusic/", true)); item->SetLabel("Music Files"); item->SetLabelPreformated(true); items.Add(item); // video item.reset(new CFileItem("virtualpath://upnpvideo/", true)); item->SetLabel("Video Files"); item->SetLabelPreformated(true); items.Add(item); // pictures item.reset(new CFileItem("virtualpath://upnppictures/", true)); item->SetLabel("Picture Files"); item->SetLabelPreformated(true); items.Add(item); // music library item.reset(new CFileItem("musicdb://", true)); item->SetLabel("Music Library"); item->SetLabelPreformated(true); items.Add(item); // video library item.reset(new CFileItem("videodb://", true)); item->SetLabel("Video Library"); item->SetLabelPreformated(true); items.Add(item); return true; } else if (path == "virtualpath://upnpmusic" || path == "virtualpath://upnpvideo" || path == "virtualpath://upnppictures") { // look for all shares given a container VECSOURCES *shares = NULL; if (path == "virtualpath://upnpmusic") { shares = g_settings.GetSourcesFromType("upnpmusic"); } else if (path == "virtualpath://upnpvideo") { shares = g_settings.GetSourcesFromType("upnpvideo"); } else if (path == "virtualpath://upnppictures") { shares = g_settings.GetSourcesFromType("upnppictures"); } if (shares) { for (unsigned int i = 0; i < shares->size(); i++) { // Does this share contains any local paths? CMediaSource &share = shares->at(i); // reconstruct share name as it could have been replaced by // a path if there was just one entry NPT_String share_name = path + "/"; share_name += share.strName + "/"; if (GetMatchingSource((const char*)share_name, share, paths) && paths.size()) { item.reset(new CFileItem((const char*)share_name, true)); item->SetLabel(share.strName); item->SetLabelPreformated(true); items.Add(item); } } } return true; } else if (!GetMatchingSource((const char*)path, share, paths)) { // split to remove share name from path NPT_String share_name; NPT_String file_path; bool bret = SplitPath(path, share_name, file_path); if (!bret || share_name.GetLength() == 0 || file_path.GetLength() == 0) { return false; } // make sure the file_path is the beginning of a share paths if (!FindSourcePath(share_name, file_path, true)) return false; // use the share name to figure out what extensions to use if (share_name.StartsWith("virtualpath://upnpmusic")) { CDirectory::GetDirectory( (const char*)file_path, items, g_stSettings.m_musicExtensions); } else if (share_name.StartsWith("virtualpath://upnpvideo")) { CDirectory::GetDirectory( (const char*)file_path, items, g_stSettings.m_videoExtensions); } else if (share_name.StartsWith("virtualpath://upnppictures")) { CDirectory::GetDirectory( (const char*)file_path, items, g_stSettings.m_pictureExtensions); } // paths should be prefixed for (int i=0; i < (int) items.Size(); ++i) { items[i]->m_strPath = share_name + "/" + items[i]->m_strPath.c_str(); } } else { // use the path to figure out what extensions to use if (path.StartsWith("virtualpath://upnpmusic")) { SetMask(g_stSettings.m_musicExtensions); } else if (path.StartsWith("virtualpath://upnpvideo")) { SetMask(g_stSettings.m_videoExtensions); } else if (path.StartsWith("virtualpath://upnppictures")) { SetMask(g_stSettings.m_pictureExtensions); } // dont allow prompting, this is a background task // although I don't think it matters here SetAllowPrompting(false); // it's a virtual path, get all items CVirtualPathDirectory::GetDirectory(strPath, items); // paths should be prefixed for (int i=0; i < (int) items.Size(); ++i) { items[i]->m_strPath = strPath + "/" + items[i]->m_strPath.c_str(); } } // always return true // this will make sure that even if nothing is found in a share // it doesn't fail upnp return true; }