bool CGUIWindowPVRCommon::PlayRecording(CFileItem *item, bool bPlayMinimized /* = false */) { if (item->GetPath().Left(17) != "pvr://recordings/") return false; CStdString stream = item->GetPVRRecordingInfoTag()->m_strStreamURL; if (stream == "") return false; /* Isolate the folder from the filename */ size_t found = stream.find_last_of("/"); if (found == CStdString::npos) found = stream.find_last_of("\\"); if (found != CStdString::npos) { /* Check here for asterisk at the begin of the filename */ if (stream[found+1] == '*') { /* Create a "stack://" url with all files matching the extension */ CStdString ext = URIUtils::GetExtension(stream); CStdString dir = stream.substr(0, found).c_str(); CFileItemList items; CDirectory::GetDirectory(dir, items); items.Sort(SORT_METHOD_FILE ,SORT_ORDER_ASC); vector<int> stack; for (int i = 0; i < items.Size(); ++i) { if (URIUtils::GetExtension(items[i]->GetPath()) == ext) stack.push_back(i); } if (stack.size() > 0) { /* If we have a stack change the path of the item to it */ CStackDirectory dir; CStdString stackPath = dir.ConstructStackPath(items, stack); item->SetPath(stackPath); } } else { /* If no asterisk is present play only the given stream URL */ item->SetPath(stream); } } else { CLog::Log(LOGERROR, "PVRManager - %s - can't open recording: no valid filename", __FUNCTION__); CGUIDialogOK::ShowAndGetInput(19033,0,19036,0); return false; } g_application.getApplicationMessenger().PlayFile(*item, false); return true; }
CStdString CGUILabelControl::ShortenPath(const CStdString &path) { if (m_width == 0 || path.empty()) return path; char cDelim = '\0'; size_t nPos; nPos = path.find_last_of( '\\' ); if ( nPos != std::string::npos ) cDelim = '\\'; else { nPos = path.find_last_of( '/' ); if ( nPos != std::string::npos ) cDelim = '/'; } if ( cDelim == '\0' ) return path; CStdString workPath(path); // remove trailing slashes if (workPath.size() > 3) if (!StringUtils::EndsWith(workPath, "://") && !StringUtils::EndsWith(workPath, ":\\")) if (nPos == workPath.size() - 1) { workPath.erase(workPath.size() - 1); nPos = workPath.find_last_of( cDelim ); } if (m_label.SetText(workPath)) MarkDirtyRegion(); float textWidth = m_label.GetTextWidth(); while ( textWidth > m_width ) { size_t nGreaterDelim = workPath.find_last_of( cDelim, nPos ); if (nGreaterDelim == std::string::npos) break; nPos = workPath.find_last_of( cDelim, nGreaterDelim - 1 ); if ( nPos == std::string::npos ) break; workPath.replace( nPos + 1, nGreaterDelim - nPos - 1, "..." ); if (m_label.SetText(workPath)) MarkDirtyRegion(); textWidth = m_label.GetTextWidth(); } return workPath; }
CStdString CGUILabelControl::ShortenPath(const CStdString &path) { if (!m_label.font || m_width == 0 || path.IsEmpty()) return path; char cDelim = '\0'; size_t nPos; nPos = path.find_last_of( '\\' ); if ( nPos != std::string::npos ) cDelim = '\\'; else { nPos = path.find_last_of( '/' ); if ( nPos != std::string::npos ) cDelim = '/'; } if ( cDelim == '\0' ) return path; CStdString workPath(path); // remove trailing slashes if (workPath.size() > 3) if (workPath.Right(3).Compare("://") != 0 && workPath.Right(2).Compare(":\\") != 0) if (nPos == workPath.size() - 1) { workPath.erase(workPath.size() - 1); nPos = workPath.find_last_of( cDelim ); } float fTextHeight, fTextWidth; m_textLayout.Update(workPath); m_textLayout.GetTextExtent(fTextWidth, fTextHeight); while ( fTextWidth > m_width ) { size_t nGreaterDelim = workPath.find_last_of( cDelim, nPos ); if (nGreaterDelim == std::string::npos) break; nPos = workPath.find_last_of( cDelim, nGreaterDelim - 1 ); if ( nPos == std::string::npos ) break; workPath.replace( nPos + 1, nGreaterDelim - nPos - 1, "..." ); m_textLayout.Update(workPath); m_textLayout.GetTextExtent(fTextWidth, fTextHeight); } return workPath; }
CStdString CCDDARipper::GetTrackName(CFileItem *item) { // get track number from "cdda://local/01.cdda" int trackNumber = atoi(item->GetPath().substr(13, item->GetPath().size() - 13 - 5).c_str()); // Format up our ripped file label CFileItem destItem(*item); destItem.SetLabel(""); // get track file name format from audiocds.trackpathformat setting, // use only format part starting from the last '/' CStdString strFormat = CSettings::Get().GetString("audiocds.trackpathformat"); size_t pos = strFormat.find_last_of("/\\"); if (pos != std::string::npos) strFormat.erase(0, pos+1); CLabelFormatter formatter(strFormat, ""); formatter.FormatLabel(&destItem); // grab the label to use it as our ripped filename CStdString track = destItem.GetLabel(); if (track.empty()) track = StringUtils::Format("%s%02i", "Track-", trackNumber); AddonPtr addon; CAddonMgr::Get().GetAddon(CSettings::Get().GetString("audiocds.encoder"), addon); if (addon) { boost::shared_ptr<CAudioEncoder> enc = boost::static_pointer_cast<CAudioEncoder>(addon); track += enc->extension; } return track; }
void URIUtils::RemoveExtension(CStdString& strFileName) { if(IsURL(strFileName)) { CURL url(strFileName); strFileName = url.GetFileName(); RemoveExtension(strFileName); url.SetFileName(strFileName); strFileName = url.Get(); return; } size_t period = strFileName.find_last_of("./\\"); if (period != string::npos && strFileName[period] == '.') { CStdString strExtension = strFileName.substr(period); StringUtils::ToLower(strExtension); strExtension += "|"; CStdString strFileMask; strFileMask = g_advancedSettings.m_pictureExtensions; strFileMask += "|" + g_advancedSettings.m_musicExtensions; strFileMask += "|" + g_advancedSettings.m_videoExtensions; strFileMask += "|" + g_advancedSettings.m_subtitlesExtensions; #if defined(TARGET_DARWIN) strFileMask += "|.py|.xml|.milk|.xpr|.xbt|.cdg|.app|.applescript|.workflow"; #else strFileMask += "|.py|.xml|.milk|.xpr|.xbt|.cdg"; #endif strFileMask += "|"; if (strFileMask.find(strExtension) != std::string::npos) strFileName.erase(period); } }
bool URIUtils::HasExtension(const CStdString& strFileName) { if (IsURL(strFileName)) { CURL url(strFileName); return HasExtension(url.GetFileName()); } size_t iPeriod = strFileName.find_last_of("./\\"); return iPeriod != string::npos && strFileName[iPeriod] == '.'; }
/* handles both / and \, and options in urls*/ const CStdString URIUtils::GetFileName(const CStdString& strFileNameAndPath) { if(IsURL(strFileNameAndPath)) { CURL url(strFileNameAndPath); return GetFileName(url.GetFileName()); } /* find the last slash */ const size_t slash = strFileNameAndPath.find_last_of("/\\"); return strFileNameAndPath.substr(slash+1); }
/* handles both / and \, and options in urls*/ const CStdString URIUtils::GetFileName(const CStdString& strFileNameAndPath) { if(IsURL(strFileNameAndPath)) { CURL url(strFileNameAndPath); return GetFileName(url.GetFileName()); } /* find any slashes */ const int slash1 = strFileNameAndPath.find_last_of('/'); const int slash2 = strFileNameAndPath.find_last_of('\\'); /* select the last one */ int slash; if(slash2>slash1) slash = slash2; else slash = slash1; return strFileNameAndPath.substr(slash+1); }
CStdString OutlookAddinRegistrar::GetPESValueForRegistry() { CStdString sFileName = GetFile(); int pos = (x64_int_cast) sFileName.find_last_of(_T("\\")); sFileName = sFileName.substr(0, pos+1); sFileName += _T("Workshare.Client.OutlookExtension.dll"); return _T("4.0;") + sFileName + _T(";1;00000100000001;1001000"); }
/* returns filename extension including period of filename */ CStdString URIUtils::GetExtension(const CStdString& strFileName) { if (IsURL(strFileName)) { CURL url(strFileName); return GetExtension(url.GetFileName()); } size_t period = strFileName.find_last_of("./\\"); if (period == string::npos || strFileName[period] != '.') return CStdString(); return strFileName.substr(period); }
CStdString LocalTempCopyOfFile::RemoveExtension(CStdString sFileName) { CStdString sFileNameWithoutExtension; size_t index = sFileName.find_last_of(_T(".")); if ( index != -1 ) { sFileNameWithoutExtension = sFileName.Left(index); } else { sFileNameWithoutExtension = sFileName; } return sFileNameWithoutExtension; }
CStdString URIUtils::GetDirectory(const CStdString &strFilePath) { // Will from a full filename return the directory the file resides in. // Keeps the final slash at end and possible |option=foo options. size_t iPosSlash = strFilePath.find_last_of("/\\"); if (iPosSlash == string::npos) return ""; // No slash, so no path (ignore any options) size_t iPosBar = strFilePath.rfind('|'); if (iPosBar == string::npos) return strFilePath.substr(0, iPosSlash + 1); // Only path return strFilePath.substr(0, iPosSlash + 1) + strFilePath.substr(iPosBar); // Path + options }
/* returns filename extension including period of filename */ const CStdString URIUtils::GetExtension(const CStdString& strFileName) { if(IsURL(strFileName)) { CURL url(strFileName); return GetExtension(url.GetFileName()); } int period = strFileName.find_last_of('.'); if(period >= 0) { if( strFileName.find_first_of('/', period+1) != string::npos ) return ""; if( strFileName.find_first_of('\\', period+1) != string::npos ) return ""; return strFileName.substr(period); } else return ""; }
void CService::BuildServiceType() { CStdString str = LibPath(); CStdString ext; size_t p = str.find_last_of('.'); if (p != string::npos) ext = str.substr(p + 1); #ifdef HAS_PYTHON CStdString pythonExt = ADDON_PYTHON_EXT; pythonExt.erase(0, 2); if ( ext.Equals(pythonExt) ) m_type = PYTHON; else #endif { m_type = UNKNOWN; CLog::Log(LOGERROR, "ADDON: extension '%s' is not currently supported for service addon", ext.c_str()); } }
CStdString CCDDARipper::GetAlbumDirName(const MUSIC_INFO::CMusicInfoTag& infoTag) { CStdString strAlbumDir; // use audiocds.trackpathformat setting to format // directory name where CD tracks will be stored, // use only format part ending at the last '/' strAlbumDir = CSettings::Get().GetString("audiocds.trackpathformat"); size_t pos = strAlbumDir.find_last_of("/\\"); if (pos == std::string::npos) return ""; // no directory strAlbumDir = strAlbumDir.substr(0, pos); // replace %A with album artist name if (strAlbumDir.find("%A") != std::string::npos) { CStdString strAlbumArtist = StringUtils::Join(infoTag.GetAlbumArtist(), g_advancedSettings.m_musicItemSeparator); if (strAlbumArtist.empty()) strAlbumArtist = StringUtils::Join(infoTag.GetArtist(), g_advancedSettings.m_musicItemSeparator); if (strAlbumArtist.empty()) strAlbumArtist = "Unknown Artist"; else StringUtils::Replace(strAlbumArtist, '/', '_'); StringUtils::Replace(strAlbumDir, "%A", strAlbumArtist); } // replace %B with album title if (strAlbumDir.find("%B") != std::string::npos) { CStdString strAlbum = infoTag.GetAlbum(); if (strAlbum.empty()) strAlbum = StringUtils::Format("Unknown Album %s", CDateTime::GetCurrentDateTime().GetAsLocalizedDateTime().c_str()); else StringUtils::Replace(strAlbum, '/', '_'); StringUtils::Replace(strAlbumDir, "%B", strAlbum); } // replace %G with genre if (strAlbumDir.find("%G") != std::string::npos) { CStdString strGenre = StringUtils::Join(infoTag.GetGenre(), g_advancedSettings.m_musicItemSeparator); if (strGenre.empty()) strGenre = "Unknown Genre"; else StringUtils::Replace(strGenre, '/', '_'); StringUtils::Replace(strAlbumDir, "%G", strGenre); } // replace %Y with year if (strAlbumDir.find("%Y") != std::string::npos) { CStdString strYear = infoTag.GetYearString(); if (strYear.empty()) strYear = "Unknown Year"; else StringUtils::Replace(strYear, '/', '_'); StringUtils::Replace(strAlbumDir, "%Y", strYear); } return strAlbumDir; }
bool CWINSMBDirectory::ConnectToShare(const CURL& url) { NETRESOURCE nr; CURL urlIn(url); DWORD dwRet=-1; CStdString strUNC("\\\\"+url.GetHostName()); if(!url.GetShareName().empty()) strUNC.append("\\"+url.GetShareName()); CStdString strPath; memset(&nr,0,sizeof(nr)); nr.dwType = RESOURCETYPE_ANY; nr.dwScope = RESOURCE_GLOBALNET; nr.lpRemoteName = (char*)strUNC.c_str(); // in general we shouldn't need the password manager as we won't disconnect from shares yet IMAPPASSWORDS it = g_passwordManager.m_mapSMBPasswordCache.find(strUNC); if(it != g_passwordManager.m_mapSMBPasswordCache.end()) { // if share found in cache use it to supply username and password CURL murl(it->second); // map value contains the full url of the originally authenticated share. map key is just the share CStdString strPassword = murl.GetPassWord(); CStdString strUserName = murl.GetUserName(); urlIn.SetPassword(strPassword); urlIn.SetUserName(strUserName); } else if(urlIn.GetUserNameA().empty() && !g_guiSettings.GetString("smb.username").IsEmpty()) { urlIn.SetPassword(g_guiSettings.GetString("smb.password")); urlIn.SetUserName(g_guiSettings.GetString("smb.username")); } CStdString strAuth = URLEncode(urlIn); while(dwRet != NO_ERROR) { strPath = URLEncode(urlIn); LPCTSTR pUser = urlIn.GetUserNameA().empty() ? NULL : (LPCTSTR)urlIn.GetUserNameA().c_str(); LPCTSTR pPass = urlIn.GetPassWord().empty() ? NULL : (LPCTSTR)urlIn.GetPassWord().c_str(); dwRet = WNetAddConnection2(&nr, pPass, pUser, CONNECT_TEMPORARY); CLog::Log(LOGDEBUG,"Trying to connect to %s with username(%s) and password(%s)", strUNC.c_str(), urlIn.GetUserNameA().c_str(), urlIn.GetPassWord().c_str()); if(dwRet == ERROR_ACCESS_DENIED || dwRet == ERROR_INVALID_PASSWORD || dwRet == ERROR_LOGON_FAILURE) { CLog::Log(LOGERROR,"Couldn't connect to %s, access denied", strUNC.c_str()); if (m_allowPrompting) { g_passwordManager.SetSMBShare(strPath); if (!g_passwordManager.GetSMBShareUserPassword()) // Do this bit via a threadmessage? break; CURL urlnew( g_passwordManager.GetSMBShare() ); urlIn.SetUserName(urlnew.GetUserName()); urlIn.SetPassword(urlnew.GetPassWord()); } else break; } else if(dwRet == ERROR_SESSION_CREDENTIAL_CONFLICT) { DWORD dwRet2=-1; CStdString strRN = nr.lpRemoteName; do { dwRet2 = WNetCancelConnection2((LPCSTR)strRN.c_str(), 0, false); strRN.erase(strRN.find_last_of("\\"),CStdString::npos); } while(dwRet2 == ERROR_NOT_CONNECTED && !strRN.Equals("\\\\")); } else if(dwRet != NO_ERROR) { break; } } if(dwRet != NO_ERROR) { CLog::Log(LOGERROR,"Couldn't connect to %s, error code %d", strUNC.c_str(), dwRet); return false; } else if (strPath != strAuth && !strUNC.IsEmpty()) // we succeeded so, if path was changed, return the correct one and cache it { g_passwordManager.m_mapSMBPasswordCache[strUNC] = strPath; } return true; }
CStdString CKeymapLoader::ParseWin32HIDName(const CStdString& deviceLongName) { return deviceLongName.Mid(deviceLongName.find_last_of('\\')+1, deviceLongName.find_last_of('#') - deviceLongName.find_last_of('\\')); }
CStdString FileOps::GetFileName(const CStdString &path, char separator) { size_t pos = path.find_last_of(separator); return path.substr(pos + 1); }
CStdString FileOps::GetDirectoryName(const CStdString &path, char separator) { size_t pos = path.find_last_of(separator); return path.substr(0, pos); }
bool CWINSMBDirectory::ConnectToShare(const CURL& url) { NETRESOURCE nr; CURL urlIn(url); DWORD dwRet=-1; CStdString strUNC("\\\\"+url.GetHostName()); if(!url.GetShareName().empty()) strUNC.append("\\"+url.GetShareName()); CStdString strPath; memset(&nr,0,sizeof(nr)); nr.dwType = RESOURCETYPE_ANY; nr.lpRemoteName = (char*)strUNC.c_str(); // in general we shouldn't need the password manager as we won't disconnect from shares yet CPasswordManager::GetInstance().AuthenticateURL(urlIn); CStdString strAuth = URLEncode(urlIn); while(dwRet != NO_ERROR) { strPath = URLEncode(urlIn); LPCTSTR pUser = urlIn.GetUserNameA().empty() ? NULL : (LPCTSTR)urlIn.GetUserNameA().c_str(); LPCTSTR pPass = urlIn.GetPassWord().empty() ? NULL : (LPCTSTR)urlIn.GetPassWord().c_str(); dwRet = WNetAddConnection2(&nr, pPass, pUser, CONNECT_TEMPORARY); #ifdef _DEBUG CLog::Log(LOGDEBUG,"Trying to connect to %s with username(%s) and password(%s)", strUNC.c_str(), urlIn.GetUserNameA().c_str(), urlIn.GetPassWord().c_str()); #else CLog::Log(LOGDEBUG,"Trying to connect to %s with username(%s) and password(%s)", strUNC.c_str(), urlIn.GetUserNameA().c_str(), "XXXX"); #endif if(dwRet == ERROR_ACCESS_DENIED || dwRet == ERROR_INVALID_PASSWORD || dwRet == ERROR_LOGON_FAILURE) { CLog::Log(LOGERROR,"Couldn't connect to %s, access denied", strUNC.c_str()); if (m_flags & DIR_FLAG_ALLOW_PROMPT) RequireAuthentication(urlIn.Get()); break; } else if(dwRet == ERROR_SESSION_CREDENTIAL_CONFLICT) { DWORD dwRet2=-1; CStdString strRN = nr.lpRemoteName; do { dwRet2 = WNetCancelConnection2((LPCSTR)strRN.c_str(), 0, false); strRN.erase(strRN.find_last_of("\\"),CStdString::npos); } while(dwRet2 == ERROR_NOT_CONNECTED && !strRN.Equals("\\\\")); } else if(dwRet != NO_ERROR) { break; } } if(dwRet != NO_ERROR) { CLog::Log(LOGERROR,"Couldn't connect to %s, error code %d", strUNC.c_str(), dwRet); return false; } return true; }
bool CIniFile::ReadFile() { // Normally you would use ifstream, but the SGI CC compiler has // a few bugs with ifstream. So ... fstream used. fstream f; CStdString line; CStdString keyname, valuename, value; CStdString::size_type pLeft, pRight; f.open( (LPCSTR)path, fstream::in ); if ( f.fail()){ f.open( (LPCSTR)path, fstream::out ); if ( f.fail() ) return false; f.close(); f.open( (LPCSTR)path, fstream::in ); } while( getline( f, line)) { if ( !line.length() ){ continue; } // To be compatible with Win32, check for existence of '\r'. // Win32 files have the '\r' and Unix files don't at the end of a line. // Note that the '\r' will be written to INI files from // Unix so that the created INI file can be read under Win32 // without change. if ( line[line.length() - 1] == '\r') line = line.substr( 0, line.length() - 1); if ( line.length()) { // Check that the user hasn't openned a binary file by checking the first // character of each line! if ( !isprint( line[0])) { printf( "Failing on char %d\n", line[0]); f.close(); return false; } if (( pLeft = line.find_first_of(";#[=")) != CStdString::npos) { switch ( line[pLeft]) { case '[': if ((pRight = line.find_last_of("]")) != CStdString::npos && pRight > pLeft) { keyname = line.substr( pLeft + 1, pRight - pLeft - 1); AddKeyName( keyname); } break; case '=': valuename = line.substr( 0, pLeft); value = line.substr( pLeft + 1); SetValue( keyname, valuename, value); break; case ';': case '#': if ( !names.size()) HeaderComment( line.substr( pLeft + 1)); else KeyComment( keyname, line.substr( pLeft + 1)); break; } } } } f.close(); if ( names.size()) return true; return false; }