From a21194b8b6fad1e4bf22c4253f5b94979db535db Mon Sep 17 00:00:00 2001 From: driAn Date: Mon, 17 Nov 2008 21:47:22 +0000 Subject: [PATCH] fixed working directory of winservice to make relative paths work (BUG 2301962) git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@3595 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/servercontroller.h | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/source/src/servercontroller.h b/source/src/servercontroller.h index b9c521e8..a3ca21eb 100644 --- a/source/src/servercontroller.h +++ b/source/src/servercontroller.h @@ -35,16 +35,22 @@ struct winservice : servercontroller void keepalive() { - report(SERVICE_RUNNING, 0); - handleevents(); + if(statushandle) + { + report(SERVICE_RUNNING, 0); + handleevents(); + } }; void stop() { - report(SERVICE_STOP_PENDING, 0); - if(stopevent) CloseHandle(stopevent); - status.dwControlsAccepted &= ~(SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN); - report(SERVICE_STOPPED, 0); + if(statushandle) + { + report(SERVICE_STOP_PENDING, 0); + if(stopevent) CloseHandle(stopevent); + status.dwControlsAccepted &= ~(SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN); + report(SERVICE_STOPPED, 0); + } } void handleevents() @@ -78,6 +84,15 @@ struct winservice : servercontroller int WINAPI svcmain() // new server thread's entry point { + // fix working directory to make relative paths work + if(argv && argv[0]) + { + string procpath; + s_strcpy(procpath, parentdir(argv[0])); + s_strcpy(procpath, parentdir(procpath)); + SetCurrentDirectory((LPSTR)procpath); + } + statushandle = RegisterServiceCtrlHandler(name, (LPHANDLER_FUNCTION)callbacks::requesthandler); if(!statushandle) return EXIT_FAILURE; status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;