From: Iain Patterson Date: Mon, 23 Dec 2013 16:14:22 +0000 (+0000) Subject: Changed arguments to nssm_gui(). X-Git-Tag: v2.22~120 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=69df8a039d4a5c6e3e955fe75167bb472292fc1d;p=nssm.git Changed arguments to nssm_gui(). The second argument to nssm_gui() is now an nssm_service_t pointer rather than a string. This will allow the function to be extended later to edit existing services. --- diff --git a/gui.cpp b/gui.cpp index 80d74ef..94da622 100644 --- a/gui.cpp +++ b/gui.cpp @@ -4,9 +4,9 @@ static enum { NSSM_TAB_APPLICATION, NSSM_TAB_DETAILS, NSSM_TAB_LOGON, NSSM_TAB_S static HWND tablist[NSSM_NUM_TABS]; static int selected_tab; -int nssm_gui(int resource, TCHAR *name) { +int nssm_gui(int resource, nssm_service_t *service) { /* Create window */ - HWND dlg = CreateDialog(0, MAKEINTRESOURCE(resource), 0, install_dlg); + HWND dlg = CreateDialogParam(0, MAKEINTRESOURCE(resource), 0, nssm_dlg, (LPARAM) service); if (! dlg) { popup_message(MB_OK, NSSM_GUI_CREATEDIALOG_FAILED, error_string(GetLastError())); return 1; @@ -17,8 +17,8 @@ int nssm_gui(int resource, TCHAR *name) { ShowWindow(dlg, SW_SHOW); /* Set service name if given */ - if (name) { - SetDlgItemText(dlg, IDC_NAME, name); + if (service->name[0]) { + SetDlgItemText(dlg, IDC_NAME, service->name); /* No point making user click remove if the name is already entered */ if (resource == IDD_REMOVE) { HWND button = GetDlgItem(dlg, IDC_REMOVE); @@ -604,7 +604,7 @@ INT_PTR CALLBACK tab_dlg(HWND tab, UINT message, WPARAM w, LPARAM l) { } /* Install/remove dialogue callback */ -INT_PTR CALLBACK install_dlg(HWND window, UINT message, WPARAM w, LPARAM l) { +INT_PTR CALLBACK nssm_dlg(HWND window, UINT message, WPARAM w, LPARAM l) { switch (message) { /* Creating the dialogue */ case WM_INITDIALOG: diff --git a/gui.h b/gui.h index ad6bc56..5cc9cea 100644 --- a/gui.h +++ b/gui.h @@ -6,11 +6,11 @@ #include #include "resource.h" -int nssm_gui(int, TCHAR *); +int nssm_gui(int, nssm_service_t *); void centre_window(HWND); int install(HWND); int remove(HWND); void browse(HWND); -INT_PTR CALLBACK install_dlg(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK nssm_dlg(HWND, UINT, WPARAM, LPARAM); #endif diff --git a/service.cpp b/service.cpp index 57dc7a2..09fbe1f 100644 --- a/service.cpp +++ b/service.cpp @@ -80,17 +80,17 @@ void cleanup_nssm_service(nssm_service_t *service) { /* About to install the service */ int pre_install_service(int argc, TCHAR **argv) { + nssm_service_t *service = alloc_nssm_service(); + set_nssm_service_defaults(service); + if (argc) _sntprintf_s(service->name, _countof(service->name), _TRUNCATE, _T("%s"), argv[0]); + /* Show the dialogue box if we didn't give the service name and path */ - if (argc < 2) return nssm_gui(IDD_INSTALL, argv[0]); + if (argc < 2) return nssm_gui(IDD_INSTALL, service); - nssm_service_t *service = alloc_nssm_service(); if (! service) { print_message(stderr, NSSM_EVENT_OUT_OF_MEMORY, _T("service"), _T("pre_install_service()")); return 1; } - - set_nssm_service_defaults(service); - _sntprintf_s(service->name, _countof(service->name), _TRUNCATE, _T("%s"), argv[0]); _sntprintf_s(service->exe, _countof(service->exe), _TRUNCATE, _T("%s"), argv[1]); /* Arguments are optional */ @@ -122,11 +122,13 @@ int pre_install_service(int argc, TCHAR **argv) { /* About to remove the service */ int pre_remove_service(int argc, TCHAR **argv) { + nssm_service_t *service = alloc_nssm_service(); + set_nssm_service_defaults(service); + if (argc) _sntprintf_s(service->name, _countof(service->name), _TRUNCATE, _T("%s"), argv[0]); + /* Show dialogue box if we didn't pass service name and "confirm" */ - if (argc < 2) return nssm_gui(IDD_REMOVE, argv[0]); + if (argc < 2) return nssm_gui(IDD_REMOVE, service); if (str_equiv(argv[1], _T("confirm"))) { - nssm_service_t *service = alloc_nssm_service(); - _sntprintf_s(service->name, _countof(service->name), _TRUNCATE, _T("%s"), argv[0]); int ret = remove_service(service); cleanup_nssm_service(service); return ret;