diff --git a/src/include/paths.h b/src/include/paths.h index f9ec972..7c4f458 100644 --- a/src/include/paths.h +++ b/src/include/paths.h @@ -1,4 +1,4 @@ -char* appdata_path(); +char* appdata_home_path(); int folder_exists(const char* path); int setup_appdata(); char* custom_appdata_path(const char* folder_name); \ No newline at end of file diff --git a/src/main.c b/src/main.c index 5d13a5f..519d344 100644 --- a/src/main.c +++ b/src/main.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include #ifdef _WIN32 #include #elif __linux__ || __APPLE__ @@ -9,11 +11,26 @@ #endif + + int main(void) { - puts("Hello, World!"); + char *log_path = malloc(256); + cwk_path_join(appdata_home_path(), "error.log", log_path, 256); + FILE *fp_e = fopen(log_path, "w"); + log_add_fp(fp_e, LOG_ERROR); + free(log_path); + + log_path = malloc(256); + cwk_path_join(appdata_home_path(), "debug.log", log_path, 256); + FILE *fp_d = fopen(log_path, "w"); + log_add_fp(fp_d, LOG_DEBUG); + free(log_path); + + + setup_appdata(); - printf_s("Appdata path: %s\n", appdata_path()); + log_info("Appdata path: %s", appdata_home_path()); const char *cupath = custom_appdata_path("ToDoLists"); - printf_s("Custom appdata path: %s\n", cupath); + log_info("Custom appdata path: %s", cupath); return 0; } \ No newline at end of file diff --git a/src/paths.c b/src/paths.c index 04c8337..0c7f334 100644 --- a/src/paths.c +++ b/src/paths.c @@ -12,10 +12,15 @@ // if (result == NULL) { // return NULL; // Handle memory allocation failure -char* appdata_path() { +char* appdata_home_path() { log_debug("Getting appdata path"); char* path = malloc(256); +#ifdef _WIN32 cwk_path_join(getenv("APPDATA"), APPDATA_FOLDER, path, 256); +#elif __linux__ || __APPLE__ + cwk_path_join(getenv("HOME"), ".local", path, 256); + cwk_path_join(path, APPDATA_FOLDER, path, 256); +#endif log_debug("Appdata path: %s", path); return path; } @@ -31,7 +36,7 @@ int folder_exists(const char* path) { } int setup_appdata() { - char* path = appdata_path(); + char* path = appdata_home_path(); if (!folder_exists(path)) { mkdir(path); @@ -50,7 +55,7 @@ int setup_appdata() { char* custom_appdata_path(const char* folder_name) { char *path = malloc(256); - cwk_path_join(appdata_path(), folder_name, path, 256); + cwk_path_join(appdata_home_path(), folder_name, path, 256); if (!folder_exists(path)) { log_debug("Custom appdata folder does not exist, creating: %s", path);