Example #1
0
void PathHelper::RemoveFromPath(CStdString sPath)
{
	CStdString sFullPath = GetProcessPath();

	sFullPath.ToLower();
	sPath.ToLower();

	if ( sPath.Right(1) == _T("\\") )
	{
		sPath = sPath.Left(sPath.length() - 1);
	}

	int nStart = (x64_int_cast)sFullPath.find(sPath);

	while (nStart >= 0)  // there may be multiple copies
	{
		int nEnd = nStart + (x64_int_cast)sPath.length() + 1;

		sFullPath = sFullPath.Left(nStart) + sFullPath.Right(sFullPath.length() - nEnd );

		sFullPath.TrimRight();
		sFullPath.TrimLeft();

		if (sFullPath.Left(1) == _T(";"))
			sFullPath = sFullPath.Mid(1);

		sFullPath.Replace(_T(";;"),_T(";"));

		nStart = (x64_int_cast)sFullPath.find(sPath);
	}

	SetProcessPath(sFullPath);
}
void CLocalFilesSource::RequestItems(bool bUseCurPath)
{
  CBoxeeSort previousSort = m_sourceSort;
  CStdString strPath = GetBasePath();


  if (strPath.Find("sources://all") >= 0 || strPath.CompareNoCase("network://protocols") == 0)
  {
    m_sourceSort.Reset();
  }
  else if (strPath.IsEmpty() ||
      strPath == "network:/" ||
      strPath.Equals("afp:/") ||
      (strPath.Left(6).Equals("afp://") && strPath.Right(6).Equals(".local")) ||
      strPath.Left(15).Equals("smb://computers") ||
      strPath == "nfs:/" ||
      (strPath.Left(6).Equals("nfs://") && strPath.Right(6).Equals(".local")) ||
      strPath.Left(6).Equals("upnp:/") ||
      strPath.Left(5).Equals("bms:/")
      )
  {
    CBoxeeSort specialCasesSort(VIEW_SORT_METHOD_ATOZ, SORT_METHOD_LABEL, SORT_ORDER_ASC, g_localizeStrings.Get(53505), "start");
    m_sourceSort = specialCasesSort;
  }  

  CBrowseWindowSource::RequestItems(bUseCurPath);
  m_sourceSort = previousSort;
}
void CGUIWindowBoxeeBrowseLocal::UpdateSortButtonState()
{
  CStdString strPath =  ((CLocalBrowseWindowState*)m_windowState)->GetCurrentPath();

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

  if (strPath.IsEmpty() ||
      strPath == "sources://all" ||
      strPath == "network:/" ||
      strPath == "network://protocols" ||
      strPath.Equals("afp:/") ||
      (strPath.Left(6).Equals("afp://") && strPath.Right(6).Equals(".local")) ||
      strPath.Left(15).Equals("smb://computers") ||
      strPath == "nfs:/" ||
      (strPath.Left(6).Equals("nfs://") && strPath.Right(6).Equals(".local")) ||
      strPath.Left(6).Equals("upnp:/") ||
      strPath.Left(5).Equals("bms:/")
      )
  {
    SET_CONTROL_HIDDEN(SORT_DROPDOWN_BUTTON);
  }
  else
  {
    SET_CONTROL_VISIBLE(SORT_DROPDOWN_BUTTON);
  }

  return;
}
Example #4
0
void StringUtils::RemoveCRLF(CStdString& strLine)
{
  while ( strLine.size() && (strLine.Right(1) == "\n" || strLine.Right(1) == "\r") )
  {
    strLine = strLine.Left(std::max(0, (int)strLine.size() - 1));
  }
}
Example #5
0
bool CPVRChannelGroupsContainer::GetDirectory(const CStdString& strPath, CFileItemList &results)
{
    CStdString strBase(strPath);

    /* get the filename from curl */
    CURL url(strPath);
    CStdString fileName = url.GetFileName();
    URIUtils::RemoveSlashAtEnd(fileName);

    if (fileName == "channels")
    {
        CFileItemPtr item;

        /* all tv channels */
        item.reset(new CFileItem(strBase + "/tv/", true));
        item->SetLabel(g_localizeStrings.Get(19020));
        item->SetLabelPreformated(true);
        results.Add(item);

        /* all radio channels */
        item.reset(new CFileItem(strBase + "/radio/", true));
        item->SetLabel(g_localizeStrings.Get(19021));
        item->SetLabelPreformated(true);
        results.Add(item);

        return true;
    }
    else if (fileName == "channels/tv")
    {
        return GetGroupsDirectory(&results, false);
    }
    else if (fileName == "channels/radio")
    {
        return GetGroupsDirectory(&results, true);
    }
    else if (fileName.Left(12) == "channels/tv/")
    {
        CStdString strGroupName(fileName.substr(12));
        URIUtils::RemoveSlashAtEnd(strGroupName);
        CPVRChannelGroupPtr group = GetTV()->GetByName(strGroupName);
        if (!group)
            group = GetGroupAllTV();
        if (group)
            group->GetMembers(results, !fileName.Right(7).Equals(".hidden"));
        return true;
    }
    else if (fileName.Left(15) == "channels/radio/")
    {
        CStdString strGroupName(fileName.substr(15));
        URIUtils::RemoveSlashAtEnd(strGroupName);
        CPVRChannelGroupPtr group = GetRadio()->GetByName(strGroupName);
        if (!group)
            group = GetGroupAllRadio();
        if (group)
            group->GetMembers(results, !fileName.Right(7).Equals(".hidden"));
        return true;
    }

    return false;
}
Example #6
0
  bool Codec::Init(const CStdString & strFile, unsigned int filecache) {
    m_bufferSize = 2048 * sizeof(int16_t) * 50;
    m_buffer = new char[m_bufferSize];
    CStdString uri = URIUtils::GetFileName(strFile);
    CStdString extension = uri.Right(uri.GetLength() - uri.Find('.') - 1);
    if (extension.Left(12) == "spotifyradio") {
      //if its a radiotrack the radionumber and tracknumber is secretly encoded at the end of the extension
      CStdString trackStr = extension.Right(
          extension.GetLength() - extension.ReverseFind('#') - 1);
      Logger::printOut(extension);
      CStdString radioNumber = extension.Left(uri.Find('#'));
      Logger::printOut(radioNumber);
      radioNumber = radioNumber.Right(
          radioNumber.GetLength() - radioNumber.Find('#') - 1);
      Logger::printOut("loading codec radio");
      RadioHandler::getInstance()->pushToTrack(atoi(radioNumber),
          atoi(trackStr));
    }
    //we have a non legit extension so remove it manually
    uri = uri.Left(uri.Find('.'));

    Logger::printOut("trying to load track:");
    Logger::printOut(uri);
    sp_link *spLink = sp_link_create_from_string(uri);
    m_currentTrack = sp_link_as_track(spLink);
    sp_track_add_ref(m_currentTrack);
    sp_link_release(spLink);
    m_endOfTrack = false;
    m_bufferPos = 0;
    m_startStream = false;
    m_isPlayerLoaded = false;
    m_TotalTime = sp_track_duration(m_currentTrack);

    //prefetch the next track!

	  CPlayList& playlist = g_playlistPlayer.GetPlaylist(PLAYLIST_MUSIC);
	  int nextSong = g_playlistPlayer.GetNextSong();

	  if (nextSong >= 0 && nextSong < playlist.size()){
	  	CFileItemPtr song = playlist[nextSong];
	  	if (song != NULL){
	  		CStdString uri = song->GetPath();
	  		if (uri.Left(7).Equals("spotify")){
	  			uri = uri.Left(uri.Find('.'));
	  	    Logger::printOut("prefetching track:");
	  	    Logger::printOut(uri);
	  	    sp_link *spLink = sp_link_create_from_string(uri);
	  	    sp_track* track = sp_link_as_track(spLink);
	  	    sp_session_player_prefetch(getSession(), track);
	  	    sp_link_release(spLink);
	  		}
	  	}
	  }

    return true;
  }
