More error handling

experimental/UWP_Inject
Peter Repukat 3 years ago
parent 534a986115
commit 21251ced18

@ -184,12 +184,17 @@ void SteamTarget::focusWindow(WindowHandle hndl)
std::filesystem::path SteamTarget::getSteamPath() const std::filesystem::path SteamTarget::getSteamPath() const
{ {
#ifdef _WIN32 #ifdef _WIN32
// TODO: check if keys/value exist try {
// steam should always be open and have written reg values... // TODO: check if keys/value exist
winreg::RegKey key{HKEY_CURRENT_USER, L"SOFTWARE\\Valve\\Steam"}; // steam should always be open and have written reg values...
const auto res = key.GetStringValue(L"SteamPath"); winreg::RegKey key{HKEY_CURRENT_USER, L"SOFTWARE\\Valve\\Steam"};
spdlog::info(L"Detected Steam Path: {}", res); const auto res = key.GetStringValue(L"SteamPath");
return res; spdlog::info(L"Detected Steam Path: {}", res);
return res;
} catch (winreg::RegException e) {
spdlog::error("Couldn't get Steam path from Registry; {}", e.what());
}
return L"";
#else #else
return L""; // TODO return L""; // TODO
#endif #endif
@ -198,12 +203,18 @@ std::filesystem::path SteamTarget::getSteamPath() const
std::wstring SteamTarget::getSteamUserId() const std::wstring SteamTarget::getSteamUserId() const
{ {
#ifdef _WIN32 #ifdef _WIN32
// TODO: check if keys/value exist try {
// steam should always be open and have written reg values... // TODO: check if keys/value exist
winreg::RegKey key{HKEY_CURRENT_USER, L"SOFTWARE\\Valve\\Steam\\ActiveProcess"}; // steam should always be open and have written reg values...
const auto res = std::to_wstring(key.GetDwordValue(L"ActiveUser")); winreg::RegKey key{HKEY_CURRENT_USER, L"SOFTWARE\\Valve\\Steam\\ActiveProcess"};
spdlog::info(L"Detected Steam UserId: {}", res); const auto res = std::to_wstring(key.GetDwordValue(L"ActiveUser"));
return res; spdlog::info(L"Detected Steam UserId: {}", res);
return res;
}
catch (winreg::RegException e) {
spdlog::error("Couldn't get Steam path from Registry; {}", e.what());
}
return L"";
#else #else
return L""; // TODO return L""; // TODO
#endif #endif
@ -220,6 +231,10 @@ std::vector<std::string> SteamTarget::getOverlayHotkey()
auto root = tyti::vdf::read(config_file); auto root = tyti::vdf::read(config_file);
auto children = root.childs["system"]; auto children = root.childs["system"];
if (children->attribs.find("InGameOverlayShortcutKey") == children->attribs.end()) {
spdlog::warn("Couldn't detect overlay hotkey, using default: Shift+Tab");
return {"Shift", "KEY_TAB"}; // default
}
auto hotkeys = children->attribs.at("InGameOverlayShortcutKey"); auto hotkeys = children->attribs.at("InGameOverlayShortcutKey");
// has anyone more than 4 keys to open overlay?! // has anyone more than 4 keys to open overlay?!
@ -257,6 +272,10 @@ std::vector<std::string> SteamTarget::getScreenshotHotkey()
auto root = tyti::vdf::read(config_file); auto root = tyti::vdf::read(config_file);
auto children = root.childs["system"]; auto children = root.childs["system"];
if (children->attribs.find("InGameOverlayScreenshotHotKey") == children->attribs.end()) {
spdlog::warn("Couldn't detect overlay hotkey, using default: F12");
return {"KEY_F12"}; //default
}
auto hotkeys = children->attribs.at("InGameOverlayScreenshotHotKey"); auto hotkeys = children->attribs.at("InGameOverlayScreenshotHotKey");
// has anyone more than 4 keys to screenshot?! // has anyone more than 4 keys to screenshot?!
@ -293,6 +312,10 @@ bool SteamTarget::getXBCRebindingEnabled()
std::ifstream config_file(config_path); std::ifstream config_file(config_path);
auto root = tyti::vdf::read(config_file); auto root = tyti::vdf::read(config_file);
if (root.attribs.find("SteamController_XBoxSupport") == root.attribs.end()) {
spdlog::warn("\"Xbox Configuration Support\" is disabled in Steam. This may cause doubled Inputs!");
return false;
}
auto xbsup = root.attribs.at("SteamController_XBoxSupport"); auto xbsup = root.attribs.at("SteamController_XBoxSupport");
if (xbsup != "1") { if (xbsup != "1") {
spdlog::warn("\"Xbox Configuration Support\" is disabled in Steam. This may cause doubled Inputs!"); spdlog::warn("\"Xbox Configuration Support\" is disabled in Steam. This may cause doubled Inputs!");

Loading…
Cancel
Save