ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) { enum OptionType { OPT_HELP = 1, OPT_DEBUG, OPT_DATADIR, OPT_LOGLEVEL, OPT_LANGUAGE, OPT_LANGDIR, OPT_VBO }; option options[] = { { "help", no_argument, nullptr, OPT_HELP }, { "debug", no_argument, nullptr, OPT_DEBUG }, { "datadir", required_argument, nullptr, OPT_DATADIR }, { "loglevel", required_argument, nullptr, OPT_LOGLEVEL }, { "language", required_argument, nullptr, OPT_LANGUAGE }, { "langdir", required_argument, nullptr, OPT_LANGDIR }, { "vbo", required_argument, nullptr, OPT_VBO } }; opterr = 0; int c = 0; int index = -1; while ((c = getopt_long_only(argc, argv, "", options, &index)) != -1) { if (c == '?') { if (optopt == 0) GetLogger()->Error("Invalid argument: %s\n", argv[optind-1]); else GetLogger()->Error("Expected argument for option: %s\n", argv[optind-1]); m_exitCode = 1; return PARSE_ARGS_FAIL; } index = -1; switch (c) { case OPT_HELP: { GetLogger()->Message("\n"); GetLogger()->Message("Colobot %s (%s)\n", COLOBOT_CODENAME, COLOBOT_VERSION); GetLogger()->Message("\n"); GetLogger()->Message("List of available options:\n"); GetLogger()->Message(" -help this help\n"); GetLogger()->Message(" -debug enable debug mode (more info printed in logs)\n"); GetLogger()->Message(" -datadir path set custom data directory path\n"); GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n"); GetLogger()->Message(" -language lang set language (one of: en, de, fr, pl)\n"); GetLogger()->Message(" -langdir path set custom language directory path\n"); GetLogger()->Message(" -vbo mode set OpenGL VBO mode (one of: auto, enable, disable)\n"); return PARSE_ARGS_HELP; } case OPT_DEBUG: { SetDebugMode(true); break; } case OPT_DATADIR: { m_dataPath = optarg; GetLogger()->Info("Using custom data dir: '%s'\n", m_dataPath.c_str()); break; } case OPT_LOGLEVEL: { LogLevel logLevel; if (! CLogger::ParseLogLevel(optarg, logLevel)) { GetLogger()->Error("Invalid log level: \"%s\"\n", optarg); return PARSE_ARGS_FAIL; } GetLogger()->Message("[*****] Log level changed to %s\n", optarg); GetLogger()->SetLogLevel(logLevel); break; } case OPT_LANGUAGE: { Language language; if (! ParseLanguage(optarg, language)) { GetLogger()->Error("Invalid language: \"%s\"\n", optarg); return PARSE_ARGS_FAIL; } GetLogger()->Info("Using language %s\n", optarg); m_language = language; break; } case OPT_LANGDIR: { m_langPath = optarg; GetLogger()->Info("Using custom language dir: '%s'\n", m_langPath.c_str()); break; } case OPT_VBO: { std::string vbo; vbo = optarg; if (vbo == "auto") m_deviceConfig.vboMode = Gfx::VBO_MODE_AUTO; else if (vbo == "enable") m_deviceConfig.vboMode = Gfx::VBO_MODE_ENABLE; else if (vbo == "disable") m_deviceConfig.vboMode = Gfx::VBO_MODE_DISABLE; else { GetLogger()->Error("Invalid vbo mode: \"%s\"\n", optarg); return PARSE_ARGS_FAIL; } break; } default: assert(false); // should never get here } } return PARSE_ARGS_OK; }
void CSettings::LoadSettings() { CApplication* app = CApplication::GetInstancePointer(); CRobotMain* main = CRobotMain::GetInstancePointer(); Gfx::CEngine* engine = Gfx::CEngine::GetInstancePointer(); Gfx::CCamera* camera = main->GetCamera(); CSoundInterface* sound = app->GetSound(); int iValue = 0; float fValue = 0.0f; bool bValue = false; std::string sValue = ""; GetConfigFile().GetBoolProperty("Setup", "Tooltips", m_tooltips); GetConfigFile().GetBoolProperty("Setup", "InterfaceGlint", m_interfaceGlint); GetConfigFile().GetBoolProperty("Setup", "InterfaceRain", m_interfaceRain); GetConfigFile().GetBoolProperty("Setup", "Soluce4", m_soluce4); GetConfigFile().GetBoolProperty("Setup", "Movies", m_movies); GetConfigFile().GetBoolProperty("Setup", "FocusLostPause", m_focusLostPause); if (GetConfigFile().GetBoolProperty("Setup", "OldCameraScroll", bValue)) camera->SetOldCameraScroll(bValue); if (GetConfigFile().GetBoolProperty("Setup", "CameraInvertX", bValue)) camera->SetCameraInvertX(bValue); if (GetConfigFile().GetBoolProperty("Setup", "CameraInvertY", bValue)) camera->SetCameraInvertY(bValue); if (GetConfigFile().GetBoolProperty("Setup", "InterfaceEffect", bValue)) camera->SetEffect(bValue); if (GetConfigFile().GetBoolProperty("Setup", "Blood", bValue)) camera->SetBlood(bValue); if (GetConfigFile().GetBoolProperty("Setup", "Autosave", bValue)) main->SetAutosave(bValue); if (GetConfigFile().GetIntProperty("Setup", "AutosaveInterval", iValue)) main->SetAutosaveInterval(iValue); if (GetConfigFile().GetIntProperty("Setup", "AutosaveSlots", iValue)) main->SetAutosaveSlots(iValue); if (GetConfigFile().GetBoolProperty("Setup", "ObjectDirty", bValue)) engine->SetDirty(bValue); if (GetConfigFile().GetBoolProperty("Setup", "FogMode", bValue)) { engine->SetFog(bValue); camera->SetOverBaseColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)); // TODO: color ok? } if (GetConfigFile().GetBoolProperty("Setup", "LightMode", bValue)) engine->SetLightMode(bValue); if (GetConfigFile().GetIntProperty("Setup", "JoystickIndex", iValue)) { if (iValue >= 0) { auto joysticks = app->GetJoystickList(); for(const auto& joystick : joysticks) { if (joystick.index == iValue) { app->ChangeJoystick(joystick); app->SetJoystickEnabled(true); } } } else { app->SetJoystickEnabled(false); } } if (GetConfigFile().GetFloatProperty("Setup", "ParticleDensity", fValue)) engine->SetParticleDensity(fValue); if (GetConfigFile().GetFloatProperty("Setup", "ClippingDistance", fValue)) engine->SetClippingDistance(fValue); if (GetConfigFile().GetIntProperty("Setup", "AudioVolume", iValue)) sound->SetAudioVolume(iValue); if (GetConfigFile().GetIntProperty("Setup", "MusicVolume", iValue)) sound->SetMusicVolume(iValue); if (GetConfigFile().GetBoolProperty("Setup", "EditIndentMode", bValue)) engine->SetEditIndentMode(bValue); if (GetConfigFile().GetIntProperty("Setup", "EditIndentValue", iValue)) engine->SetEditIndentValue(iValue); if (GetConfigFile().GetIntProperty("Setup", "MipmapLevel", iValue)) engine->SetTextureMipmapLevel(iValue); if (GetConfigFile().GetIntProperty("Setup", "Anisotropy", iValue)) engine->SetTextureAnisotropyLevel(iValue); if (GetConfigFile().GetFloatProperty("Setup", "ShadowColor", fValue)) engine->SetShadowColor(fValue); if (GetConfigFile().GetFloatProperty("Setup", "ShadowRange", fValue)) engine->SetShadowRange(fValue); if (GetConfigFile().GetIntProperty("Setup", "MSAA", iValue)) engine->SetMultiSample(iValue); if (GetConfigFile().GetIntProperty("Setup", "FilterMode", iValue)) engine->SetTextureFilterMode(static_cast<Gfx::TexFilter>(iValue)); if (GetConfigFile().GetBoolProperty("Setup", "ShadowMapping", bValue)) engine->SetShadowMapping(bValue); if (GetConfigFile().GetBoolProperty("Setup", "ShadowMappingQuality", bValue)) engine->SetShadowMappingQuality(bValue); if (GetConfigFile().GetIntProperty("Setup", "ShadowMappingResolution", iValue)) { if (iValue == 0) { engine->SetShadowMappingOffscreen(false); } else { engine->SetShadowMappingOffscreen(true); engine->SetShadowMappingOffscreenResolution(iValue); } } if (GetConfigFile().GetBoolProperty("Experimental", "TerrainShadows", bValue)) engine->SetTerrainShadows(bValue); CInput::GetInstancePointer()->LoadKeyBindings(); GetConfigFile().GetFloatProperty("Edit", "FontSize", m_fontSize); GetConfigFile().GetFloatProperty("Edit", "WindowPosX", m_windowPos.x); GetConfigFile().GetFloatProperty("Edit", "WindowPosY", m_windowPos.y); GetConfigFile().GetFloatProperty("Edit", "WindowDimX", m_windowDim.x); GetConfigFile().GetFloatProperty("Edit", "WindowDimY", m_windowDim.y); GetConfigFile().GetBoolProperty ("Edit", "IOPublic", m_IOPublic); GetConfigFile().GetFloatProperty("Edit", "IOPosX", m_IOPos.x); GetConfigFile().GetFloatProperty("Edit", "IOPosY", m_IOPos.y); GetConfigFile().GetFloatProperty("Edit", "IODimX", m_IODim.x); GetConfigFile().GetFloatProperty("Edit", "IODimY", m_IODim.y); m_language = LANGUAGE_ENV; if (GetConfigFile().GetStringProperty("Language", "Lang", sValue)) { if (!sValue.empty() && !ParseLanguage(sValue, m_language)) { GetLogger()->Error("Failed to parse language '%s' from config file. Default language will be used.\n", sValue.c_str()); } } app->SetLanguage(m_language); }
int ParseInputFile() { char pszKeyWord[MAX]; // input token char pszParam[MAX]; // parameter for keyword CODEPAGE CP; // codepage structure LANGUAGE Lang; // language structure LANG_EXCEPT LangExcept; // language exception structure LOCALE_HEADER LocHdr; // header locale structure LOCALE_STATIC LocStat; // static length locale structure LOCALE_VARIABLE LocVar; // variable length locale structure UNICODE Unic; // unicode structure CTYPES CTypes; // ctypes structure SORTKEY Sortkey; // sortkey structure - sorting SORT_TABLES SortTbls; // sort tables structure - sorting IDEOGRAPH_EXCEPT IdeographExcept; // ideograph exception structure - sorting while (fscanf(pInputFile, "%s", pszKeyWord) == 1) { if (_strcmpi(pszKeyWord, "CODEPAGE") == 0) { if (Verbose) printf("\n\nFound CODEPAGE keyword.\n"); // // Initialize CodePage structure. // memset(&CP, 0, sizeof(CODEPAGE)); memset(pszParam, 0, MAX * sizeof(char)); CP.pszName = pszParam; // // Get CODEPAGE parameter string. // if (GetKeyParam(pszParam)) { return (1); } // // Get the valid keywords for CODEPAGE. // if (ParseCodePage(&CP, pszKeyWord)) { return (1); } // // Write the CODEPAGE tables to an output file. // if (WriteCodePage(&CP)) { return (1); } } else if (_strcmpi(pszKeyWord, "LANGUAGE") == 0) { if (Verbose) printf("\n\nFound LANGUAGE keyword.\n"); // // Initialize Language structure. // memset(&Lang, 0, sizeof(LANGUAGE)); // // Get LANGUAGE parameter string. // if (GetKeyParam(pszParam)) { return (1); } // // Get the valid keywords for LANGUAGE. // if (ParseLanguage(&Lang, pszKeyWord)) { return (1); } // // Write the LANGUAGE tables to an output file. // if (WriteLanguage(&Lang)) { return (1); } } else if (_strcmpi(pszKeyWord, "LANGUAGE_EXCEPTION") == 0) { if (Verbose) printf("\n\nFound LANGUAGE_EXCEPTION keyword.\n"); // // Initialize Language structure. // memset(&LangExcept, 0, sizeof(LANG_EXCEPT)); // // Get the valid keywords for LANGUAGE_EXCEPTION. // if (ParseLangException(&LangExcept, pszKeyWord)) { return (1); } // // Write the LANGUAGE_EXCEPTION tables to an output file. // if (WriteLangException(&LangExcept)) { return (1); } } else if (_strcmpi(pszKeyWord, "LOCALE") == 0) { if (Verbose) printf("\n\nFound LOCALE keyword.\n"); // // Get the valid keywords for LOCALE. // Write the LOCALE information to an output file. // if (ParseWriteLocale( &LocHdr, &LocStat, &LocVar, pszKeyWord )) { return (1); } } else if (_strcmpi(pszKeyWord, "UNICODE") == 0) { if (Verbose) printf("\n\nFound UNICODE keyword.\n"); // // Initialize Unicode structure. // memset(&Unic, 0, sizeof(UNICODE)); // // Get the valid keywords for UNICODE. // if (ParseUnicode(&Unic, pszKeyWord)) { return (1); } // // Write the UNICODE tables to an output file. // if (WriteUnicode(&Unic)) { return (1); } } else if (_strcmpi(pszKeyWord, "CTYPES") == 0) { if (Verbose) printf("\n\nFound CTYPES keyword.\n"); // // Initialize CTypes structure. // memset(&CTypes, 0, sizeof(CTYPES)); // // Get the valid keywords for CTYPES. // if (ParseCTypes(&CTypes)) { return (1); } // // Write the CTYPES tables to different output files. // if (WriteCTypes(&CTypes)) { return (1); } } else if (_strcmpi(pszKeyWord, "SORTKEY") == 0) { if (Verbose) printf("\n\nFound SORTKEY keyword.\n"); // // Initialize Sortkey structure. // memset(&Sortkey, 0, sizeof(SORTKEY)); // // Get the valid keywords for SORTKEY. // if (ParseSortkey(&Sortkey, pszKeyWord)) { return (1); } // // Write the SORTKEY tables to an output file. // if (WriteSortkey(&Sortkey)) { return (1); } } else if (_strcmpi(pszKeyWord, "SORTTABLES") == 0) { if (Verbose) printf("\n\nFound SORTTABLES keyword.\n"); // // Initialize Sort Tables structure. // memset(&SortTbls, 0, sizeof(SORT_TABLES)); // // Get the valid keywords for SORTTABLES. // if (ParseSortTables(&SortTbls, pszKeyWord)) { return (1); } // // Write the Sort Tables to an output file. // if (WriteSortTables(&SortTbls)) { return (1); } } else if (_strcmpi(pszKeyWord, "IDEOGRAPH_EXCEPTION") == 0) { if (Verbose) printf("\n\nFound IDEOGRAPH_EXCEPTION keyword.\n"); // // Initialize Ideograph Exception structure. // memset(&IdeographExcept, 0, sizeof(IDEOGRAPH_EXCEPT)); // // Get the valid keywords for IDEOGRAPH_EXCEPTION. // if (ParseIdeographExceptions(&IdeographExcept)) { return (1); } // // Write the Ideograph Exceptions to the given output file. // if (WriteIdeographExceptions(&IdeographExcept)) { return (1); } } else { printf("Parse Error: Invalid Instruction '%s'.\n", pszKeyWord); return (1); } } // // Return success. // return (0); }