void SaveIni(INIFile &theINI, const char *filename) { std::fstream file(filename, std::ios::out); if(!file.good()) return; // just iterate the hashes and values and dump them to a file. INIFile::iterator section= theINI.begin(); while(section != theINI.end()) { if(section->first > "") file << std::endl << "[" << section->first << "]" << std::endl; INISection::iterator pair = section->second.begin(); while(pair != section->second.end()) { if(pair->second > "") file << pair->first << "=" << pair->second << std::endl; else file << pair->first << std::endl; pair++; } section++; } file.close(); }
void PluginDialog::readPreferenceEntries(const INIFile& inifile) { PreferencesEntry::readPreferenceEntries(inifile); plugin_model_.pluginsLoaded(); for (std::list<PreferencesEntry*>::iterator child_it = child_entries_.begin(); child_it != child_entries_.end(); ++child_it) { (*child_it)->readPreferenceEntries(inifile); } PluginManager& man = PluginManager::instance(); if(inifile.hasEntry(getINIFileSectionName(), "ActivePlugins")) { String active_plugins = inifile.getValue(getINIFileSectionName(), "ActivePlugins"); man.setAutoActivatePlugins(active_plugins.c_str()); } if(inifile.hasEntry(getINIFileSectionName(), "PluginDirectories")) { String plugin_directories = inifile.getValue(getINIFileSectionName(), "PluginDirectories"); man.setPluginDirectories(plugin_directories); } }
void Preferences::fetchPreferences(INIFile& inifile) { // the position of the window int x_pos = x(); int y_pos = y(); if (inifile.hasEntry("WINDOWS", "Preferences::x")) { x_pos = inifile.getValue("WINDOWS", "Preferences::x").toInt(); } if (inifile.hasEntry("WINDOWS", "Preferences::y")) { y_pos = inifile.getValue("WINDOWS", "Preferences::y").toInt(); } x_pos = BALL_MAX(x_pos, 20); y_pos = BALL_MAX(y_pos, 20); move(x_pos, y_pos); HashSet<PreferencesEntry*>::Iterator it = entries_.begin(); for (; +it; it++) { (**it).readPreferenceEntries(inifile); } }
void ColoringSettingsDialog::readPreferenceEntries(INIFile& inifile) { PreferencesEntry::readPreferenceEntries(inifile); if ( inifile.hasEntry("COLORING_OPTIONS", "ResidueNames") && inifile.hasEntry("COLORING_OPTIONS", "ResidueNameColors")) { String residue_names = inifile.getValue("COLORING_OPTIONS", "ResidueNames"); String residue_name_colors = inifile.getValue("COLORING_OPTIONS", "ResidueNameColors"); std::vector<String> split_names; residue_names.split(split_names); std::vector<String> split_colors; residue_name_colors.split(split_colors); if (split_names.size() != split_colors.size()) { Log.warn() << "ColoringSettingsDialog::fetchPreferences: residue name coloring in inifile is invalid!" << std::endl; } std::vector<ColorRGBA> split_color_rgba(split_colors.size()); for (Position i=0; i<split_color_rgba.size(); ++i) { split_color_rgba[i] = ColorRGBA(split_colors[i]); } residue_table_->setContent(split_names, split_color_rgba); } }
void RemoveIniSetting(INIFile &theINI, const char *section, const char *key) { INIFile::iterator iSection = theINI.find(std::string(section)); if(iSection != theINI.end()) { INISection::iterator apair = iSection->second.find(std::string(key)); if(apair != iSection->second.end()) iSection->second.erase(apair); } }
std::string GetIniSetting(INIFile &theINI, const char *section, const char *key, const char *defaultval) { std::string result(defaultval); INIFile::iterator iSection = theINI.find(std::string(section)); if(iSection != theINI.end()) { INISection::iterator apair = iSection->second.find(std::string(key)); if(apair != iSection->second.end()) result = apair->second; } return result; }
void PythonSettings::readPreferenceEntries(const INIFile& inifile) { PreferencesEntry::readPreferenceEntries(inifile); if (inifile.hasEntry("PYTHON", "font")) { font_.fromString(inifile.getValue("PYTHON", "font").c_str()); } else { font_ = QFont("Helvetica", 12); } font_label->setFont(font_); }
void PythonSettings::writePreferenceEntries(INIFile& inifile) { PreferencesEntry::writePreferenceEntries(inifile); // the font size inifile.insertValue("PYTHON", "font", ascii(font_.toString())); }
void RuleEvaluator::extractSection_(INIFile& file, const String& symbol) { // assemble the section name String section_name(prefix_ + ":" + symbol); // abort if the INI file does not contain the requested section if (!file.hasSection(section_name)) { return; } // create a new entry for symbol if (!rule_map_.has(symbol)) { rule_map_.insert(symbol, list<pair<Expression, String> >()); } // iterate over all lines of the respective section INIFile::LineIterator it = file.getSectionFirstLine(section_name); ++it;//skip section line for (; +it ; it.getSectionNextLine()) { String line(*it); // empty lines or comment lines (starting with ';' or '#') are ignored if (line.has('=') && (line[0] != ';') && (line[0] != '#')) { if (line[0] == '=') { Log.error() << "RuleEvaluator:: invalid rule in line: " << line << endl; continue; } String value = line.before("="); String expression_string; if (line.after("=").isValid()) { expression_string = line.after("="); } expression_string.trim(); value.trim(); // push the expression into the list rule_map_[symbol].push_back(pair<Expression, String>(Expression(expression_string), value)); } } }
TestData_INIFile() :ini() { if(!ini.OpenFile("test/test.ini")) { throw std::string("Could not open file test/test.ini"); } }
void Mod::ReadForgeInfo(QByteArray contents) { // Read the data m_name = "Minecraft Forge"; m_mod_id = "Forge"; m_homeurl = "http://www.minecraftforge.net/forum/"; INIFile ini; if (!ini.loadFile(contents)) return; QString major = ini.get("forge.major.number", "0").toString(); QString minor = ini.get("forge.minor.number", "0").toString(); QString revision = ini.get("forge.revision.number", "0").toString(); QString build = ini.get("forge.build.number", "0").toString(); m_version = major + "." + minor + "." + revision + "." + build; }
bool InitServer() { srand(time(NULL)); //日志等级 INISection * configPath = g_serverIni.GetSection("config"); if (!configPath) { IME_ERROR("Miss section [config] in config ini"); return false; } std::string strLogLevel; if (!configPath->ReadString("loglevel",strLogLevel)) { IME_ERROR("Missing loglevel info"); return false; } sLog->SetLogLevel((char *)strLogLevel.c_str()); int debugmask = 0; if (!configPath->ReadInt("logdebug", debugmask)) { IME_ERROR("Missing logdebug"); return false; } IME_LOG("log debug %x", (unsigned int)debugmask); sLog->SetDebugLogMask((DebugLogFilters)debugmask); ////////////////////////////////////////////////////////////////////////// #ifdef LUA_USE_VERSION sSCript->Init(CScriptSupport::LUA_SCRIPT); sSCript->LoadScript(CSet::ScriptMainFile); #elif defined JAVASCRIPT_uSE_VERSION #endif if (!HandlerInit(MAIN_THREAD)) { IME_ERROR("man thread handler init fail"); return false; } //////// // if (!g_luaState.Init()) // { // IME_ERROR("luaState Init failed."); // return false; // } // //tolua_LuaExport_open(g_luaState.GetState()); // // if (!CLuaCtrl::Init()) // { // IME_ERROR("CLuaCtrl init error"); // return false; // } return true; }
int main(int argc, char **argv) { // read an INI. If file doesn't exist, that's OK. INIFile ini = LoadIni("test.ini"); if(ini.size()) { // Note that existing INIs will be added to, though if any of the keys // listed below already exist, this program will modify them. cout << "About to modify test.ini, which presently contains:\n"; DumpIni(ini); } cout << "\nLoading INI with the following information, plus comments\n\n"; cout <<"[Favorites]\ncolor=blue\nfood=pizza\nbeer=homebrew\n\n"; cout << "[Computing]\nOperating System=Linux\nToolkit=FLTK\nComment=Now isn't this fun?\n\n"; PutIniSetting(ini, "", "; This is a comment about the whole INI file"); PutIniSetting(ini, "Favorites", "; This is a list of favorites"); PutIniSetting(ini, "Favorites", "color", "blue"); PutIniSetting(ini, "Favorites", "food", "pizza"); PutIniSetting(ini, "Favorites", "beer", "homebrew"); PutIniSetting(ini, "Computing", "; Information about computing preferences"); PutIniSetting(ini, "Computing", "Operating System", "Linux"); PutIniSetting(ini, "Computing", "Toolkit", "FLTK"); PutIniSetting(ini, "Computing", "Comment", "This will be replaced in next line."); PutIniSetting(ini, "Computing", "Comment", "Now isn't this fun?"); cout << "\nINI Ready, saving to disk\n\n"; SaveIni(ini, "test.ini"); cout << "Loading from disk to verify.\n\n"; INIFile ini2 = LoadIni("test.ini"); cout << "Contents of ini just read\n\n"; DumpIni(ini2); cout << "\nChecking single value for section Computing, key Comment:\n"; cout << "Value is: " << GetIniSetting(ini2, "Computing", "Comment") << std::endl; cout << "\nChecking unset value for section Computing, \nkey Distribution, with default of \"RedHat\"\n"; cout << "Value is: " << GetIniSetting(ini2, "Computing", "Distribution", "RedHat") << "\n\nDone\n\n"; return (0); }
/** Constructor, loads file and prepares to play a vqa movie. * @param the graphicsengine. * @param the soundengine. * @param the name of the vqamovie. */ VQAMovie::VQAMovie(const char *filename) { INIFile *inif; char *fname = new char[strlen(filename)+5]; if( toupper(filename[0]) == 'X' ) vqafile = NULL; else { strcpy( fname, filename ); strcat( fname, ".VQA" ); vqafile = VFS_Open(fname); } delete[] fname; if (vqafile == NULL) { throw VQAError(); } // Get header information for the vqa. If the header is corrupt, we can die now. vqafile->seekSet(0); if (DecodeFORMChunk() == 1) { logger->error("VQA: Invalid FORM chunk\n"); throw VQAError(); } offsets = new Uint32[header.NumFrames]; if (DecodeFINFChunk() == 1) { delete[] offsets; logger->error("VQA: Invalid FINF chunk\n"); throw VQAError(); } CBF_LookUp = new Uint8[0x0ff00 << 3]; CBP_LookUp = new Uint8[0x0ff00 << 3]; VPT_Table = new Uint8[lowoffset<<1]; CBPOffset = 0; /* Starting offset of CBP Look up table must be zero */ CBPChunks = 0; /* Number of CBPChunks */ // FIXME: Use global config data inif = new INIFile("freecnc.ini"); scaleVideo = inif->readInt("video", "fullscreenMovies", 0); videoScaleQuality = inif->readInt("video", "movieQuality", 0); delete inif; }
void ColoringSettingsDialog::writePreferenceEntries(INIFile& inifile) { PreferencesEntry::writePreferenceEntries(inifile); if (!inifile.hasSection("COLORING_OPTIONS")) { inifile.appendSection("COLORING_OPTIONS"); } String residue_names, residue_name_colors; for (Index i=0; i<residue_table_->rowCount(); ++i) { residue_names += ascii(residue_table_->item(i, 0)->text()) + ";"; residue_name_colors += (String)(static_cast<ColorRGBA>(residue_table_->item(i, 1)->backgroundColor())) + ";"; } inifile.insertValue("COLORING_OPTIONS", "ResidueNames", residue_names); inifile.insertValue("COLORING_OPTIONS", "ResidueNameColors", residue_name_colors); }
void PluginDialog::writePreferenceEntries(INIFile& inifile) { PreferencesEntry::writePreferenceEntries(inifile); for (std::list<PreferencesEntry*>::iterator child_it = child_entries_.begin(); child_it != child_entries_.end(); ++child_it) { (*child_it)->writePreferenceEntries(inifile); } PluginManager& man = PluginManager::instance(); if(!inifile.hasSection(getINIFileSectionName())) { inifile.appendSection(getINIFileSectionName()); } String value; man.getPluginDirectories(value); inifile.insertValue(getINIFileSectionName(), "PluginDirectories", value); inifile.insertValue(getINIFileSectionName(), "ActivePlugins", man.getAutoActivatePlugins().toStdString()); }
void Preferences::writePreferences(INIFile& inifile) { // the window position inifile.insertValue("WINDOWS", "Preferences::x", String(pos().x())); inifile.insertValue("WINDOWS", "Preferences::y", String(pos().y())); HashSet<PreferencesEntry*>::Iterator it = entries_.begin(); for (; +it; it++) { (**it).writePreferenceEntries(inifile); } }
void DumpIni(INIFile &ini) { // This is essentially SaveIni() except it just dumps to stdout INIFile::iterator section= ini.begin(); while(section != ini.end()) { cout << std::endl << "[" << section->first << "]" << std::endl; INISection sectionvals = section->second; INISection::iterator pair = sectionvals.begin(); while(pair != sectionvals.end()) { cout << pair->first ; if(pair->second > "") cout << "=" << pair->second; cout << std::endl; pair++; } section++; } }
void MainControlPreferences::readPreferenceEntries(const INIFile& inifile) { PreferencesEntry::readPreferenceEntries(inifile); if (inifile.hasEntry(inifile_section_name_, "style")) { String value = inifile.getValue(inifile_section_name_, "style"); int e = style_box_->findText(value.c_str()); if (e == -1) return; style_box_->setCurrentIndex(e); } if (inifile.hasEntry(inifile_section_name_, "language")) { String value = inifile.getValue(inifile_section_name_, "language"); int e = languageComboBox_->findText(value.c_str()); if (e == -1) return; last_index_ = e; languageComboBox_->setCurrentIndex(e); } }
void PutIniSetting(INIFile &theINI, const char *section, const char *key, const char *value) { INIFile::iterator iniSection; INISection::iterator apair; if((iniSection = theINI.find(std::string(section))) == theINI.end()) { // no such section? Then add one.. INISection newsection; if(key) newsection.insert( std::pair<std::string, std::string> (std::string(key), std::string(value)) ); theINI.insert( std::pair<std::string, INISection> (std::string(section), newsection) ); } else if(key) { // found section, make sure key isn't in there already, // if it is, just drop and re-add apair = iniSection->second.find(std::string(key)); if(apair != iniSection->second.end()) iniSection->second.erase(apair); iniSection->second.insert( std::pair<std::string, std::string> (std::string(key), std::string(value)) ); } }
string GET_ENV_INI_DEFAULT_FILE( INIFile &ini_file, const string &ENV, const string &DISPLAY_PATH, const string &COMMON_PATH, const string &GROUP, const string &VAR ) { char *env = getenv(ENV.c_str()); if( env ) return env; if( ini_file.hasOption(GROUP,VAR) ) { string option = ini_file.get( GROUP, VAR ); ifstream inp( (DISPLAY_PATH + option).c_str() ); inp.close(); if(!inp.fail()) return DISPLAY_PATH + option; inp.clear(); inp.open( (COMMON_PATH + option).c_str() ); inp.close(); if(!inp.fail()) return COMMON_PATH + option; } return ""; }
void Event::writeToINI(INIFile& file) { if (Array.objectList.size() == 0) { Log::line("SECTION - Events does not exist, will not write to map.", Log::DEBUG); return; } for (auto& it : Array.objectList) { if (!it->isGlobal) { file.SetValue("Events", it->ID, it->asString()); } } }
void CNetRunnable::run() { INISection * server = g_serverIni.GetSection("server"); if (!server) { IME_ERROR("Miss section [server] in ***server.ini"); return ; } int nPort = 0; if (!server->ReadInt("listen_port",nPort)) { IME_ERROR("Miss listen_port"); return ; } IME_LOG("NetRunnable thread start!"); m_server.Init(); if (!m_server.StartServer("",nPort)) { g_stopEvent = true; } IME_LOG("NetRunnable thread exit"); }
bool RuleEvaluator::initialize (INIFile& file, const String& prefix) { // destroy the old rules rule_map_.clear(); valid_ = false; // store the new prefix prefix_ = prefix; // check whether the INI file is valid if (!file.isValid()) { // we didn't get a valid prefix file: abort return false; } // check for the sections and create the corresponding // Expressions for (Position i = 0; i < Element::NUMBER_OF_ELEMENTS; i++) { extractSection_(file, PTE[i].getSymbol()); } // the last rule is a general rule extractSection_(file, "*"); if (rule_map_.size() == 0) { Log.error() << "RuleEvaluator::initialize: no matching sections found for prefix " << prefix_ << endl; } // we create a map - done. valid_ = true; return true; }
Weapon::Weapon(const char* wname) { char *pname= 0; char *whname= 0; //char *faname= 0; //char *faimage= 0; map<string, Projectile*>::iterator projentry; map<string, Warhead*>::iterator wheadentry; INIFile * weapini; //SHPImage * fireanimtemp; //Uint8 additional; //Uint8 i; string projname, warheadname; string weapname; INIFile* rules = 0; name = string(wname); rules = new INIFile("rules.ini"); weapini = p::weappool->getWeaponsINI(); weapname = (string)wname; // UPPER the string 'weapname' for_each(weapname.begin(), weapname.end(), toupper); pname = weapini->readString(wname, "projectile"); if (pname == NULL) { logger->warning( "Unable to find projectile for weapon \"%s\" in inifile..\n", wname); throw 0; } projname = (string)pname; // UPPER the string 'projname' for_each(projname.begin(), projname.end(), toupper); projentry = p::weappool->projectilepool.find(projname); if (projentry == p::weappool->projectilepool.end() ) { try { projectile = new Projectile(string(pname), p::raLoader->lnkProjectileDataList, pc::imagepool); } catch(...) { logger->warning("Unable to find projectile \"%s\" used for weapon \"%s\".\nUnit using this weapon will be unarmed\n", pname, wname); delete[] pname; throw 0; } p::weappool->projectilepool[projname] = projectile; } else { projectile = projentry->second; } delete[] pname; whname = weapini->readString(wname, "warhead"); if (whname==NULL) { logger->warning( "Unable to find warhead for weapon \"%s\" in inifile..\n", wname); throw 0; } warheadname = (string)whname; transform(warheadname.begin(), warheadname.end(), warheadname.begin(), toupper); wheadentry = p::weappool->warheadpool.find(warheadname); if (wheadentry == p::weappool->warheadpool.end() ) { try { // Try to create the Warhead whead = new Warhead(whname, p::raLoader->lnkWarheadDataList); } catch(...) { logger->warning("Unable to find Warhead \"%s\" used for weapon \"%s\".\nUnit using this weapon will be unarmed\n", whname, wname); delete[] whname; throw 0; } p::weappool->warheadpool[warheadname] = whead; } else { whead = wheadentry->second; } delete[] whname; speed = weapini->readInt(wname, "speed", 100); range = weapini->readInt(wname, "range", 4); reloadtime = weapini->readInt(wname, "reloadtime", 50); damage = weapini->readInt(wname, "damage", 10); burst = weapini->readInt(wname, "burst", 1); heatseek = (weapini->readInt(wname, "heatseek", 0) != 0); // pc::imagepool->push_back(new SHPImage("minigun.shp", mapscaleq)); //firesound = weapini->readString(wname, "firesound"); //printf("wname = %s\n", wname); report = rules->readString(wname, "Report"); if (report != 0){ string soundWeap = report; soundWeap += string(".aud"); transform(soundWeap.begin(), soundWeap.begin(), soundWeap.end(), tolower); //logger->debug("Report = %s\n", soundWeap.c_str()); report = cppstrdup(soundWeap.c_str()); pc::sfxeng->LoadSound(report); } reloadsound = weapini->readString(wname, "reloadsound"); if (reloadsound != 0) pc::sfxeng->LoadSound(reloadsound); chargingsound = weapini->readString(wname, "chargingsound"); if (chargingsound != 0) pc::sfxeng->LoadSound(chargingsound); fuel = weapini->readInt(wname, "fuel", 0); seekfuel = weapini->readInt(wname, "seekfuel", 0); // @todo Implemente Anim in [Weapon] /* fireimage = pc::imagepool->size()<<16; faname = weapini->readString(wname, "fireimage", "none"); //printf ("%s line %i: Weapon = %s, fireimage = %s\n", __FILE__, __LINE__, wname, faname); if (strcmp((faname), ("none")) == 0) { delete[] faname; numfireimages = 0; numfiredirections = 1; fireimage = 0; } else { additional = (Uint8)weapini->readInt(faname, "additional", 0); faimage = weapini->readString(faname, "image", "minigun.shp"); try { fireanimtemp = new SHPImage(faimage, -1); } catch (ImageNotFound&) { throw 0; } delete[] faimage; faimage = NULL; numfireimages = fireanimtemp->getNumImg(); numfiredirections = weapini->readInt(faname, "directions", 1); if (numfiredirections == 0) { numfiredirections = 1; } fireimages = new Uint32[numfiredirections]; fireimages[0] = fireimage; pc::imagepool->push_back(fireanimtemp); if (additional != 0) { char* tmpname = new char[12]; for (i=2; i<=additional; ++i) { sprintf(tmpname, "image%i", i); faimage = weapini->readString(faname, tmpname, ""); if (strcmp((faimage), ("")) != 0) { try { fireanimtemp = new SHPImage(faimage, -1); } catch (ImageNotFound&) { throw 0; } fireimages[i-1]=(pc::imagepool->size()<<16); numfireimages += fireanimtemp->getNumImg(); pc::imagepool->push_back(fireanimtemp); } else { fireimages[i] = 0; logger->warning("%s was empty in [%s]\n", tmpname, faname); } delete[] faimage; faimage = NULL; } delete[] tmpname; } else if (numfiredirections != 1) { for (i=1; i<numfiredirections; ++i) { fireimages[i] = fireimage+i*(numfireimages/numfiredirections); } } delete[] faname; }*/ // Free rules.ini delete rules; }
/** Constructor, loads the map, sidebar and such. plays briefing and actionmovie */ Game::Game() { ConfigType config; VQAMovie *mov; char* message,*tmp; INIFile* fileini; LoadingScreen *loadscreen; config = getConfig(); /* set the pointer to the gfx engine */ // We let the runtime_error propagate upwards. fileini = new INIFile("files.ini"); asprintf(&tmp,"play%i",config.gamenum); message = fileini->readString("general",tmp,"TD"); free(tmp); if (!pc::sfxeng->createPlayList(message)) { logger->error("Could not create playlist!\n"); throw GameError(); } delete[] message; delete fileini; loadscreen = new LoadingScreen(); gamemode = config.gamemode; if (gamemode == 2) { try { NetConnection::initMessages(); } catch(int) { throw GameError(); } tmp = new char[64]; sprintf(tmp,"Connecting to server: %s",config.serveraddr.c_str()); loadscreen->setCurrentTask(tmp); delete[] tmp; try { pc::conn = new NetConnection(config.serveraddr.c_str(), config.serverport); } catch(int) { delete loadscreen; throw GameError(); } // after connection sending login data loadscreen->setCurrentTask("Sending Login Data"); pc::conn->login(VERSION, config.nick.c_str(), config.mside.c_str(), config.side_colour.c_str()); } /* reset the tickcounter, should be a function in the class conatining the * counter */ loadscreen->setCurrentTask("Creating the ActionEventQueue"); p::aequeue = new ActionEventQueue(); /* load the map */ loadscreen->setCurrentTask("Loading the map."); try { p::ccmap = new CnCMap(); p::ccmap->loadMap(config.mapname.c_str(), loadscreen); } catch (CnCMap::LoadMapError&) { delete loadscreen; // loadmap will have printed the error throw GameError(); } p::dispatcher = new Dispatcher(); switch (config.dispatch_mode) { case 0: break; case 1: // Record break; case 2: // Playback break; default: logger->error("Invalid dispatch mode: %i\n",config.dispatch_mode); throw GameError(); break; } ps::aiplugman = new AI::AIPlugMan(getBinaryLocation()); delete loadscreen; switch (gamemode) { case 0: /* play briefing */ try { mov = new VQAMovie(p::ccmap->getMissionData().brief); mov->play(); delete mov; } catch (VQAError&) { } try { mov = new VQAMovie(p::ccmap->getMissionData().action); mov->play(); delete mov; } catch (VQAError&) { } break; case 1: p::ppool->setupAIs(); break; case 2: break; default: break; } /* init sidebar */ try { pc::sidebar = new Sidebar(p::ppool->getLPlayer(), pc::gfxeng->getHeight(), p::ccmap->getMissionData().theater); } catch (Sidebar::SidebarError&) { throw GameError(); } /* init cursor */ pc::cursor = new Cursor(); /* init the input functions */ pc::input = new Input(pc::gfxeng->getWidth(), pc::gfxeng->getHeight(), pc::gfxeng->getMapArea()); }
void GameModeCollection::parse() { //The INI file with the game modes INIFile* file = INIManager::instance()->get(Config::modes); if (!file) { return; } //Load [Battle] INISection* battle = file->getSection("Battle"); if (battle) { for (const auto &it : *battle) { modes.push_back(std::make_unique<GameMode>(battle->getValue(it))); } } standardDefault = modes.front()->iniName; //Load [Cooperative] //Eh... does this only load 1 entry because Cooperative mode is special? INISection* coop = file->getSection("Cooperative"); if (coop) { for (const auto &it : *coop) { modes.push_back(std::make_unique<GameMode>(coop->getValue(it))); } } //Load [ManBattle] INISection* manbattle = file->getSection("ManBattle"); if (manbattle) { for (const auto &it : *manbattle) { modes.push_back(std::make_unique<GameMode>(manbattle->getValue(it))); } } //Load [FreeForAll] INISection* ffa = file->getSection("FreeForAll"); if (ffa) { for (const auto &it : *ffa) { modes.push_back(std::make_unique<GameMode>(ffa->getValue(it))); } } //Load [Unholy] INISection* unholy = file->getSection("Unholy"); if (unholy) { for (const auto &it : *unholy) { modes.push_back(std::make_unique<GameMode>(unholy->getValue(it))); } } /* Load [Siege] Removed until UI does or does not support game type. Lol, Westwood reference. Not loading this game mode until there's any confirmation from the Ares people Can't load stuff that the game doesn't use... Something about false hope IIRC INISection* siege = file->getSection("Siege"); for (const auto &it : *siege) { modes.push_back(std::make_unique<GameMode>(siege->getValue(it))); } */ }
///Runs the benchmark bool Benchmark() { INIFile ini; if(!ini.OpenFile(BenchFile)) return false; while(ini.Next()) { CurrentSection = ini.GetSection(ini.GetSection("")->GetName()); switch(Type) { case BT_STRING: case BT_STRINGRULES: if(!STL) BenchRead<const char * const, const char *>(&INISection::ReadString); #ifndef MINIINI_NO_STL else BenchRead<const std::string &, std::string>(&INISection::ReadString); #endif break; case BT_INT: if(!STL) BenchRead<const char * const, int>(&INISection::ReadInt); #ifndef MINIINI_NO_STL else BenchRead<const std::string &, int>(&INISection::ReadInt); #endif break; case BT_FLOAT: if(!STL) BenchRead<const char * const, float>(&INISection::ReadFloat); #ifndef MINIINI_NO_STL else BenchRead<const std::string &, float>(&INISection::ReadFloat); #endif break; case BT_BOOL: if(!STL) BenchRead<const char * const, bool>(&INISection::ReadBool); #ifndef MINIINI_NO_STL else BenchRead<const std::string &, bool>(&INISection::ReadBool); #endif break; case BT_MULTISTRING: BENCHREADMULTI(ReadMultiString, const char *, std::string); break; case BT_MULTIINT: BENCHREADMULTI(ReadMultiInt, int, int); break; case BT_MULTIFLOAT: BENCHREADMULTI(ReadMultiFloat, float, float); break; case BT_MULTIBOOL: BENCHREADMULTI(ReadMultiBool, bool, bool); break; case BT_STRINGS: BENCHREADARRAY(ReadStrings, const char *, std::string); break; case BT_INTS: BENCHREADARRAY(ReadInts, int, int); break; case BT_FLOATS: BENCHREADARRAY(ReadFloats, float, float); case BT_BOOLS: BENCHREADARRAY(ReadBools, bool, bool); break; default: return false; break; } } #ifdef MINIINI_BENCH_EXTRA #ifdef linux FileTime = miniini_private::bench_filetime; AllocTime = miniini_private::bench_alloctime; LoadTime = miniini_private::bench_loadtime; #endif #endif return true; }
void MainControlPreferences::writePreferenceEntries(INIFile& inifile) { PreferencesEntry::writePreferenceEntries(inifile); inifile.insertValue(inifile_section_name_, "style", ascii(style_box_->currentText())); inifile.insertValue(inifile_section_name_, "language", ascii(languageComboBox_->currentText())); }
Weapon::Weapon(const char* wname) : name(wname) { char *pname, *whname, *faname, *faimage; map<string, Projectile*>::iterator projentry; map<string, Warhead*>::iterator wheadentry; INIFile *weapini = p::weappool->getWeaponsINI(); SHPImage* fireanimtemp; Uint8 additional, i; string projname, warheadname; string weapname = (string)wname; string::iterator p = weapname.begin(); while (p!=weapname.end()) *p++ = toupper(*p); pname = weapini->readString(wname, "projectile"); if( pname == NULL ) { logger->warning("Unable to find projectile for weapon \"%s\" in inifile..\n", wname); throw 0; } projname = (string)pname; p = projname.begin(); while (p!=projname.end()) *p++ = toupper(*p); projentry = p::weappool->projectilepool.find(projname); if( projentry == p::weappool->projectilepool.end() ) { try { projectile = new Projectile(pname, weapini); } catch(int) { logger->warning("Unable to find projectile \"%s\" used for weapon \"%s\".\nUnit using this weapon will be unarmed\n", pname, wname); delete[] pname; throw 0; } p::weappool->projectilepool[projname] = projectile; } else { projectile = projentry->second; } delete[] pname; whname = weapini->readString(wname, "warhead"); if( whname == NULL ) { logger->warning("Unable to find warhead for weapon \"%s\" in inifile..\n", wname); throw 0; } warheadname = (string)whname; transform(warheadname.begin(),warheadname.end(), warheadname.begin(), toupper); wheadentry = p::weappool->warheadpool.find(warheadname); if( wheadentry == p::weappool->warheadpool.end() ) { try { whead = new Warhead(whname, weapini); } catch (int) { logger->warning("Unable to find Warhead \"%s\" used for weapon \"%s\".\nUnit using this weapon will be unarmed\n", whname, wname); delete[] whname; throw 0; } p::weappool->warheadpool[warheadname] = whead; } else { whead = wheadentry->second; } delete[] whname; speed = weapini->readInt(wname, "speed", 100); range = weapini->readInt(wname, "range", 1); reloadtime = weapini->readInt(wname, "reloadtime", 5); damage = weapini->readInt(wname, "damage", 10); burst = weapini->readInt(wname, "burst", 1); heatseek = (weapini->readInt(wname, "heatseek", 0) != 0); fireimage = pc::imagepool->size()<<16; // pc::imagepool->push_back(new SHPImage("minigun.shp", mapscaleq)); firesound = weapini->readString(wname, "firesound"); chargesound = weapini->readString(wname, "chargesound"); fuel = weapini->readInt(wname, "fuel", 0); seekfuel = weapini->readInt(wname, "seekfuel", 0); faname = weapini->readString(wname, "fireimage", "none"); if (strcasecmp(faname,"none") == 0) { delete[] faname; numfireimages = 0; numfiredirections = 1; fireimage = 0; } else { additional = (Uint8)weapini->readInt(faname,"additional",0); faimage = weapini->readString(faname, "image", "minigun.shp"); try { fireanimtemp = new SHPImage(faimage, mapscaleq); } catch (ImageNotFound&) { throw 0; } delete[] faimage; faimage = NULL; numfireimages = fireanimtemp->getNumImg(); numfiredirections = weapini->readInt(faname, "directions", 1); if (numfiredirections == 0) { numfiredirections = 1; } fireimages = new Uint32[numfiredirections]; fireimages[0] = fireimage; pc::imagepool->push_back(fireanimtemp); if (additional != 0) { char* tmpname = new char[12]; for (i=2;i<=additional;++i) { sprintf(tmpname,"image%i",i); faimage = weapini->readString(faname, tmpname, ""); if (strcasecmp(faimage,"") != 0) { try { fireanimtemp = new SHPImage(faimage, mapscaleq); } catch (ImageNotFound&) { throw 0; } fireimages[i-1]=(pc::imagepool->size()<<16); numfireimages += fireanimtemp->getNumImg(); pc::imagepool->push_back(fireanimtemp); } else { fireimages[i] = 0; logger->warning("%s was empty in [%s]\n",tmpname,faname); } delete[] faimage; faimage = NULL; } delete[] tmpname; } else if (numfiredirections != 1) { for (i=1;i<numfiredirections;++i) { fireimages[i] = fireimage+i*(numfireimages/numfiredirections); } } delete[] faname; } }