void LoadConfig(void) { FILE *configfile; char line[MAX_CONFIG_LINE+1]; int lineno,current_group,i,config_id; if ((configfile = fopen(CONFIG_FILE,"rt")) == NULL) StartupPrintf("LoadConfig can't open %s, using default configuration\n",CONFIG_FILE); else { lineno = 1; current_group = -1; while (fgets(line,MAX_CONFIG_LINE,configfile)) { current_group = LoadConfigLine(line,lineno,CONFIG_FILE,current_group); lineno++; } fclose(configfile); } for (i=0;i<LEN_CONFIG_TABLE;i++) { config_id = config_table[i].config_id; if (GetConfigByID(config_id) == NULL) AddConfig(config_id,config_table[i].default_str, config_table[i].config_type,config_table[i].is_dynamic); } }
//----------------------------------------------------------------------------- // Purpose: Loads all the game configs from disk. // Output : Returns the number of game configurations successfully loaded. //----------------------------------------------------------------------------- int COptionsConfigs::LoadGameConfigs(const char *pszFileName) { // // Read game configs - this is from an external file so we can distribute it // with Worldcraft as a set of defaults. // // Older versions of Worldcraft used a binary file. Try that first. // int nConfigsRead = ImportOldGameConfigs("GameCfg.wc"); if (nConfigsRead > 0) { remove("GameCfg.wc"); SaveGameConfigs(pszFileName); return(nConfigsRead); } // // Newer versions of Worldcraft load configs from the "GameCfg.ini" file. // int nNumConfigs = GetPrivateProfileInt("Configs", "NumConfigs", 0, pszFileName); for (int nConfig = 0; nConfig < nNumConfigs; nConfig++) { // // Each came configuration is stored in a different section, named "GameConfig0..GameConfigN". // If the "Name" key exists in this section, try to load the configuration from this section. // char szSectionName[MAX_PATH]; char szName[MAX_PATH]; sprintf(szSectionName, "GameConfig%d", nConfig); int nCount = GetPrivateProfileString(szSectionName, "Name", "", szName, sizeof(szName), pszFileName); if (nCount > 0) { CGameConfig *pConfig = AddConfig(); if (pConfig != NULL) { if (pConfig->Load(pszFileName, szSectionName)) { nConfigsRead++; } } } } return(nConfigsRead); }
int L2Window::LoadProject(QString file_name){ qDebug("L2Window::LoadProject"); QSettings sett(file_name, QSettings::IniFormat); project_file_name = file_name; qDebug("Proj File: %s", file_name.toStdString().c_str()); int proj_size = sett.value("MAIN/count", 0).toInt(); qDebug("count: %d", proj_size); if(proj_size < 1) return status; QString topic = "SETTINGS"; for(int i = 0;i < proj_size;i++){ QString var; QTextStream varstream(&var); var = topic; varstream << "/settings_file_name" << i+1; qDebug("Topic: %s", var.toStdString().c_str()); QString settings_file_name = sett.value(var.toStdString().c_str(), "default.cfg").toString(); qDebug("Settings File: %s", settings_file_name.toStdString().c_str()); if(i < cond_set_list.size()){ activeCondSet = i; LoadConfig(settings_file_name); qDebug("Load: %d", i); } else { AddConfig(settings_file_name); qDebug("Add: %d", i); } activeCondSet = 0; } while(proj_size < cond_set_list.size()){ KeyConditionsSet* tmp = cond_set_list.last(); qDebug("Removed node %s", tmp->settings_file_name.toStdString().c_str()); cond_set_list.removeLast(); delete(tmp); qDebug("Removed node %s", tmp->settings_file_name.toStdString().c_str()); } return status; }
//----------------------------------------------------------------------------- // Purpose: // Output : Returns the number of game configurations successfully imported. //----------------------------------------------------------------------------- int COptionsConfigs::ImportOldGameConfigs(const char *pszFileName) { int nConfigsRead = 0; fstream file(pszFileName, ios::in | ios::binary | ios::nocreate); if (file.is_open()) { // Read sig. char szSig[sizeof(GAMECFG_SIG)]; file.read(szSig, sizeof szSig); if (!memcmp(szSig, GAMECFG_SIG, sizeof szSig)) { // Read version. float fThisVersion; file.read((char *)&fThisVersion, sizeof(fThisVersion)); if ((fThisVersion >= 1.0) && (fThisVersion <= GAMECFG_VERSION)) { // Read number of configs. int nTotalConfigs; file.read((char *)&nTotalConfigs, sizeof(nTotalConfigs)); // Load each config. for (int i = 0; i < nTotalConfigs; i++) { CGameConfig *pConfig = AddConfig(); pConfig->Import(file, fThisVersion); nConfigsRead++; if (!g_pMapDir) { g_pMapDir = (char *)pConfig->szMapDir; } } } } file.close(); } return(nConfigsRead); }
int LibraryDetectionManager::LoadXmlDoc( TiXmlDocument& Doc ) { int loaded = 0; for ( TiXmlElement* Elem = Doc.FirstChildElement("library"); Elem; Elem = Elem->NextSiblingElement("library") ) { // Load the version of this set int version = 0; if ( Elem->QueryIntAttribute( "version", &version ) != TIXML_SUCCESS ) version = 0; // Load shortcode wxString ShortCode = wxString(Elem->Attribute("short_code"),wxConvUTF8); if ( ShortCode.IsEmpty() ) continue; // Load name wxString Name = wxString( Elem->Attribute("name"), wxConvUTF8 ); if ( Name.IsEmpty() ) continue; // Check if we already have setting of this library // I'm to lazy to firbid const_cast here ;) LibraryDetectionConfigSet* OldSet = const_cast< LibraryDetectionConfigSet* > ( GetLibrary( ShortCode ) ); LibraryDetectionConfigSet* NewSet = 0; if ( OldSet ) { // There are detection settings yet, we override only when there's newer // or same version already if ( OldSet->Version > version ) continue; // We do not upgrade OldSet->Categories.Clear(); OldSet->Configurations.clear(); OldSet->LibraryName.Clear(); NewSet = OldSet; } else { NewSet = new LibraryDetectionConfigSet; Libraries.Add( NewSet ); } // Setup configuration set NewSet->ShortCode = ShortCode; NewSet->Version = version; NewSet->LibraryName = Name; // Read categories of library for ( TiXmlAttribute* attr = Elem->FirstAttribute(); attr; attr = attr->Next() ) { // if ( !strncasecmp(attr->Name(),"category",8) ) if ( !strncmp(attr->Name(),"category",8) ) NewSet->Categories.Add( wxString( attr->Value(),wxConvUTF8 ) ); } // Check if there's corresponding pkg-config entry if ( IsPkgConfigEntry(ShortCode) ) { LibraryDetectionConfig Config; Config.PkgConfigVar = ShortCode; Config.Description = NewSet->LibraryName + _T(" (pkg-config)"); LibraryDetectionFilter Filter; Filter.Type = LibraryDetectionFilter::PkgConfig; Filter.Value = ShortCode; Config.Filters.push_back(Filter); loaded += AddConfig(Config,NewSet) ? 1 : 0; } // Load libraries LibraryDetectionConfig Initial; loaded += LoadXml( Elem, Initial, NewSet ); } return loaded; }
int LibraryDetectionManager::LoadXml(TiXmlElement* Elem,LibraryDetectionConfig& Config,LibraryDetectionConfigSet* ConfigSet,bool Filters,bool Settings) { wxString Description = wxString(Elem->Attribute("description"),wxConvUTF8); if ( !Description.empty() ) Config.Description = Description; int loaded = 0; for ( TiXmlElement* Data = Elem->FirstChildElement(); Data; Data = Data->NextSiblingElement() ) { wxString Node = wxString(Data->Value(),wxConvUTF8).MakeLower(); if ( Filters && Settings ) { // Load subnodes if ( Node == _T("filters") ) { loaded += LoadXml(Data,Config,ConfigSet,true,false); continue; } if ( Node == _T("settings") ) { loaded += LoadXml(Data,Config,ConfigSet,false,true); continue; } // pkgconfig does define both filter and setting if ( Node == _T("pkgconfig") ) { Config.PkgConfigVar = wxString(Data->Attribute("name"),wxConvUTF8); LibraryDetectionFilter Filter; Filter.Type = LibraryDetectionFilter::PkgConfig; Filter.Value = Config.PkgConfigVar; Config.Filters.push_back(Filter); continue; } } if ( Filters ) { // Load filter LibraryDetectionFilter::FilterType Type = LibraryDetectionFilter::None; if ( Node == _T("platform") ) Type = LibraryDetectionFilter::Platform; else if ( Node == _T("file") ) Type = LibraryDetectionFilter::File; else if ( Node == _T("exec") ) Type = LibraryDetectionFilter::Exec; else if ( Node == _T("compiler") ) Type = LibraryDetectionFilter::Compiler; if ( Type != LibraryDetectionFilter::None ) { LibraryDetectionFilter Filter; Filter.Type = Type; Filter.Value = wxString(Data->Attribute("name"),wxConvUTF8); if ( !Filter.Value.IsEmpty() ) Config.Filters.push_back(Filter); continue; } } if ( Settings ) { // Load setting if ( Node==_T("path") ) { wxString Include = wxString(Data->Attribute("include"),wxConvUTF8); wxString Lib = wxString(Data->Attribute("lib"),wxConvUTF8); wxString Obj = wxString(Data->Attribute("obj"),wxConvUTF8); if ( !Include.empty() ) Config.IncludePaths.Add(Include); if ( !Lib.empty() ) Config.LibPaths.Add(Lib); if ( !Obj.empty() ) Config.ObjPaths.Add(Obj); continue; } if ( Node==_T("flags") ) { wxString cFlags = wxString(Data->Attribute("cflags"),wxConvUTF8); wxString lFlags = wxString(Data->Attribute("lflags"),wxConvUTF8); if ( !cFlags.empty() ) Config.CFlags.Add(cFlags); if ( !lFlags.empty() ) Config.LFlags.Add(lFlags); continue; } if ( Node==_T("add") ) { wxString cFlags = wxString(Data->Attribute("cflags"),wxConvUTF8); wxString lFlags = wxString(Data->Attribute("lflags"),wxConvUTF8); wxString Lib = wxString(Data->Attribute("lib") ,wxConvUTF8); wxString Define = wxString(Data->Attribute("define"),wxConvUTF8); if ( !cFlags.empty() ) Config.CFlags.Add(cFlags); if ( !lFlags.empty() ) Config.LFlags.Add(lFlags); if ( !Lib.empty() ) Config.Libs.Add(Lib); if ( !Define.empty() ) Config.Defines.Add(Define); } if ( Node==_T("header") ) { wxString file = wxString(Data->Attribute("file"),wxConvUTF8); if ( !file.empty() ) Config.Headers.Add(file); } if ( Node==_T("require") ) { wxString lib = wxString(Data->Attribute("library"),wxConvUTF8); if ( !lib.empty() ) Config.Require.Add(lib); } } } if ( Settings && Filters ) { TiXmlElement* Cfg = Elem->FirstChildElement("config"); if ( Cfg ) { // If there are any sub-configurations, let's // iterate through them and load config-specific settings for ( ;Cfg; Cfg = Cfg->NextSiblingElement("config") ) { // Append sub-configuration data LibraryDetectionConfig Copy(Config); loaded += LoadXml(Cfg,Copy,ConfigSet); } } else { // No sub-config entry, so let's add this one loaded += AddConfig(Config,ConfigSet) ? 1 : 0; } } return loaded; }
int LoadConfigLine(char *line,int lineno,const char *filename,int current_group) { char *first_str,*t1; int i; first_str = strtok(line,"= \t\n"); if (first_str == NULL) return current_group; if (*first_str == '#') return current_group; if (*first_str == '[') { if (strchr(first_str,']') == NULL) { StartupPrintf("LoadConfigLine found invalid grouping (no ]) %s (%i)\n", filename,lineno); return current_group; } t1 = strtok(NULL,"= \t\n"); if (t1 != NULL) { StartupPrintf("LoadConfigLine found extra stuff after grouping %s (%i)\n", filename,lineno); return current_group; } for (i=0;i<LEN_CONFIG_TABLE;i++) if (config_table[i].config_type == CONFIG_GROUP && !stricmp(first_str,config_table[i].config_name)) return i; StartupPrintf("LoadConfig found nonexistent group %s %s (%i)\n", first_str,filename,lineno); return current_group; } if (current_group < 0 || current_group >= LEN_CONFIG_TABLE) { StartupPrintf("LoadConfig found data before a group declared %s (%i)\n", filename,lineno); return current_group; } t1 = strtok(NULL,"\n"); /* rest of the line */ if (t1 == NULL) { StartupPrintf("LoadConfig error %s (%i): no data value\n",filename,lineno); return current_group; } while (*t1 != 0 && (*t1 == ' ' || *t1 == '\t')) t1++; /* skip whitespace */ if (*t1 == '<' && *(t1+strlen(t1)-1) == '>') { *(t1+strlen(t1)-1) = 0; t1++; } else t1 = strtok(t1," \t\n"); for (i=current_group+1;i<LEN_CONFIG_TABLE;i++) { if (config_table[i].config_type == CONFIG_GROUP) break; if (!stricmp(first_str,config_table[i].config_name)) { const char *s = AddConfig(config_table[i].config_id,t1,config_table[i].config_type, config_table[i].is_dynamic); if (s != NULL) StartupPrintf("LoadConfig error %s (%i): `%s' is %s\n", filename,lineno,t1,s); break; } } if (i == LEN_CONFIG_TABLE || config_table[i].config_type == CONFIG_GROUP) StartupPrintf("LoadConfig can't match value %s (%i)\n",filename,lineno); return current_group; }
BOOL Config(int argc, _TCHAR* argv[]) { EventLog log; HKEY key; LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\EasyDynamicDNS"), 0, KEY_READ | KEY_WRITE, &key); if (result == ERROR_SUCCESS) { tstring command = _T("show"); if (argc > 0) command = argv[0]; if (_tcsicmp(command.c_str(), _T("show")) == 0) { if (argc > 1) _tprintf(_T("Syntax error; use \"/config help\" for more information.\n")); else { DWORD timeout = LoadTimeout(key); _tprintf(_T("Update dynamic DNS domains every %d minutes.\n\n"), timeout / (1000 * 60)); int i = 0; BOOL found; do { DomainInfo info; found = LoadConfig(key, i, info); if (found == TRUE) { _tprintf(_T("Entry #%d\n"), i); _tprintf(_T(" Host Name: %s\n"), info.hostname.c_str()); _tprintf(_T(" Top Level Domain: %s\n"), info.tld.c_str()); _tprintf(_T(" My IP Address: %s\n"), (info.myip.length() > 0 ? info.myip.c_str() : _T("<my PC's address>"))); _tprintf(_T(" MX: %s\n"), info.mx.c_str()); _tprintf(_T(" Back MX: %s\n"), info.backmx.c_str()); _tprintf(_T(" Wildcard: %s\n"), info.wildcard.c_str()); _tprintf(_T(" easyDNS URL: %s\n"), (info.easydnsurl.length() > 0 ? info.easydnsurl.c_str() : _T("http://members.easydns.com/dyn/dyndns.php"))); _tprintf(_T(" HTTP Timeout: %d sec\n"), info.httpTimeout / 1000); _tprintf(_T(" Username: %s\n"), info.username.c_str()); _tprintf(_T(" Password: ********\n")); _tprintf(_T(" Proxy: %s\n"), info.proxy.c_str()); _tprintf(_T(" Proxy Port: %d\n"), info.proxyPort); } i++; } while (i < 100); } } else if (_tcsicmp(command.c_str(), _T("add")) == 0) { if (argc != 13) _tprintf(_T("Syntax error; use \"/config help\" for more information.\n")); else { int i = 0; BOOL found; do { DomainInfo info; found = LoadConfig(key, i, info); if (found != TRUE) { info.hostname = argv[1]; info.tld = argv[2]; info.myip = argv[3]; info.mx = argv[4]; info.backmx = argv[5]; info.wildcard = argv[6]; if (argv[7][0] != 0) info.easydnsurl = argv[7]; info.httpTimeout = atoi(argv[8]) * 1000; info.username = argv[9]; info.password = argv[10]; //info.domain = argv[11]; info.proxy = argv[11]; info.proxyPort = atoi(argv[12]); if (AddConfig(key, i, info) != TRUE) { TCHAR x[50]; wsprintf(x, _T("DomainInfo%03d"), i); _tprintf(_T("Error saving to registry\n")); RegDeleteKey(key, x); } } i++; } while (i < 100 && found == TRUE); if (found == TRUE) _tprintf(_T("There is not room for another entry.\n")); } } else if (_tcsicmp(command.c_str(), _T("prompt")) == 0) { if (argc != 1) _tprintf(_T("Syntax error; use \"/config help\" for more information.\n")); else { int i = 0; BOOL found; do { DomainInfo info; found = LoadConfig(key, i, info); if (found != TRUE) { TCHAR buf[256]; _tprintf("Enter your setup as described below. This program does not do much validation;\n" "please follow the instructions carefully.\n\n"); _tprintf("Host Name = the full hostname being updated (REQUIRED)\n"); info.hostname = _getts(buf); _tprintf("Top Level Domain = the root domain of your hostname, for example if your\n" "hostname is \"example.co.uk\" you should set \"tld\" to \"co.uk\". This field\n" "can be omitted in cases of second level domains like example.com\n"); info.tld = _getts(buf); _tprintf("My IP Address = the IP address of the client to be updated. Send \"0.0.0.0\"\n" "to set record to an offline state (sets record to \"offline.easydns.com\"). If\n" "you are behind a firewall or NAT set this to 1.1.1.1 and our system will detect\n" "your remote IP for you. Leave blank to use your PC's address.\n"); info.myip = _getts(buf); _tprintf("MX = use this parameter as the MX handler for the domain being updated, it\n" "defaults to preference 5. (OPTIONAL)\n"); info.mx = _getts(buf); _tprintf("Back MX = either \"YES\" or \"NO\", if \"YES\" we set smtp.easydns.com to\n" "be a backup mail spool for domain being updated at preference 100. (OPTIONAL)\n"); info.backmx = _getts(buf); _tprintf("Wildcard = either \"ON\" or \"OFF\", if \"ON\" sets a wildcard host record for\n" "the domain being updated equal to the IP address specified in \"myip\" (OPTIONAL)\n"); info.wildcard = _getts(buf); _tprintf("easyDNS URL = the url to send the update to; defaults to\n" "http://members.easydns.com/dyn/dyndns.php (OPTIONAL)\n"); info.easydnsurl = _getts(buf); _tprintf("HTTP Timeout = Number of seconds to allow the request to complete. 0 for\n" "no timeout.\n"); info.httpTimeout = atoi(_getts(buf)) * 1000; _tprintf("Username = easyDNS user name (REQUIRED)\n"); info.username = _getts(buf); _tprintf("Password = easyDNS password (which is stored securely) (REQUIRED)\n"); info.password = _getts(buf); _tprintf("Proxy = proxy server (leave blank if you don't have one)\n"); info.proxy = _getts(buf); _tprintf("Proxy Port = proxy port; 0 if you don't have one\n"); info.proxyPort = atoi(_getts(buf)); if (AddConfig(key, i, info) != TRUE) { TCHAR x[50]; wsprintf(x, _T("DomainInfo%03d"), i); _tprintf(_T("Error saving to registry\n")); RegDeleteKey(key, x); } } i++; } while (i < 100 && found == TRUE); if (found == TRUE) _tprintf(_T("There is not room for another entry.\n")); } } else if (_tcsicmp(command.c_str(), _T("delete")) == 0) { if (argc != 2) _tprintf(_T("Syntax error; use \"/config help\" for more information.\n")); else { int i = atoi(argv[1]); TCHAR x[50]; wsprintf(x, _T("DomainInfo%03d"), i); if (RegDeleteKey(key, x) != ERROR_SUCCESS) _tprintf(_T("Item %d not found.\n"), i); } } else if (_tcsicmp(command.c_str(), _T("clear")) == 0) { if (argc != 1) _tprintf(_T("Syntax error; use \"/config help\" for more information.\n")); else { for (int i = 0; i < 100; i++) { TCHAR x[50]; wsprintf(x, _T("DomainInfo%03d"), i); RegDeleteKey(key, x); } } } else if (_tcsicmp(command.c_str(), _T("timeout")) == 0) { if (argc != 2) _tprintf(_T("Syntax error; use \"/config help\" for more information.\n")); else { int i = atoi(argv[1]) * 1000 * 60; if (SaveTimeout(key, i) != TRUE) _tprintf(_T("Unable to set timeout.\n")); } } else { _tprintf(_T("Subcommands:\n")); _tprintf(_T("\tprompt: prompt for setup with help\n")); _tprintf(_T("\tadd hostname tld myip mx backmx wildcard easydnsurl httpTimeoutSec username password proxy proxyPort\n")); _tprintf(_T("\tdelete n: delete entry number n\n")); _tprintf(_T("\tclear: erase the entired configuration (be careful!)\n")); _tprintf(_T("\ttimeout n: set the timeout to n minutes\n")); _tprintf(_T("\thelp: show this text\n")); _tprintf(_T("\tshow: display the configuration\n")); } RegCloseKey(key); } else { log.LogLastError("Unable to open registry, please install first"); _tprintf(_T("Unable to open registry\n")); return FALSE; } return TRUE; }