本文整理汇总了C++中xfile::CFile::OpenForWrite方法的典型用法代码示例。如果您正苦于以下问题:C++ CFile::OpenForWrite方法的具体用法?C++ CFile::OpenForWrite怎么用?C++ CFile::OpenForWrite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xfile::CFile
的用法示例。
在下文中一共展示了CFile::OpenForWrite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateThumbnailFromSurface
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;
}
示例2: CreateThumbnailFromSurface
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;
}
示例3: memset
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: Download
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;
}
示例5: saveLyrics
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() );
}
示例6: Get
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;
}
示例7: SaveFile
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;
}
示例8: CreateThumbnailFromSurface
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;
}
示例9: SaveFile
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;
}
示例10: writeCacheFile
//-------------------------------------------------------------------------------------------------------------------
bool Xcddb::writeCacheFile( const char* pBuffer, uint32_t discid )
{
if (cCacheDir.size() == 0)
return false;
XFILE::CFile file;
if (file.OpenForWrite(GetCacheFile(discid), true))
{
const bool ret = ( (size_t) file.Write((void*)pBuffer, strlen(pBuffer) + 1) == strlen(pBuffer) + 1);
file.Close();
return ret;
}
return false;
}
示例11: writeToFile
bool fileOps::writeToFile ( CStdString filePath, char* writeBuffer, int writeLength )
{
XFILE::CFile file;
if (file.OpenForWrite(filePath))
{
file.Write((const void*)writeBuffer,writeLength);
file.Close();
return true;
}
else
{
return false;
}
}
示例12: writeCacheFile
//-------------------------------------------------------------------------------------------------------------------
bool Xcddb::writeCacheFile( const char* pBuffer, uint32_t discid )
{
if (cCacheDir.size() == 0)
return false;
XFILE::CFile file;
if (file.OpenForWrite(GetCacheFile(discid), true))
{
OutputDebugString ( "Current cd saved to local cddb.\n" );
file.Write( (void*) pBuffer, strlen( pBuffer ) + 1 );
file.Close();
return true;
}
return false;
}
示例13: Download
bool COpenSubtitlesSearch::Download(const CFileItem *subItem,std::vector<std::string> &items)
{
ulxr::MethodCall methodcall(ULXR_PCHAR("DownloadSubtitles"));
ulxr::Array subtitleIDlist;
ulxr::RpcString ID = subItem->GetProperty("IDSubtitleFile").asString();
subtitleIDlist.addItem(ID);
ulxr::RpcString token = m_strToken;
methodcall.addParam(token);
methodcall.addParam(subtitleIDlist);
ulxr::MethodResponse response = ServerChat(methodcall);
ulxr::Struct cap = response.getResult();
if (response.isOK() && cap.hasMember(ULXR_PCHAR("status")))
{
ulxr::RpcString status = cap.getMember(ULXR_PCHAR("status"));
CLog::Log(LOGDEBUG, "%s - response - %s", __PRETTY_FUNCTION__, status.getString().c_str());
if (status.getString() == "200 OK")
{
if (cap.hasMember(ULXR_PCHAR("data")))
{
ulxr::Array subs = cap.getMember(ULXR_PCHAR("data"));
for (unsigned i = 0; i < subs.size(); ++i)
{
ulxr::Struct entry = subs.getItem(i);
ulxr::RpcString data = entry.getMember(ULXR_PCHAR("data"));
std::string zipdata = data.getString();
std::string zipdata64Decoded = Base64::Decode(zipdata);
std::string zipdata64DecodedInflated;
CSubtitleUtilities::gzipInflate(zipdata64Decoded,zipdata64DecodedInflated);
XFILE::CFile file;
std::string destination = StringUtils::Format("special://temp/%s.%s",
StringUtils::CreateUUID().c_str(),
subItem->GetProperty("SubFormat").asString().c_str()
);
file.OpenForWrite(destination);
file.Write(zipdata64DecodedInflated.c_str(), zipdata64DecodedInflated.size());
items.push_back(destination);
}
CLog::Log(LOGDEBUG, "%s - OpenSubitles subfile downloaded", __PRETTY_FUNCTION__);
return true;
}
}
}
return false;
}
示例14: SetCoverArtFromBuffer
void CAirTunesServer::SetCoverArtFromBuffer(const char *buffer, unsigned int size)
{
XFILE::CFile tmpFile;
if(!size)
return;
CSingleLock lock(m_metadataLock);
if (tmpFile.OpenForWrite(TMP_COVERART_PATH, true))
{
int writtenBytes=0;
writtenBytes = tmpFile.Write(buffer, size);
tmpFile.Close();
if (writtenBytes > 0)
RefreshCoverArt();
}
}
示例15: Save
void CGameClientInGameSaves::Save(GAME_MEMORY memoryType)
{
uint8_t *gameMemory = nullptr;
size_t size = 0;
try
{
m_dllStruct->GetMemory(memoryType, &gameMemory, &size);
}
catch (...)
{
CLog::Log(LOGERROR, "GAME: %s: Exception caught in GetMemory()", m_gameClient->ID().c_str());
}
if (size > 0)
{
const std::string path = GetPath(memoryType);
XFILE::CFile file;
if (file.OpenForWrite(path, true))
{
ssize_t written = 0;
written = file.Write(gameMemory, size);
file.Close();
if (written == static_cast<ssize_t>(size))
{
CLog::Log(LOGINFO, "GAME: In-game saves (%s) written to %s", CGameClientTranslator::ToString(memoryType), path.c_str());
}
else
{
CLog::Log(LOGERROR, "GAME: Failed to write in-game saves (%s): %ld/%ld bytes written", CGameClientTranslator::ToString(memoryType), written, size);
}
}
else
{
CLog::Log(LOGERROR, "GAME: Unable to open in-game saves (%s) from file %s", CGameClientTranslator::ToString(memoryType), path.c_str());
}
}
else
{
CLog::Log(LOGDEBUG, "GAME: No in-game saves (%s) to save", CGameClientTranslator::ToString(memoryType));
}
}