Permalink
Browse files

[tool][xbmc-txupdate] updated to version 0.92

  • Loading branch information...
1 parent 5104a60 commit bb77b029dd79b3b1119e701655d82d106fc50194 @alanwww1 alanwww1 committed Mar 24, 2013
@@ -114,18 +114,18 @@ bool CAddonXMLHandler::ProcessAddonXMLFile (std::string AddonXMLFilename, TiXmlD
m_strResourceData += g_CharsetUtils.ToUTF8(addonXMLEncoding, CstrToString(pMainAttrId)) + "\n";
pMainAttrId=pRootElement->Attribute("version");
- m_strResourceData += "# Addon version: ";
+// m_strResourceData += "# Addon version: ";
if (!pMainAttrId)
{
CLog::Log(logWARNING, "AddonXMLHandler: No version name was available in addon.xml file: %s\n", AddonXMLFilename.c_str());
- m_strResourceData += "0.0.1\n";
+// m_strResourceData += "0.0.1\n";
m_strAddonVersion = "0.0.1";
}
else
{
m_strAddonVersion = g_CharsetUtils.ToUTF8(addonXMLEncoding, CstrToString(pMainAttrId));
BumpVersionNumber();
- m_strResourceData += g_CharsetUtils.ToUTF8(addonXMLEncoding, m_strAddonVersion) + "\n";
+// m_strResourceData += g_CharsetUtils.ToUTF8(addonXMLEncoding, m_strAddonVersion) + "\n";
}
pMainAttrId=pRootElement->Attribute("provider-name");
@@ -463,6 +463,8 @@ bool CAddonXMLHandler::ProcessCoreVersion(std::string filename, std::string &str
{
m_strResourceData.clear();
+ return true; // Don't include the version text in the PO files
+
size_t startpos = strBuffer.find("#define VERSION_MAJOR ") + 22;
size_t endpos = strBuffer.find_first_of(" \n\r", startpos);
m_strResourceData += "# XBMC-core v" + strBuffer.substr(startpos, endpos-startpos);
@@ -24,6 +24,7 @@
#include <errno.h>
#include "../Log.h"
#include <sstream>
+#include <algorithm>
CCharsetUtils g_CharsetUtils;
@@ -34,6 +35,13 @@ std::string CCharsetUtils::IntToStr(int number)
return ss.str();//return a string with the contents of the stream
};
+std::string CCharsetUtils::ChrToStr(char chr)
+{
+ std::stringstream ss;
+ ss << chr;
+ return ss.str(); //return a string with the contents of the stream
+};
+
std::string CCharsetUtils::UnescapeCPPString(const std::string &strInput)
{
std::string strOutput;
@@ -256,3 +264,8 @@ bool CCharsetUtils::IsValidUTF8(std::string const &strToCheck)
}
return true;
};
+
+size_t CCharsetUtils::GetCharCountInStr(std::string const &strToCheck, unsigned char chrToFInd)
+{
+ return std::count(strToCheck.begin(), strToCheck.end(), chrToFInd);
+}
@@ -41,13 +41,15 @@ class CCharsetUtils
{
public:
std::string IntToStr(int number);
+ std::string ChrToStr(char chr);
std::string UnescapeCPPString(const std::string &strInput);
std::string EscapeStringCPP(const std::string &strInput);
std::string EscapeStringXML(const std::string &strInput);
std::string ToUTF8(std::string strEncoding, const std::string& str);
std::string UnWhitespace(std::string strInput);
std::string stringCharsetToUtf8(const std::string& strCP, std::string strIn);
bool IsValidUTF8(std::string const &strToCheck);
+ size_t GetCharCountInStr(std::string const &strToCheck, unsigned char chrToFInd);
};
extern CCharsetUtils g_CharsetUtils;
@@ -45,69 +45,59 @@ std::string CHTTPHandler::GetURLToSTR(std::string strURL, bool bSkiperror /*=fal
{
std::string strBuffer;
std::string strCacheFile = CacheFileNameFromURL(strURL);
- bool bIsTooLongUrl = strCacheFile == "cache_for_long_URL_download";
- strCacheFile = m_strCacheDir + "GET" + strCacheFile;
+ strCacheFile = m_strCacheDir + "GET/" + strCacheFile;
if (!g_File.FileExist(strCacheFile) || g_File.GetFileAge(strCacheFile) > g_Settings.GetHTTPCacheExpire() * 60)
{
- long result = curlURLToCache(strCacheFile, strURL, bSkiperror);
+ long result = curlURLToCache(strCacheFile, strURL, bSkiperror, strBuffer);
if (result < 200 || result >= 400)
return "";
}
+ else
+ strBuffer = g_File.ReadFileToStr(strCacheFile);
- strBuffer = g_File.ReadFileToStr(strCacheFile);
-
- if (bIsTooLongUrl)
- g_File.DeleteFile(strCacheFile);
return strBuffer;
};
-long CHTTPHandler::curlURLToCache(std::string strCacheFile, std::string strURL, bool bSkiperror)
+long CHTTPHandler::curlURLToCache(std::string strCacheFile, std::string strURL, bool bSkiperror, std::string &strBuffer)
{
CURLcode curlResult;
- FILE *dloadfile;
+ strBuffer.clear();
strURL = URLEncode(strURL);
CLoginData LoginData = GetCredentials(strURL);
if(m_curlHandle)
{
- dloadfile = fopen((strCacheFile + "_dload").c_str(),"wb");
curl_easy_setopt(m_curlHandle, CURLOPT_URL, strURL.c_str());
- curl_easy_setopt(m_curlHandle, CURLOPT_WRITEFUNCTION, Write_CurlData_File);
+ curl_easy_setopt(m_curlHandle, CURLOPT_WRITEFUNCTION, Write_CurlData_String);
if (!LoginData.strLogin.empty())
{
curl_easy_setopt(m_curlHandle, CURLOPT_USERNAME, LoginData.strLogin.c_str());
curl_easy_setopt(m_curlHandle, CURLOPT_PASSWORD, LoginData.strPassword.c_str());
}
curl_easy_setopt(m_curlHandle, CURLOPT_FAILONERROR, true);
- curl_easy_setopt(m_curlHandle, CURLOPT_WRITEDATA, dloadfile);
+ curl_easy_setopt(m_curlHandle, CURLOPT_WRITEDATA, &strBuffer);
curl_easy_setopt(m_curlHandle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
curl_easy_setopt(m_curlHandle, CURLOPT_SSL_VERIFYPEER, 0);
curlResult = curl_easy_perform(m_curlHandle);
long http_code = 0;
curl_easy_getinfo (m_curlHandle, CURLINFO_RESPONSE_CODE, &http_code);
- fseek (dloadfile, 0, SEEK_END);
- size_t filesize=ftell (dloadfile);
- fclose(dloadfile);
-
if (curlResult == 0 && http_code >= 200 && http_code < 400)
CLog::Log(logINFO, "HTTPHandler: curlURLToCache finished with success from URL %s to cachefile %s, read filesize: %ibytes",
- strURL.c_str(), strCacheFile.c_str(), filesize);
+ strURL.c_str(), strCacheFile.c_str(), strBuffer.size());
else
{
- g_File.DeleteFile(strCacheFile+"_dload");
if (!bSkiperror)
CLog::Log(logERROR, "HTTPHandler: curlURLToCache finished with error code: %i from URL %s to localdir %s",
http_code, strURL.c_str(), strCacheFile.c_str());
CLog::Log(logINFO, "HTTPHandler: curlURLToCache finished with code: %i from URL %s", http_code, strURL.c_str());
return http_code;
}
- g_File.CopyFile(strCacheFile+"_dload", strCacheFile);
- g_File.DeleteFile(strCacheFile+"_dload");
+ g_File.WriteFileFromStr(strCacheFile, strBuffer);
return http_code;
}
else
@@ -195,14 +185,9 @@ void CHTTPHandler::SetCacheDir(std::string strCacheDir)
std::string CHTTPHandler::CacheFileNameFromURL(std::string strURL)
{
- if (strURL.size() > 200)
- {
- CLog::Log(logWARNING, "HTTPHandler: Can't make HTTP cache for too long URL: %s", strURL.c_str());
- return "cache_for_long_URL_download";
- }
std::string strResult;
- std::string strCharsToKeep = "/.=?";
- std::string strReplaceChars = "_-=?";
+ std::string strCharsToKeep = "/.-=_() ";
+ std::string strReplaceChars = "/.-=_() ";
std::string hexChars = "01234567890abcdef";
@@ -212,7 +197,8 @@ std::string CHTTPHandler::CacheFileNameFromURL(std::string strURL)
strResult += *it;
else
{
- if (size_t pos = strCharsToKeep.find(*it) != std::string::npos)
+ size_t pos = strCharsToKeep.find(*it);
+ if (pos != std::string::npos)
strResult += strReplaceChars[pos];
else
{
@@ -223,6 +209,9 @@ std::string CHTTPHandler::CacheFileNameFromURL(std::string strURL)
}
}
+ if (strResult.at(strResult.size()-1) == '/')
+ strResult[strResult.size()-1] = '-';
+
return strResult;
};
@@ -305,10 +294,9 @@ bool CHTTPHandler::PutFileToURL(std::string const &strFilePath, std::string cons
{
std::string strBuffer;
std::string strCacheFile = CacheFileNameFromURL(strURL);
- bool bIsTooLongUrl = strCacheFile == "cache_for_long_URL_download";
- strCacheFile = m_strCacheDir + "PUT" + strCacheFile;
+ strCacheFile = m_strCacheDir + "PUT/" + strCacheFile;
- if (!bIsTooLongUrl && g_File.FileExist(strCacheFile) && ComparePOFiles(strCacheFile, strFilePath))
+ if (g_File.FileExist(strCacheFile) && ComparePOFiles(strCacheFile, strFilePath))
{
CLog::Log(logINFO, "HTTPHandler::PutFileToURL: not necesarry to upload file as it has not changed from last upload. File: %s",
strFilePath.c_str());
@@ -325,8 +313,8 @@ bool CHTTPHandler::PutFileToURL(std::string const &strFilePath, std::string cons
}
CLog::Log(logINFO, "HTTPHandler::PutFileToURL: File upload was successful so creating a copy at the .httpcache directory");
- if (!bIsTooLongUrl)
- g_File.CopyFile(strFilePath, strCacheFile);
+ g_File.CopyFile(strFilePath, strCacheFile);
+
buploaded = true;
return true;
@@ -424,7 +412,9 @@ bool CHTTPHandler::ComparePOFilesInMem(CPOHandler * pPOHandler1, CPOHandler * pP
if (bLangIsEN)
{
POEntry1.msgStr.clear();
+ POEntry1.msgStrPlural.clear();
POEntry2.msgStr.clear();
+ POEntry2.msgStrPlural.clear();
}
if (!(POEntry1 == POEntry2))
@@ -445,8 +435,7 @@ bool CHTTPHandler::CreateNewResource(std::string strResname, std::string strENPO
std::string const &strURLENTransl)
{
std::string strCacheFile = CacheFileNameFromURL(strURLENTransl);
- bool bIsTooLongUrl = strCacheFile == "cache_for_long_URL_download";
- strCacheFile = m_strCacheDir + "PUT" + strCacheFile;
+ strCacheFile = m_strCacheDir + "PUT/" + strCacheFile;
CURLcode curlResult;
@@ -495,8 +484,7 @@ bool CHTTPHandler::CreateNewResource(std::string strResname, std::string strENPO
{
CLog::Log(logINFO, "CHTTPHandler::CreateNewResource finished with success for resource %s from EN PO file %s to URL %s",
strResname.c_str(), strENPOFilePath.c_str(), strURL.c_str());
- if (!bIsTooLongUrl)
- g_File.CopyFile(strENPOFilePath, strCacheFile);
+ g_File.CopyFile(strENPOFilePath, strCacheFile);
g_Json.ParseUploadedStrForNewRes(strServerResp, stradded);
}
else
@@ -514,10 +502,8 @@ bool CHTTPHandler::CreateNewResource(std::string strResname, std::string strENPO
void CHTTPHandler::DeleteCachedFile (std::string const &strURL, std::string strPrefix)
{
std::string strCacheFile = CacheFileNameFromURL(strURL);
- if (strCacheFile == "cache_for_long_URL_download")
- return;
- strCacheFile = m_strCacheDir + strPrefix + strCacheFile;
+ strCacheFile = m_strCacheDir + strPrefix + "/" + strCacheFile;
if (g_File.FileExist(strCacheFile))
g_File.DeleteFile(strCacheFile);
}
@@ -56,7 +56,7 @@ class CHTTPHandler
private:
CURL *m_curlHandle;
std::string m_strCacheDir;
- long curlURLToCache(std::string strCacheFile, std::string strURL, bool bSkiperror);
+ long curlURLToCache(std::string strCacheFile, std::string strURL, bool bSkiperror, std::string &strBuffer);
long curlPUTPOFileToURL(std::string const &strFilePath, std::string const &strURL, size_t &stradded, size_t &strupd);
CLoginData GetCredentials (std::string strURL);
Oops, something went wrong.

0 comments on commit bb77b02

Please sign in to comment.