Beispiel #1
0
// \brief Override the function to change the default behavior on how
// a selected item history should look like
void CGUIMediaWindow::GetDirectoryHistoryString(const CFileItem* pItem, CStdString& strHistoryString)
{
  if (pItem->m_bIsShareOrDrive)
  {
    // We are in the virual directory

    // History string of the DVD drive
    // must be handel separately
    if (pItem->m_iDriveType == CMediaSource::SOURCE_TYPE_DVD)
    {
      // Remove disc label from item label
      // and use as history string, m_strPath
      // can change for new discs
      CStdString strLabel = pItem->GetLabel();
      int nPosOpen = strLabel.Find('(');
      int nPosClose = strLabel.ReverseFind(')');
      if (nPosOpen > -1 && nPosClose > -1 && nPosClose > nPosOpen)
      {
        strLabel.Delete(nPosOpen + 1, (nPosClose) - (nPosOpen + 1));
        strHistoryString = strLabel;
      }
      else
        strHistoryString = strLabel;
    }
    else
    {
      // Other items in virual directory
      CStdString strPath = pItem->m_strPath;
      URIUtils::RemoveSlashAtEnd(strPath);

      strHistoryString = pItem->GetLabel() + strPath;
    }
  }
  else if (pItem->m_lEndOffset>pItem->m_lStartOffset && pItem->m_lStartOffset != -1)
  {
    // Could be a cue item, all items of a cue share the same filename
    // so add the offsets to build the history string
    strHistoryString.Format("%ld%ld", pItem->m_lStartOffset, pItem->m_lEndOffset);
    strHistoryString += pItem->m_strPath;
  }
  else
  {
    // Normal directory items
    strHistoryString = pItem->m_strPath;
  }
  URIUtils::RemoveSlashAtEnd(strHistoryString);
  strHistoryString.ToLower();
}
Beispiel #2
0
bool CBaseTexture::LoadFromFileInMem(unsigned char* buffer, size_t size, const std::string& mimeType, unsigned int maxWidth, unsigned int maxHeight)
{
  if (!buffer || !size)
    return false;

  //ImageLib is sooo sloow for jpegs. Try our own decoder first. If it fails, fall back to ImageLib.
  if (mimeType == "image/jpeg")
  {
    CJpegIO jpegfile;
    if (jpegfile.Read(buffer, size, maxWidth, maxHeight))
    {
      if (jpegfile.Width() > 0 && jpegfile.Height() > 0)
      {
        Allocate(jpegfile.Width(), jpegfile.Height(), XB_FMT_A8R8G8B8);
        if (jpegfile.Decode(m_pixels, GetPitch(), XB_FMT_A8R8G8B8))
        {
          m_hasAlpha=false;
          ClampToEdge();
          return true;
        }
      }
    }
  }
  DllImageLib dll;
  if (!dll.Load())
    return false;

  ImageInfo image;
  memset(&image, 0, sizeof(image));

  unsigned int width = maxWidth ? std::min(maxWidth, g_Windowing.GetMaxTextureSize()) : g_Windowing.GetMaxTextureSize();
  unsigned int height = maxHeight ? std::min(maxHeight, g_Windowing.GetMaxTextureSize()) : g_Windowing.GetMaxTextureSize();

  CStdString ext = mimeType;
  int nPos = ext.Find('/');
  if (nPos > -1)
    ext.Delete(0, nPos + 1);

  if(!dll.LoadImageFromMemory(buffer, size, ext.c_str(), width, height, &image))
  {
    CLog::Log(LOGERROR, "Texture manager unable to load image from memory");
    return false;
  }
  LoadFromImage(image);
  dll.ReleaseImage(&image);

  return true;
}
Beispiel #3
0
void CHTMLUtil::getAttributeOfTag(const CStdString& strTagAndValue, const CStdString& strTag, CStdString& strValue)
{
  // strTagAndValue contains:
  // like <a href=""value".....
  strValue = strTagAndValue;
  int iStart = strTagAndValue.Find(strTag);
  if (iStart < 0) return ;
  iStart += (int)strTag.size();
  while (strTagAndValue[iStart + 1] == 0x20 || strTagAndValue[iStart + 1] == 0x27 || strTagAndValue[iStart + 1] == 34) iStart++;
  int iEnd = iStart + 1;
  while (strTagAndValue[iEnd] != 0x27 && strTagAndValue[iEnd] != 0x20 && strTagAndValue[iEnd] != 34 && strTagAndValue[iEnd] != '>') iEnd++;
  if (iStart >= 0 && iEnd >= 0)
  {
    strValue = strTagAndValue.Mid(iStart, iEnd - iStart);
  }
}
Beispiel #4
0
bool CNfsConnection::splitUrlIntoExportAndPath(const CURL& url, CStdString &exportPath, CStdString &relativePath)
{
    bool ret = false;
    
    //refresh exportlist if empty or hostname change
    if(m_exportList.empty() || !url.GetHostName().Equals(m_hostName,false))
    {
      m_exportList = GetExportList(url);
    }

    if(!m_exportList.empty())
    {
      relativePath = "";
      exportPath = "";
      
      CStdString path = url.GetFileName();
      
      //GetFileName returns path without leading "/"
      //but we need it because the export paths start with "/"
      //and path.Find(*it) wouldn't work else
      if(!path.empty() && path[0] != '/')
      {
        path = "/" + path;
      }
      
      std::list<CStdString>::iterator it;
      
      for(it=m_exportList.begin();it!=m_exportList.end();it++)
      {
        //if path starts with the current export path
        if( path.Find(*it) ==  0 )
        {
          exportPath = *it;
          //handle special case where root is exported
          //in that case we don't want to stripp off to
          //much from the path
          if( exportPath == "/" )
            relativePath = "//" + path.Right((path.length()) - exportPath.length());
          else
            relativePath = "//" + path.Right((path.length()-1) - exportPath.length());
          ret = true;
          break;          
        }
      }
    }
    return ret;
}
Beispiel #5
0
long CSaveAsObject::CreateFileTypesSafeArray(const CStdString& sFormatString, CSDSafeArray& safeArray, const long& lFormatIndex)
{
	// These MUST be a complete list of possible file formats, otherwise the format index will be off :(

	std::vector<CStdString> vValidFileFormats;
	vValidFileFormats.push_back(_T("Workshare DeltaFile"));
	vValidFileFormats.push_back(_T("Word 97-2003 Document"));
	vValidFileFormats.push_back(_T("Word Document"));
	vValidFileFormats.push_back(_T("Text Only"));
	vValidFileFormats.push_back(_T("Rich Text Format"));
	vValidFileFormats.push_back(_T("HTML Document"));
	vValidFileFormats.push_back(_T("Works 6.0 & 7.0"));
	vValidFileFormats.push_back(_T("Word 97-2003 & 6.0/95 - RTF"));
	vValidFileFormats.push_back(_T("Adobe Acrobat File"));
	vValidFileFormats.push_back(_T("Adobe Acrobat PDF/A File"));

	/*DE9488: For the moment we don't want the Excel and Powerpoint to show in the menu, but at a later
	 *date we will add this to save menus*/
	//vValidFileFormats.push_back(_T("Excel Document"));
	//vValidFileFormats.push_back(_T("Excel 2007 Document"));
	//vValidFileFormats.push_back(_T("PowerPoint Document"));
	//vValidFileFormats.push_back(_T("PowerPoint 2007 Document"));

	std::vector<CStdString> vRequiredFileFormats;
	std::vector<CStdString>::iterator iter; 
	
	for(iter = vValidFileFormats.begin(); iter != vValidFileFormats.end(); ++iter )
	{
		if(sFormatString.Find(*iter) != -1)
		{
			vRequiredFileFormats.push_back(*iter);
		}
	}
	
	long lVectorIndex = GetVectorIndexFormatPosition(sFormatString, lFormatIndex, vRequiredFileFormats);
	int index = 0;
	if(safeArray.Create(VT_BSTR, (x64_int_cast)vRequiredFileFormats.size()))
	{
		for(iter = vRequiredFileFormats.begin(); iter != vRequiredFileFormats.end(); ++iter )
		{
			safeArray.PutElement(index, bstr_t(iter->c_str()).copy());
			++index;
		}
	}
	return lVectorIndex;
}
Beispiel #6
0
CStdString CStackDirectory::GetFirstStackedFile(const CStdString &strPath)
{
    // the stacked files are always in volume order, so just get up to the first filename
    // occurence of " , "
    CStdString file, folder;
    int pos = strPath.Find(" , ");
    if (pos > 0)
        URIUtils::Split(strPath.Left(pos), folder, file);
    else
        URIUtils::Split(strPath, folder, file); // single filed stacks - should really not happen

    // remove "stack://" from the folder
    folder = folder.Mid(8);
    file.Replace(",,", ",");

    return URIUtils::AddFileToFolder(folder, file);
}
Beispiel #7
0
void CLastFmManager::Parameter(const CStdString& key, const CStdString& data, CStdString& value)
{
  value = "";
  vector<CStdString> params;
  StringUtils::SplitString(data, "\n", params);
  for (int i = 0; i < (int)params.size(); i++)
  {
    CStdString tmp = params[i];
    if (int pos = tmp.Find(key) >= 0)
    {
      tmp.Delete(pos - 1, key.GetLength() + 1);
      value = tmp;
      break;
    }
  }
  CLog::Log(LOGDEBUG, "Parameter %s -> %s", key.c_str(), value.c_str());
}
Beispiel #8
0
void IpRanges::Compute()
{
	m_ipRangePrefixes.clear();
	m_ipRangeBitWidths.clear();
	std::list<CStdString>::iterator it;

	for(it = m_asciiIpRanges.begin(); it != m_asciiIpRanges.end(); it++)
	{
		CStdString cidrPrefixLengthString;
		unsigned int cidrPrefixLength = 32;		// by default, x.x.x.x/32
		CStdString cidrIpAddressString;
		struct in_addr cidrIpAddress;
		
		CStdString entry = *it;
		int slashPosition = entry.Find('/');
		if(slashPosition > 0)
		{
			cidrIpAddressString = entry.Left(slashPosition);
			cidrPrefixLengthString = entry.Mid(slashPosition+1);

			bool notAnInt = false;
			try
			{
				cidrPrefixLength = StringToInt(cidrPrefixLengthString);
			}
			catch (...) {notAnInt = true;}
			if(cidrPrefixLength < 1 || cidrPrefixLength > 32 || notAnInt)
			{
				throw (CStdString("IpRanges: invalid CIDR prefix length" + entry));
			}
		}
		else
		{
			cidrIpAddressString = entry;
		}

		if(ACE_OS::inet_aton((PCSTR)cidrIpAddressString, &cidrIpAddress))
		{
			unsigned int rangeBitWidth = 32-cidrPrefixLength;
			unsigned int prefix = ntohl((unsigned int)cidrIpAddress.s_addr) >> (rangeBitWidth);
			m_ipRangePrefixes.push_back(prefix);
			m_ipRangeBitWidths.push_back(rangeBitWidth);
		}
		else
		{
			throw (CStdString("invalid IP range:" + entry));
Beispiel #9
0
CPeripheral *CPeripherals::GetByPath(const CStdString &strPath) const
{
  if (!strPath.Left(14).Equals("peripherals://"))
    return NULL;

  CStdString strPathCut = strPath.Right(strPath.length() - 14);
  CStdString strBus = strPathCut.Left(strPathCut.Find('/'));

  CSingleLock lock(m_critSection);
  for (unsigned int iBusPtr = 0; iBusPtr < m_busses.size(); iBusPtr++)
  {
    if (strBus.Equals(PeripheralTypeTranslator::BusTypeToString(m_busses.at(iBusPtr)->Type())))
      return m_busses.at(iBusPtr)->GetByPath(strPath);
  }

  return NULL;
}
Beispiel #10
0
bool CHttpApi::checkForFunctionTypeParas(CStdString &cmd, CStdString &paras)
{
  int open, close;
  open = cmd.Find("(");
  if (open>0)
  {
    close=cmd.length();
    while (close>open && cmd.Mid(close,1)!=")")
      close--;
    if (close>open)
    {
      paras = cmd.Mid(open + 1, close - open - 1);
      cmd = cmd.Left(open);
      return (close-open)>1;
    }
  }
  return false;
}
bool CVirtualPathDirectory::GetTypeAndSource(const CStdString& strPath, CStdString& strType, CStdString& strSource)
{
  // format: virtualpath://type/sourcename
  CStdString strTemp = strPath;
  CUtil::RemoveSlashAtEnd(strTemp);
  CStdString strTest = "virtualpath://";
  if (strTemp.Left(strTest.length()).Equals(strTest))
  {
    strTemp = strTemp.Mid(strTest.length());
    int iPos = strTemp.Find('/');
    if (iPos < 1)
      return false;
    strType = strTemp.Mid(0, iPos);
    strSource = strTemp.Mid(iPos + 1);
    //CLog::Log(LOGDEBUG,"CVirtualPathDirectory::GetTypeAndSource(%s) = [%s],[%s]", strPath.c_str(), strType.c_str(), strSource.c_str());
    return true;
  }
  return false;
}
bool Addon_music_spotify::GetOneTrack(CFileItemList& items, CStdString& path) {
  Logger::printOut("get one track");
  CURL url(path);
  CStdString uri = url.GetFileNameWithoutPath();
  if (uri.Left(13).Equals("spotify:track")) {
      if (isReady()) {
      sp_link *spLink = sp_link_create_from_string(uri.Left(uri.Find('.')));
      if (!spLink) return false;
      sp_track *spTrack = sp_link_as_track(spLink);
      if (spTrack) {
        SxTrack* track = TrackStore::getInstance()->getTrack(spTrack);
        items.Add(Utils::SxTrackToItem(track));
        sp_track_release(spTrack);
      }
      sp_link_release(spLink);
    } 
  }
  return true;  
}
void CGUIWindowBoxeeBrowseLocal::UpdateEjectButtonState()
{
#ifndef HAS_EMBEDDED
  SET_CONTROL_HIDDEN(BUTTON_EJECT);
  SET_CONTROL_HIDDEN(BUTTON_EJECT_USER);
#else
  CStdString strPath =  ((CLocalBrowseWindowState*)m_windowState)->GetCurrentPath();

  if (CUtil::HasSlashAtEnd(strPath))
  {
    // remove slash at the end
    strPath.Delete(strPath.size() - 1);
  }

  if(!strPath.Equals("afp://") && !strPath.Equals("afp://all") && strPath.Find("afp://") != -1)
  {
    SET_CONTROL_VISIBLE(BUTTON_EJECT_USER);
    SET_CONTROL_HIDDEN(BUTTON_EJECT);
    return;
  }

  if (strPath != "network://protocols" && strPath != "")
  {
    SET_CONTROL_HIDDEN(BUTTON_EJECT);
    SET_CONTROL_HIDDEN(BUTTON_EJECT_USER);
    return;
  }


  VECSOURCES removableDrives;
  g_mediaManager.GetRemovableDrives(removableDrives);
  if (removableDrives.size() == 0)
  {
    SET_CONTROL_HIDDEN(BUTTON_EJECT);
    SET_CONTROL_HIDDEN(BUTTON_EJECT_USER);
    return;
  }

  SET_CONTROL_HIDDEN(BUTTON_EJECT_USER);
  SET_CONTROL_VISIBLE(BUTTON_EJECT);
#endif
}
Beispiel #14
0
void CAdvancedSettings::GetCustomExtensions(TiXmlElement *pRootElement, CStdString& extensions)
{
  CStdString extraExtensions;
  CSettings::GetString(pRootElement,"add",extraExtensions,"");
  if (extraExtensions != "")
    extensions += "|" + extraExtensions;
  CSettings::GetString(pRootElement,"remove",extraExtensions,"");
  if (extraExtensions != "")
  {
    CStdStringArray exts;
    StringUtils::SplitString(extraExtensions,"|",exts);
    for (unsigned int i=0;i<exts.size();++i)
    {
      int iPos = extensions.Find(exts[i]);
      if (iPos == -1)
        continue;
      extensions.erase(iPos,exts[i].size()+1);
    }
  }
}
Beispiel #15
0
bool CAppRegistry::Has(const CStdString& key)
{
  CSingleLock lock(m_lock);
  
  CStdString tempKey = key;
  size_t i = 0;
  
  // If we are asked for a variable with {}, take it from the vector, otherwise return the first
  int pos1 = key.Find("{");
  int pos2 = key.Find("}");
  if (pos1 >= 0 && pos2 > 0)
  {
    i = atoi(key.Mid(pos1+1, pos2 - pos1-1).c_str());
    tempKey = key.Mid(0, pos1);
  }
  
  if (m_data.find(tempKey) == m_data.end())
    return false;
  return true;
}
Beispiel #16
0
static void SetupRarOptions(CFileItem& item, const CStdString& path)
{
  CStdString path2(path);
  if (item.IsVideoDb() && item.HasVideoInfoTag())
    path2 = item.GetVideoInfoTag()->m_strFileNameAndPath;
  CURL url(path2);
  CStdString opts = url.GetOptions();
  if (opts.Find("flags") > -1)
    return;
  if (opts.size())
    opts += "&flags=8";
  else
    opts = "?flags=8";
  url.SetOptions(opts);
  if (item.IsVideoDb() && item.HasVideoInfoTag())
    item.GetVideoInfoTag()->m_strFileNameAndPath = url.Get();
  else
    item.SetPath(url.Get());
  g_directoryCache.ClearDirectory(url.GetWithoutFilename());
}
Beispiel #17
0
bool CNfsConnection::splitUrlIntoExportAndPath(const CURL& url, CStdString &exportPath, CStdString &relativePath)
{
    bool ret = false;
    
    if(m_exportList.empty())
    {
      m_exportList = GetExportList(url);
    }

    if(!m_exportList.empty())
    {
      relativePath = "";
      exportPath = "";
      
      CStdString path = url.GetFileName();
      
      //GetFileName returns path without leading "/"
      //but we need it because the export paths start with "/"
      //and path.Find(*it) wouldn't work else
      if(path[0] != '/')
      {
        path = "/" + path;
      }
      
      std::list<CStdString>::iterator it;
      
      for(it=m_exportList.begin();it!=m_exportList.end();it++)
      {
        //if path starts with the current export path
        if( path.Find(*it) ==  0 )
        {
          exportPath = *it;
          relativePath = "//" + path.Right((path.length()-1) - exportPath.length());
          ret = true;
          break;          
        }
      }
    }
    return ret;
}
Beispiel #18
0
void CTextSearch::GetAndCutNextTerm(CStdString &strSearchTerm, CStdString &strNextTerm)
{
  CStdString strFindNext(" ");

  if (StringUtils::EndsWith(strSearchTerm, "\""))
  {
    strSearchTerm.erase(0, 1);
    strFindNext = "\"";
  }

  int iNextPos = strSearchTerm.Find(strFindNext);
  if (iNextPos != -1)
  {
    strNextTerm = strSearchTerm.Left(iNextPos);
    strSearchTerm.erase(0, iNextPos + 1);
  }
  else
  {
    strNextTerm = strSearchTerm;
    strSearchTerm.clear();
  }
}
Beispiel #19
0
void CPVRRecording::Update(const CPVRRecording &tag)
{
  m_strRecordingId    = tag.m_strRecordingId;
  m_iClientId         = tag.m_iClientId;
  m_strTitle          = tag.m_strTitle;
  m_recordingTime     = tag.m_recordingTime;
  m_duration          = tag.m_duration;
  m_iPriority         = tag.m_iPriority;
  m_iLifetime         = tag.m_iLifetime;
  m_strDirectory      = tag.m_strDirectory;
  m_strPlot           = tag.m_strPlot;
  m_strPlotOutline    = tag.m_strPlotOutline;
  m_strStreamURL      = tag.m_strStreamURL;
  m_strChannelName    = tag.m_strChannelName;
  m_genre             = tag.m_genre;
  m_strIconPath       = tag.m_strIconPath;
  m_strThumbnailPath  = tag.m_strThumbnailPath;
  m_strFanartPath     = tag.m_strFanartPath;

  if (g_PVRClients->SupportsRecordingPlayCount(m_iClientId))
    m_playCount       = tag.m_playCount;

  CStdString strShow;
  strShow.Format("%s - ", g_localizeStrings.Get(20364).c_str());
  if (m_strPlotOutline.Left(strShow.size()).Equals(strShow))
  {
    CStdString strEpisode = m_strPlotOutline;
    CStdString strTitle = m_strDirectory;
    
    int pos = strTitle.ReverseFind('/');
    strTitle.erase(0, pos + 1);
    strEpisode.erase(0, strShow.size());
    m_strTitle.Format("%s - %s", strTitle.c_str(), strEpisode);
    pos = strEpisode.Find('-');
    strEpisode.erase(0, pos + 2);
    m_strPlotOutline = strEpisode;
  }
  UpdatePath();
}
Beispiel #20
0
void CGUIBaseContainer::OnJumpSMS(int letter)
{
  static const char letterMap[8][6] = { "ABC2", "DEF3", "GHI4", "JKL5", "MNO6", "PQRS7", "TUV8", "WXYZ9" };

  // only 2..9 supported
  if (letter < 2 || letter > 9 || !m_letterOffsets.size())
    return;

  const CStdString letters = letterMap[letter - 2];
  
  // find where we currently are
  int offset = CorrectOffset(m_offset, m_cursor);
  unsigned int currentLetter = 0;
  while (currentLetter + 1 < m_letterOffsets.size() && m_letterOffsets[currentLetter + 1].first <= offset)
    currentLetter++;
  
  // now switch to the next letter
  CStdString current = m_letterOffsets[currentLetter].second;
  int startPos = (letters.Find(current.ToUpper()) + 1) % letters.size();
  
  // now jump to letters[startPos], or another one in the same range if possible
  int pos = startPos;
  while (true)
  {
    // check if we can jump to this letter
    for (unsigned int i = 0; i < m_letterOffsets.size(); i++)
    {
      if (m_letterOffsets[i].second.ToLower() == letters.Mid(pos, 1).ToLower())
      {
        SelectItem(m_letterOffsets[i].first);
        return;
      }
    }
    pos = (pos + 1) % letters.size();
    if (pos == startPos)
      return;
  }
}
/// \brief Build a directory history string
/// \param pItem Item to build the history string from
/// \param strHistoryString History string build as return value
void CGUIWindowFileManager::GetDirectoryHistoryString(const CFileItem* pItem, CStdString& strHistoryString)
{
  if (pItem->m_bIsShareOrDrive)
  {
    // We are in the virtual directory

    // History string of the DVD drive
    // must be handel separately
    if (pItem->m_iDriveType == CMediaSource::SOURCE_TYPE_DVD)
    {
      // Remove disc label from item label
      // and use as history string, m_strPath
      // can change for new discs
      CStdString strLabel = pItem->GetLabel();
      int nPosOpen = strLabel.Find('(');
      int nPosClose = strLabel.ReverseFind(')');
      if (nPosOpen > -1 && nPosClose > -1 && nPosClose > nPosOpen)
      {
        strLabel.Delete(nPosOpen + 1, (nPosClose) - (nPosOpen + 1));
        strHistoryString = strLabel;
      }
      else
        strHistoryString = strLabel;
    }
    else
    {
      // Other items in virtual directory
      strHistoryString = pItem->GetLabel() + pItem->m_strPath;
      CUtil::RemoveSlashAtEnd(strHistoryString);
    }
  }
  else
  {
    // Normal directory items
    strHistoryString = pItem->m_strPath;
    CUtil::RemoveSlashAtEnd(strHistoryString);
  }
}
Beispiel #22
0
const CStdString CPVRRecordings::GetDirectoryFromPath(const CStdString &strPath, const CStdString &strBase) const
{
  CStdString strReturn;
  CStdString strUsePath = TrimSlashes(strPath);
  CStdString strUseBase = TrimSlashes(strBase);

  /* strip the base or return an empty value if it doesn't fit or match */
  if (!strUseBase.IsEmpty())
  {
    if (strUsePath.GetLength() <= strUseBase.GetLength() || strUsePath.Left(strUseBase.GetLength()) != strUseBase)
      return strReturn;
    strUsePath.erase(0, strUseBase.GetLength());
  }

  /* check for more occurences */
  int iDelimiter = strUsePath.Find('/');
  if (iDelimiter > 0)
    strReturn = strUsePath.Left(iDelimiter);
  else
    strReturn = strUsePath;

  return TrimSlashes(strReturn);
}
void TestGlobalMethods::TestReplaceFileExtension()
{
	CStdString sFile = _T("NotPDF.doc");
	CStdString sExtension = _T("pdf");
	CStdString sResult = ReplaceFileExtension(sFile, sExtension.c_str());
	int iPosition = sResult.ReverseFind(_T('.'));
	CStdString sNewExtension = sResult.Right((int)sResult.length() - (iPosition + 1));
	assertMessage(0 != iPosition, _T("Failed to locate file extension separator '.'"));
	assertMessage(0 == (int)sExtension.CompareNoCase(sNewExtension), _T("Failed to match the expected extension 'pdf'"));

	sFile = _T("IsPDF.pdf");
	sExtension = _T("pdf");
	sResult = ReplaceFileExtension(sFile, sExtension.c_str());
	sNewExtension = sResult.Right((int)sResult.length() - (sResult.Find(_T("."), 0) + 1));
	assertMessage(sExtension.length() == sNewExtension.length(), _T("We expected the extension lengths to be equal"));

	sFile = _T("NoExtension");
	sExtension = _T("pdf");
	sResult = ReplaceFileExtension(sFile, sExtension.c_str());
	iPosition = sResult.ReverseFind(_T('.'));
	assertMessage(0 != iPosition, _T("Failed to locate file extension separator '.'"));
	assertMessage(0 == (int)sExtension.CompareNoCase(sResult.Right((int)sResult.length() - (iPosition + 1))), _T("Failed to match the expected extension 'pdf'"));
}
Beispiel #24
0
const CStdString CPVRRecordings::GetDirectoryFromPath(const CStdString &strPath, const CStdString &strBase) const
{
  CStdString strReturn;
  CStdString strUsePath = TrimSlashes(strPath);
  CStdString strUseBase = TrimSlashes(strBase);

  /* strip the base or return an empty value if it doesn't fit or match */
  if (!strUseBase.IsEmpty())
  {
    /* adding "/" to make sure that base matches the complete folder name and not only parts of it */
    if (strUsePath.GetLength() <= strUseBase.GetLength() || strUsePath.Left(strUseBase.GetLength() + 1) != strUseBase + "/")
      return strReturn;
    strUsePath.erase(0, strUseBase.GetLength());
  }

  /* check for more occurences */
  int iDelimiter = strUsePath.Find('/');
  if (iDelimiter > 0)
    strReturn = strUsePath.Left(iDelimiter);
  else
    strReturn = strUsePath;

  return TrimSlashes(strReturn);
}
Beispiel #25
0
void URIUtils::RemoveExtension(CStdString& strFileName)
{
  if(IsURL(strFileName))
  {
    CURL url(strFileName);
    strFileName = url.GetFileName();
    RemoveExtension(strFileName);
    url.SetFileName(strFileName);
    strFileName = url.Get();
    return;
  }

  int iPos = strFileName.ReverseFind(".");
  // Extension found
  if (iPos > 0)
  {
    CStdString strExtension;
    GetExtension(strFileName, strExtension);
    strExtension.ToLower();
    strExtension += "|";

    CStdString strFileMask;
    strFileMask = g_settings.m_pictureExtensions;
    strFileMask += "|" + g_settings.m_musicExtensions;
    strFileMask += "|" + g_settings.m_videoExtensions;
#if defined(__APPLE__)
    strFileMask += "|.py|.xml|.milk|.xpr|.xbt|.cdg|.app|.applescript|.workflow";
#else
    strFileMask += "|.py|.xml|.milk|.xpr|.xbt|.cdg";
#endif
    strFileMask += "|";

    if (strFileMask.Find(strExtension) >= 0)
      strFileName = strFileName.Left(iPos);
  }
}
Beispiel #26
0
void CAppRegistry::Unset(const CStdString& key)
{
  CSingleLock lock(m_lock);

  CStdString tempKey = key;
  size_t i = 0;

  // If we are asked for a variable with {}, take it from the vector, otherwise return the first
  int pos1 = key.Find("{");
  int pos2 = key.Find("}");
  if (pos1 >= 0 && pos2 > 0)
  {
    i = atoi(key.Mid(pos1+1, pos2 - pos1-1).c_str());
    tempKey = key.Mid(0, pos1);
  }

  // Check if the key exists
  if (m_data.find(tempKey) == m_data.end())
    return;

  // Check that the index is not out of bounds
  RegistryValue& values = m_data[tempKey];
  if (i > values.size()-1)
    return;

  // Remove the item from the deque
  values.erase(values.begin() + i);
  
  // If the the map item has an empty deque, delete it 
  if (values.size() == 0)
  {
    m_data.erase(tempKey);
  }
  
  Save();
}
void CLastFMDirectory::AddEntry(int iString, CStdString strPath, CStdString strIconPath, bool bFolder, CFileItemList &items)
{
  CStdString strLabel = g_localizeStrings.Get(iString);
  strLabel.Replace("%name%", m_objname);
  strLabel.Replace("%type%", m_objtype);
  strLabel.Replace("%request%", m_objrequest);
  strPath.Replace("%name%", m_encodedobjname);
  strPath.Replace("%type%", m_objtype);
  strPath.Replace("%request%", m_objrequest);

  CFileItemPtr pItem(new CFileItem);
  pItem->SetLabel(strLabel);
  pItem->m_strPath = strPath;
  pItem->m_bIsFolder = bFolder;
  pItem->SetLabelPreformated(true);
  //the extra info is used in the mediawindows to determine which items are needed in the contextmenu
  if (strPath.Find("lastfm://xbmc") >= 0)
  {
    pItem->SetCanQueue(false);
    pItem->SetExtraInfo("lastfmitem");
  }

  items.Add(pItem);
}
Beispiel #28
0
bool URIUtils::IsDVD(const CStdString& strFile)
{
  CStdString strFileLow = strFile;
  strFileLow.MakeLower();
  if (strFileLow.Find("video_ts.ifo") != -1 && IsOnDVD(strFile))
    return true;

#if defined(_WIN32)
  if (strFile.Left(6).Equals("dvd://"))
    return true;

  if(strFile.Mid(1) != ":\\"
  && strFile.Mid(1) != ":")
    return false;

  if(GetDriveType(strFile.c_str()) == DRIVE_CDROM)
    return true;
#else
  if (strFileLow == "iso9660://" || strFileLow == "udf://" || strFileLow == "dvd://1" )
    return true;
#endif

  return false;
}
Beispiel #29
0
bool URIUtils::IsDVD(const CStdString& strFile)
{
  CStdString strFileLow = strFile;
  strFileLow.MakeLower();
  if (strFileLow.Find("video_ts.ifo") != -1 && IsOnDVD(strFile))
    return true;

#if defined(TARGET_WINDOWS)
  if (StringUtils::StartsWithNoCase(strFile, "dvd://"))
    return true;

  if(strFile.Mid(1) != ":\\"
  && strFile.Mid(1) != ":")
    return false;

  if(GetDriveType(strFile.c_str()) == DRIVE_CDROM)
    return true;
#else
  if (strFileLow == "iso9660://" || strFileLow == "udf://" || strFileLow == "dvd://1" )
    return true;
#endif

  return false;
}
Beispiel #30
0
void TestInterwoven::TestGetMatterFoldersEmailAdressesFromDocumentID()
{
	CScopedTestDoc doc;
	DocProviderWorker worker;
	worker.Init();
	worker.VerifySessionForServer("WORKSITE-C2");

	CStdString  sDocNum = CIManTestUtils::GetDocNumFromDocID(doc.GetDocId());

	INRTDatabasePtr pDatabase;
	worker.m_pSessionsManager->GetSessionForServer(_T("WORKSITE-C2"))->GetDatabaseForName(_T("idocsdb1"), pDatabase);

	IManDocumentPtr pSearchedDocument = CIManTestUtils::GetDocumentFromDatabase_Helper(worker.GetSessionsMgr()->GetNRTDMS(), pDatabase, sDocNum);
	assertMessage(pSearchedDocument != NULL, _T("Failed to find document : ") + doc.GetDocId());

	IManDocumentFolderPtr pDocFolder = CIManTestUtils::GetFolder_Helper(pDatabase, FOLDER_NAME);
	IManDocumentsPtr pDocs = pDocFolder->Contents;
	IManContentPtr pContentPtr = pSearchedDocument;

	HRESULT hr = pDocs->raw_AddDocumentReference( pSearchedDocument, &pContentPtr);

	CStdString sEmailString = worker.GetMatterFoldersEmailAddressesFromDocumentID(doc.GetDocId());
	assertMessage(sEmailString.Find(_T("*****@*****.**"))!=-1, _T("GetMatterFolderEmailAdressFromDocumentID() failed to return a correct folder email address string"));
}