shithub: pt2-clone

Download patch

ref: 1e43b50e5d6817507fd8dc0849f052d4d7a6c0a8
parent: ed51fabbc1feaa0a4fadb7541fb9527bfccbe185
author: Olav Sørensen <olav.sorensen@live.no>
date: Fri Oct 28 17:48:50 EDT 2022

Fix config load problem on macOS/Linux

--- 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 @@
 		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 @@
 		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 @@
 	colorsDotIniFound = loadColorsDotIni();
 
 	// check in ~/.protracker/
-	if (!colorsDotIniFound && changePathToDesktop() && chdir(".protracker") == 0)
+	if (!colorsDotIniFound && changePathToHome() && chdir(".protracker") == 0)
 		loadColorsDotIni();
 #endif
 
--- a/src/pt2_diskop.c
+++ b/src/pt2_diskop.c
@@ -393,6 +393,17 @@
 #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);
--- a/src/pt2_diskop.h
+++ b/src/pt2_diskop.h
@@ -28,5 +28,8 @@
 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