Fix bug not accepting paired device after reboot

This commit is contained in:
loki
2021-06-10 17:44:40 +02:00
parent e53f65c305
commit 988bf33b40
+8 -10
View File
@@ -98,7 +98,7 @@ void save_state() {
pt::read_json(config::nvhttp.file_state, root); pt::read_json(config::nvhttp.file_state, root);
} }
catch(std::exception &e) { catch(std::exception &e) {
BOOST_LOG(error) << e.what(); BOOST_LOG(error) << "Couldn't read "sv << config::nvhttp.file_state << ": "sv << e.what();
return; return;
} }
} }
@@ -127,14 +127,14 @@ void save_state() {
pt::write_json(config::nvhttp.file_state, root); pt::write_json(config::nvhttp.file_state, root);
} }
catch(std::exception &e) { catch(std::exception &e) {
BOOST_LOG(error) << e.what(); BOOST_LOG(error) << "Couldn't write "sv << config::nvhttp.file_state << ": "sv << e.what();
return; return;
} }
} }
void load_state() { void load_state() {
auto file_state = fs::current_path() / config::nvhttp.file_state; if(!fs::exists(config::nvhttp.file_state)) {
if(!fs::exists(file_state)) { BOOST_LOG(info) << "DOENST EXIST"sv;
http::unique_id = util::uuid_t::generate().string(); http::unique_id = util::uuid_t::generate().string();
return; return;
} }
@@ -144,20 +144,18 @@ void load_state() {
pt::read_json(config::nvhttp.file_state, root); pt::read_json(config::nvhttp.file_state, root);
} }
catch(std::exception &e) { catch(std::exception &e) {
BOOST_LOG(warning) << e.what(); BOOST_LOG(error) << "Couldn't read "sv << config::nvhttp.file_state << ": "sv << e.what();
return; return;
} }
auto unique_id_p = root.find("root.uniqueid"s); auto unique_id_p = root.get_optional<std::string>("root.uniqueid");
if(unique_id_p == root.not_found()) { if(!unique_id_p) {
// This file doesn't contain moonlight credentials // This file doesn't contain moonlight credentials
http::unique_id = util::uuid_t::generate().string(); http::unique_id = util::uuid_t::generate().string();
return; return;
} }
else { http::unique_id = std::move(*unique_id_p);
http::unique_id = root.get<std::string>("root.uniqueid");
}
auto device_nodes = root.get_child("root.devices"); auto device_nodes = root.get_child("root.devices");