From 5f758e821af54b244dc9f5f60822f99028267121 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Mon, 28 Nov 2011 20:42:10 +0100 Subject: more winsys fixes and build as c++ --- plugins/winsys/winsys.cpp | 336 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 336 insertions(+) create mode 100644 plugins/winsys/winsys.cpp (limited to 'plugins/winsys/winsys.cpp') diff --git a/plugins/winsys/winsys.cpp b/plugins/winsys/winsys.cpp new file mode 100644 index 00000000..b3a77629 --- /dev/null +++ b/plugins/winsys/winsys.cpp @@ -0,0 +1,336 @@ +/* XChat-WDK + * Copyright (c) 2011 Berke Viktor. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include +#include +#include + +#include "xchat-plugin.h" + +static xchat_plugin *ph; /* plugin handle */ + +static char * +getOsName (void) +{ + static char winver[32]; + double mhz; + OSVERSIONINFOEX osvi; + SYSTEM_INFO si; + + osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX); + GetVersionEx ((LPOSVERSIONINFOW)&osvi); + + GetSystemInfo (&si); + + strcpy (winver, "Windows "); + + switch (osvi.dwMajorVersion) + { + case 5: + switch (osvi.dwMinorVersion) + { + case 1: + strcat (winver, "XP"); + break; + case 2: + if (osvi.wProductType == VER_NT_WORKSTATION) + { + strcat (winver, "XP x64 Edition"); + } + else + { + if (GetSystemMetrics(SM_SERVERR2) == 0) + { + strcat (winver, "Server 2003"); + } + else + { + strcat (winver, "Server 2003 R2"); + } + } + break; + } + break; + case 6: + switch (osvi.dwMinorVersion) + { + case 0: + if (osvi.wProductType == VER_NT_WORKSTATION) + { + strcat (winver, "Vista"); + } + else + { + strcat (winver, "Server 2008"); + } + break; + case 1: + if (osvi.wProductType == VER_NT_WORKSTATION) + { + strcat (winver, "7"); + } + else + { + strcat (winver, "Server 2008 R2"); + } + break; + case 2: + if (osvi.wProductType == VER_NT_WORKSTATION) + { + strcat (winver, "8"); + } + else + { + strcat (winver, "8 Server"); + } + break; + } + break; + } + + if (si.wProcessorArchitecture == 9) + { + strcat (winver, " (x64)"); + } + else + { + strcat (winver, " (x86)"); + } + + return winver; +} + +#if 0 +static char* +getCpuName (void) +{ + // Get extended ids. + unsigned int nExIds; + unsigned int i; + int CPUInfo[4] = {-1}; + static char CPUBrandString[128]; + + __cpuid (CPUInfo, 0x80000000); + nExIds = CPUInfo[0]; + + /* Get the information associated with each extended ID. */ + for (i=0x80000000; i <= nExIds; ++i) + { + __cpuid (CPUInfo, i); + + if (i == 0x80000002) + { + memcpy (CPUBrandString, CPUInfo, sizeof (CPUInfo)); + } + else if (i == 0x80000003) + { + memcpy( CPUBrandString + 16, CPUInfo, sizeof (CPUInfo)); + } + else if (i == 0x80000004) + { + memcpy (CPUBrandString + 32, CPUInfo, sizeof (CPUInfo)); + } + } + + return CPUBrandString; +} +#endif + +static char* +getCpuMhz (void) +{ + HKEY hKey; + int result; + int data; + int dataSize; + double cpuspeed; + static char buffer[16]; + const char *cpuspeedstr; + + if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, TEXT("Hardware\\Description\\System\\CentralProcessor\\0"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) + { + dataSize = sizeof (data); + result = RegQueryValueEx (hKey, TEXT("~MHz"), 0, 0, (LPBYTE)&data, (LPDWORD)&dataSize); + RegCloseKey (hKey); + if (result == ERROR_SUCCESS) + { + cpuspeed = ( data > 1000 ) ? data / 1000 : data; + cpuspeedstr = ( data > 1000 ) ? "GHz" : "MHz"; + sprintf (buffer, "%.2f %s", cpuspeed, cpuspeedstr); + } + } + + return buffer; +} + +static char* +getMemoryInfo (void) +{ + static char buffer[16]; + MEMORYSTATUSEX meminfo; + + meminfo.dwLength = sizeof (meminfo); + GlobalMemoryStatusEx (&meminfo); + + sprintf (buffer, "%I64d MB Total (%I64d MB Free)", meminfo.ullTotalPhys/1024/1024, meminfo.ullAvailPhys/1024/1024); + + return buffer; +} + +static char* +getWmiInfo (int mode) +{ + /* for more details about this wonderful API, see + http://msdn.microsoft.com/en-us/site/aa394138 + http://msdn.microsoft.com/en-us/site/aa390423 + http://msdn.microsoft.com/en-us/library/windows/desktop/aa394138%28v=vs.85%29.aspx + http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/d6420012-e432-4964-8506-6f6b65e5a451 + */ + + char buffer[128]; + HRESULT hres; + HRESULT hr; + IWbemLocator *pLoc = NULL; + IWbemServices *pSvc = NULL; + IEnumWbemClassObject *pEnumerator = NULL; + IWbemClassObject *pclsObj; + ULONG uReturn = 0; + + strcpy (buffer, "Unknown"); + hres = CoInitializeEx (0, COINIT_MULTITHREADED); + + if (FAILED (hres)) + { + 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)) + { + CoUninitialize (); + return buffer; + } + + hres = CoCreateInstance (CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc); + + if (FAILED (hres)) + { + CoUninitialize (); + return buffer; + } + + hres = pLoc->ConnectServer (_bstr_t (L"root\\CIMV2"), NULL, NULL, 0, NULL, 0, 0, &pSvc); + + if (FAILED (hres)) + { + pLoc->Release (); + CoUninitialize (); + return buffer; + } + + hres = CoSetProxyBlanket (pSvc, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE); + + if (FAILED (hres)) + { + pSvc->Release (); + pLoc->Release (); + CoUninitialize (); + return buffer; + } + + if (mode) + { + hres = pSvc->ExecQuery (_bstr_t ("WQL"), _bstr_t ("SELECT * FROM Win32_VideoController"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); + } + else + { + hres = pSvc->ExecQuery (_bstr_t ("WQL"), _bstr_t ("SELECT * FROM Win32_Processor"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); + } + + if (FAILED (hres)) + { + pSvc->Release (); + pLoc->Release (); + CoUninitialize (); + return buffer; + } + + while (pEnumerator) + { + hr = pEnumerator->Next (WBEM_INFINITE, 1, &pclsObj, &uReturn); + if (0 == uReturn) + { + break; + } + VARIANT vtProp; + hr = pclsObj->Get (L"Name", 0, &vtProp, 0, 0); + WideCharToMultiByte (CP_ACP, 0, vtProp.bstrVal, -1, buffer, SysStringLen (vtProp.bstrVal)+1, NULL, NULL); + VariantClear (&vtProp); + } + + pSvc->Release (); + pLoc->Release (); + pEnumerator->Release (); + pclsObj->Release (); + CoUninitialize (); + + return buffer; +} + +static int +printInfo() +{ + xchat_printf (ph, "OS:\t%s\n", getOsName ()); + xchat_printf (ph, "CPU:\t%s (%s)\n", getWmiInfo (0), getCpuMhz ()); + xchat_printf (ph, "RAM:\t%s\n", getMemoryInfo ()); + xchat_printf (ph, "VGA:\t%s\n", getWmiInfo (1)); + /* will work correctly for up to 50 days, should be enough */ + xchat_printf (ph, "Uptime:\t%.2f Hours\n", (float) GetTickCount() / 1000 / 60 / 60); + return XCHAT_EAT_XCHAT; +} + +int +xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg) +{ + ph = plugin_handle; + + *plugin_name = "WinSys"; + *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_command (ph, "MENU -ietc\\download.png ADD \"Window/Display System Info\" \"WINSYS\""); + + xchat_printf (ph, "%s plugin loaded\n", *plugin_name); + + return 1; /* return 1 for success */ +} + +int +xchat_plugin_deinit (void) +{ + xchat_command (ph, "MENU DEL \"Window/Display System Info\""); + xchat_print (ph, "WinSys plugin unloaded\n"); + return 1; +} -- cgit 1.4.1 From de8865585304a2d78874e0e42ba69bb25d9d5565 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Mon, 28 Nov 2011 22:54:17 +0100 Subject: now winsys actually works as a plugin --- plugins/winsys/makefile.mak | 2 +- plugins/winsys/winsys.cpp | 36 +++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 16 deletions(-) (limited to 'plugins/winsys/winsys.cpp') diff --git a/plugins/winsys/makefile.mak b/plugins/winsys/makefile.mak index cb480ac0..31f24eb1 100644 --- a/plugins/winsys/makefile.mak +++ b/plugins/winsys/makefile.mak @@ -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 diff --git a/plugins/winsys/winsys.cpp b/plugins/winsys/winsys.cpp index b3a77629..54f4641d 100644 --- a/plugins/winsys/winsys.cpp +++ b/plugins/winsys/winsys.cpp @@ -38,7 +38,7 @@ getOsName (void) SYSTEM_INFO si; osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX); - GetVersionEx ((LPOSVERSIONINFOW)&osvi); + GetVersionEx ((LPOSVERSIONINFOW) &osvi); GetSystemInfo (&si); @@ -120,8 +120,8 @@ getOsName (void) return winver; } -#if 0 -static char* +#if 0 /* x86-only, SDK-only, use WMI instead */ +static char * getCpuName (void) { // Get extended ids. @@ -156,7 +156,7 @@ getCpuName (void) } #endif -static char* +static char * getCpuMhz (void) { HKEY hKey; @@ -183,7 +183,7 @@ getCpuMhz (void) return buffer; } -static char* +static char * getMemoryInfo (void) { static char buffer[16]; @@ -192,12 +192,12 @@ 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; } -static char* +static char * getWmiInfo (int mode) { /* for more details about this wonderful API, see @@ -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) { -- cgit 1.4.1 From 687203adbbb962f79780586dcf601622b6e4a3ec Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Mon, 28 Nov 2011 23:11:43 +0100 Subject: fix winsys freeze --- plugins/winsys/winsys.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/winsys/winsys.cpp') diff --git a/plugins/winsys/winsys.cpp b/plugins/winsys/winsys.cpp index 54f4641d..299b8f87 100644 --- a/plugins/winsys/winsys.cpp +++ b/plugins/winsys/winsys.cpp @@ -186,7 +186,7 @@ getCpuMhz (void) static char * getMemoryInfo (void) { - static char buffer[16]; + static char buffer[32]; MEMORYSTATUSEX meminfo; meminfo.dwLength = sizeof (meminfo); -- cgit 1.4.1 From d010c4ff1b0b8afcac0d61e24af2276aa9f8f0e7 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Mon, 28 Nov 2011 23:41:17 +0100 Subject: MSVC-style print --- plugins/winsys/winsys.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/winsys/winsys.cpp') diff --git a/plugins/winsys/winsys.cpp b/plugins/winsys/winsys.cpp index 299b8f87..b6d27f45 100644 --- a/plugins/winsys/winsys.cpp +++ b/plugins/winsys/winsys.cpp @@ -192,7 +192,7 @@ getMemoryInfo (void) meminfo.dwLength = sizeof (meminfo); GlobalMemoryStatusEx (&meminfo); - sprintf (buffer, "%lld MB Total (%lld MB Free)", meminfo.ullTotalPhys / 1024 / 1024, meminfo.ullAvailPhys / 1024 / 1024); + sprintf (buffer, "%I64d MB Total (%I64d MB Free)", meminfo.ullTotalPhys / 1024 / 1024, meminfo.ullAvailPhys / 1024 / 1024); return buffer; } -- cgit 1.4.1 From 6f019e63f13085d1c5f0133a4e2f31a0a365eb77 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Tue, 29 Nov 2011 01:10:57 +0100 Subject: winsys cosmetics and extensions --- plugins/winsys/winsys.cpp | 78 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 14 deletions(-) (limited to 'plugins/winsys/winsys.cpp') diff --git a/plugins/winsys/winsys.cpp b/plugins/winsys/winsys.cpp index b6d27f45..08e5d809 100644 --- a/plugins/winsys/winsys.cpp +++ b/plugins/winsys/winsys.cpp @@ -29,6 +29,29 @@ static xchat_plugin *ph; /* plugin handle */ +static int +getCpuArch (void) +{ + OSVERSIONINFOEX osvi; + SYSTEM_INFO si; + + osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX); + GetVersionEx ((LPOSVERSIONINFOW) &osvi); + + GetSystemInfo (&si); + + if (si.wProcessorArchitecture == 9) + { + return 64; + } + else + { + return 86; + } +} + +#if 0 +/* use WMI instead, wProcessorArchitecture displays current binary arch instead OS arch anyway */ static char * getOsName (void) { @@ -120,7 +143,7 @@ getOsName (void) return winver; } -#if 0 /* x86-only, SDK-only, use WMI instead */ +/* x86-only, SDK-only, use WMI instead */ static char * getCpuName (void) { @@ -264,13 +287,18 @@ getWmiInfo (int mode) return buffer; } - if (mode) - { - hres = pSvc->ExecQuery (_bstr_t ("WQL"), _bstr_t ("SELECT * FROM Win32_VideoController"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); - } - else + switch (mode) { - hres = pSvc->ExecQuery (_bstr_t ("WQL"), _bstr_t ("SELECT * FROM Win32_Processor"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); + case 0: + hres = pSvc->ExecQuery (_bstr_t ("WQL"), _bstr_t ("SELECT * FROM Win32_OperatingSystem"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); + break; + case 1: + hres = pSvc->ExecQuery (_bstr_t ("WQL"), _bstr_t ("SELECT * FROM Win32_Processor"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); + break; + case 2: + hres = pSvc->ExecQuery (_bstr_t ("WQL"), _bstr_t ("SELECT * FROM Win32_VideoController"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); + break; + } if (FAILED (hres)) @@ -290,7 +318,18 @@ getWmiInfo (int mode) break; } VARIANT vtProp; - hr = pclsObj->Get (L"Name", 0, &vtProp, 0, 0); + switch (mode) + { + case 0: + hr = pclsObj->Get (L"Caption", 0, &vtProp, 0, 0); + break; + case 1: + hr = pclsObj->Get (L"Name", 0, &vtProp, 0, 0); + break; + case 2: + hr = pclsObj->Get (L"Name", 0, &vtProp, 0, 0); + break; + } WideCharToMultiByte (CP_ACP, 0, vtProp.bstrVal, -1, buffer, SysStringLen (vtProp.bstrVal)+1, NULL, NULL); VariantClear (&vtProp); } @@ -306,12 +345,23 @@ getWmiInfo (int mode) static int 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 ()); - xchat_printf (ph, "RAM:\t%s\n", getMemoryInfo ()); - xchat_printf (ph, "VGA:\t%s\n", getWmiInfo (1)); - /* will work correctly for up to 50 days, should be enough */ - xchat_printf (ph, "Uptime:\t%.2f Hours\n", (float) GetTickCount() / 1000 / 60 / 60); + if (xchat_list_int (ph, NULL, "type") >= 2) + { + /* xchat_commandf (ph, "ME * WinSys - system details *"); + xchat_commandf (ph, "ME ***************************"); */ + xchat_commandf (ph, "ME * Client: XChat-WDK %s (x%d)", xchat_get_info (ph, "wdk_version"), getCpuArch ()); + xchat_commandf (ph, "ME * OS: %s", getWmiInfo (0)); + xchat_commandf (ph, "ME * CPU: %s (%s)", getWmiInfo (1), getCpuMhz ()); + xchat_commandf (ph, "ME * RAM: %s", getMemoryInfo ()); + xchat_commandf (ph, "ME * VGA: %s", getWmiInfo (2)); + /* will work correctly for up to 50 days, should be enough */ + xchat_commandf (ph, "ME * Uptime: %.2f Hours", (float) GetTickCount() / 1000 / 60 / 60); + } + else + { + /* print standard error message */ + xchat_printf (ph, "No channel joined. Try /join #"); + } return XCHAT_EAT_XCHAT; } -- cgit 1.4.1 From 7b0555e380ca92285925d18c1045f28f9298bfd6 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Tue, 29 Nov 2011 03:58:20 +0100 Subject: own icon for winsys --- build/etc/system.png | Bin 0 -> 3578 bytes plugins/winsys/winsys.cpp | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 build/etc/system.png (limited to 'plugins/winsys/winsys.cpp') diff --git a/build/etc/system.png b/build/etc/system.png new file mode 100644 index 00000000..fc4282c7 Binary files /dev/null and b/build/etc/system.png differ diff --git a/plugins/winsys/winsys.cpp b/plugins/winsys/winsys.cpp index 08e5d809..a3fa94f9 100644 --- a/plugins/winsys/winsys.cpp +++ b/plugins/winsys/winsys.cpp @@ -375,7 +375,7 @@ xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugi *plugin_version = "1.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_command (ph, "MENU -ietc\\system.png ADD \"Window/Display System Info\" \"WINSYS\""); xchat_printf (ph, "%s plugin loaded\n", *plugin_name); -- cgit 1.4.1 From b5934a75b338f72c34ebf3e8e31cee57dd34d697 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Tue, 29 Nov 2011 04:05:54 +0100 Subject: display sysinfo for self when not in channel/dialog --- plugins/winsys/winsys.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'plugins/winsys/winsys.cpp') diff --git a/plugins/winsys/winsys.cpp b/plugins/winsys/winsys.cpp index a3fa94f9..f8d74e2b 100644 --- a/plugins/winsys/winsys.cpp +++ b/plugins/winsys/winsys.cpp @@ -359,9 +359,14 @@ printInfo (char *word[], char *word_eol[], void *user_data) } else { - /* print standard error message */ - xchat_printf (ph, "No channel joined. Try /join #"); + xchat_printf (ph, " * Client: XChat-WDK %s (x%d)\n", xchat_get_info (ph, "wdk_version"), getCpuArch ()); + xchat_printf (ph, " * OS: %s\n", getWmiInfo (0)); + xchat_printf (ph, " * CPU: %s (%s)\n", getWmiInfo (1), getCpuMhz ()); + xchat_printf (ph, " * RAM: %s\n", getMemoryInfo ()); + xchat_printf (ph, " * VGA: %s\n", getWmiInfo (2)); + xchat_printf (ph, " * Uptime: %.2f Hours\n", (float) GetTickCount() / 1000 / 60 / 60); } + return XCHAT_EAT_XCHAT; } -- cgit 1.4.1 From e2f7e4f091465f8f6d9fbcbf320b470e0e32e6c1 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Thu, 1 Dec 2011 23:01:52 +0100 Subject: speed up winsys executions --- plugins/winsys/winsys.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'plugins/winsys/winsys.cpp') diff --git a/plugins/winsys/winsys.cpp b/plugins/winsys/winsys.cpp index f8d74e2b..2f68f75b 100644 --- a/plugins/winsys/winsys.cpp +++ b/plugins/winsys/winsys.cpp @@ -28,6 +28,10 @@ #include "xchat-plugin.h" static xchat_plugin *ph; /* plugin handle */ +static int firstRun; +static char *wmiOs; +static char *wmiCpu; +static char *wmiVga; static int getCpuArch (void) @@ -230,7 +234,7 @@ getWmiInfo (int mode) http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/d6420012-e432-4964-8506-6f6b65e5a451 */ - static char buffer[128]; + char *buffer = (char *) malloc (128); HRESULT hres; HRESULT hr; IWbemLocator *pLoc = NULL; @@ -345,25 +349,34 @@ getWmiInfo (int mode) static int printInfo (char *word[], char *word_eol[], void *user_data) { + /* query WMI info only at the first time WinSys is called, then cache it to save time */ + if (firstRun) + { + xchat_printf (ph, "WinSys first execution, querying and caching WMI info...\n"); + wmiOs = getWmiInfo (0); + wmiCpu = getWmiInfo (1); + wmiVga = getWmiInfo (2); + firstRun = 0; + } if (xchat_list_int (ph, NULL, "type") >= 2) { /* xchat_commandf (ph, "ME * WinSys - system details *"); xchat_commandf (ph, "ME ***************************"); */ xchat_commandf (ph, "ME * Client: XChat-WDK %s (x%d)", xchat_get_info (ph, "wdk_version"), getCpuArch ()); - xchat_commandf (ph, "ME * OS: %s", getWmiInfo (0)); - xchat_commandf (ph, "ME * CPU: %s (%s)", getWmiInfo (1), getCpuMhz ()); + xchat_commandf (ph, "ME * OS: %s", wmiOs); + xchat_commandf (ph, "ME * CPU: %s (%s)", wmiCpu, getCpuMhz ()); xchat_commandf (ph, "ME * RAM: %s", getMemoryInfo ()); - xchat_commandf (ph, "ME * VGA: %s", getWmiInfo (2)); + xchat_commandf (ph, "ME * VGA: %s", wmiVga); /* will work correctly for up to 50 days, should be enough */ xchat_commandf (ph, "ME * Uptime: %.2f Hours", (float) GetTickCount() / 1000 / 60 / 60); } else { xchat_printf (ph, " * Client: XChat-WDK %s (x%d)\n", xchat_get_info (ph, "wdk_version"), getCpuArch ()); - xchat_printf (ph, " * OS: %s\n", getWmiInfo (0)); - xchat_printf (ph, " * CPU: %s (%s)\n", getWmiInfo (1), getCpuMhz ()); + xchat_printf (ph, " * OS: %s\n", wmiOs); + xchat_printf (ph, " * CPU: %s (%s)\n", wmiCpu, getCpuMhz ()); xchat_printf (ph, " * RAM: %s\n", getMemoryInfo ()); - xchat_printf (ph, " * VGA: %s\n", getWmiInfo (2)); + xchat_printf (ph, " * VGA: %s\n", wmiVga); xchat_printf (ph, " * Uptime: %.2f Hours\n", (float) GetTickCount() / 1000 / 60 / 60); } @@ -379,6 +392,8 @@ 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"; + firstRun = 1; + xchat_hook_command (ph, "WINSYS", XCHAT_PRI_NORM, printInfo, NULL, NULL); xchat_command (ph, "MENU -ietc\\system.png ADD \"Window/Display System Info\" \"WINSYS\""); -- cgit 1.4.1 From e2acf19d42b874eecd1b142a0e1192721fb295f5 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Fri, 2 Dec 2011 01:05:59 +0100 Subject: don't use hardcoded strings for plugin names --- plugins/checksum/checksum.c | 13 ++++++++----- plugins/exec/exec.c | 13 ++++++++----- plugins/upd/upd.c | 13 ++++++++----- plugins/winsys/winsys.cpp | 15 +++++++++------ 4 files changed, 33 insertions(+), 21 deletions(-) (limited to 'plugins/winsys/winsys.cpp') diff --git a/plugins/checksum/checksum.c b/plugins/checksum/checksum.c index 12fc0d93..103a80ca 100644 --- a/plugins/checksum/checksum.c +++ b/plugins/checksum/checksum.c @@ -42,6 +42,9 @@ #endif static xchat_plugin *ph; /* plugin handle */ +static const char name[] = "Checksum"; +static const char desc[] = "Calculate checksum for DCC file transfers"; +static const char version[] = "2.0"; static int config_fail; /* variable for config availability */ /* Use of OpenSSL SHA256 interface: http://adamlamers.com/?p=5 */ @@ -324,9 +327,9 @@ xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugi { ph = plugin_handle; - *plugin_name = "Checksum"; - *plugin_desc = "Calculate checksum for DCC file transfers"; - *plugin_version = "2.0"; + *plugin_name = name; + *plugin_desc = desc; + *plugin_version = version; init (); @@ -334,13 +337,13 @@ xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugi xchat_hook_print (ph, "DCC RECV Complete", XCHAT_PRI_NORM, dccrecv_cb, NULL); xchat_hook_print (ph, "DCC Offer", XCHAT_PRI_NORM, dccoffer_cb, NULL); - xchat_print (ph, "Checksum plugin loaded\n"); + xchat_printf (ph, "%s plugin loaded\n", name); return 1; } int xchat_plugin_deinit (void) { - xchat_print (ph, "Checksum plugin unloaded\n"); + xchat_printf (ph, "%s plugin unloaded\n", name); return 1; } diff --git a/plugins/exec/exec.c b/plugins/exec/exec.c index b043ae83..fc8c8ec9 100644 --- a/plugins/exec/exec.c +++ b/plugins/exec/exec.c @@ -26,6 +26,9 @@ #include "xchat-plugin.h" static xchat_plugin *ph; /* plugin handle */ +static const char name[] = "Exec"; +static const char desc[] = "Execute commands inside XChat"; +static const char version[] = "1.0"; static int run_command (char *word[], char *word_eol[], void *userdata) @@ -107,12 +110,12 @@ xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugi { ph = plugin_handle; - *plugin_name = "Exec"; - *plugin_desc = "Execute commands inside XChat"; - *plugin_version = "1.0"; + *plugin_name = name; + *plugin_desc = desc; + *plugin_version = version; xchat_hook_command (ph, "EXEC", XCHAT_PRI_NORM, run_command, 0, 0); - xchat_printf (ph, "%s plugin loaded\n", *plugin_name); + xchat_printf (ph, "%s plugin loaded\n", name); return 1; /* return 1 for success */ } @@ -120,6 +123,6 @@ xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugi int xchat_plugin_deinit (void) { - xchat_print (ph, "Exec plugin unloaded\n"); + xchat_print (ph, "%s plugin unloaded\n", name); return 1; } diff --git a/plugins/upd/upd.c b/plugins/upd/upd.c index 3eec06dc..7ab5edca 100644 --- a/plugins/upd/upd.c +++ b/plugins/upd/upd.c @@ -26,6 +26,9 @@ #include "xchat-plugin.h" static xchat_plugin *ph; /* plugin handle */ +static const char name[] = "Update Checker"; +static const char desc[] = "Check for XChat-WDK updates automatically"; +static const char version[] = "2.0"; /* we need this to store the result of the initial update check since the return value is preserved for XCHAT_EAT */ static int update_available; @@ -117,14 +120,14 @@ xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugi { ph = plugin_handle; - *plugin_name = "Update Checker"; - *plugin_desc = "Plugin for checking for XChat-WDK updates"; - *plugin_version = "2.0"; + *plugin_name = name; + *plugin_desc = desc; + *plugin_version = version; xchat_hook_command (ph, "UPDCHK", XCHAT_PRI_NORM, print_version, 0, 0); xchat_command (ph, "MENU -ietc\\download.png ADD \"Help/Check for Updates\" \"UPDCHK\""); - xchat_printf (ph, "%s plugin loaded\n", *plugin_name); + xchat_printf (ph, "%s plugin loaded\n", name); /* only start the timer if there's no update available during startup */ if (!update_available) @@ -140,6 +143,6 @@ int xchat_plugin_deinit (void) { xchat_command (ph, "MENU DEL \"Help/Check for updates\""); - xchat_print (ph, "Update Checker plugin unloaded\n"); + xchat_printf (ph, "%s plugin unloaded\n", name); return 1; } diff --git a/plugins/winsys/winsys.cpp b/plugins/winsys/winsys.cpp index 2f68f75b..55a5ddaf 100644 --- a/plugins/winsys/winsys.cpp +++ b/plugins/winsys/winsys.cpp @@ -28,6 +28,9 @@ #include "xchat-plugin.h" static xchat_plugin *ph; /* plugin handle */ +static const char name[] = "WinSys"; +static const char desc[] = "Display info about your hardware and OS"; +static const char version[] = "1.0"; static int firstRun; static char *wmiOs; static char *wmiCpu; @@ -352,7 +355,7 @@ printInfo (char *word[], char *word_eol[], void *user_data) /* query WMI info only at the first time WinSys is called, then cache it to save time */ if (firstRun) { - xchat_printf (ph, "WinSys first execution, querying and caching WMI info...\n"); + xchat_printf (ph, "%s first execution, querying and caching WMI info...\n", name); wmiOs = getWmiInfo (0); wmiCpu = getWmiInfo (1); wmiVga = getWmiInfo (2); @@ -388,16 +391,16 @@ xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugi { ph = plugin_handle; - *plugin_name = "WinSys"; - *plugin_desc = "Display info about your hardware and OS"; - *plugin_version = "1.0"; + *plugin_name = name; + *plugin_desc = desc; + *plugin_version = version; firstRun = 1; xchat_hook_command (ph, "WINSYS", XCHAT_PRI_NORM, printInfo, NULL, NULL); xchat_command (ph, "MENU -ietc\\system.png ADD \"Window/Display System Info\" \"WINSYS\""); - xchat_printf (ph, "%s plugin loaded\n", *plugin_name); + xchat_printf (ph, "%s plugin loaded\n", name); return 1; /* return 1 for success */ } @@ -407,6 +410,6 @@ int xchat_plugin_deinit (void) { xchat_command (ph, "MENU DEL \"Window/Display System Info\""); - xchat_print (ph, "WinSys plugin unloaded\n"); + xchat_printf (ph, "%s plugin unloaded\n", name); return 1; } -- cgit 1.4.1 From 1fe5dfae7f27053a286edc597695873618977f17 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Fri, 2 Dec 2011 01:09:52 +0100 Subject: apparently this is not allowed in C++ --- plugins/winsys/winsys.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'plugins/winsys/winsys.cpp') diff --git a/plugins/winsys/winsys.cpp b/plugins/winsys/winsys.cpp index 55a5ddaf..68c47016 100644 --- a/plugins/winsys/winsys.cpp +++ b/plugins/winsys/winsys.cpp @@ -28,9 +28,9 @@ #include "xchat-plugin.h" static xchat_plugin *ph; /* plugin handle */ -static const char name[] = "WinSys"; -static const char desc[] = "Display info about your hardware and OS"; -static const char version[] = "1.0"; +static char name[] = "WinSys"; +static char desc[] = "Display info about your hardware and OS"; +static char version[] = "1.0"; static int firstRun; static char *wmiOs; static char *wmiCpu; -- cgit 1.4.1 From a2f84209c0a9dc0030a7d2a1e67ca81b319334bb Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Sat, 3 Dec 2011 18:52:13 +0100 Subject: print system info in one line for others --- plugins/winsys/winsys.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'plugins/winsys/winsys.cpp') diff --git a/plugins/winsys/winsys.cpp b/plugins/winsys/winsys.cpp index 68c47016..2c1c7f83 100644 --- a/plugins/winsys/winsys.cpp +++ b/plugins/winsys/winsys.cpp @@ -363,15 +363,15 @@ printInfo (char *word[], char *word_eol[], void *user_data) } if (xchat_list_int (ph, NULL, "type") >= 2) { - /* xchat_commandf (ph, "ME * WinSys - system details *"); - xchat_commandf (ph, "ME ***************************"); */ - xchat_commandf (ph, "ME * Client: XChat-WDK %s (x%d)", xchat_get_info (ph, "wdk_version"), getCpuArch ()); - xchat_commandf (ph, "ME * OS: %s", wmiOs); - xchat_commandf (ph, "ME * CPU: %s (%s)", wmiCpu, getCpuMhz ()); - xchat_commandf (ph, "ME * RAM: %s", getMemoryInfo ()); - xchat_commandf (ph, "ME * VGA: %s", wmiVga); - /* will work correctly for up to 50 days, should be enough */ - xchat_commandf (ph, "ME * Uptime: %.2f Hours", (float) GetTickCount() / 1000 / 60 / 60); + /* uptime will work correctly for up to 50 days, should be enough */ + xchat_commandf (ph, "ME ** Client: XChat-WDK %s (x%d) ** OS: %s ** CPU: %s (%s) ** RAM: %s ** VGA: %s ** Uptime: %.2f Hours **", + xchat_get_info (ph, "wdk_version"), + getCpuArch (), + wmiOs, + wmiCpu, + getCpuMhz (), + getMemoryInfo (), + wmiVga, (float) GetTickCount() / 1000 / 60 / 60); } else { -- cgit 1.4.1 From 4a127d0bb4c3a265c7ffef9bdbd449aac8311c8a Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Sat, 3 Dec 2011 18:59:43 +0100 Subject: add some branding to winsys output --- plugins/winsys/winsys.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/winsys/winsys.cpp') diff --git a/plugins/winsys/winsys.cpp b/plugins/winsys/winsys.cpp index 2c1c7f83..0b4aef1e 100644 --- a/plugins/winsys/winsys.cpp +++ b/plugins/winsys/winsys.cpp @@ -364,7 +364,7 @@ printInfo (char *word[], char *word_eol[], void *user_data) if (xchat_list_int (ph, NULL, "type") >= 2) { /* uptime will work correctly for up to 50 days, should be enough */ - xchat_commandf (ph, "ME ** Client: XChat-WDK %s (x%d) ** OS: %s ** CPU: %s (%s) ** RAM: %s ** VGA: %s ** Uptime: %.2f Hours **", + xchat_commandf (ph, "ME ** WinSys ** Client: XChat-WDK %s (x%d) ** OS: %s ** CPU: %s (%s) ** RAM: %s ** VGA: %s ** Uptime: %.2f Hours **", xchat_get_info (ph, "wdk_version"), getCpuArch (), wmiOs, -- cgit 1.4.1 From 370cb88c44193f6c3e53765511463da3b70f141f Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Tue, 6 Dec 2011 02:35:00 +0100 Subject: typofix --- plugins/winsys/winsys.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/winsys/winsys.cpp') diff --git a/plugins/winsys/winsys.cpp b/plugins/winsys/winsys.cpp index 0b4aef1e..1a58f26a 100644 --- a/plugins/winsys/winsys.cpp +++ b/plugins/winsys/winsys.cpp @@ -58,7 +58,7 @@ getCpuArch (void) } #if 0 -/* use WMI instead, wProcessorArchitecture displays current binary arch instead OS arch anyway */ +/* use WMI instead, wProcessorArchitecture displays current binary arch instead of OS arch anyway */ static char * getOsName (void) { -- cgit 1.4.1 From 1b84f0467a169e2b20018dce0787973a0ba52273 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Tue, 6 Dec 2011 02:36:26 +0100 Subject: forgot to bump version --- plugins/winsys/winsys.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/winsys/winsys.cpp') diff --git a/plugins/winsys/winsys.cpp b/plugins/winsys/winsys.cpp index 1a58f26a..398767d0 100644 --- a/plugins/winsys/winsys.cpp +++ b/plugins/winsys/winsys.cpp @@ -30,7 +30,7 @@ static xchat_plugin *ph; /* plugin handle */ static char name[] = "WinSys"; static char desc[] = "Display info about your hardware and OS"; -static char version[] = "1.0"; +static char version[] = "1.1"; static int firstRun; static char *wmiOs; static char *wmiCpu; -- cgit 1.4.1