diff options
author | Vadim ProductEngine <vsavchuk@productengine.com> | 2011-06-07 00:17:21 +0300 |
---|---|---|
committer | Vadim ProductEngine <vsavchuk@productengine.com> | 2011-06-07 00:17:21 +0300 |
commit | 4e05ea6ebda88f3e2af4b585f629b11f3729096e (patch) | |
tree | 89ae134019175416da4f75fab5b8685213150796 /indra/newview/llwlparammanager.cpp | |
parent | 9f4779e09997e70246c3c0c5f831bf55d4ed6a4f (diff) |
STORM-1255 WIP Implemented creating, editing and removing local sky presets.
Diffstat (limited to 'indra/newview/llwlparammanager.cpp')
-rw-r--r-- | indra/newview/llwlparammanager.cpp | 230 |
1 files changed, 88 insertions, 142 deletions
diff --git a/indra/newview/llwlparammanager.cpp b/indra/newview/llwlparammanager.cpp index 5980410e64..01aed7c0f1 100644 --- a/indra/newview/llwlparammanager.cpp +++ b/indra/newview/llwlparammanager.cpp @@ -265,167 +265,74 @@ void LLWLParamManager::refreshRegionPresets() addAllSkies(LLEnvKey::SCOPE_REGION, LLEnvManagerNew::instance().getRegionSettings().getSkyMap()); } -void LLWLParamManager::loadPresets(const std::string& file_name) +void LLWLParamManager::loadAllPresets() { - std::string path_name(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/skies", "")); - LL_INFOS2("AppInit", "Shaders") << "Loading Default WindLight settings from " << path_name << LL_ENDL; - - bool found = true; - LLDirIterator app_settings_iter(path_name, "*.xml"); - while(found) - { - std::string name; - found = app_settings_iter.next(name); - if(found) - { - name=name.erase(name.length()-4); + // First, load system (coming out of the box) sky presets. + loadPresetsFromDir(getSysDir()); - // bugfix for SL-46920: preventing filenames that break stuff. - char * curl_str = curl_unescape(name.c_str(), name.size()); - std::string unescaped_name(curl_str); - curl_free(curl_str); - curl_str = NULL; - - LL_DEBUGS2("AppInit", "Shaders") << "name: " << name << LL_ENDL; - loadPreset(LLWLParamKey(unescaped_name, LLWLParamKey::SCOPE_LOCAL),FALSE); - } - } + // Then load user presets. Note that user day presets will modify any system ones already loaded. + loadPresetsFromDir(getUserDir()); +} - // And repeat for user presets, note the user presets will modify any system presets already loaded +void LLWLParamManager::loadPresetsFromDir(const std::string& dir) +{ + LL_INFOS2("AppInit", "Shaders") << "Loading sky presets from " << dir << LL_ENDL; - std::string path_name2(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/skies", "")); - LL_INFOS2("AppInit", "Shaders") << "Loading User WindLight settings from " << path_name2 << LL_ENDL; - - found = true; - LLDirIterator user_settings_iter(path_name2, "*.xml"); - while(found) + LLDirIterator dir_iter(dir, "*.xml"); + while (1) { - std::string name; - found = user_settings_iter.next(name); - if(found) + std::string file; + if (!dir_iter.next(file)) { - name=name.erase(name.length()-4); - - // bugfix for SL-46920: preventing filenames that break stuff. - char * curl_str = curl_unescape(name.c_str(), name.size()); - std::string unescaped_name(curl_str); - curl_free(curl_str); - curl_str = NULL; + break; // no more files + } - LL_DEBUGS2("AppInit", "Shaders") << "name: " << name << LL_ENDL; - loadPreset(LLWLParamKey(unescaped_name,LLWLParamKey::SCOPE_LOCAL),FALSE); + std::string path = dir + file; + if (!loadPreset(path)) + { + llwarns << "Error loading sky preset from " << path << llendl; } } - } -// untested and unmaintained! sanity-check me before using -/* -void LLWLParamManager::savePresets(const std::string & fileName) +bool LLWLParamManager::loadPreset(const std::string& path) { - //Nobody currently calls me, but if they did, then its reasonable to write the data out to the user's folder - //and not over the RO system wide version. - - LLSD paramsData(LLSD::emptyMap()); - - std::string pathName(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight", fileName)); + llifstream xml_file; + std::string name(gDirUtilp->getBaseFileName(LLURI::unescape(path), /*strip_exten = */ true)); - for(std::map<LLWLParamKey, LLWLParamSet>::iterator mIt = mParamList.begin(); - mIt != mParamList.end(); - ++mIt) + xml_file.open(path.c_str()); + if (!xml_file) { - paramsData[mIt->first.name] = mIt->second.getAll(); + return false; } - llofstream presetsXML(pathName); - - LLPointer<LLSDFormatter> formatter = new LLSDXMLFormatter(); - - formatter->format(paramsData, presetsXML, LLSDFormatter::OPTIONS_PRETTY); + LL_DEBUGS2("AppInit", "Shaders") << "Loading sky " << name << LL_ENDL; - presetsXML.close(); -} -*/ + LLSD params_data; + LLPointer<LLSDParser> parser = new LLSDXMLParser(); + parser->parse(xml_file, params_data, LLSDSerialize::SIZE_UNLIMITED); + xml_file.close(); -void LLWLParamManager::loadPreset(const LLWLParamKey key, bool propagate) -{ - if(mParamList.find(key) == mParamList.end()) // key does not already exist in mapping + LLWLParamKey key(name, LLEnvKey::SCOPE_LOCAL); + if (hasParamSet(key)) { - if(key.scope == LLWLParamKey::SCOPE_LOCAL) // local scope, so try to load from file - { - // bugfix for SL-46920: preventing filenames that break stuff. - char * curl_str = curl_escape(key.name.c_str(), key.name.size()); - std::string escaped_filename(curl_str); - curl_free(curl_str); - curl_str = NULL; - - escaped_filename += ".xml"; - - std::string pathName(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/skies", escaped_filename)); - llinfos << "Loading WindLight sky setting from " << pathName << llendl; - - llifstream presetsXML; - presetsXML.open(pathName.c_str()); - - // That failed, try loading from the users area instead. - if(!presetsXML) - { - pathName=gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/skies", escaped_filename); - llinfos << "Loading User WindLight sky setting from " << pathName << llendl; - presetsXML.open(pathName.c_str()); - } - - if (presetsXML) - { - loadPresetFromXML(key, presetsXML); - presetsXML.close(); - } - else - { - llwarns << "Could not load local WindLight sky setting " << key.toString() << llendl; - return; - } - } - else - { - llwarns << "Attempted to load non-local WindLight sky settings " << key.toString() << "; not found in parameter mapping." << llendl; - return; - } + setParamSet(key, params_data); } - - if(propagate) + else { - getParamSet(key, mCurParams); - propagateParameters(); + addParamSet(key, params_data); } -} - -void LLWLParamManager::loadPresetFromXML(LLWLParamKey key, std::istream & presetsXML) -{ - LLSD paramsData(LLSD::emptyMap()); - LLPointer<LLSDParser> parser = new LLSDXMLParser(); - - parser->parse(presetsXML, paramsData, LLSDSerialize::SIZE_UNLIMITED); - - std::map<LLWLParamKey, LLWLParamSet>::iterator mIt = mParamList.find(key); - if(mIt == mParamList.end()) addParamSet(key, paramsData); - else setParamSet(key, paramsData); + return true; } void LLWLParamManager::savePreset(LLWLParamKey key) { - // bugfix for SL-46920: preventing filenames that break stuff. - char * curl_str = curl_escape(key.name.c_str(), key.name.size()); - std::string escaped_filename(curl_str); - curl_free(curl_str); - curl_str = NULL; - - escaped_filename += ".xml"; + llassert(key.scope == LLEnvKey::SCOPE_LOCAL && !key.name.empty()); // make an empty llsd LLSD paramsData(LLSD::emptyMap()); - std::string pathName(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/skies", escaped_filename)); + std::string pathName(getUserDir() + escapeString(key.name) + ".xml"); // fill it with LLSD windlight params paramsData = mParamList[key].getAll(); @@ -718,6 +625,12 @@ bool LLWLParamManager::getParamSet(const LLWLParamKey& key, LLWLParamSet& param) return false; } +bool LLWLParamManager::hasParamSet(const LLWLParamKey& key) +{ + LLWLParamSet dummy; + return getParamSet(key, dummy); +} + bool LLWLParamManager::setParamSet(const LLWLParamKey& key, LLWLParamSet& param) { llassert(!key.name.empty()); @@ -746,6 +659,15 @@ bool LLWLParamManager::setParamSet(const LLWLParamKey& key, const LLSD & param) void LLWLParamManager::removeParamSet(const LLWLParamKey& key, bool delete_from_disk) { + // *TODO: notify interested parties that a sky preset has been removed. + + if (key.scope == LLEnvKey::SCOPE_REGION) + { + llwarns << "Removing region skies not supported" << llendl; + llassert(key.scope == LLEnvKey::SCOPE_LOCAL); + return; + } + // remove from param list std::map<LLWLParamKey, LLWLParamSet>::iterator mIt = mParamList.find(key); if(mIt != mParamList.end()) @@ -759,30 +681,30 @@ void LLWLParamManager::removeParamSet(const LLWLParamKey& key, bool delete_from_ mDay.removeReferencesTo(key); - if(delete_from_disk && key.scope == LLWLParamKey::SCOPE_LOCAL) + if (delete_from_disk) { - std::string path_name(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/skies", "")); - - // use full curl escaped name - char * curl_str = curl_escape(key.name.c_str(), key.name.size()); - std::string escaped_name(curl_str); - curl_free(curl_str); - curl_str = NULL; - + std::string path_name(getUserDir()); + std::string escaped_name = escapeString(key.name); + if(gDirUtilp->deleteFilesInDir(path_name, escaped_name + ".xml") < 1) { - LL_WARNS("WindLight") << "Unable to delete key " << key.toString() << " from disk; not found." << LL_ENDL; + LL_WARNS("WindLight") << "Error removing sky preset " << key.name << " from disk" << LL_ENDL; } } } +bool LLWLParamManager::isSystemPreset(const std::string& preset_name) +{ + // *TODO: file system access is excessive here. + return gDirUtilp->fileExists(getSysDir() + escapeString(preset_name) + ".xml"); +} // virtual static void LLWLParamManager::initSingleton() { LL_DEBUGS("Windlight") << "Initializing sky" << LL_ENDL; - loadPresets(LLStringUtil::null); + loadAllPresets(); // load the day std::string preferred_day = LLEnvManagerNew::instance().getDayCycleName(); @@ -813,3 +735,27 @@ void LLWLParamManager::initSingleton() applyUserPrefs(false); } + +// static +std::string LLWLParamManager::getSysDir() +{ + return gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/skies", ""); +} + +// static +std::string LLWLParamManager::getUserDir() +{ + return gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS , "windlight/skies", ""); +} + +// static +std::string LLWLParamManager::escapeString(const std::string& str) +{ + // Don't use LLURI::escape() because it doesn't encode '-' characters + // which may break handling of some system presets like "A-12AM". + char* curl_str = curl_escape(str.c_str(), str.size()); + std::string escaped_str(curl_str); + curl_free(curl_str); + + return escaped_str; +} |