X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=base%2Fapplications%2Fmscutils%2Fservman%2Fpropsheet_general.c;h=42b5f9abd67a301fdaadabfe1613725798856526;hp=f03272f5da905a87c7e33f877be32a0df64d6a46;hb=e2e699118fce8da24018c6e3a1f339b1c138ebcc;hpb=753f07c723690b484ad19095c9009ccff183423f diff --git a/base/applications/mscutils/servman/propsheet_general.c b/base/applications/mscutils/servman/propsheet_general.c index f03272f5da9..42b5f9abd67 100644 --- a/base/applications/mscutils/servman/propsheet_general.c +++ b/base/applications/mscutils/servman/propsheet_general.c @@ -10,6 +10,15 @@ #include "precomp.h" +typedef struct _PAGEDATA +{ + PSERVICEPROPSHEET dlgInfo; + BOOL bDisplayNameChanged; + BOOL bDescriptionChanged; + BOOL bBinaryPathChanged; + BOOL bStartTypeChanged; +} PAGEDATA, *PPAGEDATA; + static VOID SetButtonStates(PSERVICEPROPSHEET dlgInfo, @@ -35,7 +44,6 @@ SetButtonStates(PSERVICEPROPSHEET dlgInfo, { hButton = GetDlgItem(hwndDlg, IDC_START); EnableWindow (hButton, TRUE); - HeapFree(GetProcessHeap(), 0, lpServiceConfig); } else if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) ) { @@ -49,18 +57,20 @@ SetButtonStates(PSERVICEPROPSHEET dlgInfo, } hButton = GetDlgItem(hwndDlg, IDC_START_PARAM); - EnableWindow(hButton, (State == SERVICE_STOPPED)); + EnableWindow(hButton, (State == SERVICE_STOPPED && lpServiceConfig && lpServiceConfig->dwStartType != SERVICE_DISABLED)); + + if (lpServiceConfig) + HeapFree(GetProcessHeap(), 0, lpServiceConfig); /* set the main toolbar */ SetMenuAndButtonStates(dlgInfo->Info); } - static VOID SetServiceStatusText(PSERVICEPROPSHEET dlgInfo, HWND hwndDlg) { - LPTSTR lpStatus; + LPWSTR lpStatus; UINT id; if (dlgInfo->pService->ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING) @@ -76,11 +86,11 @@ SetServiceStatusText(PSERVICEPROPSHEET dlgInfo, hInstance, id)) { - SendDlgItemMessage(hwndDlg, - IDC_SERV_STATUS, - WM_SETTEXT, - 0, - (LPARAM)lpStatus); + SendDlgItemMessageW(hwndDlg, + IDC_SERV_STATUS, + WM_SETTEXT, + 0, + (LPARAM)lpStatus); LocalFree(lpStatus); } } @@ -90,12 +100,12 @@ SetServiceStatusText(PSERVICEPROPSHEET dlgInfo, * values and sets it to value of the selected item */ static VOID -SetStartupType(LPTSTR lpServiceName, +SetStartupType(LPWSTR lpServiceName, HWND hwndDlg) { HWND hList; LPQUERY_SERVICE_CONFIG pServiceConfig; - LPTSTR lpBuf; + LPWSTR lpBuf; DWORD StartUp = 0; UINT i; @@ -107,10 +117,10 @@ SetStartupType(LPTSTR lpServiceName, hInstance, i)) { - SendMessage(hList, - CB_ADDSTRING, - 0, - (LPARAM)lpBuf); + SendMessageW(hList, + CB_ADDSTRING, + 0, + (LPARAM)lpBuf); LocalFree(lpBuf); } } @@ -126,10 +136,10 @@ SetStartupType(LPTSTR lpServiceName, case SERVICE_DISABLED: StartUp = 2; break; } - SendMessage(hList, - CB_SETCURSEL, - StartUp, - 0); + SendMessageW(hList, + CB_SETCURSEL, + StartUp, + 0); HeapFree(ProcessHeap, 0, @@ -137,7 +147,6 @@ SetStartupType(LPTSTR lpServiceName, } } - /* * Populates the General Properties dialog with * the relevant service information @@ -147,30 +156,30 @@ InitGeneralPage(PSERVICEPROPSHEET dlgInfo, HWND hwndDlg) { LPQUERY_SERVICE_CONFIG pServiceConfig; - LPTSTR lpDescription; + LPWSTR lpDescription; /* set the service name */ - SendDlgItemMessage(hwndDlg, - IDC_SERV_NAME, - WM_SETTEXT, - 0, - (LPARAM)dlgInfo->pService->lpServiceName); + SendDlgItemMessageW(hwndDlg, + IDC_SERV_NAME, + WM_SETTEXT, + 0, + (LPARAM)dlgInfo->pService->lpServiceName); /* set the display name */ - SendDlgItemMessage(hwndDlg, - IDC_DISP_NAME, - WM_SETTEXT, - 0, - (LPARAM)dlgInfo->pService->lpDisplayName); + SendDlgItemMessageW(hwndDlg, + IDC_DISP_NAME, + WM_SETTEXT, + 0, + (LPARAM)dlgInfo->pService->lpDisplayName); /* set the description */ if ((lpDescription = GetServiceDescription(dlgInfo->pService->lpServiceName))) { - SendDlgItemMessage(hwndDlg, - IDC_DESCRIPTION, - WM_SETTEXT, - 0, - (LPARAM)lpDescription); + SendDlgItemMessageW(hwndDlg, + IDC_DESCRIPTION, + WM_SETTEXT, + 0, + (LPARAM)lpDescription); HeapFree(ProcessHeap, 0, @@ -180,14 +189,14 @@ InitGeneralPage(PSERVICEPROPSHEET dlgInfo, pServiceConfig = GetServiceConfig(dlgInfo->pService->lpServiceName); if (pServiceConfig) { - SendDlgItemMessage(hwndDlg, - IDC_EXEPATH, - WM_SETTEXT, - 0, - (LPARAM)pServiceConfig->lpBinaryPathName); + SendDlgItemMessageW(hwndDlg, + IDC_EXEPATH, + WM_SETTEXT, + 0, + (LPARAM)pServiceConfig->lpBinaryPathName); HeapFree(ProcessHeap, - 0, - pServiceConfig); + 0, + pServiceConfig); } @@ -199,20 +208,18 @@ InitGeneralPage(PSERVICEPROPSHEET dlgInfo, if (dlgInfo->Info->bIsUserAnAdmin) { - HWND hEdit = GetDlgItem(hwndDlg, - IDC_EDIT); - EnableWindow(hEdit, - TRUE); + EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT), TRUE); } } - VOID -SaveDlgInfo(PSERVICEPROPSHEET dlgInfo, +SaveDlgInfo(PPAGEDATA pPageData, HWND hwndDlg) { LPQUERY_SERVICE_CONFIG pServiceConfig = NULL; - HWND hList; + PWSTR pDisplayName = NULL; + PWSTR pDescription; + INT nLength; DWORD StartUp; pServiceConfig = HeapAlloc(ProcessHeap, @@ -222,56 +229,96 @@ SaveDlgInfo(PSERVICEPROPSHEET dlgInfo, { pServiceConfig->dwServiceType = SERVICE_NO_CHANGE; pServiceConfig->dwErrorControl = SERVICE_NO_CHANGE; + pServiceConfig->dwStartType = SERVICE_NO_CHANGE; - hList = GetDlgItem(hwndDlg, IDC_START_TYPE); - StartUp = SendMessage(hList, - CB_GETCURSEL, - 0, - 0); - switch (StartUp) + if (pPageData->bStartTypeChanged) { - case 0: pServiceConfig->dwStartType = SERVICE_AUTO_START; break; - case 1: pServiceConfig->dwStartType = SERVICE_DEMAND_START; break; - case 2: pServiceConfig->dwStartType = SERVICE_DISABLED; break; + StartUp = SendDlgItemMessageW(hwndDlg, IDC_START_TYPE, CB_GETCURSEL, 0, 0); + switch (StartUp) + { + case 0: + pServiceConfig->dwStartType = SERVICE_AUTO_START; + break; + + case 1: + pServiceConfig->dwStartType = SERVICE_DEMAND_START; + break; + case 2: + pServiceConfig->dwStartType = SERVICE_DISABLED; + break; + } + } + + if (pPageData->bBinaryPathChanged) + { + nLength = SendDlgItemMessageW(hwndDlg, IDC_EXEPATH, WM_GETTEXTLENGTH, 0, 0); + pServiceConfig->lpBinaryPathName = HeapAlloc(ProcessHeap, + HEAP_ZERO_MEMORY, + (nLength + 1) * sizeof(WCHAR)); + if (pServiceConfig->lpBinaryPathName != NULL) + SendDlgItemMessageW(hwndDlg, IDC_EXEPATH, WM_GETTEXT, nLength + 1, (LPARAM)pServiceConfig->lpBinaryPathName); + } + + if (pPageData->bDisplayNameChanged) + { + nLength = SendDlgItemMessageW(hwndDlg, IDC_DISP_NAME, WM_GETTEXTLENGTH, 0, 0); + pDisplayName = HeapAlloc(ProcessHeap, + HEAP_ZERO_MEMORY, + (nLength + 1) * sizeof(WCHAR)); + if (pDisplayName != NULL) + { + SendDlgItemMessageW(hwndDlg, IDC_DISP_NAME, WM_GETTEXT, nLength + 1, (LPARAM)pDisplayName); + + if (pPageData->dlgInfo->pService->lpDisplayName) + HeapFree(ProcessHeap, 0, pPageData->dlgInfo->pService->lpDisplayName); + + pPageData->dlgInfo->pService->lpDisplayName = pDisplayName; + pServiceConfig->lpDisplayName = pDisplayName; + } } if (SetServiceConfig(pServiceConfig, - dlgInfo->pService->lpServiceName, + pPageData->dlgInfo->pService->lpServiceName, NULL)) { - ChangeListViewText(dlgInfo->Info, - dlgInfo->pService, - LVSTARTUP); + if (pPageData->bDisplayNameChanged) + ChangeListViewText(pPageData->dlgInfo->Info, + pPageData->dlgInfo->pService, + LVNAME); + + if (pPageData->bStartTypeChanged) + ChangeListViewText(pPageData->dlgInfo->Info, + pPageData->dlgInfo->pService, + LVSTARTUP); } - HeapFree(ProcessHeap, - 0, - pServiceConfig); - } -} + if (pServiceConfig->lpBinaryPathName != NULL) + HeapFree(ProcessHeap, 0, pServiceConfig->lpBinaryPathName); + HeapFree(ProcessHeap, 0, pServiceConfig); + } -static -VOID -OnStart(HWND hwndDlg, - PSERVICEPROPSHEET dlgInfo) -{ - WCHAR szStartParams[256]; - LPWSTR lpStartParams = NULL; + if (pPageData->bDescriptionChanged) + { + nLength = SendDlgItemMessageW(hwndDlg, IDC_DESCRIPTION, WM_GETTEXTLENGTH, 0, 0); + pDescription = HeapAlloc(ProcessHeap, HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR)); + if (pDescription != NULL) + { + SendDlgItemMessageW(hwndDlg, IDC_DESCRIPTION, WM_GETTEXT, nLength + 1, (LPARAM)pDescription); - if (GetDlgItemText(hwndDlg, IDC_START_PARAM, szStartParams, 256) > 0) - lpStartParams = szStartParams; + if (SetServiceDescription(pPageData->dlgInfo->pService->lpServiceName, + pDescription)) + { + ChangeListViewText(pPageData->dlgInfo->Info, + pPageData->dlgInfo->pService, + LVDESC); + } - if (DoStart(dlgInfo->Info, lpStartParams)) - { - UpdateServiceStatus(dlgInfo->pService); - ChangeListViewText(dlgInfo->Info, dlgInfo->pService, LVSTATUS); - SetButtonStates(dlgInfo, hwndDlg); - SetServiceStatusText(dlgInfo, hwndDlg); + HeapFree(ProcessHeap, 0, pDescription); + } } } - /* * General Property dialog callback. * Controls messages to the General dialog @@ -282,12 +329,12 @@ GeneralPageProc(HWND hwndDlg, WPARAM wParam, LPARAM lParam) { - PSERVICEPROPSHEET dlgInfo; + PPAGEDATA pPageData; /* Get the window context */ - dlgInfo = (PSERVICEPROPSHEET)GetWindowLongPtr(hwndDlg, - GWLP_USERDATA); - if (dlgInfo == NULL && uMsg != WM_INITDIALOG) + pPageData = (PPAGEDATA)GetWindowLongPtr(hwndDlg, + GWLP_USERDATA); + if (pPageData == NULL && uMsg != WM_INITDIALOG) { return FALSE; } @@ -295,94 +342,151 @@ GeneralPageProc(HWND hwndDlg, switch (uMsg) { case WM_INITDIALOG: - { - dlgInfo = (PSERVICEPROPSHEET)(((LPPROPSHEETPAGE)lParam)->lParam); - if (dlgInfo != NULL) + pPageData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PAGEDATA)); + if (pPageData != NULL) { SetWindowLongPtr(hwndDlg, GWLP_USERDATA, - (LONG_PTR)dlgInfo); - InitGeneralPage(dlgInfo, hwndDlg); - SetButtonStates(dlgInfo, hwndDlg); + (LONG_PTR)pPageData); + + pPageData->dlgInfo = (PSERVICEPROPSHEET)(((LPPROPSHEETPAGE)lParam)->lParam); + if (pPageData->dlgInfo != NULL) + { + InitGeneralPage(pPageData->dlgInfo, hwndDlg); + SetButtonStates(pPageData->dlgInfo, hwndDlg); + } } - } - break; + break; + + case WM_DESTROY: + HeapFree(GetProcessHeap(), 0, pPageData); + break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_START_TYPE: if (HIWORD(wParam) == CBN_SELCHANGE) + { + pPageData->bStartTypeChanged = TRUE; PropSheet_Changed(GetParent(hwndDlg), hwndDlg); - break; - - case IDC_START: - OnStart(hwndDlg, dlgInfo); - break; + } + break; - case IDC_STOP: - if (DoStop(dlgInfo->Info)) + case IDC_DISP_NAME: + if (HIWORD(wParam) == EN_CHANGE) { - UpdateServiceStatus(dlgInfo->pService); - ChangeListViewText(dlgInfo->Info, dlgInfo->pService, LVSTATUS); - SetButtonStates(dlgInfo, hwndDlg); - SetServiceStatusText(dlgInfo, hwndDlg); + pPageData->bDisplayNameChanged = TRUE; + PropSheet_Changed(GetParent(hwndDlg), hwndDlg); } - break; + break; - case IDC_PAUSE: - if (DoPause(dlgInfo->Info)) + case IDC_DESCRIPTION: + if (HIWORD(wParam) == EN_CHANGE) { - UpdateServiceStatus(dlgInfo->pService); - ChangeListViewText(dlgInfo->Info, dlgInfo->pService, LVSTATUS); - SetButtonStates(dlgInfo, hwndDlg); - SetServiceStatusText(dlgInfo, hwndDlg); + pPageData->bDescriptionChanged = TRUE; + PropSheet_Changed(GetParent(hwndDlg), hwndDlg); } - break; + break; - case IDC_RESUME: - if (DoResume(dlgInfo->Info)) + case IDC_EXEPATH: + if (HIWORD(wParam) == EN_CHANGE) { - UpdateServiceStatus(dlgInfo->pService); - ChangeListViewText(dlgInfo->Info, dlgInfo->pService, LVSTATUS); - SetButtonStates(dlgInfo, hwndDlg); - SetServiceStatusText(dlgInfo, hwndDlg); + pPageData->bBinaryPathChanged = TRUE; + PropSheet_Changed(GetParent(hwndDlg), hwndDlg); } - break; + break; - case IDC_EDIT: + case IDC_START: { - HWND hName, hDesc, hExePath; + WCHAR szStartParams[256]; + LPWSTR lpStartParams = NULL; - hName = GetDlgItem(hwndDlg, IDC_DISP_NAME); - hDesc = GetDlgItem(hwndDlg, IDC_DESCRIPTION); - hExePath = GetDlgItem(hwndDlg, IDC_EXEPATH); + if (GetDlgItemText(hwndDlg, IDC_START_PARAM, szStartParams, 256) > 0) + lpStartParams = szStartParams; - SendMessage(hName, EM_SETREADONLY, FALSE, 0); - SendMessage(hDesc, EM_SETREADONLY, FALSE, 0); - SendMessage(hExePath, EM_SETREADONLY, FALSE, 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_START_PARAM), FALSE); + + RunActionWithProgress(hwndDlg, + pPageData->dlgInfo->pService->lpServiceName, + pPageData->dlgInfo->pService->lpDisplayName, + ACTION_START, + lpStartParams); + + UpdateServiceStatus(pPageData->dlgInfo->pService); + ChangeListViewText(pPageData->dlgInfo->Info, pPageData->dlgInfo->pService, LVSTATUS); + SetButtonStates(pPageData->dlgInfo, hwndDlg); + SetServiceStatusText(pPageData->dlgInfo, hwndDlg); + break; } - break; - case IDC_START_PARAM: - PropSheet_Changed(GetParent(hwndDlg), hwndDlg); - break; + case IDC_STOP: + RunActionWithProgress(hwndDlg, + pPageData->dlgInfo->pService->lpServiceName, + pPageData->dlgInfo->pService->lpDisplayName, + ACTION_STOP, + NULL); + + UpdateServiceStatus(pPageData->dlgInfo->pService); + ChangeListViewText(pPageData->dlgInfo->Info, pPageData->dlgInfo->pService, LVSTATUS); + SetButtonStates(pPageData->dlgInfo, hwndDlg); + SetServiceStatusText(pPageData->dlgInfo, hwndDlg); + break; + + case IDC_PAUSE: + RunActionWithProgress(hwndDlg, + pPageData->dlgInfo->pService->lpServiceName, + pPageData->dlgInfo->pService->lpDisplayName, + ACTION_PAUSE, + NULL); + + UpdateServiceStatus(pPageData->dlgInfo->pService); + ChangeListViewText(pPageData->dlgInfo->Info, pPageData->dlgInfo->pService, LVSTATUS); + SetButtonStates(pPageData->dlgInfo, hwndDlg); + SetServiceStatusText(pPageData->dlgInfo, hwndDlg); + break; + + case IDC_RESUME: + RunActionWithProgress(hwndDlg, + pPageData->dlgInfo->pService->lpServiceName, + pPageData->dlgInfo->pService->lpDisplayName, + ACTION_RESUME, + NULL); + + UpdateServiceStatus(pPageData->dlgInfo->pService); + ChangeListViewText(pPageData->dlgInfo->Info, pPageData->dlgInfo->pService, LVSTATUS); + SetButtonStates(pPageData->dlgInfo, hwndDlg); + SetServiceStatusText(pPageData->dlgInfo, hwndDlg); + break; + + case IDC_EDIT: + SendDlgItemMessage(hwndDlg, IDC_DISP_NAME, EM_SETREADONLY, FALSE, 0); + SendDlgItemMessage(hwndDlg, IDC_DESCRIPTION, EM_SETREADONLY, FALSE, 0); + SendDlgItemMessage(hwndDlg, IDC_EXEPATH, EM_SETREADONLY, FALSE, 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT), FALSE); + break; } break; case WM_NOTIFY: + switch (((LPNMHDR)lParam)->code) { - LPNMHDR lpnm = (LPNMHDR)lParam; - - switch (lpnm->code) - { - case PSN_APPLY: - SaveDlgInfo(dlgInfo, hwndDlg); - SetButtonStates(dlgInfo, hwndDlg); + case PSN_APPLY: + if (pPageData->bDisplayNameChanged || + pPageData->bDescriptionChanged || + pPageData->bBinaryPathChanged || + pPageData->bStartTypeChanged) + { + SaveDlgInfo(pPageData, hwndDlg); + SetButtonStates(pPageData->dlgInfo, hwndDlg); + pPageData->bDisplayNameChanged = FALSE; + pPageData->bDescriptionChanged = FALSE; + pPageData->bBinaryPathChanged = FALSE; + pPageData->bStartTypeChanged = FALSE; + } break; - } } - break; + break; } return FALSE;