Exemplo n.º 1
0
void LootState::init(const std::string& cmdLineGame) {
    // Do some preliminary locale / UTF-8 support setup here, in case the settings file reading requires it.
    //Boost.Locale initialisation: Specify location of language dictionaries.
  boost::locale::generator gen;
  gen.add_messages_path(LootPaths::getL10nPath().string());
  gen.add_messages_domain("loot");

  //Boost.Locale initialisation: Generate and imbue locales.
  locale::global(gen(Language(LanguageCode::english).GetLocale() + ".UTF-8"));
  boost::filesystem::path::imbue(locale());

  // Check if the LOOT local app data folder exists, and create it if not.
  if (!fs::exists(LootPaths::getLootDataPath())) {
    BOOST_LOG_TRIVIAL(info) << "Local app data LOOT folder doesn't exist, creating it.";
    try {
      fs::create_directory(LootPaths::getLootDataPath());
    } catch (exception& e) {
      initErrors_.push_back((format(translate("Error: Could not create LOOT settings file. %1%")) % e.what()).str());
    }
  }
  if (fs::exists(LootPaths::getSettingsPath())) {
    try {
      LootSettings::load(LootPaths::getSettingsPath());
    } catch (exception& e) {
      initErrors_.push_back((format(translate("Error: Settings parsing failed. %1%")) % e.what()).str());
    }
  }

  //Set up logging.
  boost::log::add_file_log(
    boost::log::keywords::file_name = LootPaths::getLogPath().string().c_str(),
    boost::log::keywords::auto_flush = true,
    boost::log::keywords::format = (
      boost::log::expressions::stream
      << "[" << boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "%H:%M:%S") << "]"
      << " [" << boost::log::trivial::severity << "]: "
      << boost::log::expressions::smessage
      )
  );
  boost::log::add_common_attributes();
  boost::log::core::get()->set_logging_enabled(isDebugLoggingEnabled());

  // Log some useful info.
  BOOST_LOG_TRIVIAL(info) << "LOOT Version: " << LootVersion::major << "." << LootVersion::minor << "." << LootVersion::patch;
  BOOST_LOG_TRIVIAL(info) << "LOOT Build Revision: " << LootVersion::revision;
#ifdef _WIN32
        // Check if LOOT is being run through Mod Organiser.
  bool runFromMO = GetModuleHandle(ToWinWide("hook.dll").c_str()) != NULL;
  if (runFromMO) {
    BOOST_LOG_TRIVIAL(info) << "LOOT is being run through Mod Organiser.";
  }
#endif

        // The CEF debug log is appended to, not overwritten, so it gets really long.
        // Delete the current CEF debug log.
  fs::remove(LootPaths::getLootDataPath() / "CEFDebugLog.txt");

  // Now that settings have been loaded, set the locale again to handle translations.
  if (getLanguage().GetCode() != LanguageCode::english) {
    BOOST_LOG_TRIVIAL(debug) << "Initialising language settings.";
    Language lang(getLanguage());
    BOOST_LOG_TRIVIAL(debug) << "Selected language: " << lang.GetName();

    //Boost.Locale initialisation: Generate and imbue locales.
    locale::global(gen(lang.GetLocale() + ".UTF-8"));
    boost::filesystem::path::imbue(locale());
  }

  // Detect games & select startup game
  //-----------------------------------

  //Detect installed games.
  BOOST_LOG_TRIVIAL(debug) << "Detecting installed games.";
  games_ = toGames(getGameSettings());

  try {
    BOOST_LOG_TRIVIAL(debug) << "Selecting game.";
    selectGame(cmdLineGame);
    BOOST_LOG_TRIVIAL(debug) << "Initialising game-specific settings.";
    currentGame_->Init(true);
    // Update game path in settings object.
    storeGameSettings(toGameSettings(games_));
  } catch (GameDetectionError& e) {
    initErrors_.push_back(e.what());
  } catch (std::exception& e) {
    BOOST_LOG_TRIVIAL(error) << "Game-specific settings could not be initialised. " << e.what();
    initErrors_.push_back((format(translate("Error: Game-specific settings could not be initialised. %1%")) % e.what()).str());
  }
  BOOST_LOG_TRIVIAL(debug) << "Game selected is " << currentGame_->Name();
}
Exemplo n.º 2
0
    void LootState::Init(const std::string& cmdLineGame) {
        // Do some preliminary locale / UTF-8 support setup here, in case the settings file reading requires it.
        //Boost.Locale initialisation: Specify location of language dictionaries.
        boost::locale::generator gen;
        gen.add_messages_path(g_path_l10n.string());
        gen.add_messages_domain("loot");

        //Boost.Locale initialisation: Generate and imbue locales.
        locale::global(gen(Language(Language::english).Locale() + ".UTF-8"));
        boost::filesystem::path::imbue(locale());

        // Check if the LOOT local app data folder exists, and create it if not.
        if (!fs::exists(g_path_local)) {
            BOOST_LOG_TRIVIAL(info) << "Local app data LOOT folder doesn't exist, creating it.";
            try {
                fs::create_directory(g_path_local);
            }
            catch (exception& e) {
                _initErrors.push_back((format(translate("Error: Could not create LOOT settings file. %1%")) % e.what()).str());
            }
        }
        if (fs::exists(g_path_settings)) {
            try {
                loot::ifstream in(g_path_settings);
                _settings = YAML::Load(in);
                in.close();
            }
            catch (exception& e) {
                _initErrors.push_back((format(translate("Error: Settings parsing failed. %1%")) % e.what()).str());
            }
        }
        // Check if the settings are valid (or if they don't exist).
        if (!AreSettingsValid()) {
            _settings = GetDefaultSettings();
        }

        //Set up logging.
        boost::log::add_file_log(
            boost::log::keywords::file_name = g_path_log.string().c_str(),
            boost::log::keywords::auto_flush = true,
            boost::log::keywords::format = (
            boost::log::expressions::stream
            << "[" << boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "%H:%M:%S") << "]"
            << " [" << boost::log::trivial::severity << "]: "
            << boost::log::expressions::smessage
            )
            );
        boost::log::add_common_attributes();
        bool enableDebugLogging = false;
        if (_settings["enableDebugLogging"]) {
            enableDebugLogging = _settings["enableDebugLogging"].as<bool>();
        }
        if (enableDebugLogging)
            boost::log::core::get()->set_logging_enabled(true);
        else
            boost::log::core::get()->set_logging_enabled(false);

        // Log some useful info.
        BOOST_LOG_TRIVIAL(info) << "LOOT Version: " << g_version_major << "." << g_version_minor << "." << g_version_patch;
        BOOST_LOG_TRIVIAL(info) << "LOOT Build Revision: " << g_build_revision;
