Skip to content

Commit

Permalink
Fix config load problem on macOS/Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
8bitbubsy committed Oct 28, 2022
1 parent ed51fab commit 1e43b50
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/pt2_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
11 changes: 11 additions & 0 deletions src/pt2_diskop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/pt2_diskop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 1e43b50

Please sign in to comment.