コード例 #1
0
ファイル: ImageCache.cpp プロジェクト: EasyCoding/desura-app
void ImageCache::saveToDb()
{
	try
	{
		std::string dbLoc = getWebCoreDb(m_szAppDataPath.c_str());
		sqlite3x::sqlite3_connection db(dbLoc.c_str());
		//sqlite3x::sqlite3_transaction trans(db);

		for (size_t x=0; x<m_vUpdateList.size(); x++)
		{
			sqlite3x::sqlite3_command cmd(db, "REPLACE INTO imagecache (path, hash, ttl) VALUES (?, ?, DATETIME('NOW', '+5 day'));");

			cmd.bind(1, UTIL::OS::getRelativePath(m_mImageMap[m_vUpdateList[x]]));
			cmd.bind(2, (int)m_vUpdateList[x]);

			cmd.executenonquery();
		}

		//trans.commit();

		m_vUpdateList.clear();
		m_LastUpdateTime = time(nullptr) + 5*60;
	}
	catch(std::exception &ex)
	{
		Warning("Failed to update imagecache in webcore: {0}\n", ex.what());
	}
}
コード例 #2
0
ファイル: WebCore.cpp プロジェクト: Mailaender/desura-app
void WebCoreClass::clearNameCache()
{
	try
	{
		sqlite3x::sqlite3_connection db(getWebCoreDb(m_szAppDataPath.c_str()).c_str());
		db.executenonquery("DELETE FROM namecache");
	}
	catch (std::exception &ex)
	{
		Warning(gcString("Failed to clear namecache table: {0}\n", ex.what()));
	}
}
コード例 #3
0
ファイル: ImageCache.cpp プロジェクト: EasyCoding/desura-app
void ImageCache::loadFromDb()
{
	try
	{
		sqlite3x::sqlite3_connection db(getWebCoreDb(m_szAppDataPath.c_str()).c_str());
		sqlite3x::sqlite3_command cmd(db, "SELECT * FROM imagecache WHERE ttl > DATETIME('NOW');");
		sqlite3x::sqlite3_reader reader = cmd.executereader();

		while (reader.read())
		{
			m_mImageMap[reader.getint(0)] = UTIL::OS::getAbsPath(reader.getstring(1));
		}
	}
	catch (std::exception)
	{
	}
}
コード例 #4
0
DesuraId WebCoreClass::nameToId(const char* name, const char* type)
{
	if (!name)
		throw gcException(ERR_BADITEM, "The name is NULL");

	gcString key("{0}-{1}", name, type);
	uint32 hash = UTIL::MISC::RSHash_CSTR(key.c_str());

	try 
	{
		sqlite3x::sqlite3_connection db(getWebCoreDb(m_szAppDataPath.c_str()).c_str());
		gcString q("select internalid from namecache where nameid='{0}' and ttl > DATETIME('NOW');",  hash);

		DesuraId id(db.executeint64(q.c_str()));
		if (id.isOk())
			return id;
	}
	catch(std::exception &) 
	{
	}

	TiXmlDocument doc;
	PostMap post;

	post["nameid"] = name;
	post["sitearea"] = type;

	TiXmlNode *uNode = postToServer(getNameLookUpUrl(), "iteminfo", post, doc);
	TiXmlNode* cNode = uNode->FirstChild("item");

	if (cNode)
	{
		TiXmlElement* cEl = cNode->ToElement();
		
		if (cEl)
		{
			const char* idStr = cEl->Attribute("siteareaid");
			const char* typeS = cEl->Attribute("sitearea");

			DesuraId id(idStr, typeS);

			if (!id.isOk() || DesuraId::getTypeString(id.getType()) != type)
			{
				throw gcException(ERR_BADXML);
			}
			else
			{
				try 
				{
					sqlite3x::sqlite3_connection db(getWebCoreDb(m_szAppDataPath.c_str()).c_str());
					gcString q("replace into namecache (internalid, nameid, ttl) values ('{0}','{1}', DATETIME('NOW', '+5 day'));", id.toInt64(), hash);
					db.executenonquery(q.c_str());
				}
				catch(std::exception &ex) 
				{
					Warning(gcString("Failed to update namecache in webcore: {0}\n", ex.what()));
				}	

				return id;
			}
		}
	}

	throw gcException(ERR_BADXML);
}