summaryrefslogtreecommitdiffstats
path: root/PICA_node.c
diff options
context:
space:
mode:
authorAnton <anton@picapica>2019-03-15 20:28:02 +0400
committerAnton <anton@picapica>2019-03-15 20:28:02 +0400
commit1c0f790240ad499a3705151b79bb2388d28fe18c (patch)
tree07c3ccbb30b0aaaa1d3b897d456d61fa1c443685 /PICA_node.c
parent8efba55c86e0437ae65e0b0f5ab7271956265a8d (diff)
downloadpica-pica-1c0f790240ad499a3705151b79bb2388d28fe18c.tar.gz
pica-pica-1c0f790240ad499a3705151b79bb2388d28fe18c.zip
pica-node: set default paths relative to current directory on Windows. Set current directory to executable directory when running as a service
Diffstat (limited to 'PICA_node.c')
-rw-r--r--PICA_node.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/PICA_node.c b/PICA_node.c
index 574aa9b..80c6367 100644
--- a/PICA_node.c
+++ b/PICA_node.c
@@ -3727,7 +3727,7 @@ void WINAPI SvcHandler(DWORD ctl)
void WINAPI winservice_main(DWORD argc, LPTSTR *argv)
{
- char logfilepath[MAX_PATH];
+ char filepath[MAX_PATH];
int ret;
HANDLE logfile;
@@ -3739,13 +3739,19 @@ void WINAPI winservice_main(DWORD argc, LPTSTR *argv)
service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
service_status.dwServiceSpecificExitCode = 0;
- if (S_OK != SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, logfilepath))
+ if (S_OK != SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, filepath))
return;
- strncat_s(logfilepath, MAX_PATH, "\\pica-node.log", MAX_PATH);
+ strncat_s(filepath, MAX_PATH, "\\pica-node.log", MAX_PATH);
- freopen(logfilepath, "w", stdout);
- freopen(logfilepath, "w", stderr);
+ freopen(filepath, "w", stdout);
+ freopen(filepath, "w", stderr);
+
+ //set current directory to executable location directory
+ GetModuleFileName(GetModuleHandle(NULL), filepath, MAX_PATH);
+ //strip exe filename part
+ *(strrchr(filepath, '\\') + 1) = 0;
+ SetCurrentDirectory(filepath);
ReportSvcStatus(SERVICE_START_PENDING, NO_ERROR, 3000);