Example #7
0
File: dialog.cpp Project: foen/xbmc
  PyObject* Dialog_Numeric(PyObject *self, PyObject *args)
  {
    int inputtype = 0;
    CStdString value;
    PyObject *heading = NULL;
    char *cDefault = NULL;
    SYSTEMTIME timedate;
    GetLocalTime(&timedate);
    if (!PyArg_ParseTuple(args, (char*)"iO|s", &inputtype, &heading, &cDefault))  return NULL;

    CStdString utf8Heading;
    if (heading && PyXBMCGetUnicodeString(utf8Heading, heading, 1))
    {
      if (inputtype == 1)
      {
        if (cDefault && strlen(cDefault) == 10)
        {
          CStdString sDefault = cDefault;
          timedate.wDay = atoi(sDefault.Left(2));
          timedate.wMonth = atoi(sDefault.Mid(3,4));
          timedate.wYear = atoi(sDefault.Right(4));
        }
        bool gotDate;
        Py_BEGIN_ALLOW_THREADS
        gotDate = CGUIDialogNumeric::ShowAndGetDate(timedate, utf8Heading);
        Py_END_ALLOW_THREADS
        if (gotDate)
          value.Format("%2d/%2d/%4d", timedate.wDay, timedate.wMonth, timedate.wYear);
        else
        {
          Py_INCREF(Py_None);
          return Py_None;
        }
      }
      else if (inputtype == 2)
      {
        if (cDefault && strlen(cDefault) == 5)
        {
          CStdString sDefault = cDefault;
          timedate.wHour = atoi(sDefault.Left(2));
          timedate.wMinute = atoi(sDefault.Right(2));
        }
        bool gotTime;
        Py_BEGIN_ALLOW_THREADS
        gotTime = CGUIDialogNumeric::ShowAndGetTime(timedate, utf8Heading);
        Py_END_ALLOW_THREADS
        if (gotTime)
          value.Format("%2d:%02d", timedate.wHour, timedate.wMinute);
        else
        {
          Py_INCREF(Py_None);
          return Py_None;
        }
      }
      else if (inputtype == 3)
Example #8
0
bool CPeripheralCecAdapter::TranslateComPort(CStdString &strLocation)
{
    if (strLocation.Left(18).Equals("peripherals://usb/") && strLocation.Right(4).Equals(".dev"))
    {
        strLocation = strLocation.Right(strLocation.length() - 18);
        strLocation = strLocation.Left(strLocation.length() - 4);
        return true;
    }

    return false;
}
Example #9
0
String Dialog::numeric(int inputtype, const String& heading, const String& defaultt)
{
    DelayedCallGuard dcguard(languageHook);
    CStdString value;
    SYSTEMTIME timedate;
    GetLocalTime(&timedate);

    if (!heading.empty())
    {
        if (inputtype == 1)
        {
            if (!defaultt.empty() && defaultt.size() == 10)
            {
                CStdString sDefault = defaultt;
                timedate.wDay = atoi(sDefault.Left(2));
                timedate.wMonth = atoi(sDefault.Mid(3,4));
                timedate.wYear = atoi(sDefault.Right(4));
            }
            if (CGUIDialogNumeric::ShowAndGetDate(timedate, heading))
                value.Format("%2d/%2d/%4d", timedate.wDay, timedate.wMonth, timedate.wYear);
            else
                return emptyString;
        }
        else if (inputtype == 2)
        {
            if (!defaultt.empty() && defaultt.size() == 5)
            {
                CStdString sDefault = defaultt;
                timedate.wHour = atoi(sDefault.Left(2));
                timedate.wMinute = atoi(sDefault.Right(2));
            }
            if (CGUIDialogNumeric::ShowAndGetTime(timedate, heading))
                value.Format("%2d:%02d", timedate.wHour, timedate.wMinute);
            else
                return emptyString;
        }
        else if (inputtype == 3)
        {
            value = defaultt;
            if (!CGUIDialogNumeric::ShowAndGetIPAddress(value, heading))
                return emptyString;
        }
        else
        {
            value = defaultt;
            if (!CGUIDialogNumeric::ShowAndGetNumber(value, heading))
                return emptyString;
        }
    }
    return value;
}
Example #10
0
DocXDocumentStore::DocXDocumentStore( CStdString sFileName, bool bReadOnly, bool )
	:	m_sFileName(sFileName),
		m_dwChecksum(0)
{
	if( _waccess( sFileName, bReadOnly ? 04 : 06 ) != 0 )
		Workshare::Exception::Throw(CStdString(_T("Invalid file name")), -1, _T(__FILE__), _T(__FUNCTION__), __LINE__);

	if( sFileName.Right(5).CompareNoCase( _T(".docx")) != 0 &&
		sFileName.Right(5).CompareNoCase( _T(".docm")) != 0 )
		Workshare::Exception::Throw(CStdString(_T("Invalid file name")), -1, _T(__FILE__), _T(__FUNCTION__), __LINE__);
		
	m_dwChecksum = GetDocumentChecksum( bReadOnly );
	m_spDocument.reset(new Document(sFileName.c_str(), bReadOnly));
}
Example #11
0
//========================================================================
int CFileURLProtocol::Open(AML_URLContext *h, const char *filename, int flags)
{
  if (flags != URL_RDONLY)
  {
    CLog::Log(LOGDEBUG, "CFileURLProtocol::Open: Only read-only is supported");
    return -EINVAL;
  }

  CStdString url = filename;
  if (url.Left(strlen("xb-http://")).Equals("xb-http://"))
  {
    url = url.Right(url.size() - strlen("xb-"));
  }
  else if (url.Left(strlen("xb-https://")).Equals("xb-https://"))
  {
    url = url.Right(url.size() - strlen("xb-"));
  }
  else if (url.Left(strlen("xb-ftp://")).Equals("xb-ftp://"))
  {
    url = url.Right(url.size() - strlen("xb-"));
  }
  else if (url.Left(strlen("xb-ftps://")).Equals("xb-ftps://"))
  {
    url = url.Right(url.size() - strlen("xb-"));
  }
  else if (url.Left(strlen("xb-hdhomerun://")).Equals("xb-hdhomerun://"))
  {
    url = url.Right(url.size() - strlen("xb-"));
  }
  CLog::Log(LOGDEBUG, "CFileURLProtocol::Open filename2(%s)", url.c_str());
  // open the file, always in read mode, calc bitrate
  unsigned int cflags = READ_BITRATE;
  XFILE::CFile *cfile = new XFILE::CFile();

  if (CFileItem(url, true).IsInternetStream())
    cflags |= READ_CACHED;

  // open file in binary mode
  if (!cfile->Open(url, cflags))
  {
    delete cfile;
    return -EIO;
  }

  h->priv_data = (void *)cfile;

  return 0;
}
Example #12
0
void DocFileField::UpdateSaveDate(WordParserInfo& wpi)
{
    if ( wpi.m_FileSaveTime.wYear == 0)
        return;

    CStdString sInst = GetInst()->GetAllInstructionText().GetData();
    if (sInst.Find(L"SAVEDATE") < 0)
        return;

    int iPos = sInst.Find(L"@");
    if (iPos < 0)
        return;

    // strip out the format
    iPos = sInst.Find(L"\"", iPos);
    sInst = sInst.Right(sInst.length() - iPos - 1);
    iPos = sInst.Find(L"\"", 0);
    sInst = sInst.Left(iPos);

    CStdString sOut = GetDateString(sInst, wpi.m_FileSaveTime);
    if (sOut.IsEmpty())
        return;

    int iCount = the_RTFFieldResult->GetCount();
    for (int i=0; i<iCount; i++)
    {
        if (the_RTFFieldResult->At(i)->GetType() == rotPcdata)
        {
            ((RTFPCData*)the_RTFFieldResult->At(i))->SetContent(sOut.c_str());
        }
    }
}
Example #13
0
bool CWebServer::PrepareDownload(const char *path, CVariant &details, std::string &protocol)
{
  bool exists = false;
  CFile *file = new CFile();
  if (file->Open(path))
  {
    exists = true;
    file->Close();
  }

  delete file;

  if (exists)
  {
    protocol = "http";
    string url;
    CStdString strPath = path;
    if (strPath.Left(8) == "image://" ||
       (strPath.Left(10) == "special://" && strPath.Right(4) == ".tbn"))
      url = "image/";
    else
      url = "vfs/";
    CURL::Encode(strPath);
    url += strPath;
    details["path"] = url;
  }

  return exists;
}
Example #14
0
// Get the thread name using the implementation dependant typeid() class
// and attempt to clean it.
CStdString CThread::GetTypeName(void)
{
  CStdString name = typeid(*this).name();
 
#if defined(_MSC_VER)
  // Visual Studio 2010 returns the name as "class CThread" etc
  if (name.substr(0, 6) == "class ")
    name = name.Right(name.length() - 6);
#elif defined(__GNUC__) && !defined(__clang__)
  // gcc provides __cxa_demangle to demangle the name
  char* demangled = NULL;
  int   status;

  demangled = __cxa_demangle(name.c_str(), NULL, 0, &status);
  if (status == 0)
    name = demangled;
  else
    CLog::Log(LOGDEBUG,"%s, __cxa_demangle(%s) failed with status %d", __FUNCTION__, name.c_str(), status);

  if (demangled)
    free(demangled);
#endif

  return name;
}
Example #15
0
/*!
 \brief Test if file have an allowed extension, as specified with SetMask()
 \param strFile File to test
 \return \e true if file is allowed
 \note If extension is ".ifo", filename format must be "vide_ts.ifo" or
       "vts_##_0.ifo". If extension is ".dat", filename format must be
       "AVSEQ##(#).DAT", "ITEM###(#).DAT" or "MUSIC##(#).DAT".
 */
bool IDirectory::IsAllowed(const CStdString& strFile) const
{
    if (m_strFileMask.empty() || strFile.empty())
        return true;

    // Check if strFile have an allowed extension
    if (!URIUtils::HasExtension(strFile, m_strFileMask))
        return false;

    // We should ignore all non dvd/vcd related ifo and dat files.
    if (URIUtils::HasExtension(strFile, ".ifo"))
    {
        CStdString fileName = URIUtils::GetFileName(strFile);

        // Allow filenames of the form video_ts.ifo or vts_##_0.ifo
        return fileName.CompareNoCase("video_ts.ifo") == 0 ||
               (fileName.length() == 12 && fileName.Left(4).CompareNoCase("vts_") == 0 &&
                fileName.Right(6).CompareNoCase("_0.ifo") == 0);
    }

    if (URIUtils::HasExtension(strFile, ".dat"))
    {
        CStdString fileName = URIUtils::GetFileName(strFile);

        // Allow filenames of the form AVSEQ##(#).DAT, ITEM###(#).DAT
        // and MUSIC##(#).DAT
        return (fileName.length() == 11 || fileName.length() == 12) &&
               (fileName.Left(5).CompareNoCase("AVSEQ") == 0 || fileName.Left(5).CompareNoCase("MUSIC") == 0 ||
                fileName.Left(4).CompareNoCase("ITEM") == 0);
    }

    return true;
}
Example #16
0
bool CPVRDatabase::DeleteChannelsFromGroup(const CPVRChannelGroup &group, const vector<int> &channelsToDelete)
{
  bool bDelete(true);
  unsigned int iDeletedChannels(0);

  while (iDeletedChannels < channelsToDelete.size())
  {
    CStdString strChannelsToDelete;
    CStdString strWhereClause;

    for (unsigned int iChannelPtr = 0; iChannelPtr + iDeletedChannels < channelsToDelete.size() && iChannelPtr < 50; iChannelPtr++)
      strChannelsToDelete.AppendFormat(", %d", channelsToDelete.at(iDeletedChannels + iChannelPtr));

    if (!strChannelsToDelete.IsEmpty())
    {
      strChannelsToDelete = strChannelsToDelete.Right(strChannelsToDelete.length() - 2);
      strWhereClause = FormatSQL("idGroup = %u AND idChannel IN (%s)", group.GroupID(), strChannelsToDelete.c_str());
      bDelete = DeleteValues("map_channelgroups_channels", strWhereClause) && bDelete;
    }

    iDeletedChannels += 50;
  }

  return bDelete;
}
Example #17
0
/*!
 \brief Test a file for an extension specified with SetMask().
 \param strFile File to test
 \return Returns \e true, if file is allowed.
 */
bool IDirectory::IsAllowed(const CStdString& strFile) const
{
    CStdString strExtension;
    if ( !m_strFileMask.size() ) return true;
    if ( !strFile.size() ) return true;

    URIUtils::GetExtension(strFile, strExtension);

    if (!strExtension.size()) return false;

    strExtension.ToLower();
    strExtension += '|'; // ensures that we have a | at the end of it
    if (m_strFileMask.Find(strExtension) != -1)
    {   // it's allowed, but we should also ignore all non dvd related ifo files.
        if (strExtension.Equals(".ifo|"))
        {
            CStdString fileName = URIUtils::GetFileName(strFile);
            if (fileName.Equals("video_ts.ifo")) return true;
            if (fileName.length() == 12 && fileName.Left(4).Equals("vts_") && fileName.Right(6).Equals("_0.ifo")) return true;
            return false;
        }
        if (strExtension.Equals(".dat|"))
        {
            CStdString fileName = URIUtils::GetFileName(strFile);
            /* VCD filenames are of the form AVSEQ##(#).DAT, ITEM###(#).DAT, MUSIC##(#).DAT - i.e. all 11 or 12 characters long
               starting with AVSEQ, MUSIC or ITEM */
            if ((fileName.length() == 11 || fileName.length() == 12) &&
                    (fileName.Left(5).Equals("AVSEQ") || fileName.Left(5).Equals("MUSIC") || fileName.Left(4).Equals("ITEM")))
                return true;
            return false;
        }
        return true;
    }
    return false;
}
Example #18
0
void Serializer::GetCsvMap(const char* key, std::map<CStdString, CStdString>& value, bool required)
{
    std::list<CStdString> cvsList;
    GetCsv(key, cvsList, required);

    for(std::list<CStdString>::iterator it = cvsList.begin(); it != cvsList.end(); it++)
    {
        CStdString keyValuePair = *it;
        int colonPos = keyValuePair.Find(':');
        if(colonPos != -1)
        {
            CStdString key = keyValuePair.Left(colonPos);
            CStdString val = keyValuePair.Right(keyValuePair.size() - colonPos - 1);

            CStdString unescapedKey;
            UnEscapePair(key, unescapedKey);
            CStdString unescapedVal;
            UnEscapePair(val, unescapedVal);

            value.insert(std::make_pair(unescapedKey, unescapedVal));
        }
        else
        {
            throw(CStdString("DeSerializer: GetCsvMap: missing colon in map element"));
        }
    }
}
/*!
 \brief Test a file for an extension specified with SetMask().
 \param strFile File to test
 \return Returns \e true, if file is allowed.
 */
bool IDirectory::IsAllowed(const CStdString& strFile) const
{
  CStdString strExtension;
  if ( !m_strFileMask.size() ) return true;
  if ( !strFile.size() ) return true;

  CUtil::GetExtension(strFile, strExtension);

  if (!strExtension.size()) return false;

  strExtension.ToLower();
  strExtension += '|'; // ensures that we have a | at the end of it
  if (m_strFileMask.Find(strExtension) != -1)
  { // it's allowed, but we should also ignore all non dvd related ifo files.
    if (strExtension.Equals(".ifo|"))
    {
      CStdString fileName = CUtil::GetFileName(strFile);
      if (fileName.Equals("video_ts.ifo")) return true;
      if (fileName.length() == 12 && fileName.Left(4).Equals("vts_") && fileName.Right(6).Equals("_0.ifo")) return true;
      return false;
    }
    return true;
  }
  return false;
}
Example #20
0
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");
  int pos = max(strFormat.ReverseFind('/'), strFormat.ReverseFind('\\'));
  if (pos != -1)
  {
    strFormat = strFormat.Right(strFormat.GetLength() - pos - 1);
  }

  CLabelFormatter formatter(strFormat, "");
  formatter.FormatLabel(&destItem);

  // grab the label to use it as our ripped filename
  CStdString track = destItem.GetLabel();
  if (track.IsEmpty())
    track.Format("%s%02i", "Track-", trackNumber);
  track += GetExtension(CSettings::Get().GetInt("audiocds.encoder"));

  return track;
}
Example #21
0
BOOL CObjectEntry::SetValueStringFormat(CStdString strFormattedValue)
{
    CMmcDataConversion conversion;
    unsigned __int64 uInt64Value(0);
    CStdString strValue = _T("");
    int iIndex;
    BOOL oResult(TRUE);

    //Remove leading text
    iIndex = strFormattedValue.FindOneOf("0123456789");
    if(iIndex != -1) strValue = strFormattedValue.Right(strFormattedValue.GetLength()-iIndex); else strValue = strFormattedValue;

    //Check Types
    if(conversion.DecUInt64Str2UInt64(strValue, &uInt64Value, FALSE))
    {
        m_ValueStringFormat = OVF_DEC;
        oResult = TRUE;
    }
    else if(conversion.HexUInt64Str2UInt64(strValue, &uInt64Value, FALSE))
    {
        m_ValueStringFormat = OVF_HEX;
        oResult = TRUE;
    }
    else
    {
        m_ValueStringFormat = OVF_DEC;
        oResult = FALSE;
    }

    return oResult;
}
bool Addon_music_spotify::GetTracks(CFileItemList& items, CStdString& path,
		CStdString artistName, int albumId) {
	Logger::printOut("get tracks");
	CURL url(path);
	CStdString uri = url.GetFileNameWithoutPath();
	//the path will look something like this "musicdb://2/spotify:artist:0LcJLqbBmaGUft1e9Mm8HV/-1/"
	//if we are trying to show all tracks for a spotify artist, we cant use the params becouse they are only integers.
	CURL url2(path.Left(path.GetLength() - 3));
	CStdString artist = url2.GetFileNameWithoutPath();

	if (uri.Left(13).Equals("spotify:album")) {
		return getAlbumTracks(items, uri);
	} else if (artist.Left(14).Equals("spotify:artist")) {
		return getArtistTracks(items, artist);
	} else if (uri.Left(16).Equals("spotify:playlist")) {
		uri.Delete(0, 17);
		return getPlaylistTracks(items, atoi(uri));
	} else if (artist.Left(15).Equals("spotify:toplist")) {
		return g_spotify->getTopListTracks(items);
	} else if (uri.Left(13).Equals("spotify:radio")) {
		return getRadioTracks(items, atoi(uri.Right(1)));
	} else if (uri.Left(13).Equals("spotify:track")) {
		return getAlbumTracksFromTrack(items, uri);
	} else if (albumId == -1) {
		return getAllTracks(items, artistName);
	}
	return true;
}
Example #23
0
CStdString SystemFolderInfo::GetDefaultUserAppDataPath()
{
	CStdString sPath;

	switch (GetWindowsVersion())
	{
	case WINDOWS_95:
	case WINDOWS_ME:
	case WINDOWS_98:
		sPath = GetWindowsPath() + _T("\\Application Data");
		break;

	case WINDOWS_NT:
		{
			sPath = GetLocalUserAppDataPath();

			int nPos = sPath.Find(_T("\\"), GetProfilesRoot().size()+1);

			sPath = GetProfilesRoot() + _T("\\Default User\\") + sPath.Right(sPath.size() - nPos - 1);
		}
		break;

	case WINDOWS_2K:
	case WINDOWS_XP:
	case WINDOWS_2003SERVER:
	default:
		sPath = GetFolderPath(CSIDL_APPDATA, (HANDLE)-1);
		break;

	}

	ValidatePath(sPath, CSIDL_APPDATA);
	return sPath;
}
Example #24
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;
}
Example #25
0
bool CAFPDirectory::ResolveSymlink( const CStdString &dirName, const CStdString &fileName, 
                                    struct stat *stat, CURL &resolvedUrl)
{
  CSingleLock lock(gAfpConnection); 
  int ret = 0;  
  bool retVal = true;
  char resolvedLink[MAX_PATH];
  CStdString fullpath = dirName;
  URIUtils::AddSlashAtEnd(fullpath);
  fullpath += fileName;
  
