/** * @file llregionnamecache.h * @author Dale Glass * @brief Region name cache * * Copyright (c) 2006-2007, Linden Research, Inc. * * Second Life Viewer Source Code * The source code in this file ("Source Code") is provided by Linden Lab * to you under the terms of the GNU General Public License, version 2.0 * ("GPL"), unless you have obtained a separate licensing agreement * ("Other License"), formally executed by you and Linden Lab. Terms of * the GPL can be found in doc/GPL-license.txt in this distribution, or * online at http://secondlife.com/developers/opensource/gplv2 * * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or * online at http://secondlife.com/developers/opensource/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, * and agree to abide by those obligations. * * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, * COMPLETENESS OR PERFORMANCE. */ #include "llviewerprecompiledheaders.h" // must be first include #include "llregionnamecache.h" #include "llxmltree.h" LLRegionNameCache *gRegionNameCache = NULL; void LLRegionNameCache::put(const LLUUID ®ion, const LLString &name) { if ( !name.empty() ) { llinfos << "Adding region to cache: " << name << " (" << region << ")" << llendl; mCache[region] = LLRegionNameCacheEntry(name); } else { llinfos << "Not adding region to cache, name empty for " << region << llendl; } } LLString LLRegionNameCache::get(const LLUUID ®ion) { if ( region.isNull() ) return "?"; if ( mCache.count( region ) > 0 ) return mCache[region].regionName; return "(" + region.asString() + ")"; } void LLRegionNameCache::exportFile(const LLString &filename) { llinfos << "Writing region name cache to " << filename << llendl; llofstream file; file.open(filename.c_str()); if (!file.is_open()) { llerrs << "Failed to open region name cache file " << filename << " for writing" << llendl; return; } file << "\n"; file << "\n"; std::map::iterator iter; for(iter = mCache.begin(); iter != mCache.end(); iter++) { LLUUID id = iter->first; LLRegionNameCacheEntry *reg = &iter->second; if ( ! reg->isStatic ) { file << "\t" << reg->regionName.c_str() << "\n"; } } file << "\n"; file.close(); } void LLRegionNameCache::importFile(const LLString &filename, bool is_static) { llinfos << "Loading cache from " << filename << llendl; LLXmlTree xml_tree; if ( !xml_tree.parseFile(filename) ) { llwarns << "Unable to parse region name cache file " << filename << llendl; return; } LLXmlTreeNode *rootp = xml_tree.getRoot(); if (!rootp) { llwarns << "Region name cache file has no root element" << llendl; return; } LLXmlTreeNode* child_nodep = rootp->getFirstChild(); S32 count = 0; while( child_nodep ) { LLString name = child_nodep->getName(); if ( name != "entry" ) { llwarns << "Ignoring unknown tag in region name cache: " << name << llendl; child_nodep = rootp->getNextChild(); continue; } LLUUID region_id; child_nodep->getAttributeUUID("id", region_id); if ( region_id.isNull() ) { llwarns << "Ignoring bad entry in region name cache, failed to parse region id" << llendl; child_nodep = rootp->getNextChild(); return; } LLString region_name = child_nodep->getTextContents(); mCache[region_id] = LLRegionNameCacheEntry(region_name, is_static); child_nodep = rootp->getNextChild(); count++; } llinfos << "Loaded " << count << " entries from cache" << llendl; }