本文整理汇总了C++中xfile::auto_buffer::length方法的典型用法代码示例。如果您正苦于以下问题:C++ auto_buffer::length方法的具体用法?C++ auto_buffer::length怎么用?C++ auto_buffer::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xfile::auto_buffer
的用法示例。
在下文中一共展示了auto_buffer::length方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadCert
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;
}
示例2: OnJobComplete
void CGUIDialogAddonInfo::OnJobComplete(unsigned int jobID, bool success,
CJob* job)
{
if (!m_changelog)
return;
CGUIDialogTextViewer* pDlgInfo = (CGUIDialogTextViewer*)g_windowManager.GetWindow(WINDOW_DIALOG_TEXT_VIEWER);
m_jobid = 0;
if (!success)
{
pDlgInfo->SetText(g_localizeStrings.Get(195));
}
else
{
CFile file;
XFILE::auto_buffer buf;
if (file.LoadFile("special://temp/" +
URIUtils::GetFileName(((CFileOperationJob*)job)->GetItems()[0]->GetPath()), buf) > 0)
{
std::string str(buf.get(), buf.length());
m_item->SetProperty("Addon.Changelog", str);
pDlgInfo->SetText(str);
}
}
CGUIMessage msg(GUI_MSG_NOTIFY_ALL, WINDOW_DIALOG_TEXT_VIEWER, 0, GUI_MSG_UPDATE);
g_windowManager.SendThreadMessage(msg);
}
示例3: LoadFile
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;
}
示例4: GetPrivacyPolicy
std::string CSysInfo::GetPrivacyPolicy()
{
if (m_privacyPolicy.empty())
{
CFile file;
XFILE::auto_buffer buf;
if (file.LoadFile("special://xbmc/privacy-policy.txt", buf) > 0)
{
std::string strBuf(buf.get(), buf.length());
m_privacyPolicy = strBuf;
}
else
m_privacyPolicy = g_localizeStrings.Get(19055);
}
return m_privacyPolicy;
}
示例5: Get
bool CScraperUrl::Get(const SUrlEntry& scrURL, std::string& strHTML, XFILE::CCurlFile& http, const CStdString& cacheContext)
{
CURL url(scrURL.m_url);
http.SetReferer(scrURL.m_spoof);
CStdString strCachePath;
if (scrURL.m_isgz)
http.SetContentEncoding("gzip");
if (!scrURL.m_cache.empty())
{
strCachePath = URIUtils::AddFileToFolder(g_advancedSettings.m_cachePath,
"scrapers/" + cacheContext + "/" + scrURL.m_cache);
if (XFILE::CFile::Exists(strCachePath))
{
XFILE::CFile file;
XFILE::auto_buffer buffer;
if (file.LoadFile(strCachePath, buffer))
{
strHTML.assign(buffer.get(), buffer.length());
return true;
}
}
}
CStdString strHTML1(strHTML);
if (scrURL.m_post)
{
CStdString strOptions = url.GetOptions();
strOptions = strOptions.substr(1);
url.SetOptions("");
if (!http.Post(url.Get(), strOptions, strHTML1))
return false;
}
else
if (!http.Get(url.Get(), strHTML1))
return false;
strHTML = strHTML1;
std::string mimeType(http.GetMimeType());
CMime::EFileType ftype = CMime::GetFileTypeFromMime(mimeType);
if (ftype == CMime::FileTypeUnknown)
ftype = CMime::GetFileTypeFromContent(strHTML);
if (ftype == CMime::FileTypeZip || ftype == CMime::FileTypeGZip)
{
XFILE::CZipFile file;
std::string strBuffer;
int iSize = file.UnpackFromMemory(strBuffer,strHTML,scrURL.m_isgz); // FIXME: use FileTypeGZip instead of scrURL.m_isgz?
if (iSize > 0)
{
strHTML = strBuffer;
CLog::Log(LOGDEBUG, "%s: Archive \"%s\" was unpacked in memory", __FUNCTION__, scrURL.m_url.c_str());
}
else
CLog::Log(LOGWARNING, "%s: \"%s\" looks like archive, but cannot be unpacked", __FUNCTION__, scrURL.m_url.c_str());
}
std::string reportedCharset(http.GetServerReportedCharset());
if (ftype == CMime::FileTypeHtml)
{
std::string realHtmlCharset, converted;
if (!CCharsetDetection::ConvertHtmlToUtf8(strHTML, converted, reportedCharset, realHtmlCharset))
CLog::Log(LOGWARNING, "%s: Can't find precise charset for HTML \"%s\", using \"%s\" as fallback", __FUNCTION__, scrURL.m_url.c_str(), realHtmlCharset.c_str());
else
CLog::Log(LOGDEBUG, "%s: Using \"%s\" charset for HTML \"%s\"", __FUNCTION__, realHtmlCharset.c_str(), scrURL.m_url.c_str());
strHTML = converted;
}
else if (ftype == CMime::FileTypeXml)
{
CXBMCTinyXML xmlDoc;
xmlDoc.Parse(strHTML, reportedCharset);
std::string realXmlCharset(xmlDoc.GetUsedCharset());
if (!realXmlCharset.empty())
{
CLog::Log(LOGDEBUG, "%s: Using \"%s\" charset for XML \"%s\"", __FUNCTION__, realXmlCharset.c_str(), scrURL.m_url.c_str());
std::string converted;
g_charsetConverter.ToUtf8(realXmlCharset, strHTML, converted);
strHTML = converted;
}
}
else if (ftype == CMime::FileTypePlainText || StringUtils::CompareNoCase(mimeType.substr(0, 5), "text/") == 0)
{
std::string realTextCharset, converted;
CCharsetDetection::ConvertPlainTextToUtf8(strHTML, converted, reportedCharset, realTextCharset);
strHTML = converted;
if (reportedCharset != realTextCharset)
CLog::Log(LOGWARNING, "%s: Using \"%s\" charset for plain text \"%s\" instead of server reported \"%s\" charset", __FUNCTION__, realTextCharset.c_str(), scrURL.m_url.c_str(), reportedCharset.c_str());
else
CLog::Log(LOGDEBUG, "%s: Using \"%s\" charset for plain text \"%s\"", __FUNCTION__, realTextCharset.c_str(), scrURL.m_url.c_str());
}
else if (!reportedCharset.empty())
{
CLog::Log(LOGDEBUG, "%s: Using \"%s\" charset for \"%s\"", __FUNCTION__, reportedCharset.c_str(), scrURL.m_url.c_str());
if (reportedCharset != "UTF-8")
//.........这里部分代码省略.........
示例6: Get
bool CScraperUrl::Get(const SUrlEntry& scrURL, std::string& strHTML, XFILE::CCurlFile& http, const CStdString& cacheContext)
{
CURL url(scrURL.m_url);
http.SetReferer(scrURL.m_spoof);
CStdString strCachePath;
if (scrURL.m_isgz)
http.SetContentEncoding("gzip");
if (!scrURL.m_cache.IsEmpty())
{
strCachePath = URIUtils::AddFileToFolder(g_advancedSettings.m_cachePath,
"scrapers/" + cacheContext + "/" + scrURL.m_cache);
if (XFILE::CFile::Exists(strCachePath))
{
XFILE::CFile file;
XFILE::auto_buffer buffer;
if (file.LoadFile(strCachePath, buffer))
{
strHTML.assign(buffer.get(), buffer.length());
return true;
}
}
}
CStdString strHTML1(strHTML);
if (scrURL.m_post)
{
CStdString strOptions = url.GetOptions();
strOptions = strOptions.substr(1);
url.SetOptions("");
if (!http.Post(url.Get(), strOptions, strHTML1))
return false;
}
else
if (!http.Get(url.Get(), strHTML1))
return false;
strHTML = strHTML1;
std::string fileCharset(http.GetServerReportedCharset());
if (scrURL.m_url.Find(".zip") > -1 )
{
XFILE::CZipFile file;
CStdString strBuffer;
int iSize = file.UnpackFromMemory(strBuffer,strHTML,scrURL.m_isgz);
if (iSize)
{
fileCharset.clear();
strHTML.clear();
strHTML.append(strBuffer.c_str(),strBuffer.data()+iSize);
}
}
if (!fileCharset.empty() && fileCharset != "UTF-8")
{
std::string converted;
if (g_charsetConverter.ToUtf8(fileCharset, strHTML, converted) && !converted.empty())
strHTML = converted;
}
if (!scrURL.m_cache.IsEmpty())
{
CStdString strCachePath = URIUtils::AddFileToFolder(g_advancedSettings.m_cachePath,
"scrapers/" + cacheContext + "/" + scrURL.m_cache);
XFILE::CFile file;
if (file.OpenForWrite(strCachePath,true))
file.Write(strHTML.data(),strHTML.size());
file.Close();
}
return true;
}