Browse Source

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.
Iain Patterson 8 years ago
parent
commit
69df8a039d
3 changed files with 17 additions and 15 deletions
  1. 5 5
      gui.cpp
  2. 2 2
      gui.h
  3. 10 8
      service.cpp

+ 5 - 5
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:

+ 2 - 2
gui.h

@@ -6,11 +6,11 @@
 #include <commctrl.h>
 #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

+ 10 - 8
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;