bool _ELC_::Project :: compileSources(_ELENA_::Compiler& compiler, _ELENA_::Parser& parser) { bool debugMode = BoolSetting(_ELENA_::opDebugMode); _ELENA_::Unresolveds unresolveds(_ELENA_::Unresolved(), NULL); for (_ELENA_::SourceIterator it = _sources.start(); !it.Eof(); it++) { _ELENA_::Map<_ELENA_::ident_t, _ELENA_::ProjectSettings::VItem>* source = *it; // create module _ELENA_::ident_t name = source->get(ELC_NAMESPACE_KEY); _ELENA_::ModuleInfo moduleInfo = compiler.createModule(name, *this, debugMode); _ELENA_::ident_t target = source->get(ELC_TARGET_NAME); int type = !emptystr(target) ? _targets.get(target, ELC_TYPE_NAME, 1) : 1; if (type == 1) { // if it is a normal ELENA source file _ELENA_::ForwardIterator file_it = source->getIt(ELC_INCLUDE); while (!file_it.Eof()) { // compile a source file compile(*file_it, compiler, parser, moduleInfo, unresolveds); file_it = source->nextIt(ELC_INCLUDE, file_it); } } else if (type == 2) { // if it is a script file _ELENA_::ScriptParser scriptParser; // load options _ELENA_::Map<_ELENA_::ident_t, _ELENA_::TargetSettings::VItem>* targetInfo = _targets.get(target, (_ELENA_::Map<_ELENA_::ident_t, _ELENA_::TargetSettings::VItem>*)NULL); _ELENA_::TargetIterator option_it = targetInfo->getIt(ELC_OPTION); while (!option_it.Eof()) { if (!scriptParser.setOption(*option_it, StrSetting(_ELENA_::opProjectPath))) { raiseError(errInvalidTargetOption, *option_it); } option_it = targetInfo->nextIt(ELC_OPTION, option_it); } // compile script files _ELENA_::ForwardIterator file_it = source->getIt(ELC_INCLUDE); while (!file_it.Eof()) { compile(*file_it, compiler, scriptParser, moduleInfo, unresolveds); file_it = source->nextIt(ELC_INCLUDE, file_it); } } saveModule(moduleInfo.codeModule, "nl"); if (moduleInfo.debugModule) saveModule(moduleInfo.debugModule, "dnl"); } // validate the unresolved forward refereces if unresolved reference warning is enabled compiler.validateUnresolved(unresolveds, *this); return !HasWarnings(); }
void SettingsManager::save(string const& aFileName) { SimpleXML xml; xml.addTag("DCPlusPlus"); xml.stepIn(); xml.addTag("Settings"); xml.stepIn(); int i; string type("type"), curType("string"); for(i=STR_FIRST; i<STR_LAST; i++) { if (i == INCOMING_CONNECTIONS) continue; if(i == CONFIG_VERSION) { xml.addTag(settingTags[i], m_version); xml.addChildAttrib(type, curType); } else if(isSet[i]) { xml.addTag(settingTags[i], get(StrSetting(i), false)); xml.addChildAttrib(type, curType); } } curType = "int"; for(i=INT_FIRST; i<INT_LAST; i++) { if(isSet[i]) { xml.addTag(settingTags[i], get(IntSetting(i), false)); xml.addChildAttrib(type, curType); } } curType = "int64"; for(i=INT64_FIRST; i<INT64_LAST; i++) { if(isSet[i]) { xml.addTag(settingTags[i], get(Int64Setting(i), false)); xml.addChildAttrib(type, curType); } } xml.stepOut(); fire(SettingsManagerListener::Save(), xml); try { File out(aFileName + ".tmp", File::WRITE, File::CREATE | File::TRUNCATE); BufferedOutputStream<false> f(&out); f.write(SimpleXML::utf8Header); xml.toXML(&f); f.flush(); out.close(); File::deleteFile(aFileName); File::renameFile(aFileName + ".tmp", aFileName); } catch(const FileException&) { // ... } }
void FireSettingsManager::load(string const& aFileName) { try { SimpleXML xml; xml.fromXML(File(aFileName, File::READ, File::OPEN).read()); xml.resetCurrentChild(); xml.stepIn(); if(xml.findChild("FireSettings")) { xml.stepIn(); int i; for(i=STR_FIRST; i<STR_LAST; i++) { const string& attr = settingTags[i]; dcassert(attr.find("SENTRY") == string::npos); if(xml.findChild(attr)) set(StrSetting(i), xml.getChildData()); xml.resetCurrentChild(); } for(i=INT_FIRST; i<INT_LAST; i++) { const string& attr = settingTags[i]; dcassert(attr.find("SENTRY") == string::npos); if(xml.findChild(attr)) set(IntSetting(i), Util::toInt(xml.getChildData())); xml.resetCurrentChild(); } for(i=INT64_FIRST; i<INT64_LAST; i++) { const string& attr = settingTags[i]; dcassert(attr.find("SENTRY") == string::npos); if(xml.findChild(attr)) set(Int64Setting(i), Util::toInt64(xml.getChildData())); xml.resetCurrentChild(); } xml.stepOut(); } fire(FireSettingsManagerListener::Load(), xml); // fire(FireSettingsManagerListener::Load(), &xml); xml.stepOut(); } catch(const Exception&) { } }
void _ELC_::Project :: cleanUp() { _ELENA_::Path rootPath(StrSetting(_ELENA_::opProjectPath), StrSetting(_ELENA_::opOutputPath)); for (_ELENA_::SourceIterator it = _sources.start(); !it.Eof(); it++) { _ELENA_::ident_t ns = _sources.get(it.key(), ELC_NAMESPACE_KEY, DEFAULT_STR); _ELENA_::Path path; // remove module path.copy(rootPath.c_str()); _loader.nameToPath(ns, path, "nl"); //_wremove(path); // remove debug module path.copy(rootPath.c_str()); _loader.nameToPath(ns, path, "dnl"); //_wremove(path); } }
void SettingsManager::load(string const& aFileName) { try { SimpleXML xml; xml.fromXML(File(aFileName, File::READ, File::OPEN).read()); xml.resetCurrentChild(); xml.stepIn(); if(xml.findChild("Settings")) { xml.stepIn(); int i; for(i=STR_FIRST; i<STR_LAST; i++) { const string& attr = settingTags[i]; dcassert(attr.find("SENTRY") == string::npos); if(xml.findChild(attr)) set(StrSetting(i), xml.getChildData()); xml.resetCurrentChild(); } for(i=INT_FIRST; i<INT_LAST; i++) { const string& attr = settingTags[i]; dcassert(attr.find("SENTRY") == string::npos); if(xml.findChild(attr)) set(IntSetting(i), Util::toInt(xml.getChildData())); xml.resetCurrentChild(); } for(i=INT64_FIRST; i<INT64_LAST; i++) { const string& attr = settingTags[i]; dcassert(attr.find("SENTRY") == string::npos); if(xml.findChild(attr)) set(Int64Setting(i), Util::toInt64(xml.getChildData())); xml.resetCurrentChild(); } xml.stepOut(); } if(SETTING(PRIVATE_ID).length() != 39 || CID(SETTING(PRIVATE_ID)).isZero()) { set(PRIVATE_ID, CID::generate().toBase32()); } double v = Util::toDouble(SETTING(CONFIG_VERSION)); // if(v < 0.x) { // Fix old settings here } if(v <= 0.674) { // Formats changed, might as well remove these... set(LOG_FORMAT_POST_DOWNLOAD, Util::emptyString); set(LOG_FORMAT_POST_UPLOAD, Util::emptyString); set(LOG_FORMAT_MAIN_CHAT, Util::emptyString); set(LOG_FORMAT_PRIVATE_CHAT, Util::emptyString); set(LOG_FORMAT_STATUS, Util::emptyString); set(LOG_FORMAT_SYSTEM, Util::emptyString); set(LOG_FILE_MAIN_CHAT, Util::emptyString); set(LOG_FILE_STATUS, Util::emptyString); set(LOG_FILE_PRIVATE_CHAT, Util::emptyString); set(LOG_FILE_UPLOAD, Util::emptyString); set(LOG_FILE_DOWNLOAD, Util::emptyString); set(LOG_FILE_SYSTEM, Util::emptyString); } if(SETTING(SET_MINISLOT_SIZE) < 64) set(SET_MINISLOT_SIZE, 64); if(SETTING(AUTODROP_INTERVAL) < 1) set(AUTODROP_INTERVAL, 1); if(SETTING(AUTODROP_ELAPSED) < 1) set(AUTODROP_ELAPSED, 1); if(SETTING(AUTO_SEARCH_LIMIT) > 5) set(AUTO_SEARCH_LIMIT, 5); else if(SETTING(AUTO_SEARCH_LIMIT) < 1) set(AUTO_SEARCH_LIMIT, 1); #ifdef _DEBUG set(PRIVATE_ID, CID::generate().toBase32()); #endif setDefault(UDP_PORT, SETTING(TCP_PORT)); File::ensureDirectory(SETTING(TLS_TRUSTED_CERTIFICATES_PATH)); fire(SettingsManagerListener::Load(), xml); xml.stepOut(); } catch(const Exception&) { if(CID(SETTING(PRIVATE_ID)).isZero()) set(PRIVATE_ID, CID::generate().toBase32()); } }
void SettingsManager::load(string const& aFileName, bool main) { try { SimpleXML xml; xml.fromXML(File(aFileName, File::READ, File::OPEN).read()); xml.resetCurrentChild(); xml.stepIn(); if(xml.findChild("Settings")) { xml.stepIn(); for(int i=STR_FIRST; i<STR_LAST; i++) { const string& attr = settingTags[i]; dcassert(attr.find(SENTRY) == string::npos); if(xml.findChild(attr)) set(StrSetting(i), xml.getChildData()); xml.resetCurrentChild(); } for(int i=INT_FIRST+1; i<INT_LAST; i++) { const string& attr = settingTags[i]; dcassert(attr.find(SENTRY) == string::npos); if(xml.findChild(attr)) set(IntSetting(i), Util::toInt(xml.getChildData())); xml.resetCurrentChild(); } for(int i=INT64_FIRST; i<INT64_LAST; i++) { const string& attr = settingTags[i]; dcassert(attr.find(SENTRY) == string::npos); if(xml.findChild(attr)) set(Int64Setting(i), Util::toInt64(xml.getChildData())); xml.resetCurrentChild(); } xml.stepOut(); } if (main) { double v = Util::toDouble(SETTING(CONFIG_VERSION)); // if(v < 0.x) { // Fix old settings here } if(v <= 0.674 || SETTING(PRIVATE_ID).length() != 39 || CID(SETTING(PRIVATE_ID)).isZero()) { set(PRIVATE_ID, CID::generate().toBase32()); // Formats changed, might as well remove these... set(LOG_FORMAT_POST_DOWNLOAD, Util::emptyString); set(LOG_FORMAT_POST_UPLOAD, Util::emptyString); set(LOG_FORMAT_MAIN_CHAT, Util::emptyString); set(LOG_FORMAT_PRIVATE_CHAT, Util::emptyString); set(LOG_FORMAT_STATUS, Util::emptyString); set(LOG_FORMAT_SYSTEM, Util::emptyString); set(LOG_FILE_MAIN_CHAT, Util::emptyString); set(LOG_FILE_STATUS, Util::emptyString); set(LOG_FILE_PRIVATE_CHAT, Util::emptyString); set(LOG_FILE_UPLOAD, Util::emptyString); set(LOG_FILE_DOWNLOAD, Util::emptyString); set(LOG_FILE_SYSTEM, Util::emptyString); } if(v <= 16) { set(HUBLIST_SERVERS, Util::emptyString); } #ifdef _DEBUG set(PRIVATE_ID, CID::generate().toBase32()); #endif setDefault(UDP_PORT, SETTING(TCP_PORT)); #ifdef PPA_INCLUDE_SSL File::ensureDirectory(SETTING(TLS_TRUSTED_CERTIFICATES_PATH)); #endif fire(SettingsManagerListener::Load(), xml); } xml.stepOut(); } catch(const Exception&) { if (main) { if(CID(SETTING(PRIVATE_ID)).isZero()) set(PRIVATE_ID, CID::generate().toBase32()); } } if (main) { if(SETTING(TCP_PORT) == 0) { set(TCP_PORT, (int)Util::rand(1025, 8000)); } if(SETTING(UDP_PORT) == 0) { set(UDP_PORT, (int)Util::rand(1025, 8000)); } if(SETTING(TLS_PORT) == 0) { set(TLS_PORT, (int)Util::rand(1025, 32000)); } } }
void SettingsManager::save(string const& aFileName) { SimpleXML xml; xml.addTag("DCPlusPlus"); xml.stepIn(); xml.addTag("Settings"); xml.stepIn(); int i; string type("type"), curType("string"); for(i=STR_FIRST; i<STR_LAST; i++) { if(i == CONFIG_VERSION) { xml.addTag(settingTags[i], VERSIONSTRING); xml.addChildAttrib(type, curType); } else if(isSet[i]) { xml.addTag(settingTags[i], get(StrSetting(i), false)); xml.addChildAttrib(type, curType); } } curType = "int"; for(i=INT_FIRST; i<INT_LAST; i++) { if(isSet[i]) { xml.addTag(settingTags[i], get(IntSetting(i), false)); xml.addChildAttrib(type, curType); } } for(i=FLOAT_FIRST; i<FLOAT_LAST; i++) { if(isSet[i]) { xml.addTag(settingTags[i], static_cast<int>(get(FloatSetting(i), false) * 1000.)); xml.addChildAttrib(type, curType); } } curType = "int64"; for(i=INT64_FIRST; i<INT64_LAST; i++) { if(isSet[i]) { xml.addTag(settingTags[i], get(Int64Setting(i), false)); xml.addChildAttrib(type, curType); } } xml.stepOut(); xml.addTag("SearchTypes"); xml.stepIn(); for(SearchTypesIterC i = searchTypes.begin(); i != searchTypes.end(); ++i) { xml.addTag("SearchType", Util::toString(";", i->second)); xml.addChildAttrib("Id", i->first); } xml.stepOut(); fire(SettingsManagerListener::Save(), xml); try { File out(aFileName + ".tmp", File::WRITE, File::CREATE | File::TRUNCATE); BufferedOutputStream<false> f(&out); f.write(SimpleXML::utf8Header); xml.toXML(&f); f.flush(); out.close(); File::deleteFile(aFileName); File::renameFile(aFileName + ".tmp", aFileName); } catch(const FileException&) { // ... } }