X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=gui.cpp;h=85a7256521d255551c01f4cf315c2db8715f9403;hb=750d1a3c6f420b042ea5e1b0c8963648a6422b57;hp=d9b7011d73ee1fd2e747700585ec979a82a78c85;hpb=73dbba7a2e6150dea8f58dd2c25ab914a0636308;p=nssm.git diff --git a/gui.cpp b/gui.cpp index d9b7011..85a7256 100644 --- a/gui.cpp +++ b/gui.cpp @@ -146,27 +146,15 @@ int nssm_gui(int resource, nssm_service_t *service) { } if (envlen) { - /* Replace NULL with CRLF. Leave NULL NULL as the end marker. */ - unsigned long i, j; - unsigned long newlen = envlen; - for (i = 0; i < envlen; i++) if (! env[i] && env[i + 1]) newlen++; - - TCHAR *formatted = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, newlen * sizeof(TCHAR)); - if (formatted) { - for (i = 0, j = 0; i < envlen; i++) { - formatted[j] = env[i]; - if (! env[i]) { - if (env[i + 1]) { - formatted[j] = _T('\r'); - formatted[++j] = _T('\n'); - } - } - j++; - } + TCHAR *formatted; + unsigned long newlen; + if (format_environment(env, envlen, &formatted, &newlen)) { + popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("environment"), _T("nssm_dlg()")); + } + else { SetDlgItemText(tablist[NSSM_TAB_ENVIRONMENT], IDC_ENVIRONMENT, formatted); HeapFree(GetProcessHeap(), 0, formatted); } - else popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("environment"), _T("nssm_dlg()")); } if (service->envlen && service->env_extralen) popup_message(MB_OK | MB_ICONWARNING, NSSM_GUI_WARN_ENVIRONMENT); } @@ -483,28 +471,15 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service return 5; } - /* Strip CR and replace LF with NULL. */ - unsigned long newlen = 0; - unsigned long i, j; - for (i = 0; i < envlen; i++) if (env[i] != _T('\r')) newlen++; - /* Must end with two NULLs. */ - newlen += 2; - - TCHAR *newenv = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, newlen * sizeof(TCHAR)); - if (! newenv) { + TCHAR *newenv; + unsigned long newlen; + if (unformat_environment(env, envlen, &newenv, &newlen)) { HeapFree(GetProcessHeap(), 0, env); popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("environment"), _T("install()")); cleanup_nssm_service(service); return 5; } - for (i = 0, j = 0; i < envlen; i++) { - if (env[i] == _T('\r')) continue; - if (env[i] == _T('\n')) newenv[j] = _T('\0'); - else newenv[j] = env[i]; - j++; - } - HeapFree(GetProcessHeap(), 0, env); env = newenv; envlen = newlen;