mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Implemented thread locking.
Fixes #258. CodeMaid didn't clean up header files, so there are some formatting changes to app.h here too.
This commit is contained in:
+19
-1
@@ -239,6 +239,9 @@ namespace loot {
|
||||
}
|
||||
|
||||
void LootState::UpdateGames(std::vector<Game>& games) {
|
||||
// Acquire the lock for the scope of this method.
|
||||
base::AutoLock lock_scope(_lock);
|
||||
|
||||
unordered_set<string> 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";
|
||||
|
||||
+14
-11
@@ -20,7 +20,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LOOT. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifndef __LOOT_GUI_APP__
|
||||
#define __LOOT_GUI_APP__
|
||||
@@ -29,14 +29,14 @@
|
||||
|
||||
#include <include/cef_app.h>
|
||||
#include <include/wrapper/cef_message_router.h>
|
||||
#include <include/base/cef_lock.h>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
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<CefBrowser> browser,
|
||||
CefProcessId source_process,
|
||||
CefRefPtr<CefProcessMessage> message) OVERRIDE;
|
||||
CefProcessId source_process,
|
||||
CefRefPtr<CefProcessMessage> message) OVERRIDE;
|
||||
private:
|
||||
CefRefPtr<CefMessageRouterRendererSide> message_router_;
|
||||
|
||||
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) OVERRIDE;
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> 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<std::string>& 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;
|
||||
|
||||
Reference in New Issue
Block a user