예제 #1
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));
}
예제 #2
0
void CKaraokeLyricsText::saveLyrics()
{
  XFILE::CFile file;

  CStdString out;

  for ( unsigned int i = 0; i < m_lyrics.size(); i++ )
  {
    CStdString timing;
    timing.Format( "%02d:%02d.%d", m_lyrics[i].timing / 600, (m_lyrics[i].timing % 600) / 10, (m_lyrics[i].timing % 10) );

    if ( (m_lyrics[i].flags & LYRICS_NEW_PARAGRAPH) != 0 )
      out += "\n\n";

    if ( (m_lyrics[i].flags & LYRICS_NEW_LINE) != 0 )
      out += "\n";

    out += "[" + timing + "]" + m_lyrics[i].text;
  }

  out += "\n";

  if ( !file.OpenForWrite( "special://temp/tmp.lrc", true ) )
    return;

  file.Write( out, out.size() );
}
예제 #3
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);
    }
  }
}
예제 #4
0
HRESULT CD3DEffect::Open(D3D_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID* ppData, UINT* pBytes)
{
  XFILE::CFile includeFile;

  std::string fileName("special://xbmc/system/shaders/");
  fileName.append(pFileName);

  if (!includeFile.Open(fileName))
  {
    CLog::Log(LOGERROR, "%s: Could not open 3DLUT file: %s", __FUNCTION__, fileName.c_str());
    return E_FAIL;
  }

  int64_t length = includeFile.GetLength();
  void *pData = malloc(length);
  if (includeFile.Read(pData, length) != length)
  {
    free(pData);
    return E_FAIL;
  }
  *ppData = pData;
  *pBytes = length;

  return S_OK;
}
예제 #5
0
파일: XBMCTinyXML.cpp 프로젝트: 7orlum/xbmc
bool CXBMCTinyXML::LoadFile(const std::string& _filename, TiXmlEncoding encoding)
{
  value = _filename.c_str();

  XFILE::CFile file;
  XFILE::auto_buffer buffer;

  if (file.LoadFile(value, buffer) <= 0)
  {
    SetError(TIXML_ERROR_OPENING_FILE, NULL, NULL, TIXML_ENCODING_UNKNOWN);
    return false;
  }

  // Delete the existing data:
  Clear();
  location.Clear();

  std::string data(buffer.get(), buffer.length());
  buffer.clear(); // free memory early

  if (encoding == TIXML_ENCODING_UNKNOWN)
    Parse(data, file.GetContentCharset());
  else
    Parse(data, encoding);

  if (Error())
    return false;
  return true;
}
예제 #6
0
파일: Texture.cpp 프로젝트: davilla/mrmc
bool CBaseTexture::LoadFromFileInternal(const std::string& texturePath, unsigned int maxWidth, unsigned int maxHeight, bool autoRotate, bool requirePixels, const std::string& strMimeType)
{
  if (URIUtils::HasExtension(texturePath, ".dds"))
  { // special case for DDS images
    CDDSImage image;
    if (image.ReadFile(texturePath))
    {
      Update(image.GetWidth(), image.GetHeight(), 0, image.GetFormat(), image.GetData(), false);
      return true;
    }
    return false;
  }

  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();

  // Read image into memory to use our vfs
  XFILE::CFile file;
  XFILE::auto_buffer buf;

  if (file.LoadFile(texturePath, buf) <= 0)
    return false;

  CURL url(texturePath);
  // make sure resource:// paths are properly resolved
  if (url.IsProtocol("resource"))
  {
    std::string translatedPath;
    if (XFILE::CResourceFile::TranslatePath(url, translatedPath))
      url.Parse(translatedPath);
  }

  // handle xbt:// paths differently because it allows loading the texture directly from memory
  if (url.IsProtocol("xbt"))
  {
    XFILE::CXbtFile xbtFile;
    if (!xbtFile.Open(url))
      return false;

    return LoadFromMemory(xbtFile.GetImageWidth(), xbtFile.GetImageHeight(), 0, xbtFile.GetImageFormat(),
                          xbtFile.HasImageAlpha(), reinterpret_cast<unsigned char*>(buf.get()));
  }

  IImage* pImage;

  if(strMimeType.empty())
    pImage = ImageFactory::CreateLoader(texturePath);
  else
    pImage = ImageFactory::CreateLoaderFromMimeType(strMimeType);

  if (!LoadIImage(pImage, (unsigned char *)buf.get(), buf.size(), width, height, autoRotate))
  {
    CLog::Log(LOGDEBUG, "%s - Load of %s failed.", __FUNCTION__, texturePath.c_str());
    delete pImage;
    return false;
  }
  delete pImage;

  return true;
}
예제 #7
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;
}
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;
}
예제 #9
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;
}
예제 #10
0
//========================================================================
int CFileURLProtocol::Open(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-"));
  }
  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, false).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;
}
예제 #11
0
파일: POUtils.cpp 프로젝트: FLyrfors/xbmc
bool CPODocument::LoadFile(const std::string &pofilename)
{
  CURL poFileUrl(pofilename);
  if (!XFILE::CFile::Exists(poFileUrl))
    return false;

  XFILE::CFile file;
  XFILE::auto_buffer buf;
  if (file.LoadFile(poFileUrl, buf) < 18) // at least a size of a minimalistic header
  {
    CLog::Log(LOGERROR, "%s: can't load file \"%s\" or file is too small", __FUNCTION__,  pofilename.c_str());
    return false;
  }
  
  m_strBuffer = '\n';
  m_strBuffer.append(buf.get(), buf.size());
  buf.clear();

  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;
}
예제 #12
0
파일: Picture.cpp 프로젝트: Elzevir/xbmc
bool CPicture::CreateThumbnailFromSurface(const unsigned char *buffer, int width, int height, int stride, const std::string &thumbFile)
{
  CLog::Log(LOGDEBUG, "cached image '%s' size %dx%d", CURL::GetRedacted(thumbFile).c_str(), width, height);
  if (URIUtils::HasExtension(thumbFile, ".jpg"))
  {
#if defined(HAS_OMXPLAYER)
    if (COMXImage::CreateThumbnailFromSurface((BYTE *)buffer, width, height, XB_FMT_A8R8G8B8, stride, thumbFile.c_str()))
      return true;
#endif
  }

  unsigned char *thumb = NULL;
  unsigned int thumbsize=0;
  IImage* pImage = ImageFactory::CreateLoader(thumbFile);
  if(pImage == NULL || !pImage->CreateThumbnailFromSurface((BYTE *)buffer, width, height, XB_FMT_A8R8G8B8, stride, thumbFile.c_str(), thumb, thumbsize))
  {
    CLog::Log(LOGERROR, "Failed to CreateThumbnailFromSurface for %s", CURL::GetRedacted(thumbFile).c_str());
    delete pImage;
    return false;
  }

  XFILE::CFile file;
  const bool ret = file.OpenForWrite(thumbFile, true) && file.Write(thumb, thumbsize) == thumbsize;
  pImage->ReleaseThumbnailBuffer();
  delete pImage;

  return ret;
}
예제 #13
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;
}
예제 #14
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;
}
예제 #15
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));
}
예제 #16
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));
}
예제 #17
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)));
}
예제 #18
0
static int dvd_file_read(void *h, uint8_t* buf, int size)
{
  if(interrupt_cb(NULL))
    return -1;

  XFILE::CFile *pFile = (XFILE::CFile *)h;
  return pFile->Read(buf, size);
}
예제 #19
0
//========================================================================
int CFileURLProtocol::Read(AML_URLContext *h, unsigned char *buf, int size)
{
  XFILE::CFile *cfile = (XFILE::CFile*)h->priv_data;

  int readsize = cfile->Read(buf, size);
  //CLog::Log(LOGDEBUG, "CFileURLProtocol::Read size(%d), readsize(%d)", size, readsize);

  return readsize;
}
예제 #20
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;
}
예제 #21
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));
}
예제 #22
0
파일: FileUtils.cpp 프로젝트: Cygne/xbmc
unsigned int CFileUtils::LoadFile(const std::string &filename, void* &outputBuffer)
{
  XFILE::auto_buffer buffer;
  XFILE::CFile file;

  const unsigned int total_read = file.LoadFile(filename, buffer);
  outputBuffer = buffer.detach();

  return total_read;
}
예제 #23
0
bool CXBMCTinyXML::SaveFile(const std::string& filename) const
{
  XFILE::CFile file;
  if (file.OpenForWrite(filename, true))
  {
    TiXmlPrinter printer;
    Accept(&printer);
    return file.Write(printer.CStr(), printer.Size()) == static_cast<ssize_t>(printer.Size());
  }
  return false;
}
예제 #24
0
static offset_t dvd_file_seek(void *h, offset_t pos, int whence)
{
  if(interrupt_cb(NULL))
    return -1;

  XFILE::CFile *pFile = (XFILE::CFile *)h;
  if(whence == AVSEEK_SIZE)
    return pFile->GetLength();
  else
    return pFile->Seek(pos, whence & ~AVSEEK_FORCE);
}
예제 #25
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));
}
예제 #26
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;
}
예제 #27
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));
}
예제 #28
0
bool CXBMCTinyXML::SaveFile(const CStdString &filename) const
{
  XFILE::CFile file;
  if (file.OpenForWrite(filename, true))
  {
    TiXmlPrinter printer;
    Accept(&printer);
    file.Write(printer.CStr(), printer.Size());
    return true;
  }
  return false;
}
예제 #29
0
파일: TestFile.cpp 프로젝트: 0xheart0/xbmc
TEST(TestFile, Delete)
{
  XFILE::CFile *file;
  std::string path;

  ASSERT_NE(nullptr, file = XBMC_CREATETEMPFILE(""));
  file->Close();
  path = XBMC_TEMPFILEPATH(file);
  EXPECT_TRUE(XFILE::CFile::Exists(path));
  EXPECT_TRUE(XFILE::CFile::Delete(path));
  EXPECT_FALSE(XFILE::CFile::Exists(path));
}
예제 #30
0
  FT_Face GetFont(const std::string &filename, float size, float aspect, XUTILS::auto_buffer& memoryBuf)
  {
    // don't have it yet - create it
    if (!m_library)
      FT_Init_FreeType(&m_library);
    if (!m_library)
    {
      CLog::Log(LOGERROR, "Unable to initialize freetype library");
      return NULL;
    }

    FT_Face face;

    // ok, now load the font face
    CURL realFile(CSpecialProtocol::TranslatePath(filename));
    if (realFile.GetFileName().empty())
      return NULL;

    memoryBuf.clear();
#ifndef TARGET_WINDOWS
    if (!realFile.GetProtocol().empty())
#endif // ! TARGET_WINDOWS
    {
      // load file into memory if it is not on local drive
      // in case of win32: always load file into memory as filename is in UTF-8,
      //                   but freetype expect filename in ANSI encoding
      XFILE::CFile f;
      if (f.LoadFile(realFile, memoryBuf) <= 0)
        return NULL;
      if (FT_New_Memory_Face(m_library, (const FT_Byte*)memoryBuf.get(), memoryBuf.size(), 0, &face) != 0)
        return NULL;
    }
#ifndef TARGET_WINDOWS
    else if (FT_New_Face( m_library, realFile.GetFileName().c_str(), 0, &face ))
      return NULL;
#endif // ! TARGET_WINDOWS

    unsigned int ydpi = 72; // 72 points to the inch is the freetype default
    unsigned int xdpi = (unsigned int)MathUtils::round_int(ydpi * aspect);

    // we set our screen res currently to 96dpi in both directions (windows default)
    // we cache our characters (for rendering speed) so it's probably
    // not a good idea to allow free scaling of fonts - rather, just
    // scaling to pixel ratio on screen perhaps?
    if (FT_Set_Char_Size( face, 0, (int)(size*64 + 0.5f), xdpi, ydpi ))
    {
      FT_Done_Face(face);
      return NULL;
    }

    return face;
  };