X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=gui.cpp;h=64382f47d973f921f48b2248e55633364245a080;hb=2cd1c7c29ef4d2d3df3c5afd3ca6c788aede2bef;hp=7697e263368d39efa907c26371650cbcb2902a53;hpb=02203cb8aff4be6a094b7a9ded867c3b5d743d77;p=nssm.git diff --git a/gui.cpp b/gui.cpp index 7697e26..64382f4 100644 --- a/gui.cpp +++ b/gui.cpp @@ -67,6 +67,7 @@ int nssm_gui(int resource, nssm_service_t *service) { /* Set existing details. */ HWND combo; + HWND list; /* Application tab. */ if (service->native) SetDlgItemText(tablist[NSSM_TAB_APPLICATION], IDC_PATH, service->image); @@ -101,6 +102,21 @@ int nssm_gui(int resource, nssm_service_t *service) { SendMessage(combo, CB_SETCURSEL, priority, 0); } + if (service->affinity) { + list = GetDlgItem(tablist[NSSM_TAB_PROCESS], IDC_AFFINITY); + SendDlgItemMessage(tablist[NSSM_TAB_PROCESS], IDC_AFFINITY_ALL, BM_SETCHECK, BST_UNCHECKED, 0); + EnableWindow(GetDlgItem(tablist[NSSM_TAB_PROCESS], IDC_AFFINITY), 1); + + DWORD_PTR affinity, system_affinity; + if (GetProcessAffinityMask(GetCurrentProcess(), &affinity, &system_affinity)) { + if ((service->affinity & (__int64) system_affinity) != service->affinity) popup_message(dlg, MB_OK | MB_ICONWARNING, NSSM_GUI_WARN_AFFINITY); + } + + for (int i = 0; i < num_cpus(); i++) { + if (! (service->affinity & (1LL << (__int64) i))) SendMessage(list, LB_SETSEL, 0, i); + } + } + /* Shutdown tab. */ if (! (service->stop_method & NSSM_STOP_METHOD_CONSOLE)) { SendDlgItemMessage(tablist[NSSM_TAB_SHUTDOWN], IDC_METHOD_CONSOLE, BM_SETCHECK, BST_UNCHECKED, 0); @@ -125,6 +141,7 @@ int nssm_gui(int resource, nssm_service_t *service) { SetDlgItemInt(tablist[NSSM_TAB_EXIT], IDC_THROTTLE, service->throttle_delay, 0); combo = GetDlgItem(tablist[NSSM_TAB_EXIT], IDC_APPEXIT); SendMessage(combo, CB_SETCURSEL, service->default_exit_action, 0); + SetDlgItemInt(tablist[NSSM_TAB_EXIT], IDC_RESTART_DELAY, service->restart_delay, 0); /* I/O tab. */ SetDlgItemText(tablist[NSSM_TAB_IO], IDC_STDIN, service->stdin_path); @@ -135,9 +152,11 @@ int nssm_gui(int resource, nssm_service_t *service) { if (service->stdout_disposition == CREATE_ALWAYS) SendDlgItemMessage(tablist[NSSM_TAB_ROTATION], IDC_TRUNCATE, BM_SETCHECK, BST_CHECKED, 0); if (service->rotate_files) { SendDlgItemMessage(tablist[NSSM_TAB_ROTATION], IDC_ROTATE, BM_SETCHECK, BST_CHECKED, 0); + EnableWindow(GetDlgItem(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_ONLINE), 1); EnableWindow(GetDlgItem(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_SECONDS), 1); EnableWindow(GetDlgItem(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_BYTES_LOW), 1); } + if (service->rotate_stdout_online || service->rotate_stderr_online) SendDlgItemMessage(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_ONLINE, BM_SETCHECK, BST_CHECKED, 0); SetDlgItemInt(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_SECONDS, service->rotate_seconds, 0); if (! service->rotate_bytes_high) SetDlgItemInt(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_BYTES_LOW, service->rotate_bytes_low, 0); @@ -230,7 +249,12 @@ static inline void set_logon_enabled(unsigned char enabled) { EnableWindow(GetDlgItem(tablist[NSSM_TAB_LOGON], IDC_PASSWORD2), enabled); } +static inline void set_affinity_enabled(unsigned char enabled) { + EnableWindow(GetDlgItem(tablist[NSSM_TAB_PROCESS], IDC_AFFINITY), enabled); +} + static inline void set_rotation_enabled(unsigned char enabled) { + EnableWindow(GetDlgItem(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_ONLINE), enabled); EnableWindow(GetDlgItem(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_SECONDS), enabled); EnableWindow(GetDlgItem(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_BYTES_LOW), enabled); } @@ -438,6 +462,22 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service combo = GetDlgItem(tablist[NSSM_TAB_PROCESS], IDC_PRIORITY); service->priority = priority_index_to_constant((unsigned long) SendMessage(combo, CB_GETCURSEL, 0, 0)); + service->affinity = 0LL; + if (! (SendDlgItemMessage(tablist[NSSM_TAB_PROCESS], IDC_AFFINITY_ALL, BM_GETCHECK, 0, 0) & BST_CHECKED)) { + HWND list = GetDlgItem(tablist[NSSM_TAB_PROCESS], IDC_AFFINITY); + int selected = (int) SendMessage(list, LB_GETSELCOUNT, 0, 0); + int count = (int) SendMessage(list, LB_GETCOUNT, 0, 0); + if (! selected) { + popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_WARN_AFFINITY_NONE); + return 5; + } + else if (selected < count) { + for (int i = 0; i < count; i++) { + if (SendMessage(list, LB_GETSEL, i, 0)) service->affinity |= (1LL << (__int64) i); + } + } + } + /* Get stop method stuff. */ check_stop_method(service, NSSM_STOP_METHOD_CONSOLE, IDC_METHOD_CONSOLE); check_stop_method(service, NSSM_STOP_METHOD_WINDOW, IDC_METHOD_WINDOW); @@ -452,6 +492,7 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service combo = GetDlgItem(tablist[NSSM_TAB_EXIT], IDC_APPEXIT); service->default_exit_action = (unsigned long) SendMessage(combo, CB_GETCURSEL, 0, 0); if (service->default_exit_action == CB_ERR) service->default_exit_action = 0; + check_number(tablist[NSSM_TAB_EXIT], IDC_RESTART_DELAY, &service->restart_delay); /* Get I/O stuff. */ check_io(window, _T("stdin"), service->stdin_path, _countof(service->stdin_path), IDC_STDIN); @@ -467,6 +508,7 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service /* Get rotation stuff. */ if (SendDlgItemMessage(tablist[NSSM_TAB_ROTATION], IDC_ROTATE, BM_GETCHECK, 0, 0) & BST_CHECKED) { service->rotate_files = true; + if (SendDlgItemMessage(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_ONLINE, BM_GETCHECK, 0, 0) & BST_CHECKED) service->rotate_stdout_online = service->rotate_stderr_online = NSSM_ROTATE_ONLINE; check_number(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_SECONDS, &service->rotate_seconds); check_number(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_BYTES_LOW, &service->rotate_bytes_low); } @@ -766,6 +808,13 @@ INT_PTR CALLBACK tab_dlg(HWND tab, UINT message, WPARAM w, LPARAM l) { set_logon_enabled(1); break; + /* Affinity. */ + case IDC_AFFINITY_ALL: + if (SendDlgItemMessage(tab, LOWORD(w), BM_GETCHECK, 0, 0) & BST_CHECKED) enabled = 0; + else enabled = 1; + set_affinity_enabled(enabled); + break; + /* Shutdown methods. */ case IDC_METHOD_CONSOLE: set_timeout_enabled(LOWORD(w), IDC_KILL_CONSOLE); @@ -832,6 +881,8 @@ INT_PTR CALLBACK nssm_dlg(HWND window, UINT message, WPARAM w, LPARAM l) { HWND tabs; HWND combo; + HWND list; + int i, n; tabs = GetDlgItem(window, IDC_TAB1); if (! tabs) return 0; @@ -901,6 +952,37 @@ INT_PTR CALLBACK nssm_dlg(HWND window, UINT message, WPARAM w, LPARAM l) { SendMessage(combo, CB_INSERTSTRING, NSSM_IDLE_PRIORITY, (LPARAM) message_string(NSSM_GUI_IDLE_PRIORITY_CLASS)); SendMessage(combo, CB_SETCURSEL, NSSM_NORMAL_PRIORITY, 0); + list = GetDlgItem(tablist[NSSM_TAB_PROCESS], IDC_AFFINITY); + n = num_cpus(); + SendMessage(list, LB_SETCOLUMNWIDTH, 16, 0); + for (i = 0; i < n; i++) { + TCHAR buffer[3]; + _sntprintf_s(buffer, _countof(buffer), _TRUNCATE, _T("%d"), i); + SendMessage(list, LB_ADDSTRING, 0, (LPARAM) buffer); + } + + /* + Size to fit. + The box is high enough for four rows. It is wide enough for eight + columns without scrolling. With scrollbars it shrinks to two rows. + Note that the above only holds if we set the column width BEFORE + adding the strings. + */ + if (n < 32) { + int columns = (n - 1) / 4; + RECT rect; + GetWindowRect(list, &rect); + int width = rect.right - rect.left; + width -= (7 - columns) * 16; + int height = rect.bottom - rect.top; + if (n < 4) height -= (int) SendMessage(list, LB_GETITEMHEIGHT, 0, 0) * (4 - n); + SetWindowPos(list, 0, 0, 0, width, height, SWP_NOMOVE | SWP_NOOWNERZORDER); + } + SendMessage(list, LB_SELITEMRANGE, 1, MAKELPARAM(0, n)); + + SendDlgItemMessage(tablist[NSSM_TAB_PROCESS], IDC_AFFINITY_ALL, BM_SETCHECK, BST_CHECKED, 0); + set_affinity_enabled(0); + /* Shutdown tab. */ tab.pszText = message_string(NSSM_GUI_TAB_SHUTDOWN); tab.cchTextMax = (int) _tcslen(tab.pszText); @@ -932,6 +1014,7 @@ INT_PTR CALLBACK nssm_dlg(HWND window, UINT message, WPARAM w, LPARAM l) { SendMessage(combo, CB_INSERTSTRING, NSSM_EXIT_REALLY, (LPARAM) message_string(NSSM_GUI_EXIT_REALLY)); SendMessage(combo, CB_INSERTSTRING, NSSM_EXIT_UNCLEAN, (LPARAM) message_string(NSSM_GUI_EXIT_UNCLEAN)); SendMessage(combo, CB_SETCURSEL, NSSM_EXIT_RESTART, 0); + SetDlgItemInt(tablist[NSSM_TAB_EXIT], IDC_RESTART_DELAY, 0, 0); /* I/O tab. */ tab.pszText = message_string(NSSM_GUI_TAB_IO); @@ -948,6 +1031,7 @@ INT_PTR CALLBACK nssm_dlg(HWND window, UINT message, WPARAM w, LPARAM l) { ShowWindow(tablist[NSSM_TAB_ROTATION], SW_HIDE); /* Set defaults. */ + SendDlgItemMessage(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_ONLINE, BM_SETCHECK, BST_UNCHECKED, 0); SetDlgItemInt(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_SECONDS, 0, 0); SetDlgItemInt(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_BYTES_LOW, 0, 0); set_rotation_enabled(0);