diff --git a/src/gui/app.cpp b/src/gui/app.cpp index f19a5959..2a78b844 100644 --- a/src/gui/app.cpp +++ b/src/gui/app.cpp @@ -239,6 +239,9 @@ namespace loot { } void LootState::UpdateGames(std::vector& games) { + // Acquire the lock for the scope of this method. + base::AutoLock lock_scope(_lock); + unordered_set newGameFolders; // Update existing games, add new games. @@ -272,6 +275,9 @@ namespace loot { } void LootState::ChangeGame(const std::string& newGameFolder) { + // Acquire the lock for the scope of this method. + base::AutoLock lock_scope(_lock); + BOOST_LOG_TRIVIAL(debug) << "Changing current game to that with folder: " << newGameFolder; auto it = find(_games.begin(), _games.end(), newGameFolder); @@ -281,6 +287,9 @@ namespace loot { } Game& LootState::CurrentGame() { + // Acquire the lock for the scope of this method. + base::AutoLock lock_scope(_lock); + return _games[_currentGame]; } @@ -298,10 +307,16 @@ namespace loot { } void LootState::UpdateSettings(const YAML::Node& settings) { + // Acquire the lock for the scope of this method. + base::AutoLock lock_scope(_lock); + _settings = settings; } void LootState::SaveSettings() { + // Acquire the lock for the scope of this method. + base::AutoLock lock_scope(_lock); + _settings["lastGame"] = _games[_currentGame].FolderName(); //Save settings. @@ -321,6 +336,9 @@ namespace loot { } bool LootState::AreSettingsValid() { + // Acquire the lock for the scope of this method. + base::AutoLock lock_scope(_lock); + if (!_settings["language"]) { if (_settings["Language"]) { // Conversion from 0.6 key. @@ -396,7 +414,7 @@ namespace loot { return true; } - YAML::Node LootState::GetDefaultSettings() { + YAML::Node LootState::GetDefaultSettings() const { YAML::Node root; root["language"] = "en"; diff --git a/src/gui/app.h b/src/gui/app.h index 5f595761..482adb3d 100644 --- a/src/gui/app.h +++ b/src/gui/app.h @@ -20,7 +20,7 @@ You should have received a copy of the GNU General Public License along with LOOT. If not, see . -*/ + */ #ifndef __LOOT_GUI_APP__ #define __LOOT_GUI_APP__ @@ -29,14 +29,14 @@ #include #include +#include #include namespace loot { - class LootApp : public CefApp, - public CefBrowserProcessHandler, - public CefRenderProcessHandler { + public CefBrowserProcessHandler, + public CefRenderProcessHandler { public: LootApp(); @@ -50,23 +50,22 @@ namespace loot { // Override CefRenderProcessHandler methods. virtual bool OnProcessMessageReceived(CefRefPtr browser, - CefProcessId source_process, - CefRefPtr message) OVERRIDE; + CefProcessId source_process, + CefRefPtr message) OVERRIDE; private: CefRefPtr message_router_; virtual void OnContextCreated(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr context) OVERRIDE; + CefRefPtr frame, + CefRefPtr context) OVERRIDE; IMPLEMENT_REFCOUNTING(LootApp); }; - class LootState { + class LootState : public CefBase { public: LootState(); - // Init may fail with no void Init(const std::string& cmdLineGame); const std::vector& InitErrors() const; @@ -87,7 +86,11 @@ namespace loot { // Check if the settings file has the right root keys (doesn't check their values). bool AreSettingsValid(); - YAML::Node GetDefaultSettings(); + YAML::Node GetDefaultSettings() const; + + // Lock used to protect access to member variables. + base::Lock _lock; + IMPLEMENT_REFCOUNTING(LootState); }; extern LootState g_app_state;