now winsys actually works as a plugin

This commit is contained in:
Berke Viktor 2011-11-28 22:54:17 +01:00
parent 439c382d95
commit de88655853
2 changed files with 22 additions and 16 deletions

View File

@ -9,7 +9,7 @@ winsys.def:
echo xchat_plugin_deinit >> winsys.def
winsys.obj: winsys.cpp makefile.mak
cl $(CFLAGS) $(GLIB) /Zc:wchar_t- /I.. winsys.cpp
cl $(CFLAGS) $(GLIB) /DUNICODE /D_UNICODE /Zc:wchar_t- /I.. winsys.cpp
clean:
del *.obj

View File

@ -120,7 +120,7 @@ getOsName (void)
return winver;
}
#if 0
#if 0 /* x86-only, SDK-only, use WMI instead */
static char *
getCpuName (void)
{
@ -192,7 +192,7 @@ getMemoryInfo (void)
meminfo.dwLength = sizeof (meminfo);
GlobalMemoryStatusEx (&meminfo);
sprintf (buffer, "%I64d MB Total (%I64d MB Free)", meminfo.ullTotalPhys/1024/1024, meminfo.ullAvailPhys/1024/1024);
sprintf (buffer, "%lld MB Total (%lld MB Free)", meminfo.ullTotalPhys / 1024 / 1024, meminfo.ullAvailPhys / 1024 / 1024);
return buffer;
}
@ -207,7 +207,7 @@ getWmiInfo (int mode)
http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/d6420012-e432-4964-8506-6f6b65e5a451
*/
char buffer[128];
static char buffer[128];
HRESULT hres;
HRESULT hr;
IWbemLocator *pLoc = NULL;
@ -216,27 +216,30 @@ getWmiInfo (int mode)
IWbemClassObject *pclsObj;
ULONG uReturn = 0;
strcpy (buffer, "Unknown");
hres = CoInitializeEx (0, COINIT_MULTITHREADED);
hres = CoInitializeEx (0, COINIT_APARTMENTTHREADED | COINIT_SPEED_OVER_MEMORY);
if (FAILED (hres))
{
strcpy (buffer, "Error Code 0");
return buffer;
}
hres = CoInitializeSecurity (NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
if (FAILED (hres))
/* mysteriously failing after the first execution, but only when used as a plugin, skip it */
/*if (FAILED (hres))
{
CoUninitialize ();
strcpy (buffer, "Error Code 1");
return buffer;
}
}*/
hres = CoCreateInstance (CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
if (FAILED (hres))
{
CoUninitialize ();
strcpy (buffer, "Error Code 2");
return buffer;
}
@ -246,6 +249,7 @@ getWmiInfo (int mode)
{
pLoc->Release ();
CoUninitialize ();
strcpy (buffer, "Error Code 3");
return buffer;
}
@ -256,6 +260,7 @@ getWmiInfo (int mode)
pSvc->Release ();
pLoc->Release ();
CoUninitialize ();
strcpy (buffer, "Error Code 4");
return buffer;
}
@ -273,6 +278,7 @@ getWmiInfo (int mode)
pSvc->Release ();
pLoc->Release ();
CoUninitialize ();
strcpy (buffer, "Error Code 5");
return buffer;
}
@ -294,12 +300,11 @@ getWmiInfo (int mode)
pEnumerator->Release ();
pclsObj->Release ();
CoUninitialize ();
return buffer;
}
static int
printInfo()
printInfo (char *word[], char *word_eol[], void *user_data)
{
xchat_printf (ph, "OS:\t%s\n", getOsName ());
xchat_printf (ph, "CPU:\t%s (%s)\n", getWmiInfo (0), getCpuMhz ());
@ -319,7 +324,7 @@ xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugi
*plugin_desc = "Display info about your hardware and OS";
*plugin_version = "1.0";
xchat_hook_command (ph, "WINSYS", XCHAT_PRI_NORM, printInfo, 0, 0);
xchat_hook_command (ph, "WINSYS", XCHAT_PRI_NORM, printInfo, NULL, NULL);
xchat_command (ph, "MENU -ietc\\download.png ADD \"Window/Display System Info\" \"WINSYS\"");
xchat_printf (ph, "%s plugin loaded\n", *plugin_name);
@ -327,6 +332,7 @@ xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugi
return 1; /* return 1 for success */
}
int
xchat_plugin_deinit (void)
{