void BenchRead(bool (INISection::*Read)(T, T2&) const) { while(CurrentSection->Next()) { T2 out; (CurrentSection->*Read)(CurrentSection->CurrentTag(), out); } }
void IQ::loadRules(INIFile* file) { INISection* rulesSection = file->getSection("IQ"); if (!rulesSection) return; rulesSection->readIntValue("MaxIQLevels", MaxIQLevels); }
void VoxelAnimType::loadRules(INIFile* rules) { INISection* rulesSection = rules->getSection(ID); if (!rulesSection) return; ObjectType::loadRules(rules); rulesSection->readStringValue("Warhead", Warhead); WarheadType::Array.findOrAllocate(Warhead); }
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; }
void AircraftType::loadRules(INIFile* rules) { INISection* rulesSection = rules->getSection(ID); if (!rulesSection) return; TechnoType::loadRules(rules); rulesSection->readBoolValue("Fighter", Fighter, Fighter); rulesSection->readBoolValue("CarryAll", CarryAll, CarryAll); }
void VehicleType::loadArt(INIFile* art) { INISection* artSection = art->getSection(ID); if (!artSection) return; TechnoType::loadArt(art); artSection->readIntValue("StandingFrames", StandingFrames); artSection->readIntValue("Facings", Facings); }
void VehicleType::loadRules(INIFile* rules) { INISection* rulesSection = rules->getSection(ID); if (!rulesSection) return; TechnoType::loadRules(rules); rulesSection->readBoolValue("Harvester", Harvester); rulesSection->readBoolValue("Weeder", Weeder); rulesSection->readBoolValue("UseTurretShadow", UseTurretShadow); }
void TechnoType::loadArt(INIFile* art) { ObjectType::loadArt(art); INISection* artSection = art->getSection(ID); artSection->readBoolValue("Remapable", Remapable); artSection->readStringValue("Palette", Palette); artSection->readStringValue("TurretOffset", TurretOffsetStr); LineSplitter split(TurretOffsetStr); TurretOffset.x = split.pop_int(); TurretOffset.y = split.pop_int(); TurretOffset.z = split.pop_int(); }
void Speech::load(INIFile* file) { INISection* section = file->getSection(ID); if (!section) { return; } section->readStringValue("Text", text); Name = text; valid = true; }
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 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)) ); } }
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"); }
//Removes the entries relative to the serialization from the INI file void MeasurementUnitsContainer::RemoveDataFromINI(INISection & IniSect) { IniSect.Read(); typedef std::list<INISection::ISmap::iterator> itList; itList toDelete; INISection::ISmap & im=IniSect.GetInternalMap(); { std::_tcstring prefix(_T("MUItem")); INISection::ISmap::iterator it, end=im.end(); for(it=im.begin();it!=end;it++) { if(it->first.compare(0,prefix.size(),prefix)==0) toDelete.push_back(it); } } { itList::const_iterator it, end=toDelete.end(); for(it=toDelete.begin();it!=end;it++) im.erase(*it); } IniSect.Write(); }
//Saves the content in a INI file void MeasurementUnitsContainer::SerializeToINI(INISection & IniSect) { IniSect.BeginWrite(); //Temp buffer TCHAR sectionName[1024]={0}; //Remove the old settings RemoveDataFromINI(IniSect); //Save the list for(MUCcont::size_type pos=0;pos<measureUnits.size();pos++) { DerivedUnit * du = dynamic_cast<DerivedUnit *>(measureUnits[pos]); DefaultUnit * dfu = dynamic_cast<DefaultUnit *>(measureUnits[pos]); if(du!=NULL) { //Find the base unit in the vector and get its ID long baseUnit; MUCcont::const_iterator it=find(measureUnits.begin(),measureUnits.end(),du->GetBaseUnit()); if(it==measureUnits.end()) continue; //Cannot find it, skip else baseUnit=(long)(it-measureUnits.begin()); //Base unit _sntprintf(sectionName,ARRSIZE(sectionName)-1,_T("MUItem%lu_BaseUnit"),pos); IniSect.PutKey(sectionName,baseUnit); //Name _sntprintf(sectionName,ARRSIZE(sectionName)-1,_T("MUItem%lu_Name"),pos); IniSect.PutKey(sectionName,du->GetName()); //Coefficient _sntprintf(sectionName,ARRSIZE(sectionName)-1,_T("MUItem%lu_Coefficient"),pos); IniSect.PutKey(sectionName,du->GetCoefficient()); //Symbol _sntprintf(sectionName,ARRSIZE(sectionName)-1,_T("MUItem%lu_Symbol"),pos); IniSect.PutKey(sectionName,du->GetSymbol()); } else if(dfu!=NULL) { //Base unit _sntprintf(sectionName,ARRSIZE(sectionName)-1,_T("MUItem%lu_DefaultUnit"),pos); IniSect.PutKey(sectionName,dfu->GetDefaultUnitID()); } } IniSect.EndWrite(); }
void InfantryType::loadRules(INIFile* rules) { INISection* rulesSection = rules->getSection(ID); if (!rulesSection) return; TechnoType::loadRules(rules); rulesSection->readStringValue("OccupyWeapon", OccupyWeapon); rulesSection->readStringValue("EliteOccupyWeapon", EliteOccupyWeapon); WeaponType::Array.findOrAllocate(OccupyWeapon); WeaponType::Array.findOrAllocate(EliteOccupyWeapon); rulesSection->readBoolValue("Cyborg", Cyborg); rulesSection->readBoolValue("NotHuman", NotHuman); rulesSection->readBoolValue("Occupier", Occupier); rulesSection->readBoolValue("Civilian", Civilian); }
void House::parse(INIFile* file) { INISection* houseSection = file->getSection(ID); if (!houseSection) return; houseSection->readStringValue("Country", Country); houseSection->readIntValue("TechLevel", TechLevel); houseSection->readIntValue("Credits", Credits); houseSection->readIntValue("IQ", IQ); houseSection->readStringValue("Edge", Edge); houseSection->readBoolValue("PlayerControl", PlayerControl); houseSection->readStringValue("Color", Color); houseSection->readIntValue("PercentBuilt", PercentBuilt); houseSection->readIntValue("NodeCount", NodeCount); std::string allies_List; houseSection->readStringValue("Allies", allies_List); loadAllies(allies_List); loadNodes(houseSection); }
/** * Constructor, opens the file * * files beginning with ";" are ignored, tabs & spaces at beginning are ignored * @param filename the name of the inifile to open. */ INIFile::INIFile(const char* filename) { char line[1024]; char key[1024]; char value[1024]; // Uint32 i; char* str; VFile* inifile; string cursectionName; // INISection cursection; INISection newSection; IniEntry Entry; //int MAXLINELENGTH = 1024; //int MAXSTRINGLENGTH = 128; // Open the File inifile = VFSUtils::VFS_Open(filename); if (inifile == 0) { string s = "Unable to open "; s += filename; logger->error("%s\n", s.c_str()); throw runtime_error(s); } cursectionName = ""; // parse the inifile and write data to inidata while (inifile->getLine(line, 1024) != 0) { str = line; while ((*str) == ' ' || (*str) == '\t') { str++; } if ((*str) == ';') { continue; } if (sscanf(str, "[%[^]]]", key) == 1) { if (cursectionName != "") { //inidata[cursectionName] = cursection; Inidata[cursectionName] = newSection; // cursection.clear(); newSection.clear(); } strUpper(key); cursectionName = key; } else if (cursectionName != "" && sscanf(str, "%[^=]=%[^\r\n;]", key, value) == 2) { strUpper(key); if (strlen(key) > 0) strStripWhiteSpace(key); if (strlen(value) > 0) strStripWhiteSpace(key); str = value; while ((*str) == ' ' || (*str) == '\t') { str++; } //cursection[(string)key] = (string)str; Entry.first = (string) key; Entry.second = (string) str; newSection.push_back(Entry); // std::pair entry ((string)key, (string)str); // newSection.push_back (key, str); } } if (cursectionName != "") { //inidata[cursectionName] = cursection; Inidata[cursectionName] = newSection; // cursection.clear(); newSection.clear(); } #ifdef _DEBUG this->filename = filename; #endif // Close the file VFSUtils::VFS_Close(inifile); }
void BuildingType::loadRules(INIFile* rules) { INISection* rulesSection = rules->getSection(ID); if (!rulesSection) return; TechnoType::loadRules(rules); rulesSection->readStringValue("ToTile", ToTile, ToTile); rulesSection->readBoolValue("HasSpotlight", HasSpotlight, HasSpotlight); rulesSection->readStringValue("HalfDamageSmokeLocation1", HalfDamageSmokeLocation1_str, HalfDamageSmokeLocation1_str); LineSplitter split(HalfDamageSmokeLocation1_str); HalfDamageSmokeLocation1.x = split.pop_int(); HalfDamageSmokeLocation1.y = split.pop_int(); HalfDamageSmokeLocation1.z = split.pop_int(); rulesSection->readStringValue("HalfDamageSmokeLocation2", HalfDamageSmokeLocation2_str, HalfDamageSmokeLocation2_str); LineSplitter split2(HalfDamageSmokeLocation2_str); HalfDamageSmokeLocation2.x = split2.pop_int(); HalfDamageSmokeLocation2.y = split2.pop_int(); HalfDamageSmokeLocation2.z = split2.pop_int(); rulesSection->readBoolValue("WaterBound", WaterBound, WaterBound); rulesSection->readBoolValue("Powered", Powered, Powered); rulesSection->readIntValue("RefinerySmokeFrames", RefinerySmokeFrames, RefinerySmokeFrames); rulesSection->readBoolValue("Wall", Wall, Wall); VehicleType::Array.findOrAllocate(FreeUnit); rulesSection->readBoolValue("IsPlug", IsPlug); InfantryType::Array.findOrAllocate(SecretInfantry); VehicleType::Array.findOrAllocate(SecretUnit); BuildingType::Array.findOrAllocate(SecretBuilding); rulesSection->readBoolValue("Gate", Gate); rulesSection->readBoolValue("LaserFencePost", LaserFencePost); rulesSection->readBoolValue("LaserFence", LaserFence); rulesSection->readBoolValue("FirestormWall", FirestormWall); rulesSection->readStringValue("PowersUpBuilding", PowersUpBuilding); rulesSection->readIntValue("PowersUpToLevel", PowersUpToLevel); rulesSection->readIntValue("Power", Power); rulesSection->readIntValue("ExtraPower", ExtraPower); rulesSection->readStringValue("TurretAnim", TurretAnim); rulesSection->readStringValue("TurretAnimDamaged", TurretAnimDamaged); rulesSection->readStringValue("TurretAnimGarrisoned", TurretAnimGarrisoned); rulesSection->readIntValue("TurretAnimX", TurretAnimX); rulesSection->readIntValue("TurretAnimY", TurretAnimY); rulesSection->readIntValue("TurretAnimZAdjust", TurretAnimZAdjust); rulesSection->readIntValue("TurretAnimYSort", TurretAnimYSort); rulesSection->readBoolValue("TurretAnimPowered", TurretAnimPowered); rulesSection->readBoolValue("TurretAnimPoweredLight", TurretAnimPoweredLight); rulesSection->readBoolValue("TurretAnimPoweredEffect", TurretAnimPoweredEffect); rulesSection->readBoolValue("TurretAnimPoweredSpecial", TurretAnimPoweredSpecial); rulesSection->readBoolValue("TurretAnimIsVoxel", TurretAnimIsVoxel); rulesSection->readStringValue("VoxelBarrelFile", VoxelBarrelFile); rulesSection->readStringValue("VoxelBarrelOffsetToRotatePivotPoint", VoxelBarrelOffsetToRotatePivotPoint_str); LineSplitter split3(VoxelBarrelOffsetToRotatePivotPoint_str); VoxelBarrelOffsetToRotatePivotPoint.x = split3.pop_int(); VoxelBarrelOffsetToRotatePivotPoint.y = split3.pop_int(); VoxelBarrelOffsetToRotatePivotPoint.z = split3.pop_int(); rulesSection->readStringValue("VoxelBarrelOffsetToBuildingPivotPoint", VoxelBarrelOffsetToBuildingPivotPoint_str); LineSplitter split4(VoxelBarrelOffsetToBuildingPivotPoint_str); VoxelBarrelOffsetToBuildingPivotPoint.x = split4.pop_int(); VoxelBarrelOffsetToBuildingPivotPoint.y = split4.pop_int(); VoxelBarrelOffsetToBuildingPivotPoint.z = split4.pop_int(); rulesSection->readStringValue("VoxelBarrelOffsetToPitchPivotPoint", VoxelBarrelOffsetToPitchPivotPoint_str); LineSplitter split5(VoxelBarrelOffsetToPitchPivotPoint_str); VoxelBarrelOffsetToPitchPivotPoint.x = split5.pop_int(); VoxelBarrelOffsetToPitchPivotPoint.y = split5.pop_int(); VoxelBarrelOffsetToPitchPivotPoint.z = split5.pop_int(); rulesSection->readStringValue("VoxelBarrelOffsetToBarrelEnd", VoxelBarrelOffsetToBarrelEnd_str); LineSplitter split6(VoxelBarrelOffsetToBarrelEnd_str); VoxelBarrelOffsetToBarrelEnd.x = split6.pop_int(); VoxelBarrelOffsetToBarrelEnd.y = split6.pop_int(); VoxelBarrelOffsetToBarrelEnd.z = split6.pop_int(); rulesSection->readIntValue("Upgrades", Upgrades, Upgrades); }
void BuildingType::loadArt(INIFile* art) { INISection* artSection = art->getSection(ID); if (!artSection) return; TechnoType::loadArt(art); artSection->readIntValue("Height", Height); artSection->readIntValue("OccupyHeight", OccupyHeight); artSection->readStringValue("ToOverlay", ToOverlay); OverlayType::Array.findOrAllocate(ToOverlay); Foundation; //TODO: implement foundations artSection->readBoolValue("TerrainPalette", TerrainPalette); //Active Anim1 artSection->readStringValue("ActiveAnim", ActiveAnim); artSection->readStringValue("ActiveAnimDamaged", ActiveAnimDamaged); artSection->readIntValue("ActiveAnimX", ActiveAnimX); artSection->readIntValue("ActiveAnimY", ActiveAnimY); artSection->readIntValue("ActiveAnimZAdjust", ActiveAnimZAdjust); artSection->readIntValue("ActiveAnimYSort", ActiveAnimYSort); artSection->readBoolValue("ActiveAnimPowered", ActiveAnimPowered); artSection->readBoolValue("ActiveAnimPoweredLight", ActiveAnimPoweredLight); artSection->readBoolValue("ActiveAnimPoweredSpecial", ActiveAnimPoweredSpecial); //Active Anim2 artSection->readStringValue("ActiveAnimTwo", ActiveAnimTwo); artSection->readStringValue("ActiveAnimTwoDamaged", ActiveAnimTwoDamaged); artSection->readIntValue("ActiveAnimTwoX", ActiveAnimTwoX); artSection->readIntValue("ActiveAnimTwoY", ActiveAnimTwoY); artSection->readIntValue("ActiveAnimTwoZAdjust", ActiveAnimTwoZAdjust); artSection->readIntValue("ActiveAnimTwoYSort", ActiveAnimTwoYSort); artSection->readBoolValue("ActiveAnimTwoPowered", ActiveAnimTwoPowered); artSection->readBoolValue("ActiveAnimTwoPoweredLight", ActiveAnimTwoPoweredLight); artSection->readBoolValue("ActiveAnimTwoPoweredSpecial", ActiveAnimTwoPoweredSpecial); //Active Anim3 artSection->readStringValue("ActiveAnimThree", ActiveAnimThree); artSection->readStringValue("ActiveAnimThreeDamaged", ActiveAnimThreeDamaged); artSection->readIntValue("ActiveAnimThreeX", ActiveAnimThreeX); artSection->readIntValue("ActiveAnimThreeY", ActiveAnimThreeY); artSection->readIntValue("ActiveAnimThreeZAdjust", ActiveAnimThreeZAdjust); artSection->readIntValue("ActiveAnimThreeYSort", ActiveAnimThreeYSort); artSection->readBoolValue("ActiveAnimThreePowered", ActiveAnimThreePowered); artSection->readBoolValue("ActiveAnimThreePoweredLight", ActiveAnimThreePoweredLight); artSection->readBoolValue("ActiveAnimThreePoweredSpecial", ActiveAnimThreePoweredSpecial); //Active Anim4 artSection->readStringValue("ActiveAnimFour", ActiveAnimFour); artSection->readStringValue("ActiveAnimFourDamaged", ActiveAnimFourDamaged); artSection->readIntValue("ActiveAnimFourX", ActiveAnimFourX); artSection->readIntValue("ActiveAnimFourY", ActiveAnimFourY); artSection->readIntValue("ActiveAnimFourZAdjust", ActiveAnimFourZAdjust); artSection->readIntValue("ActiveAnimFourYSort", ActiveAnimFourYSort); artSection->readBoolValue("ActiveAnimFourPowered", ActiveAnimFourPowered); artSection->readBoolValue("ActiveAnimFourPoweredLight", ActiveAnimFourPoweredLight); artSection->readBoolValue("ActiveAnimFourPoweredSpecial", ActiveAnimFourPoweredSpecial); //Special Anims 1-4 //TODO: Rework in class? //Concept is simple: sizes are all the same and bound to 'Upgrades' key //PowerUpAnims; //PowerUpDamagedAnims; //PowerUpLocXXs; //PowerUpLocYYs; //PowerUpLocZZs; //PowerUpXYSorts; artSection->readStringValue("Rubble", Rubble); artSection->readStringValue("BibShape", BibShape); artSection->readStringValue("Image", ArtImage); }
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))); } */ }
bool INIFile::LoadBuffer(const char * buf, unsigned size) { MINIINI_ASSERT(buf, "NULL pointer was passed as buffer to load from to" "INIFile::LoadBuffer()"); MINIINI_ASSERT(!IsValid(), "LoadBuffer() was called on an INIFile that is " "already loaded"); //Allocating memory for ini sections' strings in 16 blocks- //that results in a little speed overhead but potential memory //overhead of the allocator is decreased to a bit more than //1/16 of file size. Alloc = new Allocator(size, 16); //capacity of temporary buffer of pointers to sections ui tempsectionscap = 16; INISection::InitTempData(); //temporary buffer of pointers to sections INISection * * tempsections = new INISection * [tempsectionscap]; //ptr to the current character in buffer const c * currentchar = buf; //allocated capacity of headername ui headercap = 64; //buffer to load section header name to. c * headername = new c [headercap]; //number of chars in headername ui headersize; //Loading the default INI section INISection * newsection = new INISection(); newsection->Init("[DEFAULT]", ¤tchar, Alloc); Insert(tempsections, Length, newsection); ++Length; //Iterating through lines in buffer, reading sections found while(*currentchar != '\0') { //Header() leaves currentchar at start of next line headersize = Header(currentchar, headername, headercap); //header found if(headersize) { //if temp section ptrs buffer runs out of space, reallocate it if(Length + 1 > tempsectionscap) { MINIINI_REALLOCATE(tempsections, tempsectionscap, Length, INISection *); } //Try to load new section newsection = new INISection(); newsection->Init(headername, ¤tchar, Alloc); //Insert new section if(Insert(tempsections, Length, newsection)) { ++Length; } else { delete newsection; } } } delete [] headername; //Length is at least 1 due to the default section if(Length == 1) { MINIINI_WARNING("Empty INI file/buffer."); } //copy pointers from tempsections to Sections and delete tempsections Sections = new INISection * [Length]; memcpy(Sections, tempsections, Length * sizeof(INISection *)); delete [] tempsections; INISection::DestroyTempData(); //Remove any unused memory blocks from the allocator. Alloc->Trim(); return true; }
void TechnoType::loadRules(INIFile* rules) { ObjectType::loadRules(rules); INISection* rulesSection = rules->getSection(ID); loadWeaponTypes(rulesSection); rulesSection->readStringValue("Dock", Dock); rulesSection->readStringValue("DeploysInto", DeploysInto); rulesSection->readStringValue("UndeploysInto", UndeploysInto); rulesSection->readStringValue("PowersUnit", PowersUnit); rulesSection->readStringValue("Explosion", Explosion); rulesSection->readStringValue("DestroyAnim", DestroyAnim); rulesSection->readStringValue("AirstrikeTeamType", AirstrikeTeamType); rulesSection->readStringValue("EliteAirstrikeTeamType", EliteAirstrikeTeamType); rulesSection->readStringValue("UnloadingClass", UnloadingClass); rulesSection->readStringValue("DeployingAnim", DeployingAnim); rulesSection->readStringValue("Enslaves", Enslaves); rulesSection->readStringValue("Spawns", Spawns); allocateList(BuildingType::Array, Dock); BuildingType::Array.findOrAllocate(DeploysInto); VehicleType::Array.findOrAllocate(UndeploysInto); VehicleType::Array.findOrAllocate(PowersUnit); allocateList(Animation::Array, Explosion); allocateList(Animation::Array, DestroyAnim); AircraftType::Array.findOrAllocate(AirstrikeTeamType); AircraftType::Array.findOrAllocate(EliteAirstrikeTeamType); VehicleType::Array.findOrAllocate(UnloadingClass); Animation::Array.findOrAllocate(DeployingAnim); InfantryType::Array.findOrAllocate(Enslaves); AircraftType::Array.findOrAllocate(Spawns); rulesSection->readBoolValue("Turret", Turret); rulesSection->readBoolValue("IsTrain", IsTrain); rulesSection->readIntValue("Passengers", Passengers); rulesSection->readFloatValue("Size", Size); rulesSection->readFloatValue("SizeLimit", SizeLimit); rulesSection->readIntValue("TechLevel", TechLevel); rulesSection->readIntValue("AIBasePlanningSide", AIBasePlanningSide); rulesSection->readBoolValue("NoShadow", NoShadow); rulesSection->readIntValue("ZFudgeCliff", ZFudgeCliff); rulesSection->readIntValue("ZFudgeColumn", ZFudgeColumn); rulesSection->readIntValue("ZFudgeTunnel", ZFudgeTunnel); rulesSection->readIntValue("ZFudgeBridge", ZFudgeBridge); }
/** * Constructor, opens the file * * @param filename the name of the inifile to open. */ INIFile::INIFile(const string& filename) { char line[1024]; char key[1024]; char value[1024]; char* str; VFile* inifile; string cursectionName; // INISection cursection; INISection newSection; IniEntry Entry; //int MAXLINELENGTH = 1024; //int MAXSTRINGLENGTH = 128; // Open the File inifile = VFSUtils::VFS_Open(filename.c_str()); if (inifile == 0) { string s = "Unable to open "; s += filename; Logger::getInstance()->Error(s); throw runtime_error(s); } cursectionName = ""; // parse the inifile and write data to inidata while (inifile->getLine(line, 1024) != 0) { str = line; while ((*str) == ' ' || (*str) == '\t') { str++; } if ((*str) == ';') { continue; } if (sscanf(str, "[%[^]]]", key) == 1) { if (cursectionName != "") { //inidata[cursectionName] = cursection; Inidata[cursectionName] = newSection; // cursection.clear(); newSection.clear(); } for (unsigned int i = 0; key[i] != '\0'; i++) { key[i] = toupper(key[i]); } cursectionName = key; } else if (cursectionName != "" && sscanf(str, "%[^=]=%[^\r\n;]", key, value) == 2) { for (unsigned int i = 0; key[i] != '\0'; i++) { key[i] = toupper(key[i]); } if (strlen(key) > 0) { str = key + strlen(key) - 1; while ((*str) == ' ' || (*str) == '\t') { (*str) = '\0'; if (str == key) { break; } str--; } } if (strlen(value) > 0) { str = value + strlen(value) - 1; while ((*str) == ' ' || (*str) == '\t') { (*str) = '\0'; if (str == value) { break; } str--; } } str = value; while ((*str) == ' ' || (*str) == '\t') { str++; } //cursection[(string)key] = (string)str; Entry.first = (string) key; Entry.second = (string) str; //newSection.push_back(Entry); // std::pair entry ((string)key, (string)str); // newSection.push_back (key, str); newSection[key] = str; } } if (cursectionName != "") { //inidata[cursectionName] = cursection; Inidata[cursectionName] = newSection; // cursection.clear(); newSection.clear(); } // Close the file VFSUtils::VFS_Close(inifile); }
/** Constructor, opens the file * @param the name of the inifile to open. */ INIFile::INIFile(const char* filename) { char line[1024]; char key[1024]; char value[1024]; Uint32 i; char* str; VFile* inifile; string cursectionName; INISection cursection; inifile = VFS_Open(filename); if (inifile == NULL) { string s = "Unable to open "; s += filename; throw runtime_error(s); } cursectionName = ""; // parse the inifile and write data to inidata while (inifile->getLine(line, 1024) != NULL) { str = line; while ((*str) == ' ' || (*str) == '\t') { str++; } if ((*str) == ';') { continue; } if (sscanf(str, "[%[^]]]", key) == 1) { if (cursectionName != "") { inidata[cursectionName] = cursection; cursection.clear(); } for (i = 0; key[i] != '\0'; i++) { key[i] = toupper(key[i]); } cursectionName = key; } else if (cursectionName != "" && sscanf(str, "%[^=]=%[^\r\n;]", key, value) == 2) { for (i = 0; key[i] != '\0'; i++) { key[i] = toupper(key[i]); } if (strlen(key) > 0) { str = key+strlen(key)-1; while ((*str) == ' ' || (*str) == '\t') { (*str) = '\0'; if (str == key) { break; } str--; } } if (strlen(value) > 0) { str = value+strlen(value)-1; while ((*str) == ' ' || (*str) == '\t') { (*str) = '\0'; if (str == value) { break; } str--; } } str = value; while ((*str) == ' ' || (*str) == '\t') { str++; } cursection[(string)key] = (string)str; } } if (cursectionName != "") { inidata[cursectionName] = cursection; cursection.clear(); } VFS_Close(inifile); }
//Loads the content from a INI file void MeasurementUnitsContainer::DeSerializeFromINI(INISection & IniSect) { IniSect.BeginRead(); //Clear the current container measureUnits.clear(); //Temp buffer TCHAR sectionName[1024]={0}; std::vector<serUnit> readElements; for(unsigned int count=0;;count++) { serUnit su; su.InConversion=false; su.Invalid=false; //Check if its a placeholder for a default unit _sntprintf(sectionName,ARRSIZE(sectionName)-1,_T("MUItem%lu_DefaultUnit"),count); su.DefaultUnit=IniSect.GetKey(sectionName,0); if(su.DefaultUnit==0) //It's not a placeholder { //Base unit _sntprintf(sectionName,ARRSIZE(sectionName)-1,_T("MUItem%lu_BaseUnit"),count); if(!IniSect.KeyExists(sectionName)) break; su.BaseUnit=IniSect.GetKey(sectionName,0); //Name _sntprintf(sectionName,ARRSIZE(sectionName)-1,_T("MUItem%lu_Name"),count); su.Name=IniSect.GetKey(sectionName,_T("")); if(su.Name.size()==0) break; //Coefficient _sntprintf(sectionName,ARRSIZE(sectionName)-1,_T("MUItem%lu_Coefficient"),count); su.Coefficient=IniSect.GetKey<double>(sectionName,0.0); if(su.Coefficient==0) break; //Symbol _sntprintf(sectionName,ARRSIZE(sectionName)-1,_T("MUItem%lu_Symbol"),count); su.Symbol=IniSect.GetKey(sectionName,_T("")); if(su.Symbol.size()==0) break; } //Add the element readElements.push_back(su); } IniSect.EndRead(); //If we have no elements just reset the container if(readElements.size()==0) { init(); return; } //Now we have loaded all the items; let's check and convert them //First check: items that point to nonexistent bases, check for missing default units std::vector<serUnit>::iterator it; bool defaultUnitsPresent[MeasurementUnit::maxvalue-MeasurementUnit::minvalue+1]={false}; for(it=readElements.begin();it<readElements.end();it++) { if(it->DefaultUnit==0) { //Normal unit int bu=it->BaseUnit; if(bu<0 || bu>=(int)readElements.size()) removeSU((unsigned long)(it-readElements.begin()),readElements); } else { //Placeholder for default unit if(it->DefaultUnit<MeasurementUnit::minvalue || it->DefaultUnit>MeasurementUnit::maxvalue) removeSU((unsigned long)(it-readElements.begin()),readElements); else defaultUnitsPresent[it->DefaultUnit-MeasurementUnit::minvalue]=true; } } //Add the elements to the container measureUnits.resize(readElements.size(),NULL); for(unsigned int i=0;i<readElements.size();i++) { if(measureUnits[i]==NULL) measureUnits[i]=convertSU(readElements[i],readElements,measureUnits); } //Remove the eventually NULL items (convertSU returns NULL for invalid items) measureUnits.erase(remove(measureUnits.begin(),measureUnits.end(),(MeasurementUnit*)NULL),measureUnits.end()); //Add the eventually missing default units for(unsigned int i=0;i<ARRSIZE(defaultUnitsPresent);i++) { if(!defaultUnitsPresent[i]) measureUnits.push_back(&MeasurementUnit::GetDefaultUnit(MeasurementUnit::minvalue+i)); } }