#ifdef _WIN32
        // Check if LOOT is being run through Mod Organiser.
        bool runFromMO = GetModuleHandle(ToWinWide("hook.dll").c_str()) != NULL;
        if (runFromMO) {
            BOOST_LOG_TRIVIAL(info) << "LOOT is being run through Mod Organiser.";
        }
#endif

        // The CEF debug log is appended to, not overwritten, so it gets really long.
        // Delete the current CEF debug log.
        fs::remove(g_path_local / "CEFDebugLog.txt");

        // Now that settings have been loaded, set the locale again to handle translations.
        if (_settings["language"] && _settings["language"].as<string>() != Language(Language::english).Locale()) {
            BOOST_LOG_TRIVIAL(debug) << "Initialising language settings.";
            loot::Language lang(_settings["language"].as<string>());
            BOOST_LOG_TRIVIAL(debug) << "Selected language: " << lang.Name();

            //Boost.Locale initialisation: Generate and imbue locales.
            locale::global(gen(lang.Locale() + ".UTF-8"));
            boost::filesystem::path::imbue(locale());
        }

        // Detect games & select startup game
        //-----------------------------------

        //Detect installed games.
        BOOST_LOG_TRIVIAL(debug) << "Detecting installed games.";
        try {
            _games = ToGames(GetGameSettings(_settings));
        }
        catch (YAML::Exception& e) {
            BOOST_LOG_TRIVIAL(error) << "Games' settings parsing failed. " << e.what();
            _initErrors.push_back((format(translate("Error: Games' settings parsing failed. %1%")) % e.what()).str());
            // Now redo, but with no games settings, so only the hardcoded defaults get loaded. It means the user can
            // at least still then edit them.
            _games = ToGames(GetGameSettings(YAML::Node()));
        }

        try {
            BOOST_LOG_TRIVIAL(debug) << "Selecting game.";
            SelectGame(cmdLineGame);
            BOOST_LOG_TRIVIAL(debug) << "Initialising game-specific settings.";
            _currentGame->Init(true);
            // Update game path in settings object.
            _settings["games"] = ToGameSettings(_games);
        }
        catch (loot::error &e) {
            if (e.code() == loot::error::no_game_detected) {
                _initErrors.push_back(e.what());
            }
            else {
                BOOST_LOG_TRIVIAL(error) << "Game-specific settings could not be initialised. " << e.what();
                _initErrors.push_back((format(translate("Error: Game-specific settings could not be initialised. %1%")) % e.what()).str());
            }
        }
        BOOST_LOG_TRIVIAL(debug) << "Game selected is " << _currentGame->Name();
    }