示例#1
0
文件: WebServer.cpp 项目: Arcko/xbmc
bool CWebServer::LoadCert(std::string &skey, std::string &scert)
{
  XFILE::CFile file;
  XFILE::auto_buffer buf;
  const char* keyFile = "special://userdata/server.key";
  const char* certFile = "special://userdata/server.pem";

  if (!file.Exists(keyFile) || !file.Exists(certFile))
    return false;

  if (file.LoadFile(keyFile, buf) > 0)
  {
    skey.resize(buf.length());
    skey.assign(buf.get());
    file.Close();
  }
  else
    CLog::Log(LOGDEBUG, "WebServer %s: Error loading: %s", __FUNCTION__, keyFile);

  if (file.LoadFile(certFile, buf) > 0)
  {
    scert.resize(buf.length());
    scert.assign(buf.get());
    file.Close();
  }
  else
    CLog::Log(LOGDEBUG, "WebServer %s: Error loading: %s", __FUNCTION__, certFile);

  if (!skey.empty() && !scert.empty())
  {
    CLog::Log(LOGERROR, "WebServer %s: found server key: %s, certificate: %s, HTTPS support enabled", __FUNCTION__, keyFile, certFile);
    return true;
  }
  return false;
}
int CNfoFile::Load(const CStdString& strFile)
{
  Close();
  XFILE::CFile file;
  if (file.Open(strFile))
  {
    m_size = (int)file.GetLength();
    try
    {
      m_doc = new char[m_size+1];
      m_headofdoc = m_doc;
    }
    catch (...)
    {
      CLog::Log(LOGERROR, "%s: Exception while creating file buffer",__FUNCTION__);
      return 1;
    }
    if (!m_doc)
    {
      file.Close();
      return 1;
    }
    file.Read(m_doc, m_size);
    m_doc[m_size] = 0;
    file.Close();
    return 0;
  }
  return 1;
}
示例#3
0
文件: TestFile.cpp 项目: DasMarx/xbmc
TEST(TestFile, Write)
{
  XFILE::CFile *file;
  const char str[] = "TestFile.Write test string\n";
  char buf[30];
  memset(&buf, 0, sizeof(buf));

  ASSERT_TRUE((file = XBMC_CREATETEMPFILE("")) != NULL);
  file->Close();
  ASSERT_TRUE(file->OpenForWrite(XBMC_TEMPFILEPATH(file), true));
  EXPECT_EQ((int)sizeof(str), file->Write(str, sizeof(str)));
  file->Flush();
  EXPECT_EQ(0, file->GetPosition());
  file->Close();
  ASSERT_TRUE(file->Open(XBMC_TEMPFILEPATH(file)));
  EXPECT_EQ(0, file->GetPosition());
  EXPECT_EQ((int64_t)sizeof(str), file->Seek(0, SEEK_END));
  EXPECT_EQ(0, file->Seek(0, SEEK_SET));
  EXPECT_EQ((int64_t)sizeof(str), file->GetLength());
  EXPECT_EQ(sizeof(str), file->Read(buf, sizeof(buf)));
  file->Flush();
  EXPECT_EQ((int64_t)sizeof(str), file->GetPosition());
  EXPECT_TRUE(!memcmp(str, buf, sizeof(str)));
  file->Close();
  EXPECT_TRUE(XBMC_DELETETEMPFILE(file));
}
示例#4
0
bool CScraperUrl::Get(const SUrlEntry& scrURL, string& strHTML, CHTTP& http)
{
    CURL url(scrURL.m_url);
    http.SetReferer(scrURL.m_spoof);
    CStdString strCachePath;

    if (!scrURL.m_cache.IsEmpty())
    {
        CUtil::AddFileToFolder(g_advancedSettings.m_cachePath,"scrapers\\"+scrURL.m_cache,strCachePath);
        if (XFILE::CFile::Exists(strCachePath))
        {
            XFILE::CFile file;
            file.Open(strCachePath);
            char* temp = new char[(int)file.GetLength()];
            file.Read(temp,file.GetLength());
            strHTML.append(temp,temp+file.GetLength());
            file.Close();
            delete[] temp;
            return true;
        }
    }

    if (scrURL.m_post)
    {
        CStdString strOptions = url.GetOptions();
        strOptions = strOptions.substr(1);
        url.SetOptions("");
        CStdString strUrl;
        url.GetURL(strUrl);

        if (!http.Post(strUrl, strOptions, strHTML))
            return false;
    }
    else if (!http.Get(scrURL.m_url, strHTML))
        return false;

    if (scrURL.m_url.Find(".zip") > -1)
    {
        XFILE::CFileZip file;
        CStdString strBuffer;
        int iSize = file.UnpackFromMemory(strBuffer,strHTML);
        if (iSize)
        {
            strHTML.clear();
            strHTML.append(strBuffer.c_str(),strBuffer.data()+iSize);
        }
    }

    if (!scrURL.m_cache.IsEmpty())
    {
        CStdString strCachePath;
        CUtil::AddFileToFolder(g_advancedSettings.m_cachePath,"scrapers\\"+scrURL.m_cache,strCachePath);
        XFILE::CFile file;
        if (file.OpenForWrite(strCachePath,true,true))
            file.Write(strHTML.data(),strHTML.size());
        file.Close();
    }
    return true;
}
示例#5
0
bool CPFCManager::GetDefsFile(const CStdString& strPath, TiXmlDocument& xmlDocument) {

//	CStdString strTemp = strPath;
//
//	if (!URIUtils::IsURL(strTemp)) {
//		CURL::Encode(strTemp);
//	}

  CURL urlPath(strPath);
  CStdString strFile = urlPath.GetHostName();

  URIUtils::CreateArchivePath(strFile, "pfc", strPath, DEFSFILE);

  char* defFile;
  CStdString strDoc;

  XFILE::CFile file;

  if (file.Open(strFile))
  {
    int size = (int) file.GetLength();

    try
    {
      defFile = new char[size + 1];
    }
    catch (...)
    {
      CLog::Log(LOGERROR, "%s: Exception while creating file buffer", __FUNCTION__);
      return false;
    }

    if (!defFile)
    {
      file.Close();
      return false;
    }

    file.Read(defFile, size);
    defFile[size] = 0;
    strDoc = defFile;

    file.Close();
    free(defFile);
  }

  // Laureon: Convert the document to UTF8...
  if (strDoc.Find("encoding=") == -1) g_charsetConverter.unknownToUTF8(strDoc);

  xmlDocument.Parse(strDoc.c_str());

  if (!xmlDocument.RootElement()) return false;

  return true;
}
示例#6
0
bool CKaraokeLyricsTextKAR::Load()
{
  XFILE::CFile file;
  bool succeed = true;
  m_reportedInvalidVarField = false;

  // Clear the lyrics array
  clearLyrics();

  if (file.LoadFile(m_midiFile, m_midiData) <= 0)
    return false;

  file.Close();

  // Parse MIDI
  try
  {
    parseMIDI();
  }
  catch ( const char * p )
  {
    CLog::Log( LOGERROR, "KAR lyrics loader: cannot load file: %s", p );
    succeed = false;
  }

  m_midiData.clear();
  return succeed;
}
示例#7
0
bool CCurlFile::Download(const CStdString& strURL, const CStdString& strFileName, LPDWORD pdwSize)
{
  CLog::Log(LOGINFO, "Download: %s->%s", strURL.c_str(), strFileName.c_str());

  CStdString strData;
  if (!Get(strURL, strData))
    return false;

  XFILE::CFile file;
  if (!file.OpenForWrite(strFileName, true))
  {
    CLog::Log(LOGERROR, "Unable to open file %s: %u",
    strFileName.c_str(), GetLastError());
    return false;
  }
  if (strData.size())
    file.Write(strData.c_str(), strData.size());
  file.Close();

  if (pdwSize != NULL)
  {
    *pdwSize = strData.size();
  }

  return true;
}
示例#8
0
// This test will fail until ActionDeleteFolder has a proper implementation
TEST(TestFileOperationJob, ActionDeleteFolder)
{
    XFILE::CFile *tmpfile;
    CStdString tmpfilepath, destpath;
    CFileItemList items;
    CFileOperationJob job;

    ASSERT_TRUE((tmpfile = XBMC_CREATETEMPFILE("")));
    tmpfilepath = XBMC_TEMPFILEPATH(tmpfile);
    tmpfile->Close();

    destpath = tmpfilepath;
    destpath += ".deletefolder";
    ASSERT_FALSE(XFILE::CFile::Exists(destpath));

    CFileItemPtr item(new CFileItem(destpath));
    item->SetPath(destpath);
    item->m_bIsFolder = true;
    item->Select(true);
    items.Add(item);

    job.SetFileOperation(CFileOperationJob::ActionCreateFolder, items, destpath);
    EXPECT_EQ(CFileOperationJob::ActionCreateFolder, job.GetAction());

    EXPECT_TRUE(job.DoWork());
    EXPECT_TRUE(XFILE::CDirectory::Exists(destpath));

    job.SetFileOperation(CFileOperationJob::ActionDeleteFolder, items, destpath);
    EXPECT_EQ(CFileOperationJob::ActionDeleteFolder, job.GetAction());

    EXPECT_TRUE(job.DoWork());
    EXPECT_FALSE(XFILE::CDirectory::Exists(destpath));

    EXPECT_TRUE(XBMC_DELETETEMPFILE(tmpfile));
}
示例#9
0
文件: Gif.cpp 项目: louis89/xbmc
bool Gif::IsAnimated(const char* file)
{
  if (!m_dll.IsLoaded())
    return false;

  if (m_isAnimated < 0)
  {
    m_filename = file;
    m_isAnimated = 0;

    GifFileType* gif = nullptr;
    XFILE::CFile gifFile;

    if (!gifFile.Open(file) || !Open(gif, &gifFile, ReadFromVfs))
      return false;

    if (gif)
    {
      if (Slurp(gif) && gif->ImageCount > 1)
        m_isAnimated = 1;

      Close(gif);
      gifFile.Close();
    }
  }
  return m_isAnimated > 0;
}
示例#10
0
TEST_F(TestRegExpLog, DumpOvector)
{
  CRegExp regex;
  CStdString logfile, logstring;
  char buf[100];
  unsigned int bytesread;
  XFILE::CFile file;

  logfile = CSpecialProtocol::TranslatePath("special://temp/") + "xbmc.log";
  EXPECT_TRUE(CLog::Init(CSpecialProtocol::TranslatePath("special://temp/")));
  EXPECT_TRUE(XFILE::CFile::Exists(logfile));

  EXPECT_TRUE(regex.RegComp("^(?<first>Test)\\s*(?<second>.*)\\."));
  EXPECT_EQ(0, regex.RegFind("Test string."));
  regex.DumpOvector(LOGDEBUG);
  CLog::Close();

  EXPECT_TRUE(file.Open(logfile));
  while ((bytesread = file.Read(buf, sizeof(buf) - 1)) > 0)
  {
    buf[bytesread] = '\0';
    logstring.append(buf);
  }
  file.Close();
  EXPECT_FALSE(logstring.empty());

  EXPECT_STREQ("\xEF\xBB\xBF", logstring.substr(0, 3).c_str());

  EXPECT_TRUE(regex.RegComp(".*DEBUG: regexp ovector=\\{\\[0,12\\],\\[0,4\\],"
                            "\\[5,11\\]\\}.*"));
  EXPECT_GE(regex.RegFind(logstring), 0);

  EXPECT_TRUE(XFILE::CFile::Delete(logfile));
}
示例#11
0
文件: JpegIO.cpp 项目: A600/xbmc
bool CJpegIO::Open(const CStdString &texturePath, unsigned int minx, unsigned int miny, bool read)
{
  m_texturePath = texturePath;
  unsigned int imgsize = 0;

  XFILE::CFile file;
  if (file.Open(m_texturePath.c_str(), 0))
  {
    imgsize = (unsigned int)file.GetLength();
    m_inputBuff = new unsigned char[imgsize];
    m_inputBuffSize = file.Read(m_inputBuff, imgsize);
    file.Close();

    if ((imgsize != m_inputBuffSize) || (m_inputBuffSize == 0))
      return false;
  }
  else
    return false;

  if (!read)
    return true;

  if (Read(m_inputBuff, m_inputBuffSize, minx, miny))
    return true;
  return false;
}
示例#12
0
void CAirTunesServer::SetCoverArtFromBuffer(const char *buffer, unsigned int size)
{
  XFILE::CFile tmpFile;
  const char *tmpFileName = "special://temp/airtunes_album_thumb.jpg";

  if(!size)
    return;

  if (tmpFile.OpenForWrite(tmpFileName, true))
  {
    int writtenBytes=0;
    writtenBytes = tmpFile.Write(buffer, size);
    tmpFile.Close();

    if(writtenBytes)
    {
      //reset to empty before setting the new one
      //else it won't get refreshed because the name didn't change
      g_infoManager.SetCurrentAlbumThumb("");
      g_infoManager.SetCurrentAlbumThumb(tmpFileName);
      //update the ui
      CGUIMessage msg(GUI_MSG_NOTIFY_ALL,0,0,GUI_MSG_REFRESH_THUMBS);
      g_windowManager.SendThreadMessage(msg);
    }
  }
}
bool COMXImage::CreateThumbnailFromSurface(unsigned char* buffer, unsigned int width, unsigned int height, 
    unsigned int format, unsigned int pitch, const CStdString& destFile)
{
  if(format != XB_FMT_A8R8G8B8 || !buffer) {
    CLog::Log(LOGDEBUG, "%s::%s : %s failed format=0x%x\n", CLASSNAME, __func__, destFile.c_str(), format);
    return false;
  }

  if(!Encode(buffer, height * pitch, width, height, pitch)) {
    CLog::Log(LOGDEBUG, "%s::%s : %s encode failed\n", CLASSNAME, __func__, destFile.c_str());
    return false;
  }

  XFILE::CFile file;
  if (file.OpenForWrite(destFile, true))
  {
    CLog::Log(LOGDEBUG, "%s::%s : %s width %d height %d\n", CLASSNAME, __func__, destFile.c_str(), width, height);

    file.Write(GetEncodedData(), GetEncodedSize());
    file.Close();
    return true;
  }

  return false;
}
示例#14
0
TEST(TestFileOperationJob, ActionMove)
{
    XFILE::CFile *tmpfile;
    CStdString tmpfilepath, destpath, destfile;
    CFileItemList items;
    CFileOperationJob job;

    ASSERT_TRUE((tmpfile = XBMC_CREATETEMPFILE("")));
    tmpfilepath = XBMC_TEMPFILEPATH(tmpfile);
    tmpfile->Close();

    CFileItemPtr item(new CFileItem(tmpfilepath));
    item->SetPath(tmpfilepath);
    item->m_bIsFolder = false;
    item->Select(true);
    items.Add(item);

    URIUtils::GetDirectory(tmpfilepath, destpath);
    destpath = URIUtils::AddFileToFolder(destpath, "move");
    destfile = URIUtils::AddFileToFolder(destpath, URIUtils::GetFileName(tmpfilepath));
    ASSERT_FALSE(XFILE::CFile::Exists(destfile));
    ASSERT_TRUE(XFILE::CDirectory::Create(destpath));

    job.SetFileOperation(CFileOperationJob::ActionMove, items, destpath);
    EXPECT_EQ(CFileOperationJob::ActionMove, job.GetAction());

    EXPECT_TRUE(job.DoWork());
    EXPECT_FALSE(XFILE::CFile::Exists(tmpfilepath));
    EXPECT_TRUE(XFILE::CFile::Exists(destfile));

    EXPECT_TRUE(XFILE::CFile::Delete(destfile));
    EXPECT_TRUE(XFILE::CDirectory::Remove(destpath));
}
示例#15
0
TEST(TestFileUtils, DeleteItemString)
{
  XFILE::CFile *tmpfile;

  ASSERT_NE(nullptr, (tmpfile = XBMC_CREATETEMPFILE("")));
  tmpfile->Close();  //Close tmpfile before we try to delete it
  EXPECT_TRUE(CFileUtils::DeleteItem(XBMC_TEMPFILEPATH(tmpfile)));
}
示例#16
0
文件: POUtils.cpp 项目: OV3RDOSE/xbmc
bool CPODocument::LoadFile(const std::string &pofilename)
{
  XFILE::CFile file;
  if (!file.Open(pofilename))
    return false;

  int64_t fileLength = file.GetLength();
  if (fileLength < 18) // at least a size of a minimalistic header
  {
    file.Close();
    CLog::Log(LOGERROR, "POParser: non valid length found for string file: %s", pofilename.c_str());
    return false;
  }

  m_POfilelength = static_cast<size_t> (fileLength);

  m_strBuffer.resize(m_POfilelength+1);
  m_strBuffer[0] = '\n';

  unsigned int readBytes = file.Read(&m_strBuffer[1], m_POfilelength);
  file.Close();

  if (readBytes != m_POfilelength)
  {
    CLog::Log(LOGERROR, "POParser: actual read data differs from file size, for string file: %s",
              pofilename.c_str());
    return false;
  }

  ConvertLineEnds(pofilename);

  // we make sure, to have an LF at the end of buffer
  if (*m_strBuffer.rbegin() != '\n')
  {
    m_strBuffer += "\n";
  }

  m_POfilelength = m_strBuffer.size();

  if (GetNextEntry() && m_Entry.Type == MSGID_FOUND)
    return true;

  CLog::Log(LOGERROR, "POParser: unable to read PO file header from file: %s", pofilename.c_str());
  return false;
}
示例#17
0
//========================================================================
int CFileURLProtocol::Close(AML_URLContext *h)
{
  CLog::Log(LOGDEBUG, "CFileURLProtocol::Close");
  XFILE::CFile *cfile = (XFILE::CFile*)h->priv_data;
  cfile->Close();
  delete cfile;

  return 0;
}
示例#18
0
bool CKaraokeLyricsTextLRC::Load()
{
  XFILE::CFile file;

  // Clear the lyrics array
  clearLyrics();

  if ( !file.Open( m_lyricsFile ) )
    return false;

  unsigned int lyricSize = (unsigned int) file.GetLength();

  if ( !lyricSize )
  {
    CLog::Log( LOGERROR, "LRC lyric loader: lyric file %s has zero length", m_lyricsFile.c_str() );
    return false;
  }

  // Read the file into memory array
  std::vector<char> lyricData( lyricSize );

  file.Seek( 0, SEEK_SET );

  // Read the whole file
  if ( file.Read( &lyricData[0], lyricSize) != lyricSize )
    return false; // disk error?

  file.Close();

  // Parse the correction value
  int timing_correction = MathUtils::round_int( g_advancedSettings.m_karaokeSyncDelayLRC * 10 );

  unsigned int offset = 0;

  CStdString ext, songfilename = getSongFile();
  URIUtils::GetExtension( songfilename, ext );

  // Skip windoze UTF8 file prefix, if any, and reject UTF16 files
  if ( lyricSize > 3 )
  {
    if ( (unsigned char)lyricData[0] == 0xFF && (unsigned char)lyricData[1] == 0xFE )
    {
      CLog::Log( LOGERROR, "LRC lyric loader: lyrics file is in UTF16 encoding, must be in UTF8" );
      return false;
    }

    // UTF8 prefix added by some windoze apps
    if ( (unsigned char)lyricData[0] == 0xEF && (unsigned char)lyricData[1] == 0xBB && (unsigned char)lyricData[2] == 0xBF )
      offset = 3;
  }

  if (checkMultiTime(&lyricData[offset], lyricSize - offset))
    return ParserMultiTime(&lyricData[offset], lyricSize - offset, timing_correction);
  else
    return ParserNormal(&lyricData[offset], lyricSize - offset, timing_correction);
}
示例#19
0
文件: TestFile.cpp 项目: DasMarx/xbmc
TEST(TestFile, Rename)
{
  XFILE::CFile *file;
  CStdString path1, path2;

  ASSERT_TRUE((file = XBMC_CREATETEMPFILE("")) != NULL);
  file->Close();
  path1 = XBMC_TEMPFILEPATH(file);
  ASSERT_TRUE((file = XBMC_CREATETEMPFILE("")) != NULL);
  file->Close();
  path2 = XBMC_TEMPFILEPATH(file);
  EXPECT_TRUE(XFILE::CFile::Delete(path1));
  EXPECT_FALSE(XFILE::CFile::Exists(path1));
  EXPECT_TRUE(XFILE::CFile::Exists(path2));
  EXPECT_TRUE(XFILE::CFile::Rename(path2, path1));
  EXPECT_TRUE(XFILE::CFile::Exists(path1));
  EXPECT_FALSE(XFILE::CFile::Exists(path2));
  EXPECT_TRUE(XFILE::CFile::Delete(path1));
}
示例#20
0
文件: TestFile.cpp 项目: DasMarx/xbmc
TEST(TestFile, Exists)
{
  XFILE::CFile *file;

  ASSERT_TRUE((file = XBMC_CREATETEMPFILE("")) != NULL);
  file->Close();
  EXPECT_TRUE(XFILE::CFile::Exists(XBMC_TEMPFILEPATH(file)));
  EXPECT_FALSE(XFILE::CFile::Exists(""));
  EXPECT_TRUE(XBMC_DELETETEMPFILE(file));
}
示例#21
0
HRESULT CNfoFile::Load(const CStdString& strFile)
{
  Close();
  XFILE::CFile file;
  if (file.Open(strFile, true))
  {
    m_size = (int)file.GetLength();
    m_doc = new char[m_size+1];
    if (!m_doc)
    {
      file.Close();
      return E_FAIL;
    }
    file.Read(m_doc, m_size);
    m_doc[m_size] = 0;
    file.Close();
    return S_OK;
  }
  return E_FAIL;
}
示例#22
0
TEST(TestFile, Copy)
{
  XFILE::CFile *file;
  std::string path1, path2;

  ASSERT_NE(nullptr, file = XBMC_CREATETEMPFILE(""));
  file->Close();
  path1 = XBMC_TEMPFILEPATH(file);
  ASSERT_NE(nullptr, file = XBMC_CREATETEMPFILE(""));
  file->Close();
  path2 = XBMC_TEMPFILEPATH(file);
  EXPECT_TRUE(XFILE::CFile::Delete(path1));
  EXPECT_FALSE(XFILE::CFile::Exists(path1));
  EXPECT_TRUE(XFILE::CFile::Exists(path2));
  EXPECT_TRUE(XFILE::CFile::Copy(path2, path1));
  EXPECT_TRUE(XFILE::CFile::Exists(path1));
  EXPECT_TRUE(XFILE::CFile::Exists(path2));
  EXPECT_TRUE(XFILE::CFile::Delete(path1));
  EXPECT_TRUE(XFILE::CFile::Delete(path2));
}
示例#23
0
TEST_F(TestZipFile, Read)
{
  XFILE::CFile file;
  char buf[20];
  memset(&buf, 0, sizeof(buf));
  std::string reffile, strpathinzip;
  CFileItemList itemlist;

  reffile = XBMC_REF_FILE_PATH("xbmc/filesystem/test/reffile.txt.zip");
  CURL zipUrl = URIUtils::CreateArchivePath("zip", CURL(reffile), "");
  ASSERT_TRUE(XFILE::CDirectory::GetDirectory(zipUrl, itemlist, "",
    XFILE::DIR_FLAG_NO_FILE_DIRS));
  EXPECT_GT(itemlist.Size(), 0);
  EXPECT_FALSE(itemlist[0]->GetPath().empty());
  strpathinzip = itemlist[0]->GetPath();
  ASSERT_TRUE(file.Open(strpathinzip));
  EXPECT_EQ(0, file.GetPosition());
  EXPECT_EQ(1616, file.GetLength());
  EXPECT_EQ(sizeof(buf), static_cast<size_t>(file.Read(buf, sizeof(buf))));
  file.Flush();
  EXPECT_EQ(20, file.GetPosition());
  EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
  EXPECT_TRUE(file.ReadString(buf, sizeof(buf)));
  EXPECT_EQ(39, file.GetPosition());
  EXPECT_STREQ("an award-winning fr", buf);
  EXPECT_EQ(100, file.Seek(100));
  EXPECT_EQ(100, file.GetPosition());
  EXPECT_EQ(sizeof(buf), static_cast<size_t>(file.Read(buf, sizeof(buf))));
  file.Flush();
  EXPECT_EQ(120, file.GetPosition());
  EXPECT_TRUE(!memcmp("ent hub for digital ", buf, sizeof(buf) - 1));
  EXPECT_EQ(220, file.Seek(100, SEEK_CUR));
  EXPECT_EQ(220, file.GetPosition());
  EXPECT_EQ(sizeof(buf), static_cast<size_t>(file.Read(buf, sizeof(buf))));
  file.Flush();
  EXPECT_EQ(240, file.GetPosition());
  EXPECT_TRUE(!memcmp("rs, XBMC is a non-pr", buf, sizeof(buf) - 1));
  EXPECT_EQ(1596, file.Seek(-(int64_t)sizeof(buf), SEEK_END));
  EXPECT_EQ(1596, file.GetPosition());
  EXPECT_EQ(sizeof(buf), static_cast<size_t>(file.Read(buf, sizeof(buf))));
  file.Flush();
  EXPECT_EQ(1616, file.GetPosition());
  EXPECT_TRUE(!memcmp("multimedia jukebox.\n", buf, sizeof(buf) - 1));
  EXPECT_EQ(-1, file.Seek(100, SEEK_CUR));
  EXPECT_EQ(1616, file.GetPosition());
  EXPECT_EQ(0, file.Seek(0, SEEK_SET));
  EXPECT_EQ(sizeof(buf), static_cast<size_t>(file.Read(buf, sizeof(buf))));
  file.Flush();
  EXPECT_EQ(20, file.GetPosition());
  EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
  EXPECT_EQ(0, file.Seek(0, SEEK_SET));
  EXPECT_EQ(-1, file.Seek(-100, SEEK_SET));
  file.Close();
}
示例#24
0
TEST_F(Testlog, Log)
{
    std::string logfile, logstring;
    char buf[100];
    unsigned int bytesread;
    XFILE::CFile file;
    CRegExp regex;

    std::string appName = CCompileInfo::GetAppName();
    StringUtils::ToLower(appName);
    logfile = CSpecialProtocol::TranslatePath("special://temp/") + appName + ".log";
    EXPECT_TRUE(CLog::Init(CSpecialProtocol::TranslatePath("special://temp/").c_str()));
    EXPECT_TRUE(XFILE::CFile::Exists(logfile));

    CLog::Log(LOGDEBUG, "debug log message");
    CLog::Log(LOGINFO, "info log message");
    CLog::Log(LOGNOTICE, "notice log message");
    CLog::Log(LOGWARNING, "warning log message");
    CLog::Log(LOGERROR, "error log message");
    CLog::Log(LOGSEVERE, "severe log message");
    CLog::Log(LOGFATAL, "fatal log message");
    CLog::Log(LOGNONE, "none type log message");
    CLog::Close();

    EXPECT_TRUE(file.Open(logfile));
    while ((bytesread = file.Read(buf, sizeof(buf) - 1)) > 0)
    {
        buf[bytesread] = '\0';
        logstring.append(buf);
    }
    file.Close();
    EXPECT_FALSE(logstring.empty());

    EXPECT_STREQ("\xEF\xBB\xBF", logstring.substr(0, 3).c_str());

    EXPECT_TRUE(regex.RegComp(".*DEBUG: debug log message.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);
    EXPECT_TRUE(regex.RegComp(".*INFO: info log message.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);
    EXPECT_TRUE(regex.RegComp(".*NOTICE: notice log message.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);
    EXPECT_TRUE(regex.RegComp(".*WARNING: warning log message.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);
    EXPECT_TRUE(regex.RegComp(".*ERROR: error log message.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);
    EXPECT_TRUE(regex.RegComp(".*SEVERE: severe log message.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);
    EXPECT_TRUE(regex.RegComp(".*FATAL: fatal log message.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);
    EXPECT_TRUE(regex.RegComp(".*NONE: none type log message.*"));
    EXPECT_GE(regex.RegFind(logstring), 0);

    EXPECT_TRUE(XFILE::CFile::Delete(logfile));
}
示例#25
0
文件: OMXImage.cpp 项目: A600/xbmc
bool COMXImage::CreateThumbnailFromSurface(unsigned char* buffer, unsigned int width, unsigned int height, 
    unsigned int format, unsigned int pitch, const CStdString& destFile)
{
  if(format != XB_FMT_A8R8G8B8 || !buffer)
    return false;

  // the omx encoder needs alligned sizes
  if(width%16 || height%16)
  {
    unsigned int new_width = (width + 15)&~15;
    unsigned int new_height = (height + 15)&~15;
    unsigned int new_pitch = new_width * 4;

    unsigned int size = new_height * new_pitch;
    unsigned char *dstBuffer = (unsigned char *)malloc(size);
    unsigned char *dst = dstBuffer;
    unsigned char *src = buffer;

    if(!dstBuffer)
      return false;

    memset(dst, 0x0, size);

    for(unsigned int y = 0; y < height; y++)
    {
      memcpy(dst, src, pitch);
      src += pitch;
      dst += new_pitch;
    }
    if(!Encode(dstBuffer, size, new_width, new_height))
    {
      free(dstBuffer);
      return false;
    }
    free(dstBuffer);
  }
  else
  {
    if(!Encode(buffer, height * pitch, width, height))
      return false;
  }

  XFILE::CFile file;
  if (file.OpenForWrite(destFile, true))
  {
    CLog::Log(LOGDEBUG, "%s::%s : %s width %d height %d\n", CLASSNAME, __func__, destFile.c_str(), width, height);

    file.Write(GetEncodedData(), GetEncodedSize());
    file.Close();
    return true;
  }

  return false;
}
示例#26
0
文件: TestFile.cpp 项目: DasMarx/xbmc
TEST(TestFile, Delete)
{
  XFILE::CFile *file;
  CStdString path;

  ASSERT_TRUE((file = XBMC_CREATETEMPFILE("")) != NULL);
  file->Close();
  path = XBMC_TEMPFILEPATH(file);
  EXPECT_TRUE(XFILE::CFile::Exists(path));
  EXPECT_TRUE(XFILE::CFile::Delete(path));
  EXPECT_FALSE(XFILE::CFile::Exists(path));
}
示例#27
0
文件: TestRarFile.cpp 项目: A600/xbmc
TEST(TestRarFile, Read)
{
  XFILE::CFile file;
  char buf[20];
  memset(&buf, 0, sizeof(buf));
  CStdString reffile, strrarpath, strpathinrar;
  CFileItemList itemlist;

  reffile = XBMC_REF_FILE_PATH("xbmc/filesystem/test/reffile.txt.rar");
  URIUtils::CreateArchivePath(strrarpath, "rar", reffile, "");
  ASSERT_TRUE(XFILE::CDirectory::GetDirectory(strrarpath, itemlist, "",
    XFILE::DIR_FLAG_NO_FILE_DIRS));
  strpathinrar = itemlist[0]->GetPath();
  ASSERT_TRUE(file.Open(strpathinrar));
  EXPECT_EQ(0, file.GetPosition());
  EXPECT_EQ(1616, file.GetLength());
  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  file.Flush();
  EXPECT_EQ(20, file.GetPosition());
  EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
  EXPECT_TRUE(file.ReadString(buf, sizeof(buf)));
  EXPECT_EQ(39, file.GetPosition());
  EXPECT_STREQ("an award-winning fr", buf);
  EXPECT_EQ(100, file.Seek(100));
  EXPECT_EQ(100, file.GetPosition());
  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  file.Flush();
  EXPECT_EQ(120, file.GetPosition());
  EXPECT_TRUE(!memcmp("ent hub for digital ", buf, sizeof(buf) - 1));
  EXPECT_EQ(220, file.Seek(100, SEEK_CUR));
  EXPECT_EQ(220, file.GetPosition());
  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  file.Flush();
  EXPECT_EQ(240, file.GetPosition());
  EXPECT_TRUE(!memcmp("rs, XBMC is a non-pr", buf, sizeof(buf) - 1));
  EXPECT_EQ(1596, file.Seek(-(int64_t)sizeof(buf), SEEK_END));
  EXPECT_EQ(1596, file.GetPosition());
  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  file.Flush();
  EXPECT_EQ(1616, file.GetPosition());
  EXPECT_TRUE(!memcmp("multimedia jukebox.\n", buf, sizeof(buf) - 1));
  EXPECT_EQ(1716, file.Seek(100, SEEK_CUR));
  EXPECT_EQ(1716, file.GetPosition());
  EXPECT_EQ(0, file.Seek(0, SEEK_SET));
  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  file.Flush();
  EXPECT_EQ(20, file.GetPosition());
  EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
  EXPECT_EQ(0, file.Seek(0, SEEK_SET));
  EXPECT_EQ(-1, file.Seek(-100, SEEK_SET));
  file.Close();
}
示例#28
0
文件: TestFile.cpp 项目: DasMarx/xbmc
TEST(TestFile, Stat)
{
  XFILE::CFile *file;
  struct __stat64 buffer;

  ASSERT_TRUE((file = XBMC_CREATETEMPFILE("")) != NULL);
  EXPECT_EQ(0, file->Stat(&buffer));
  file->Close();
  EXPECT_TRUE(buffer.st_mode | _S_IFREG);
  EXPECT_EQ(-1, XFILE::CFile::Stat("", &buffer));
  EXPECT_EQ(ENOENT, errno);
  EXPECT_TRUE(XBMC_DELETETEMPFILE(file));
}
示例#29
0
/* The tests for XFILE::CFileFactory are tested indirectly through
 * XFILE::CFile. Since most parts of the VFS require some form of
 * network connection, the settings and VFS URLs must be given as
 * arguments in the main testsuite program.
 */
TEST_F(TestFileFactory, Read)
{
  XFILE::CFile file;
  std::string str;
  unsigned int size, i;
  unsigned char buf[16];
  int64_t count = 0;

  std::vector<std::string> urls =
    CXBMCTestUtils::Instance().getTestFileFactoryReadUrls();

  std::vector<std::string>::iterator it;
  for (it = urls.begin(); it < urls.end(); ++it)
  {
    std::cout << "Testing URL: " << *it << std::endl;
    ASSERT_TRUE(file.Open(*it));
    std::cout << "file.GetLength(): " <<
      testing::PrintToString(file.GetLength()) << std::endl;
    std::cout << "file.Seek(file.GetLength() / 2, SEEK_CUR) return value: " <<
      testing::PrintToString(file.Seek(file.GetLength() / 2, SEEK_CUR)) << std::endl;
    std::cout << "file.Seek(0, SEEK_END) return value: " <<
      testing::PrintToString(file.Seek(0, SEEK_END)) << std::endl;
    std::cout << "file.Seek(0, SEEK_SET) return value: " <<
      testing::PrintToString(file.Seek(0, SEEK_SET)) << std::endl;
    std::cout << "File contents:" << std::endl;
    while ((size = file.Read(buf, sizeof(buf))) > 0)
    {
      str = StringUtils::Format("  %08llX", count);
      std::cout << str << "  ";
      count += size;
      for (i = 0; i < size; i++)
      {
        str = StringUtils::Format("%02X ", buf[i]);
        std::cout << str;
      }
      while (i++ < sizeof(buf))
        std::cout << "   ";
      std::cout << " [";
      for (i = 0; i < size; i++)
      {
        if (buf[i] >= ' ' && buf[i] <= '~')
          std::cout << buf[i];
        else
          std::cout << ".";
      }
      std::cout << "]" << std::endl;
    }
    file.Close();
  }
}
示例#30
0
文件: FileCurl.cpp 项目: Kr0nZ/boxee
bool CFileCurl::ReadFile(const CStdString &fileName, CStdString &out)
{
  XFILE::CFile file;
  if (file.Open(fileName))
  {
    char buffer[16384];
    unsigned int size_read; 
    while( (size_read = file.Read(buffer, sizeof(buffer)) ) > 0 )
      out.append(buffer, size_read);
    file.Close();
    return true;
  }
  return false;
}