diff options
| author | Anton <anton@picapica> | 2019-03-15 20:28:02 +0400 |
|---|---|---|
| committer | Anton <anton@picapica> | 2019-03-15 20:28:02 +0400 |
| commit | 1c0f790240ad499a3705151b79bb2388d28fe18c (patch) | |
| tree | 07c3ccbb30b0aaaa1d3b897d456d61fa1c443685 | |
| parent | 8efba55c86e0437ae65e0b0f5ab7271956265a8d (diff) | |
| download | pica-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
| -rw-r--r-- | PICA_node.c | 16 | ||||
| -rw-r--r-- | PICA_nodeconfig.h | 11 |
2 files changed, 22 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); diff --git a/PICA_nodeconfig.h b/PICA_nodeconfig.h index f65387e..c76df95 100644 --- a/PICA_nodeconfig.h +++ b/PICA_nodeconfig.h @@ -33,10 +33,21 @@ #define PICA_NODECONFIG_DEF_ANNOUNCED_ADDR "autoconfigure" #define PICA_NODECONFIG_DEF_LISTEN_PORT "2299" + +#ifndef WIN32 + #define PICA_NODECONFIG_DEF_NODES_DB_FILE PICA_LOCALSTATEDIR"/pica-node/nodelist.db" #define PICA_NODECONFIG_DEF_CONFIG_FILE PICA_SYSCONFDIR"/pica-node.conf" #define PICA_NODECONFIG_DEF_DH_PARAM_FILE PICA_INSTALLPREFIX"/share/pica-node/dhparam4096.pem" +#else + +#define PICA_NODECONFIG_DEF_NODES_DB_FILE "nodelist.db" +#define PICA_NODECONFIG_DEF_CONFIG_FILE "pica-node.conf" +#define PICA_NODECONFIG_DEF_DH_PARAM_FILE "share\\dhparam4096.pem" + +#endif + struct nodeconfig { char *announced_addr; |