  CPasswordManager::GetInstance().AuthenticateURL(resolvedUrl);
  resolvedUrl.SetProtocol("afp");
  resolvedUrl.SetHostName(gAfpConnection.GetConnectedIp());   
  
  ret = gAfpConnection.GetImpl()->afp_wrap_readlink(gAfpConnection.GetVolume(), fullpath.c_str(), resolvedLink, MAX_PATH);    
  
  if(ret == 0)
  {
    fullpath = dirName;
    URIUtils::AddSlashAtEnd(fullpath);
    fullpath.append(resolvedLink);
 
    if(resolvedLink[0] == '/')
    {
      //use the special stat function for using an extra context
      //because we are inside of a dir traversation
      //and just can't change the global nfs context here
      //without destroying something...    
      fullpath = resolvedLink;
      fullpath = fullpath.Right(fullpath.length()-1);
      resolvedUrl.SetFileName(fullpath);     
      ret = gAfpConnection.stat(resolvedUrl, stat);
      if(ret < 0)
      {
        URIUtils::AddSlashAtEnd(fullpath);
        resolvedUrl.SetFileName(fullpath);     
        ret = gAfpConnection.stat(resolvedUrl, stat);
      }
    }
    else
    {
      ret = gAfpConnection.GetImpl()->afp_wrap_getattr(gAfpConnection.GetVolume(), fullpath.c_str(), stat);
      resolvedUrl.SetFileName(gAfpConnection.GetUrl()->volumename + fullpath);            
    }

    if (ret != 0) 
    {
      CLog::Log(LOGERROR, "AFP: Failed to stat(%s) on link resolve %s\n", fullpath.c_str(), strerror(errno));
      retVal = false;;
    }
  }
  else
  {
    CLog::Log(LOGERROR, "Failed to readlink(%s) %s\n", fullpath.c_str(), strerror(errno));
    retVal = false;
  }
  return retVal;
}
Example #26
0
bool CNFSFile::IsValidFile(const CStdString& strFileName)
{
  if (strFileName.Find('/') == -1 || /* doesn't have sharename */
      strFileName.Right(2) == "/." || /* not current folder */
      strFileName.Right(3) == "/..")  /* not parent folder */
    return false;
  return true;
}
Example #27
0
bool CPlayListB4S::LoadData(istream& stream)
{
  TiXmlDocument xmlDoc;

  stream >> xmlDoc;

  if (xmlDoc.Error())
  {
    CLog::Log(LOGERROR, "Unable to parse B4S info Error: %s", xmlDoc.ErrorDesc());
    return false;
  }

  TiXmlElement* pRootElement = xmlDoc.RootElement();
  if (!pRootElement ) return false;

  TiXmlElement* pPlayListElement = pRootElement->FirstChildElement("playlist");
  if (!pPlayListElement ) return false;
  m_strPlayListName = pPlayListElement->Attribute("label");

  TiXmlElement* pEntryElement = pPlayListElement->FirstChildElement("entry");

  if (!pEntryElement) return false;
  while (pEntryElement)
  {
    CStdString strFileName = pEntryElement->Attribute("Playstring");
    int iColon = strFileName.Find(":");
    if (iColon > 0)
    {
      iColon++;
      strFileName = strFileName.Right((int)strFileName.size() - iColon);
    }
    if (strFileName.size())
    {
      TiXmlNode* pNodeInfo = pEntryElement->FirstChild("Name");
      TiXmlNode* pNodeLength = pEntryElement->FirstChild("Length");
      long lDuration = 0;
      if (pNodeLength)
      {
        lDuration = atol(pNodeLength->FirstChild()->Value());
      }
      if (pNodeInfo)
      {
        CStdString strInfo = pNodeInfo->FirstChild()->Value();
        if (URIUtils::IsRemote(m_strBasePath) && g_advancedSettings.m_pathSubstitutions.size() > 0)
          strFileName = CUtil::SubstitutePath(strFileName);
        CUtil::GetQualifiedFilename(m_strBasePath, strFileName);
        CFileItemPtr newItem(new CFileItem(strInfo));
        newItem->m_strPath = strFileName;
        newItem->GetMusicInfoTag()->SetDuration(lDuration);
        Add(newItem);
      }
    }
    pEntryElement = pEntryElement->NextSiblingElement();
  }
  return true;
}
Example #28
0
int CDAAPDirectory::GetCurrLevel(CStdString strPath)
{
  int intSPos;
  int intEPos;
  int intLevel;
  int intCnt;
  CStdString strJustPath;

  intSPos = strPath.Find("://");
  if (intSPos > -1)
    strJustPath = strPath.Right(strPath.size() - (intSPos + 3));
  else
    strJustPath = strPath;

  URIUtils::RemoveSlashAtEnd(strJustPath);

  intLevel = -1;
  intSPos = strPath.length();
  while (intSPos > -1)
  {
    intSPos = strJustPath.ReverseFind("/", intSPos);
    if (intSPos > -1) intLevel ++;
    intSPos -= 2;
  }

  m_selectedPlaylist = "";
  m_selectedArtist = "";
  m_selectedAlbum = "";
  intCnt = intLevel;
  intEPos = (strJustPath.length() - 1);
  while (intCnt >= 0)
  {
    intSPos = strJustPath.ReverseFind("/", intEPos);
    if (intSPos > -1)
    {
      if (intCnt == 2)  // album
      {
        m_selectedAlbum = strJustPath.substr(intSPos + 1, (intEPos - intSPos));
      }
      else if (intCnt == 1) // artist
      {
        m_selectedArtist = strJustPath.substr(intSPos + 1, (intEPos - intSPos));
      }
      else if (intCnt == 0) // playlist
      {
        m_selectedPlaylist = strJustPath.substr(intSPos + 1, (intEPos - intSPos));
      }

      intEPos = (intSPos - 1);
      intCnt --;
    }
  }

  return intLevel;
}
Example #29
0
CStdString CPVRRecordings::AddAllRecordingsPathExtension(const CStdString &strDirectory)
{
  if (HasAllRecordingsPathExtension(strDirectory))
    return strDirectory;

  CStdString strResult = strDirectory;
  if (!strDirectory.Right(1).Equals("/"))
    strResult = strResult + "/";

  return strResult + PVR_ALL_RECORDINGS_PATH_EXTENSION + "/";
}
Example #30
0
bool CPVRDirectory::SupportsFileOperations(const CStdString& strPath)
{
  CURL url(strPath);
  CStdString filename = url.GetFileName();
  CUtil::RemoveSlashAtEnd(filename);

  if (filename.Left(11) == "recordings/" && filename.Right(4) == ".pvr")
     return true;

  return false;
}