From d1e5f6abc9d394b53beb06a2566dd3ae52be92e8 Mon Sep 17 00:00:00 2001
From: "Dmitriy A. Gerasimov" <dmitriy.gerasimov@demlabs.net>
Date: Sat, 21 Dec 2019 16:37:29 +0700
Subject: [PATCH] [*] Replacement of macro to functions for app name and dirs
 [-] dap_defines.h

---
 dap_defines.h                  | 21 ---------------------
 dap_server_http_db_auth_tool.c | 28 ++++++++++++++++------------
 2 files changed, 16 insertions(+), 33 deletions(-)
 delete mode 100644 dap_defines.h

diff --git a/dap_defines.h b/dap_defines.h
deleted file mode 100644
index cff99e5..0000000
--- a/dap_defines.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#pragma once
-#define DAP_APP_NAME NODE_NETNAME "-node"
-
-//#ifdef _WIN32
-//  #define SYSTEM_PREFIX "%USERPROFILE%/opt/"DAP_APP_NAME
-//#else
-  #define SYSTEM_PREFIX "/opt/"DAP_APP_NAME
-//  #define SYSTEM_PREFIX "opt/"DAP_APP_NAME
-//#endif
-
-#define LOCAL_PREFIX "~/."DAP_APP_NAME
-
-#define SYSTEM_CONFIGS_DIR SYSTEM_PREFIX"/etc"
-#define LOCAL_CONFIGS_DIR LOCAL_PREFIX"/etc"
-#define SYSTEM_LOGS_DIR SYSTEM_PREFIX"/var/log"
-
-#define SYSTEM_CONFIG_GLOBAL_FILENAME SYSTEM_PREFIX"/etc/"DAP_APP_NAME".cfg"
-#define LOCAL_CONFIG_GLOBAL LOCAL_PREFIX"/etc/"DAP_APP_NAME".cfg"
-
-#define SYSTEM_PID_FILE_PATH SYSTEM_PREFIX"/run/"DAP_APP_NAME".pid"
-#define LOCAL_PID_FILE_PATH SYSTEM_PREFIX"/run/"DAP_APP_NAME".pid"
diff --git a/dap_server_http_db_auth_tool.c b/dap_server_http_db_auth_tool.c
index 25a6c85..b9d0912 100644
--- a/dap_server_http_db_auth_tool.c
+++ b/dap_server_http_db_auth_tool.c
@@ -30,13 +30,12 @@
 //#include "dap_client.h"
 #include "dap_common.h"
 #include "dap_config.h"
+#include "dap_strfuncs.h"
 
 #ifdef _WIN32
 #include "registry.h"
 #endif
 
-#include "dap_defines.h"
-
 #include "db_auth.h"
 
 static void s_help(const char * a_app_name)
@@ -49,22 +48,27 @@ static void s_help(const char * a_app_name)
 
 int main(int argc, const char * argv[])
 {
-#ifdef _WIN32
-    dap_sprintf(s_sys_dir_path, "%s/%s", regGetUsrPath(), DAP_APP_NAME);
-    l_sys_dir_path_len = strlen(s_sys_dir_path);
-#endif
 
     //    set_default_locale();
     //    command_execution_string = shell_script_filename = (char *) NULL;
+    dap_set_appname("http_db_auth_tool");
+#ifdef DAP_OS_LINUX
+    g_sys_dir_path = dap_strdup_printf("/opt/%s",dap_get_appname() );
+#elif _WIN32
+    dap_sprintf(s_sys_dir_path, "%s/%s", regGetUsrPath(), dap_get_appname() );
+#endif
+    g_sys_dir_path_len = strlen(g_sys_dir_path);
+
+    char * l_app_title = dap_strdup_printf("%s console interface",dap_get_appname());
+
+    char * l_config_path = dap_strdup_printf("%s/etc", g_sys_dir_path);
 
-    memcpy(s_sys_dir_path + l_sys_dir_path_len, SYSTEM_CONFIGS_DIR, sizeof(SYSTEM_CONFIGS_DIR) );
-    dap_common_init( DAP_APP_NAME " Console interface", NULL );
+    dap_common_init( l_app_title, NULL );
     dap_log_level_set( L_CRITICAL );
-    dap_config_init( s_sys_dir_path );
-    memset(s_sys_dir_path + l_sys_dir_path_len, '\0', MAX_PATH - l_sys_dir_path_len);
+    dap_config_init( g_sys_dir_path );
 
-    if((g_config = dap_config_open(DAP_APP_NAME)) == NULL) {
-        printf("Can't init general configurations " DAP_APP_NAME ".cfg\n");
+    if((g_config = dap_config_open(dap_get_appname())) == NULL) {
+        printf("Can't init general configurations %s.cfg\n",dap_get_appname());
         exit(-1);
     }
 
-- 
GitLab