about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/ap_state.cpp56
-rw-r--r--src/game_data.cpp7
-rw-r--r--src/logger.cpp27
-rw-r--r--src/logger.h29
-rw-r--r--src/main.cpp14
6 files changed, 43 insertions, 91 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 6dc2f4c..cd62c55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -40,7 +40,6 @@ add_executable(lingo_ap_tracker
40 "src/connection_dialog.cpp" 40 "src/connection_dialog.cpp"
41 "src/tracker_state.cpp" 41 "src/tracker_state.cpp"
42 "src/tracker_config.cpp" 42 "src/tracker_config.cpp"
43 "src/logger.cpp"
44 "src/achievements_pane.cpp" 43 "src/achievements_pane.cpp"
45 "src/settings_dialog.cpp" 44 "src/settings_dialog.cpp"
46 "src/global.cpp" 45 "src/global.cpp"
diff --git a/src/ap_state.cpp b/src/ap_state.cpp index 68a6902..4a15db0 100644 --- a/src/ap_state.cpp +++ b/src/ap_state.cpp
@@ -21,7 +21,6 @@
21#include <tuple> 21#include <tuple>
22 22
23#include "game_data.h" 23#include "game_data.h"
24#include "logger.h"
25#include "tracker_frame.h" 24#include "tracker_frame.h"
26#include "tracker_state.h" 25#include "tracker_state.h"
27 26
@@ -75,7 +74,7 @@ struct APState {
75 74
76 void Connect(std::string server, std::string player, std::string password) { 75 void Connect(std::string server, std::string player, std::string password) {
77 if (!initialized) { 76 if (!initialized) {
78 wxLogMessage("Initializing APState..."); 77 wxLogVerbose("Initializing APState...");
79 78
80 std::thread([this]() { 79 std::thread([this]() {
81 for (;;) { 80 for (;;) {
@@ -108,11 +107,10 @@ struct APState {
108 initialized = true; 107 initialized = true;
109 } 108 }
110 109
111 tracker_frame->SetStatusMessage("Connecting to Archipelago server...."); 110 wxLogStatus("Connecting to Archipelago server (%s)...", server);
112 wxLogMessage("Connecting to Archipelago server (%s)...", server);
113 111
114 { 112 {
115 wxLogMessage("Destroying old AP client..."); 113 wxLogVerbose("Destroying old AP client...");
116 114
117 std::lock_guard client_guard(client_mutex); 115 std::lock_guard client_guard(client_mutex);
118 116
@@ -156,12 +154,11 @@ struct APState {
156 apclient->set_room_info_handler([this, player, password]() { 154 apclient->set_room_info_handler([this, player, password]() {
157 inventory.clear(); 155 inventory.clear();
158 156
159 wxLogMessage("Connected to Archipelago server. Authenticating as %s %s", 157 wxLogStatus(
160 player,
161 (password.empty() ? " without password"
162 : " with password " + password));
163 tracker_frame->SetStatusMessage(
164 "Connected to Archipelago server. Authenticating..."); 158 "Connected to Archipelago server. Authenticating...");
159 wxLogVerbose("Authenticating as %s %s", player,
160 (password.empty() ? "without password"
161 : "with password " + password));
165 162
166 apclient->ConnectSlot(player, password, ITEM_HANDLING, {"Tracker"}, 163 apclient->ConnectSlot(player, password, ITEM_HANDLING, {"Tracker"},
167 {AP_MAJOR, AP_MINOR, AP_REVISION}); 164 {AP_MAJOR, AP_MINOR, AP_REVISION});
@@ -171,23 +168,19 @@ struct APState {
171 [this](const std::list<int64_t>& locations) { 168 [this](const std::list<int64_t>& locations) {
172 for (const int64_t location_id : locations) { 169 for (const int64_t location_id : locations) {
173 checked_locations.insert(location_id); 170 checked_locations.insert(location_id);
174 wxLogMessage("Location: %lld", location_id); 171 wxLogVerbose("Location: %lld", location_id);
175 } 172 }
176 173
177 RefreshTracker(false); 174 RefreshTracker(false);
178 }); 175 });
179 176
180 apclient->set_slot_disconnected_handler([this]() { 177 apclient->set_slot_disconnected_handler([this]() {
181 tracker_frame->SetStatusMessage( 178 wxLogStatus(
182 "Disconnected from Archipelago. Attempting to reconnect...");
183 wxLogMessage(
184 "Slot disconnected from Archipelago. Attempting to reconnect..."); 179 "Slot disconnected from Archipelago. Attempting to reconnect...");
185 }); 180 });
186 181
187 apclient->set_socket_disconnected_handler([this]() { 182 apclient->set_socket_disconnected_handler([this]() {
188 tracker_frame->SetStatusMessage( 183 wxLogStatus(
189 "Disconnected from Archipelago. Attempting to reconnect...");
190 wxLogMessage(
191 "Socket disconnected from Archipelago. Attempting to reconnect..."); 184 "Socket disconnected from Archipelago. Attempting to reconnect...");
192 }); 185 });
193 186
@@ -195,7 +188,7 @@ struct APState {
195 [this](const std::list<APClient::NetworkItem>& items) { 188 [this](const std::list<APClient::NetworkItem>& items) {
196 for (const APClient::NetworkItem& item : items) { 189 for (const APClient::NetworkItem& item : items) {
197 inventory[item.item]++; 190 inventory[item.item]++;
198 wxLogMessage("Item: %lld", item.item); 191 wxLogVerbose("Item: %lld", item.item);
199 } 192 }
200 193
201 RefreshTracker(false); 194 RefreshTracker(false);
@@ -219,8 +212,7 @@ struct APState {
219 212
220 apclient->set_slot_connected_handler([this]( 213 apclient->set_slot_connected_handler([this](
221 const nlohmann::json& slot_data) { 214 const nlohmann::json& slot_data) {
222 tracker_frame->SetStatusMessage("Connected to Archipelago!"); 215 wxLogStatus("Connected to Archipelago!");
223 wxLogMessage("Connected to Archipelago!");
224 216
225 data_storage_prefix = 217 data_storage_prefix =
226 "Lingo_" + std::to_string(apclient->get_player_number()) + "_"; 218 "Lingo_" + std::to_string(apclient->get_player_number()) + "_";
@@ -341,9 +333,7 @@ struct APState {
341 333
342 DestroyClient(); 334 DestroyClient();
343 335
344 tracker_frame->SetStatusMessage("Disconnected from Archipelago."); 336 wxLogStatus("Timeout while connecting to Archipelago server.");
345
346 wxLogMessage("Timeout while connecting to Archipelago server.");
347 wxMessageBox("Timeout while connecting to Archipelago server.", 337 wxMessageBox("Timeout while connecting to Archipelago server.",
348 "Connection failed", wxOK | wxICON_ERROR); 338 "Connection failed", wxOK | wxICON_ERROR);
349 } 339 }
@@ -363,11 +353,11 @@ struct APState {
363 void HandleDataStorage(const std::string& key, const nlohmann::json& value) { 353 void HandleDataStorage(const std::string& key, const nlohmann::json& value) {
364 if (value.is_boolean()) { 354 if (value.is_boolean()) {
365 data_storage[key] = value.get<bool>(); 355 data_storage[key] = value.get<bool>();
366 wxLogMessage("Data storage %s retrieved as %s", key, 356 wxLogVerbose("Data storage %s retrieved as %s", key,
367 (value.get<bool>() ? "true" : "false")); 357 (value.get<bool>() ? "true" : "false"));
368 } else if (value.is_number()) { 358 } else if (value.is_number()) {
369 data_storage[key] = value.get<int>(); 359 data_storage[key] = value.get<int>();
370 wxLogMessage("Data storage %s retrieved as %d", key, value.get<int>()); 360 wxLogVerbose("Data storage %s retrieved as %d", key, value.get<int>());
371 } else if (value.is_object()) { 361 } else if (value.is_object()) {
372 if (key.ends_with("PlayerPos")) { 362 if (key.ends_with("PlayerPos")) {
373 auto map_value = value.get<std::map<std::string, int>>(); 363 auto map_value = value.get<std::map<std::string, int>>();
@@ -376,7 +366,7 @@ struct APState {
376 data_storage[key] = value.get<std::map<std::string, int>>(); 366 data_storage[key] = value.get<std::map<std::string, int>>();
377 } 367 }
378 368
379 wxLogMessage("Data storage %s retrieved as dictionary", key); 369 wxLogVerbose("Data storage %s retrieved as dictionary", key);
380 } else if (value.is_null()) { 370 } else if (value.is_null()) {
381 if (key.ends_with("PlayerPos")) { 371 if (key.ends_with("PlayerPos")) {
382 player_pos = std::nullopt; 372 player_pos = std::nullopt;
@@ -384,15 +374,19 @@ struct APState {
384 data_storage.erase(key); 374 data_storage.erase(key);
385 } 375 }
386 376
387 wxLogMessage("Data storage %s retrieved as null", key); 377 wxLogVerbose("Data storage %s retrieved as null", key);
388 } else if (value.is_array()) { 378 } else if (value.is_array()) {
379 auto list_value = value.get<std::vector<std::string>>();
380
389 if (key.ends_with("Paintings")) { 381 if (key.ends_with("Paintings")) {
390 data_storage[key] = value.get<std::set<std::string>>(); 382 data_storage[key] =
383 std::set<std::string>(list_value.begin(), list_value.end());
391 } else { 384 } else {
392 data_storage[key] = value.get<std::vector<std::string>>(); 385 data_storage[key] = list_value;
393 } 386 }
394 387
395 wxLogMessage("Data storage %s retrieved as list", key); 388 wxLogVerbose("Data storage %s retrieved as list: [%s]", key,
389 hatkirby::implode(list_value, ", "));
396 } 390 }
397 } 391 }
398 392
@@ -425,7 +419,7 @@ struct APState {
425 } 419 }
426 420
427 void RefreshTracker(bool reset) { 421 void RefreshTracker(bool reset) {
428 wxLogMessage("Refreshing display..."); 422 wxLogVerbose("Refreshing display...");
429 423
430 RecalculateReachability(); 424 RecalculateReachability();
431 425
diff --git a/src/game_data.cpp b/src/game_data.cpp index 8af57e5..de47ba4 100644 --- a/src/game_data.cpp +++ b/src/game_data.cpp
@@ -1,5 +1,11 @@
1#include "game_data.h" 1#include "game_data.h"
2 2
3#include <wx/wxprec.h>
4
5#ifndef WX_PRECOMP
6#include <wx/wx.h>
7#endif
8
3#include <hkutil/string.h> 9#include <hkutil/string.h>
4#include <yaml-cpp/yaml.h> 10#include <yaml-cpp/yaml.h>
5 11
@@ -7,7 +13,6 @@
7#include <sstream> 13#include <sstream>
8 14
9#include "global.h" 15#include "global.h"
10#include "logger.h"
11 16
12namespace { 17namespace {
13 18
diff --git a/src/logger.cpp b/src/logger.cpp deleted file mode 100644 index dddcc4a..0000000 --- a/src/logger.cpp +++ /dev/null
@@ -1,27 +0,0 @@
1#include "logger.h"
2
3#include "global.h"
4
5Logger::Logger() : logfile_(GetAbsolutePath("debug.log")) {}
6
7void Logger::Flush() {
8 wxLog::Flush();
9
10 std::lock_guard guard(file_mutex_);
11 logfile_.flush();
12}
13
14Logger::~Logger() {
15 std::lock_guard guard(file_mutex_);
16 logfile_.flush();
17}
18
19void Logger::DoLogText(const wxString& msg) {
20#ifdef _WIN64
21 OutputDebugStringA(msg.c_str());
22 OutputDebugStringA("\r\n");
23#endif
24
25 std::lock_guard guard(file_mutex_);
26 logfile_ << msg << std::endl;
27}
diff --git a/src/logger.h b/src/logger.h deleted file mode 100644 index b1a1d99..0000000 --- a/src/logger.h +++ /dev/null
@@ -1,29 +0,0 @@
1#ifndef LOGGER_H_6E7B9594
2#define LOGGER_H_6E7B9594
3
4#include <wx/wxprec.h>
5
6#ifndef WX_PRECOMP
7#include <wx/wx.h>
8#endif
9
10#include <fstream>
11#include <mutex>
12
13class Logger : public wxLog {
14 public:
15 Logger();
16
17 void Flush() override;
18
19 ~Logger();
20
21 protected:
22 void DoLogText(const wxString& msg) override;
23
24 private:
25 std::ofstream logfile_;
26 std::mutex file_mutex_;
27};
28
29#endif /* end of include guard: LOGGER_H_6E7B9594 */
diff --git a/src/main.cpp b/src/main.cpp index db7653c..5b036ea 100644 --- a/src/main.cpp +++ b/src/main.cpp
@@ -4,14 +4,24 @@
4#include <wx/wx.h> 4#include <wx/wx.h>
5#endif 5#endif
6 6
7#include "logger.h" 7#include <fstream>
8
9#include "global.h"
8#include "tracker_config.h" 10#include "tracker_config.h"
9#include "tracker_frame.h" 11#include "tracker_frame.h"
10 12
13static std::ofstream* logfile;
14
11class TrackerApp : public wxApp { 15class TrackerApp : public wxApp {
12 public: 16 public:
13 virtual bool OnInit() { 17 virtual bool OnInit() {
14 wxLog::SetActiveTarget(new Logger()); 18 logfile = new std::ofstream(GetAbsolutePath("debug.log"));
19 wxLog::SetActiveTarget(new wxLogStream(logfile));
20
21#ifndef NDEBUG
22 wxLog::SetVerbose(true);
23 wxLog::SetActiveTarget(new wxLogWindow(nullptr, "Debug Log"));
24#endif
15 25
16 GetTrackerConfig().Load(); 26 GetTrackerConfig().Load();
17 27