From 5f772fdf70bfb49cac3c57c552ce1f10d1ea55a5 Mon Sep 17 00:00:00 2001 From: SarahW Date: Thu, 3 Jun 2021 20:36:30 +0100 Subject: [PATCH] Correct path to default NVR files on Linux --- src/nvr.c | 6 +----- src/paths.c | 12 ++++++++++++ src/paths.h | 2 ++ src/wx-sdl2.c | 6 ++++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/nvr.c b/src/nvr.c index 7a96db5..edbd35b 100644 --- a/src/nvr.c +++ b/src/nvr.c @@ -48,11 +48,7 @@ FILE *nvrfopen(char *fn, char *mode) if (mode[0] == 'r') { - strcpy(s, nvr_path); - put_backslash(s); - strcat(s, "default"); - put_backslash(s); - strcat(s, fn); + snprintf(s, 512, "%s%s", nvr_default_path, fn); return fopen(s, mode); } else diff --git a/src/paths.c b/src/paths.c index e3265b8..15d9963 100644 --- a/src/paths.c +++ b/src/paths.c @@ -25,6 +25,8 @@ char logs_path[512]; /* this is where screenshots as stored */ char screenshots_path[512]; +char nvr_default_path[512]; + char get_path_separator() { #ifdef _WIN32 @@ -129,6 +131,11 @@ void set_default_nvr_path(char *s) set_nvr_path(s); } +static void set_default_nvr_default_path(char *s) +{ + safe_strncpy(nvr_default_path, s, 512); +} + /* set the default logs path, this makes it permanent */ void set_default_logs_path(char *s) { @@ -203,6 +210,7 @@ void paths_onconfigloaded() void paths_init() { char s[512]; + char base_path[512]; char *p; get_pcem_path(pcem_path, 512); @@ -221,6 +229,10 @@ void paths_init() set_screenshots_path(s); set_logs_path(pcem_path); + get_pcem_base_path(base_path, 512); + append_filename(s, base_path, "nvr/default/", 512); + set_default_nvr_default_path(s); + add_config_callback(paths_loadconfig, paths_saveconfig, paths_onconfigloaded); } diff --git a/src/paths.h b/src/paths.h index ba54344..bf18630 100644 --- a/src/paths.h +++ b/src/paths.h @@ -4,8 +4,10 @@ extern char configs_path[512]; extern char nvr_path[512]; extern char logs_path[512]; extern char screenshots_path[512]; +extern char nvr_default_path[512]; void get_pcem_path(char *s, int size); +void get_pcem_base_path(char *s, int size); char get_path_separator(); void paths_init(); int dir_exists(char* path); diff --git a/src/wx-sdl2.c b/src/wx-sdl2.c index 172a50e..984d731 100644 --- a/src/wx-sdl2.c +++ b/src/wx-sdl2.c @@ -263,6 +263,12 @@ void get_pcem_path(char *s, int size) #endif } +void get_pcem_base_path(char *s, int size) +{ + char* path = SDL_GetBasePath(); + strcpy(s, path); +} + void set_window_title(const char *s) { sdl_set_window_title(s);