ByteString VsbDevice::doQuery(uint8_t cmdId, ByteString data) { ByteString cmdBuf(18, 0); cmdBuf[0] = cmdId; std::copy(data.begin(), data.end(), cmdBuf.begin()+2); sendFeatureReport(VSB_REPORTID, cmdBuf); bool dataOk = false; ByteString resp; for(int i = 0; i < NUM_READ_TRIES; ++i) { try { resp = getFeatureReport(VSB_REPORTID); } catch(HidDeviceError err) { if(i < NUM_READ_TRIES-1) continue; throw VsbError(std::string("HID subsystem error: ") + err.what()); } if(resp.size() < 2) continue; //Probably shouldn't ever happen, but let's not crash if it does if(!resp[0]) continue; //This also shouldn't happen... //FIXME: Implement a proper exception class to use here if(resp[0] != cmdId) throw std::runtime_error(boost::str(boost::format("Got the wrong command ID back! (%d)") % (int)resp[1])); if(resp[1] == VSB_RESP_BUSY) { //TODO: Insert a small time delay continue; } else if(resp[1] == VSB_RESP_NULL) throw VsbError("Null response code?"); else if(resp[1] == VSB_RESP_BADCMD) throw VsbError("Device reported bad command ID"); else if(resp[1] == VSB_RESP_BADCS) throw VsbError("Device reported stored configuration is corrupt/invalid"); else if(resp[1] == VSB_RESP_BADIDX) throw VsbError("Device reported bad keyseq page number"); else if(resp[1] == VSB_RESP_ERR) throw VsbError("Device reported general error"); else if(resp[1] == VSB_RESP_OK) { dataOk = true; break; } else throw VsbError("Got invalid response code"); } if(!dataOk) throw VsbError("Device failed to respond in time"); return ByteString(resp, 2); }
static bool ReadInterfaces() { ByteString buffer; if (FileSystem::FileExists(INTERFACE_VERSION_FILE)) { FileSystem::ReadFile(INTERFACE_VERSION_FILE, buffer); } else { std::string data = WebIO("Redacted").Get(hString::va("https://momo5502.com/SteamAPI/?app=%d", Global::Steam_AppID)); buffer.append(data.begin(), data.end()); FileSystem::WriteFile(INTERFACE_VERSION_FILE, buffer, false); } Json::Reader reader; Json::Value root; if (reader.parse(std::string(buffer.begin(), buffer.end()), root) && root.type() == Json::objectValue) { PARSEINTERFACE(root, _SteamApps, "Apps", INTERFACE_STEAMAPPS001) PARSEINTERFACE(root, _SteamClient, "Client", INTERFACE_STEAMCLIENT001) PARSEINTERFACE(root, _SteamContentServer, "ContentServer", INTERFACE_STEAMCONTENTSERVER001) // PARSEINTERFACE(root, _SteamController, "Controller", INTERFACE_STEAMCONTROLLER001) PARSEINTERFACE(root, _SteamFriends, "Friends", INTERFACE_STEAMFRIENDS001) PARSEINTERFACE(root, _SteamGameServer, "GameServer", INTERFACE_STEAMGAMESERVER001) PARSEINTERFACE(root, _SteamGameServerStats, "GameServerStats", INTERFACE_STEAMGAMESERVER001) PARSEINTERFACE(root, _SteamHTTP, "HTTP", INTERFACE_STEAMHTTP001) PARSEINTERFACE(root, _SteamMasterServerUpdater, "MasterServerUpdater", INTERFACE_STEAMMASTERUPDATER001) PARSEINTERFACE(root, _SteamMatchMaking, "MatchMaking", INTERFACE_STEAMMATCHMAKING001) PARSEINTERFACE(root, _SteamMatchMakingServers, "MatchMakingServers", INTERFACE_STEAMMATCHMAKINGSERVERS001) PARSEINTERFACE(root, _SteamMusic, "Music", INTERFACE_STEAMMUSIC001) // PARSEINTERFACE(root, _SteamMusicRemote, "MusicRemote", INTERFACE_STEAMMUSICREMOTE001) PARSEINTERFACE(root, _SteamNetworking, "Networking", INTERFACE_STEAMNETWORKING001) PARSEINTERFACE(root, _SteamRemoteStorage, "RemoteStorage", INTERFACE_STEAMREMOTESTORAGE001) PARSEINTERFACE(root, _SteamScreenshots, "Screenshots", INTERFACE_STEAMSCREENSHOTS001) PARSEINTERFACE(root, _SteamUnifiedMessages, "UnifiedMessages", INTERFACE_STEAMUNIFIEDMESSAGES001) PARSEINTERFACE(root, _SteamUser, "User", INTERFACE_STEAMUSER001) PARSEINTERFACE(root, _SteamUserStats, "UserStats", INTERFACE_STEAMUSERSTATS001) PARSEINTERFACE(root, _SteamUtils, "Utils", INTERFACE_STEAMUTILS001) PARSEINTERFACE(root, _SteamUGC, "UGC", INTERFACE_STEAMUGC001) return true; }