From 1e43b50e5d6817507fd8dc0849f052d4d7a6c0a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rensen?= Date: Fri, 28 Oct 2022 21:48:50 +0200 Subject: [PATCH] Fix config load problem on macOS/Linux --- src/pt2_config.c | 8 ++++---- src/pt2_diskop.c | 11 +++++++++++ src/pt2_diskop.h | 3 +++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/pt2_config.c b/src/pt2_config.c index 80c75f4..562d45e 100644 --- a/src/pt2_config.c +++ b/src/pt2_config.c @@ -17,7 +17,7 @@ #include "pt2_config.h" #include "pt2_tables.h" #include "pt2_sampler.h" -#include "pt2_diskop.h" // changePathToDesktop() +#include "pt2_diskop.h" // changePathToDesktop(), changePathToHome() #ifndef _WIN32 static char oldCwd[PATH_MAX]; @@ -87,7 +87,7 @@ void loadConfig(void) proTrackerDotIniFound = true; // check in ~/.protracker/ - if (!proTrackerDotIniFound && changePathToDesktop() && chdir(".protracker") == 0) + if (!proTrackerDotIniFound && changePathToHome() && chdir(".protracker") == 0) { f = fopen("protracker.ini", "r"); if (f != NULL) @@ -116,7 +116,7 @@ void loadConfig(void) ptDotConfigFound = true; // check in ~/.protracker/ - if (!ptDotConfigFound && changePathToDesktop() && chdir(".protracker") == 0) + if (!ptDotConfigFound && changePathToHome() && chdir(".protracker") == 0) { f = openPTDotConfig(); if (f != NULL) @@ -140,7 +140,7 @@ void loadConfig(void) colorsDotIniFound = loadColorsDotIni(); // check in ~/.protracker/ - if (!colorsDotIniFound && changePathToDesktop() && chdir(".protracker") == 0) + if (!colorsDotIniFound && changePathToHome() && chdir(".protracker") == 0) loadColorsDotIni(); #endif diff --git a/src/pt2_diskop.c b/src/pt2_diskop.c index ab0e319..43dedb1 100644 --- a/src/pt2_diskop.c +++ b/src/pt2_diskop.c @@ -393,6 +393,17 @@ bool changePathToDesktop(void) #endif } +#ifndef _WIN32 +bool changePathToHome(void) +{ + char *homePath = getenv("HOME"); + if (homePath != NULL && chdir(homePath) == 0) + return true; + + return false; +} +#endif + void setPathFromDiskOpMode(void) { UNICHAR_CHDIR((diskop.mode == DISKOP_MODE_MOD) ? editor.modulesPathU : editor.samplesPathU); diff --git a/src/pt2_diskop.h b/src/pt2_diskop.h index 61e487c..95e5d23 100644 --- a/src/pt2_diskop.h +++ b/src/pt2_diskop.h @@ -28,5 +28,8 @@ void freeDiskOpMem(void); void freeDiskOpEntryMem(void); void setPathFromDiskOpMode(void); bool changePathToDesktop(void); +#ifndef _WIN32 +bool changePathToHome(void); +#endif void renderDiskOpScreen(void); void updateDiskOp(void); \ No newline at end of file