Beautify ConnectProtocol a bit.

This commit is contained in:
momo5502 2016-01-04 13:20:04 +01:00
parent 23c7828506
commit 5574aea293

View File

@ -67,25 +67,22 @@ namespace Components
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Classes\\iw4x\\shell\\open\\command", 0, KEY_ALL_ACCESS, &hKey); LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Classes\\iw4x\\shell\\open\\command", 0, KEY_ALL_ACCESS, &hKey);
if (openRes == ERROR_SUCCESS) if (openRes == ERROR_SUCCESS)
{ {
//Insert Check of the Key Value here, so the protocol will work even if the game was moved. // Check if the game has been moved.
openRes = RegQueryValueEx(hKey, 0, 0, 0, reinterpret_cast<BYTE*>(regred), &dwsize); openRes = RegQueryValueEx(hKey, 0, 0, 0, reinterpret_cast<BYTE*>(regred), &dwsize);
if (openRes == ERROR_SUCCESS) if (openRes == ERROR_SUCCESS)
{ {
char* endPt = strstr(regred, "\" \"%1\""); char* endPtr = strstr(regred, "\" \"%1\"");
if (endPt != NULL) if (endPtr != NULL)
{ {
*endPt = 0; *endPtr = 0;
} }
else else
{ {
return false; return false;
} }
char* regredPtr = regred;
regredPtr++;
RegCloseKey(hKey); RegCloseKey(hKey);
if (strcmp(regredPtr, ownPth)) if (strcmp(regred + 1, ownPth))
{ {
openRes = RegDeleteKey(HKEY_CURRENT_USER, "SOFTWARE\\Classes\\iw4x"); openRes = RegDeleteKey(HKEY_CURRENT_USER, "SOFTWARE\\Classes\\iw4x");
} }
@ -179,26 +176,22 @@ namespace Components
if (ConnectProtocol::ConnectContainer.Evaluated) return; if (ConnectProtocol::ConnectContainer.Evaluated) return;
ConnectProtocol::ConnectContainer.Evaluated = true; ConnectProtocol::ConnectContainer.Evaluated = true;
char* args = GetCommandLine(); std::string cmdLine = GetCommandLine();
char* substr = strstr(args, "iw4x://");
if (!substr || substr == args) auto pos = cmdLine.find("iw4x://");
if (pos != std::string::npos)
{ {
return; cmdLine = cmdLine.substr(pos + 7);
pos = cmdLine.find_first_of("/");
if (pos != std::string::npos)
{
cmdLine = cmdLine.substr(0, pos);
} }
substr += 7; ConnectProtocol::ConnectContainer.ConnectString = cmdLine;
char* substr2 = strstr(substr, "/");
if (substr2 != NULL)
{
*substr2 = 0;
} }
else
{
return;
}
ConnectProtocol::ConnectContainer.ConnectString = substr;
} }
ConnectProtocol::ConnectProtocol() ConnectProtocol::ConnectProtocol()