Fixed all Codeanalysis warnings

This commit is contained in:
/dev/sdb 2016-01-03 19:29:22 +01:00
parent 1e1a415125
commit 94730e7ff2
2 changed files with 119 additions and 44 deletions

View File

@ -3,7 +3,7 @@
namespace Components namespace Components
{ {
#define MAX_PROCESSES 1024 #define MAX_PROCESSES 1024
int evaluated = 0; int evaluated = 0;
//Declarations SendMessage stuff //Declarations SendMessage stuff
@ -16,29 +16,50 @@ namespace Components
LPCTSTR sk = TEXT("SOFTWARE\\Classes\\iw4x\\shell\\open\\command"); LPCTSTR sk = TEXT("SOFTWARE\\Classes\\iw4x\\shell\\open\\command");
LPCTSTR data = "URL:iw4x Protocol"; LPCTSTR data = "URL:iw4x Protocol";
LPCTSTR value = TEXT("URL Protocol"); LPCTSTR value = TEXT("URL Protocol");
HMODULE hModule = GetModuleHandle(NULL); char ownPth[MAX_PATH] = {0};
char ownPth[MAX_PATH]; char workdir[MAX_PATH] = {0};
char workdir[MAX_PATH]; char regred[MAX_PATH] = {0};
char regred[MAX_PATH];
DWORD dwsize = MAX_PATH; DWORD dwsize = MAX_PATH;
HMODULE hModule = GetModuleHandle(NULL);
if (hModule != NULL) if (hModule != NULL)
{ {
GetModuleFileName(hModule, ownPth, (sizeof(ownPth)));
GetModuleFileName(hModule, workdir, (sizeof(workdir))); if (GetModuleFileName(hModule, ownPth, MAX_PATH) == ERROR)
//////DBG(("EXE Path: %s", ownPth));
}
else
{ {
//////DBG("Cant get executable path"); OutputDebugString("ownPth = Error");
return false; return false;
} }
if (GetModuleFileName(hModule, workdir, MAX_PATH) == ERROR)
{
OutputDebugString("workdir = Error");
return false;
}
else
{
char* endPtr = strstr(workdir, "iw4x.exe"); char* endPtr = strstr(workdir, "iw4x.exe");
if (endPtr != NULL)
{
*endPtr = 0; *endPtr = 0;
}
else
{
////DBG(("EXE Path: %s", ownPth)); return false;
////DBG(("EXE Path2: %s", workdir)); }
}
//OutputDebugString(Utils::VA("EXE Path: %s", ownPth));
}
else
{
//OutputDebugString(Utils::VA("Cant get executable path"));
return false;
}
/*OutputDebugString(Utils::VA("EXE Path: %s", ownPth));
OutputDebugString(Utils::VA("EXE Path2: %s", workdir));*/
SetCurrentDirectory(workdir); SetCurrentDirectory(workdir);
@ -50,7 +71,16 @@ namespace Components
if (openRes == ERROR_SUCCESS) if (openRes == ERROR_SUCCESS)
{ {
char* endPt = strstr(regred, "\" \"%1\""); char* endPt = strstr(regred, "\" \"%1\"");
if (endPt != NULL)
{
*endPt = 0; *endPt = 0;
}
else
{
OutputDebugString("endPt = Null");
return false;
}
char* regredPtr = regred; char* regredPtr = regred;
regredPtr++; regredPtr++;
@ -62,16 +92,25 @@ namespace Components
if (strcmp(regredPtr, ownPth)) if (strcmp(regredPtr, ownPth))
{ {
////DBG("Protocol changed, reinstall"); ////DBG("Protocol changed, reinstall");
//sk = TEXT("SOFTWARE\\Classes\\iw4x");
//openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
//if (openRes == ERROR_SUCCESS)
//{
// ////DBG("Protocol is corrupted, reinstall");
// RegDeleteKey(hKey, 0);
// RegCloseKey(hKey);
//}
sk = TEXT("SOFTWARE\\Classes\\iw4x"); sk = TEXT("SOFTWARE\\Classes\\iw4x");
openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey); openRes = RegDeleteKey(HKEY_CURRENT_USER, sk);
if (openRes == ERROR_SUCCESS) if (openRes != ERROR_SUCCESS)
{ {
////DBG("Protocol is corrupted, reinstall"); ////DBG("Protocol is corrupted, reinstall");
RegDeleteKey(hKey, 0);
RegCloseKey(hKey); //RegCloseKey(hKey);
} }
} }
else{ else{
////DBG("Protocol is already installed"); ////DBG("Protocol is already installed");
@ -79,30 +118,41 @@ namespace Components
} }
} }
else{ else{
openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey); //openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
if (openRes == ERROR_SUCCESS) //if (openRes == ERROR_SUCCESS)
//{
// ////DBG("Protocol is corrupted, reinstall");
// RegDeleteKey(hKey, 0);
// RegCloseKey(hKey);
//}
sk = TEXT("SOFTWARE\\Classes\\iw4x");
openRes = RegDeleteKey(HKEY_CURRENT_USER, sk);
if (openRes != ERROR_SUCCESS)
{ {
////DBG("Protocol is corrupted, reinstall"); ////DBG("Protocol is corrupted, reinstall");
RegDeleteKey(hKey, 0);
RegCloseKey(hKey); //RegCloseKey(hKey);
} }
} }
/*////DBG("Protocol is already installed"); //////DBG("Protocol is already installed");
return true;*/ //return true;
} }
else else
{ {
sk = TEXT("SOFTWARE\\Classes\\iw4x"); sk = TEXT("SOFTWARE\\Classes\\iw4x");
openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey); openRes = RegDeleteKey(HKEY_CURRENT_USER, sk);
if (openRes == ERROR_SUCCESS) if (openRes != ERROR_SUCCESS)
{ {
////DBG("Protocol is corrupted, reinstall"); ////DBG("Protocol is corrupted, reinstall");
RegDeleteKey(hKey, 0); //return false;
RegCloseKey(hKey); //RegCloseKey(hKey);
} }
} }
@ -176,14 +226,14 @@ namespace Components
else else
{ {
////DBG("Error creating Key shell\\open\\command"); ////DBG("Error creating Key shell\\open\\command");
RegCloseKey(hKey); //RegCloseKey(hKey);
return false; return false;
} }
} }
else else
{ {
////DBG("Error opening SOFTWARE\\Classes\\iw3mp"); ////DBG("Error opening SOFTWARE\\Classes\\iw3mp");
RegCloseKey(hKey); //RegCloseKey(hKey);
return false; return false;
} }
} }
@ -204,7 +254,7 @@ namespace Components
else else
{ {
////DBG("Error creating subkey DefaultIcon"); ////DBG("Error creating subkey DefaultIcon");
RegCloseKey(hKey); //RegCloseKey(hKey);
return false; return false;
} }
} }
@ -225,7 +275,7 @@ namespace Components
else else
{ {
////DBG("Error creating key SOFTWARE\\Classes\\iw3mp"); ////DBG("Error creating key SOFTWARE\\Classes\\iw3mp");
RegCloseKey(hKey); //RegCloseKey(hKey);
return false; return false;
} }
} }
@ -242,22 +292,37 @@ namespace Components
{ {
if (evaluated) return; if (evaluated) return;
evaluated = 1; evaluated = 1;
OutputDebugString("Evaluated = 1");
char* args = GetCommandLineA(); char* args = GetCommandLine();
OutputDebugString("GetCommandLine");
char* substr = strstr(args, "iw4x://"); char* substr = strstr(args, "iw4x://");
if (!substr || substr == args) if (!substr || substr == args)
{ {
OutputDebugString("substr==args");
OutputDebugString(substr);
OutputDebugString("substr==args");
OutputDebugString(args);
return; return;
} }
substr += 8; substr += 7;
char* substr2 = strstr(substr, "/"); char* substr2 = strstr(substr, "/");
if (substr2 != NULL)
{
*substr2 = 0; *substr2 = 0;
////DBG(("Connecting to: %s", substr)); }
else
{
OutputDebugString("substr2 = NULL");
return;
}
Command::Execute(Utils::VA("connect %s;", substr), false); ////DBG(("Connecting to: %s", substr));
OutputDebugString(Utils::VA("connect %s", substr));
Command::Execute(Utils::VA("connect %s;", substr), true);
} }
BOOL ConnectProtocol::InvokeConnect() BOOL ConnectProtocol::InvokeConnect()
@ -282,7 +347,15 @@ namespace Components
substr += 7; substr += 7;
char* substr2 = strstr(substr, "/"); char* substr2 = strstr(substr, "/");
if (substr2 != NULL)
{
*substr2 = 0; *substr2 = 0;
}
else
{
return false;
}
if (proc_id != 0) if (proc_id != 0)
{ {
@ -320,7 +393,9 @@ namespace Components
ConnectProtocol::ConnectProtocol() ConnectProtocol::ConnectProtocol()
{ {
OutputDebugString("Installing Protocol");
ConnectProtocol::InstallProtocol(); ConnectProtocol::InstallProtocol();
ConnectProtocol::EvaluateProtocol();
} }

View File

@ -6,7 +6,7 @@ namespace Components
ConnectProtocol(); ConnectProtocol();
const char* GetName() { return "ConnectProtocol"; }; const char* GetName() { return "ConnectProtocol"; };
void EvaluateProtocol(); static void EvaluateProtocol();
static BOOL InvokeConnect(); static BOOL InvokeConnect();
private: private: