本文整理汇总了C++中CFile::GetChunkSize方法的典型用法代码示例。如果您正苦于以下问题:C++ CFile::GetChunkSize方法的具体用法?C++ CFile::GetChunkSize怎么用?C++ CFile::GetChunkSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFile
的用法示例。
在下文中一共展示了CFile::GetChunkSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetFileChunkSize
int CAddonCallbacksAddon::GetFileChunkSize(const void* addonData, void* file)
{
CAddonInterfaces* helper = (CAddonInterfaces*) addonData;
if (!helper)
return 0;
CFile* cfile = (CFile*)file;
if (!cfile)
return 0;
return cfile->GetChunkSize();
}
示例2: Copy
bool CFile::Copy(const CURL& url2, const CURL& dest, XFILE::IFileCallback* pCallback, void* pContext)
{
CFile file;
const std::string pathToUrl(dest.Get());
if (pathToUrl.empty())
return false;
// special case for zips - ignore caching
CURL url(url2);
if (URIUtils::IsInZIP(url.Get()) || URIUtils::IsInAPK(url.Get()))
url.SetOptions("?cache=no");
if (file.Open(url.Get(), READ_TRUNCATED | READ_CHUNKED))
{
CFile newFile;
if (URIUtils::IsHD(pathToUrl)) // create possible missing dirs
{
std::vector<std::string> tokens;
std::string strDirectory = URIUtils::GetDirectory(pathToUrl);
URIUtils::RemoveSlashAtEnd(strDirectory); // for the test below
if (!(strDirectory.size() == 2 && strDirectory[1] == ':'))
{
CURL url(strDirectory);
std::string pathsep;
#ifndef TARGET_POSIX
pathsep = "\\";
#else
pathsep = "/";
#endif
// Try to use the recursive creation first, if it fails
// it might not be implemented for that subsystem so let's
// fall back to the old method in that case
if (!CDirectory::Create(url))
{
StringUtils::Tokenize(url.GetFileName(), tokens, pathsep.c_str());
std::string strCurrPath;
// Handle special
if (!url.GetProtocol().empty())
{
pathsep = "/";
strCurrPath += url.GetProtocol() + "://";
} // If the directory has a / at the beginning, don't forget it
else if (strDirectory[0] == pathsep[0])
strCurrPath += pathsep;
for (std::vector<std::string>::iterator iter = tokens.begin(); iter != tokens.end(); ++iter)
{
strCurrPath += *iter + pathsep;
CDirectory::Create(strCurrPath);
}
}
}
}
if (CFile::Exists(dest))
CFile::Delete(dest);
if (!newFile.OpenForWrite(dest, true)) // overwrite always
{
file.Close();
return false;
}
int iBufferSize = GetChunkSize(file.GetChunkSize(), 128 * 1024);
auto_buffer buffer(iBufferSize);
ssize_t iRead, iWrite;
unsigned long long llFileSize = file.GetLength();
unsigned long long llPos = 0;
CStopWatch timer;
timer.StartZero();
float start = 0.0f;
while (true)
{
g_application.ResetScreenSaver();
iRead = file.Read(buffer.get(), iBufferSize);
if (iRead == 0) break;
else if (iRead < 0)
{
CLog::Log(LOGERROR, "%s - Failed read from file %s", __FUNCTION__, url.GetRedacted().c_str());
llFileSize = (uint64_t)-1;
break;
}
/* write data and make sure we managed to write it all */
iWrite = 0;
while(iWrite < iRead)
{
ssize_t iWrite2 = newFile.Write(buffer.get() + iWrite, iRead - iWrite);
if(iWrite2 <=0)
break;
iWrite+=iWrite2;
}
if (iWrite != iRead)
{
CLog::Log(LOGERROR, "%s - Failed write to file %s", __FUNCTION__, dest.GetRedacted().c_str());
llFileSize = (uint64_t)-1;
//.........这里部分代码省略.........