Fixed bug when installing from the command line.
[nssm.git] / gui.cpp
diff --git a/gui.cpp b/gui.cpp
index 2642ad1..ca21ace 100644 (file)
--- a/gui.cpp
+++ b/gui.cpp
@@ -87,6 +87,8 @@ int install(HWND window) {
 \r
   nssm_service_t *service = alloc_nssm_service();\r
   if (service) {\r
+    set_nssm_service_defaults(service);\r
+\r
     /* Get service name. */\r
     if (! GetDlgItemText(window, IDC_NAME, service->name, sizeof(service->name))) {\r
       popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_SERVICE_NAME);\r
@@ -115,7 +117,6 @@ int install(HWND window) {
     }\r
 \r
     /* Get stop method stuff. */\r
-    service->stop_method = ~0;\r
     check_stop_method(service, NSSM_STOP_METHOD_CONSOLE, IDC_METHOD_CONSOLE);\r
     check_stop_method(service, NSSM_STOP_METHOD_WINDOW, IDC_METHOD_WINDOW);\r
     check_stop_method(service, NSSM_STOP_METHOD_THREADS, IDC_METHOD_THREADS);\r
@@ -134,6 +135,11 @@ int install(HWND window) {
     check_io("stdin", service->stdin_path, sizeof(service->stdin_path), IDC_STDIN);\r
     check_io("stdout", service->stdout_path, sizeof(service->stdout_path), IDC_STDOUT);\r
     check_io("stderr", service->stderr_path, sizeof(service->stderr_path), IDC_STDERR);\r
+    /* Override stdout and/or stderr. */\r
+    if (SendDlgItemMessage(tablist[NSSM_TAB_IO], IDC_TRUNCATE, BM_GETCHECK, 0, 0) & BST_CHECKED) {\r
+      if (service->stdout_path[0]) service->stdout_disposition = CREATE_ALWAYS;\r
+      if (service->stderr_path[0]) service->stderr_disposition = CREATE_ALWAYS;\r
+    }\r
 \r
     /* Get environment. */\r
     unsigned long envlen = (unsigned long) SendMessage(GetDlgItem(tablist[NSSM_TAB_ENVIRONMENT], IDC_ENVIRONMENT), WM_GETTEXTLENGTH, 0, 0);\r
@@ -157,7 +163,7 @@ int install(HWND window) {
       unsigned long i, j;\r
       for (i = 0; i < envlen; i++) if (env[i] != '\r') newlen++;\r
       /* Must end with two NULLs. */\r
-      newlen++;\r
+      newlen += 2;\r
 \r
       char *newenv = (char *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, newlen);\r
       if (! newenv) {\r