Skip to content

Commit

Permalink
macOS: revert prefs and xpram(nvram) location
Browse files Browse the repository at this point in the history
  • Loading branch information
kanjitalk755 committed Feb 10, 2024
1 parent 0a1d9c3 commit 08707d3
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 2 deletions.
84 changes: 82 additions & 2 deletions BasiliskII/src/Unix/prefs_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ prefs_desc platform_prefs_items[] = {
{NULL, TYPE_END, false, NULL} // End of list
};


#ifdef __linux__


// Standard file names and paths
#ifdef SHEEPSHAVER
static const char PREFS_FILE_NAME[] = "/.sheepshaver_prefs";
Expand Down Expand Up @@ -185,9 +189,9 @@ void LoadPrefs(const char* vmdir)
}

// No prefs file, save defaults in $XDG_CONFIG_HOME directory
#ifdef __linux__
//#ifdef __linux__
PrefsAddString("cdrom", "/dev/cdrom");
#endif
//#endif
printf("No prefs file found, creating new one at %s\n", prefs_name.c_str());
SavePrefs();
}
Expand Down Expand Up @@ -250,6 +254,82 @@ void SavePrefs(void)
}
}


#else // __linux__


// Prefs file name and path
#ifdef SHEEPSHAVER
static const char PREFS_FILE_NAME[] = ".sheepshaver_prefs";
#else
static const char PREFS_FILE_NAME[] = ".basilisk_ii_prefs";
#endif
string UserPrefsPath;
static string prefs_path;


/*
* Load preferences from settings file
*/

void LoadPrefs(const char *vmdir)
{
if (vmdir) {
prefs_path = string(vmdir) + '/' + string("prefs");
FILE *prefs = fopen(prefs_path.c_str(), "r");
if (!prefs) {
printf("No file at %s found.\n", prefs_path.c_str());
exit(1);
}
LoadPrefsFromStream(prefs);
fclose(prefs);
return;
}

// Construct prefs path
if (UserPrefsPath.empty()) {
char *home = getenv("HOME");
if (home)
prefs_path = string(home) + '/';
prefs_path += PREFS_FILE_NAME;
} else
prefs_path = UserPrefsPath;

// Read preferences from settings file
FILE *f = fopen(prefs_path.c_str(), "r");
if (f != NULL) {

// Prefs file found, load settings
LoadPrefsFromStream(f);
fclose(f);

} else {
//#ifdef __linux__
// PrefsAddString("cdrom", "/dev/cdrom");
//#endif
// No prefs file, save defaults
SavePrefs();
}
}


/*
* Save preferences to settings file
*/

void SavePrefs(void)
{
FILE *f;
if ((f = fopen(prefs_path.c_str(), "w")) != NULL) {
SavePrefsToStream(f);
fclose(f);
}
}


#endif // __linux__


/*
* Add defaults of platform-specific prefs items
* You may also override the defaults set in PrefsInit()
Expand Down
86 changes: 86 additions & 0 deletions BasiliskII/src/Unix/xpram_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ using std::string;

#include "xpram.h"


#ifdef __linux__


// XPRAM file name, set by LoadPrefs() in prefs_unix.cpp
string xpram_name;

Expand Down Expand Up @@ -73,3 +77,85 @@ void ZapPRAM(void)
assert(!xpram_name.empty());
unlink(xpram_name.c_str());
}


#else // __linux__


// XPRAM file name and path
#if POWERPC_ROM
const char XPRAM_FILE_NAME[] = ".sheepshaver_nvram";
#else
const char XPRAM_FILE_NAME[] = ".basilisk_ii_xpram";
#endif
static char xpram_path[1024];


/*
* Load XPRAM from settings file
*/

void LoadXPRAM(const char *vmdir)
{
if (vmdir) {
#if POWERPC_ROM
snprintf(xpram_path, sizeof(xpram_path), "%s/nvram", vmdir);
#else
snprintf(xpram_path, sizeof(xpram_path), "%s/xpram", vmdir);
#endif
} else {
// Construct XPRAM path
xpram_path[0] = 0;
char *home = getenv("HOME");
if (home != NULL && strlen(home) < 1000) {
strncpy(xpram_path, home, 1000);
strcat(xpram_path, "/");
}
strcat(xpram_path, XPRAM_FILE_NAME);
}

// Load XPRAM from settings file
int fd;
if ((fd = open(xpram_path, O_RDONLY)) >= 0) {
read(fd, XPRAM, XPRAM_SIZE);
close(fd);
}
}


/*
* Save XPRAM to settings file
*/

void SaveXPRAM(void)
{
int fd;
if ((fd = open(xpram_path, O_WRONLY | O_CREAT, 0666)) >= 0) {
write(fd, XPRAM, XPRAM_SIZE);
close(fd);
}
}


/*
* Delete PRAM file
*/

void ZapPRAM(void)
{
// Construct PRAM path
xpram_path[0] = 0;
char *home = getenv("HOME");
if (home != NULL && strlen(home) < 1000) {
strncpy(xpram_path, home, 1000);
strcat(xpram_path, "/");
}
strcat(xpram_path, XPRAM_FILE_NAME);

// Delete file
unlink(xpram_path);
}


#endif // __linux__

0 comments on commit 08707d3

Please sign in to comment.