Author: gedmurphy
Date: Thu Aug 23 18:57:44 2007
New Revision: 28472
URL:
http://svn.reactos.org/svn/reactos?rev=28472&view=rev
Log:
simplify some code
Added:
trunk/reactos/base/applications/mscutils/servman/reg.c
Modified:
trunk/reactos/base/applications/mscutils/servman/mainwnd.c
trunk/reactos/base/applications/mscutils/servman/precomp.h
trunk/reactos/base/applications/mscutils/servman/propsheet.c
trunk/reactos/base/applications/mscutils/servman/query.c
Modified: trunk/reactos/base/applications/mscutils/servman/mainwnd.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/mainwnd.c (original)
+++ trunk/reactos/base/applications/mscutils/servman/mainwnd.c Thu Aug 23 18:57:44 2007
@@ -304,6 +304,58 @@
}
+static VOID
+InitListViewImage(PMAIN_WND_INFO Info)
+{
+ HICON hSmIconItem, hLgIconItem; /* icon for list-view items */
+ HIMAGELIST hSmall, hLarge; /* image list for other views */
+
+
+ /* Create the icon image lists */
+ hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
+ GetSystemMetrics(SM_CYSMICON),
+ ILC_MASK | ILC_COLOR32,
+ 1,
+ 1);
+
+ hLarge = ImageList_Create(GetSystemMetrics(SM_CXICON),
+ GetSystemMetrics(SM_CYICON),
+ ILC_MASK | ILC_COLOR32,
+ 1,
+ 1);
+
+ /* Add an icon to each image list */
+ hSmIconItem = LoadImage(hInstance,
+ MAKEINTRESOURCE(IDI_SM_ICON),
+ IMAGE_ICON,
+ 16,
+ 16,
+ 0);
+
+ ImageList_AddIcon(hSmall,
+ hSmIconItem);
+
+ hLgIconItem = LoadImage(hInstance,
+ MAKEINTRESOURCE(IDI_SM_ICON),
+ IMAGE_ICON,
+ 32,
+ 32,
+ 0);
+
+ ImageList_AddIcon(hLarge,
+ hLgIconItem);
+
+ /* assign the image to the list view */
+ (void)ListView_SetImageList(Info->hListView,
+ hSmall,
+ LVSIL_SMALL);
+ (void)ListView_SetImageList(Info->hListView,
+ hLarge,
+ LVSIL_NORMAL);
+
+}
+
+
static BOOL
CreateListView(PMAIN_WND_INFO Info)
{
@@ -396,6 +448,8 @@
(void)ListView_InsertColumn(Info->hListView,
4,
&lvc);
+
+ InitListViewImage(Info);
/* check the details view menu item */
CheckMenuRadioItem(GetMenu(Info->hMainWnd),
Modified: trunk/reactos/base/applications/mscutils/servman/precomp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/precomp.h (original)
+++ trunk/reactos/base/applications/mscutils/servman/precomp.h Thu Aug 23 18:57:44 2007
@@ -59,7 +59,7 @@
struct _PROP_DLG_INFO *PropSheet;
/* status flags */
- BOOL InMenuLoop : 1;
+ BOOL InMenuLoop;
} MAIN_WND_INFO, *PMAIN_WND_INFO;
@@ -97,8 +97,8 @@
/* query.c */
ENUM_SERVICE_STATUS_PROCESS* GetSelectedService(PMAIN_WND_INFO Info);
BOOL SetDescription(LPTSTR, LPTSTR);
-BOOL GetDescription(LPTSTR, LPTSTR *);
-BOOL GetExecutablePath(PMAIN_WND_INFO Info, LPTSTR *);
+LPTSTR GetDescription(LPTSTR);
+LPTSTR GetExecutablePath(PMAIN_WND_INFO Info);
BOOL RefreshServiceList(PMAIN_WND_INFO Info);
DWORD GetServiceList(PMAIN_WND_INFO Info);
Modified: trunk/reactos/base/applications/mscutils/servman/propsheet.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/propsheet.c (original)
+++ trunk/reactos/base/applications/mscutils/servman/propsheet.c Thu Aug 23 18:57:44 2007
@@ -125,20 +125,24 @@
(LPARAM)Info->PropSheet->lpDisplayName);
/* set the description */
- if (GetDescription(Info->CurrentService->lpServiceName,
&Info->PropSheet->lpDescription))
+ if (Info->PropSheet->lpDescription =
GetDescription(Info->CurrentService->lpServiceName))
+ {
SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
IDC_DESCRIPTION,
WM_SETTEXT,
0,
(LPARAM)Info->PropSheet->lpDescription);
+ }
/* set the executable path */
- if (GetExecutablePath(Info, &Info->PropSheet->lpPathToExe))
+ if (Info->PropSheet->lpPathToExe = GetExecutablePath(Info))
+ {
SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
IDC_EXEPATH,
WM_SETTEXT,
0,
(LPARAM)Info->PropSheet->lpPathToExe);
+ }
/* set startup type */
SetStartupType(Info);
@@ -182,8 +186,8 @@
static INT_PTR CALLBACK
GeneralPageProc(HWND hwndDlg,
UINT uMsg,
- WPARAM wParam,
- LPARAM lParam)
+ WPARAM wParam,
+ LPARAM lParam)
{
PMAIN_WND_INFO Info;
@@ -247,6 +251,16 @@
break;
case WM_DESTROY:
+ if (Info->PropSheet->lpDescription)
+ HeapFree(ProcessHeap,
+ 0,
+ Info->PropSheet->lpDescription);
+
+ if (Info->PropSheet->lpPathToExe)
+ HeapFree(ProcessHeap,
+ 0,
+ Info->PropSheet->lpPathToExe);
+
break;
case WM_NOTIFY:
Modified: trunk/reactos/base/applications/mscutils/servman/query.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/query.c (original)
+++ trunk/reactos/base/applications/mscutils/servman/query.c Thu Aug 23 18:57:44 2007
@@ -27,115 +27,16 @@
}
-/* Sets the service description in the registry */
-BOOL SetDescription(LPTSTR ServiceName, LPTSTR Description)
-{
- HKEY hKey;
- LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
- TCHAR buf[300];
- TCHAR szBuf[MAX_PATH];
- LONG val;
-
-
- /* open the registry key for the service */
- _sntprintf(buf, sizeof(buf) / sizeof(TCHAR), Path, ServiceName);
- RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- buf,
- 0,
- KEY_WRITE,
- &hKey);
-
-
- if ((val = RegSetValueEx(hKey,
- _T("Description"),
- 0,
- REG_SZ,
- (LPBYTE)Description,
- (DWORD)lstrlen(szBuf)+1)) != ERROR_SUCCESS)
- {
- //GetError(val);
- return FALSE;
- }
-
-
- RegCloseKey(hKey);
- return TRUE;
-}
-
-
-
-/* Retrives the service description from the registry */
-BOOL GetDescription(LPTSTR lpServiceName, LPTSTR *retDescription)
-{
- HKEY hKey;
- LPTSTR Description = NULL;
- DWORD dwValueSize = 0;
- LONG ret;
- LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
- TCHAR buf[300];
-
- /* open the registry key for the service */
- _sntprintf(buf, sizeof(buf) / sizeof(TCHAR), Path, lpServiceName);
- RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- buf,
- 0,
- KEY_READ,
- &hKey);
-
- ret = RegQueryValueEx(hKey,
- _T("Description"),
- NULL,
- NULL,
- NULL,
- &dwValueSize);
- if (ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND && ret !=
ERROR_INVALID_HANDLE)
- {
- RegCloseKey(hKey);
- return FALSE;
- }
-
- if (ret != ERROR_FILE_NOT_FOUND)
- {
- Description = HeapAlloc(ProcessHeap,
- HEAP_ZERO_MEMORY,
- dwValueSize);
- if (Description == NULL)
- {
- RegCloseKey(hKey);
- return FALSE;
- }
-
- if(RegQueryValueEx(hKey,
- _T("Description"),
- NULL,
- NULL,
- (LPBYTE)Description,
- &dwValueSize))
- {
- HeapFree(ProcessHeap,
- 0,
- Description);
- RegCloseKey(hKey);
- return FALSE;
- }
- }
-
- /* copy pointer over */
- *retDescription = Description;
-
- return TRUE;
-}
-
/* get vendor of service binary */
-BOOL
-GetExecutablePath(PMAIN_WND_INFO Info,
- LPTSTR *ExePath)
+LPTSTR
+GetExecutablePath(PMAIN_WND_INFO Info)
{
SC_HANDLE hSCManager = NULL;
SC_HANDLE hSc = NULL;
LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;
DWORD BytesNeeded = 0;
+ LPTSTR lpExePath = NULL;
/* open handle to the SCM */
hSCManager = OpenSCManager(NULL,
@@ -157,7 +58,6 @@
goto cleanup;
}
-
if (!QueryServiceConfig(hSc,
pServiceConfig,
0,
@@ -165,97 +65,38 @@
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
- pServiceConfig = (LPQUERY_SERVICE_CONFIG)
- HeapAlloc(ProcessHeap,
- 0,
- BytesNeeded);
+ pServiceConfig = (LPQUERY_SERVICE_CONFIG) HeapAlloc(ProcessHeap,
+ 0,
+ BytesNeeded);
if (pServiceConfig == NULL)
goto cleanup;
- if (!QueryServiceConfig(hSc,
- pServiceConfig,
- BytesNeeded,
- &BytesNeeded))
- {
- HeapFree(ProcessHeap,
- 0,
- pServiceConfig);
- goto cleanup;
+ if (QueryServiceConfig(hSc,
+ pServiceConfig,
+ BytesNeeded,
+ &BytesNeeded))
+ {
+ lpExePath = HeapAlloc(ProcessHeap,
+ 0,
+ (_tcslen(pServiceConfig->lpBinaryPathName) +1 )
* sizeof(TCHAR));
+
+ _tcscpy(lpExePath, pServiceConfig->lpBinaryPathName);
}
}
- else /* exit on failure */
- {
- goto cleanup;
- }
- }
-
- *ExePath = pServiceConfig->lpBinaryPathName;
-
- CloseServiceHandle(hSCManager);
- CloseServiceHandle(hSc);
-
- return TRUE;
+ }
cleanup:
+ if (pServiceConfig)
+ HeapFree(ProcessHeap,
+ 0,
+ pServiceConfig);
if (hSCManager != NULL)
CloseServiceHandle(hSCManager);
if (hSc != NULL)
CloseServiceHandle(hSc);
- return FALSE;
+
+ return lpExePath;
}
-
-
-static VOID
-InitListViewImage(PMAIN_WND_INFO Info)
-{
- HICON hSmIconItem, hLgIconItem; /* icon for list-view items */
- HIMAGELIST hSmall, hLarge; /* image list for other views */
-
-
- /* Create the icon image lists */
- hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
- GetSystemMetrics(SM_CYSMICON),
- ILC_MASK | ILC_COLOR32,
- 1,
- 1);
-
- hLarge = ImageList_Create(GetSystemMetrics(SM_CXICON),
- GetSystemMetrics(SM_CYICON),
- ILC_MASK | ILC_COLOR32,
- 1,
- 1);
-
- /* Add an icon to each image list */
- hSmIconItem = LoadImage(hInstance,
- MAKEINTRESOURCE(IDI_SM_ICON),
- IMAGE_ICON,
- 16,
- 16,
- 0);
-
- ImageList_AddIcon(hSmall,
- hSmIconItem);
-
- hLgIconItem = LoadImage(hInstance,
- MAKEINTRESOURCE(IDI_SM_ICON),
- IMAGE_ICON,
- 32,
- 32,
- 0);
-
- ImageList_AddIcon(hLarge,
- hLgIconItem);
-
- /* assign the image to the list view */
- (void)ListView_SetImageList(Info->hListView,
- hSmall,
- LVSIL_SMALL);
- (void)ListView_SetImageList(Info->hListView,
- hLarge,
- LVSIL_NORMAL);
-
-}
-
BOOL
@@ -270,8 +111,6 @@
(void)ListView_DeleteAllItems(Info->hListView);
- InitListViewImage(Info);
-
NumServices = GetServiceList(Info);
if (NumServices)
@@ -282,7 +121,7 @@
for (Index = 0; Index < NumServices; Index++)
{
HKEY hKey = NULL;
- LPTSTR Description = NULL;
+ LPTSTR lpDescription = NULL;
LPTSTR LogOnAs = NULL;
DWORD StartUp = 0;
DWORD dwValueSize;
@@ -313,12 +152,10 @@
lvItem.iItem = ListView_GetItemCount(Info->hListView);
lvItem.iItem = ListView_InsertItem(Info->hListView, &lvItem);
-
-
/* set the description */
- if (GetDescription(Info->pServiceStatus[Index].lpServiceName,
&Description))
- {
- lvItem.pszText = Description;
+ if (lpDescription =
GetDescription(Info->pServiceStatus[Index].lpServiceName))
+ {
+ lvItem.pszText = lpDescription;
lvItem.iSubItem = 1;
SendMessage(Info->hListView,
LVM_SETITEMTEXT,
@@ -327,9 +164,8 @@
HeapFree(ProcessHeap,
0,
- Description);
- }
-
+ lpDescription);
+ }
/* set the status */
if (Info->pServiceStatus[Index].ServiceStatusProcess.dwCurrentState ==
SERVICE_RUNNING)
@@ -346,8 +182,6 @@
(LPARAM)&lvItem);
}
-
-
/* set the startup type */
dwValueSize = sizeof(DWORD);
if (RegQueryValueEx(hKey,
@@ -400,8 +234,6 @@
lvItem.iItem,
(LPARAM)&lvItem);
}
-
-
/* set Log On As */
dwValueSize = 0;
@@ -515,7 +347,7 @@
0,
BytesNeeded);
if (Info->pServiceStatus == NULL)
- return FALSE;
+ return FALSE;
/* fill array with service info */
if (EnumServicesStatusEx(ScHandle,
Added: trunk/reactos/base/applications/mscutils/servman/reg.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/reg.c (added)
+++ trunk/reactos/base/applications/mscutils/servman/reg.c Thu Aug 23 18:57:44 2007
@@ -1,0 +1,106 @@
+/*
+ * PROJECT: ReactOS Services
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: base/system/servman/reg.c
+ * PURPOSE: Query service information
+ * COPYRIGHT: Copyright 2005 - 2007 Ged Murphy <gedmurphy(a)gmail.com>
+ *
+ */
+
+#include "precomp.h"
+
+/* Sets the service description in the registry */
+BOOL SetDescription(LPTSTR ServiceName, LPTSTR Description)
+{
+ HKEY hKey;
+ LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
+ TCHAR buf[300];
+ TCHAR szBuf[MAX_PATH];
+ LONG val;
+
+
+ /* open the registry key for the service */
+ _sntprintf(buf, sizeof(buf) / sizeof(TCHAR), Path, ServiceName);
+ RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+ buf,
+ 0,
+ KEY_WRITE,
+ &hKey);
+
+
+ if ((val = RegSetValueEx(hKey,
+ _T("Description"),
+ 0,
+ REG_SZ,
+ (LPBYTE)Description,
+ (DWORD)lstrlen(szBuf)+1)) != ERROR_SUCCESS)
+ {
+ //GetError(val);
+ return FALSE;
+ }
+
+
+ RegCloseKey(hKey);
+ return TRUE;
+}
+
+
+
+/* Retrives the service description from the registry */
+LPTSTR
+GetDescription(LPTSTR lpServiceName)
+{
+ HKEY hKey;
+ LPTSTR lpDescription = NULL;
+ DWORD dwValueSize = 0;
+ LONG ret;
+ LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
+ TCHAR buf[300];
+
+ /* open the registry key for the service */
+ _sntprintf(buf, sizeof(buf) / sizeof(TCHAR), Path, lpServiceName);
+ RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+ buf,
+ 0,
+ KEY_READ,
+ &hKey);
+
+ ret = RegQueryValueEx(hKey,
+ _T("Description"),
+ NULL,
+ NULL,
+ NULL,
+ &dwValueSize);
+ if (ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND && ret !=
ERROR_INVALID_HANDLE)
+ {
+ RegCloseKey(hKey);
+ return FALSE;
+ }
+
+ if (ret != ERROR_FILE_NOT_FOUND)
+ {
+ lpDescription = HeapAlloc(ProcessHeap,
+ HEAP_ZERO_MEMORY,
+ dwValueSize);
+ if (lpDescription == NULL)
+ {
+ RegCloseKey(hKey);
+ return FALSE;
+ }
+
+ if(RegQueryValueEx(hKey,
+ _T("Description"),
+ NULL,
+ NULL,
+ (LPBYTE)lpDescription,
+ &dwValueSize))
+ {
+ HeapFree(ProcessHeap,
+ 0,
+ lpDescription);
+ RegCloseKey(hKey);
+ }
+ }
+
+ return lpDescription;
+}