mirror of
https://github.com/kanjitalk755/macemu.git
synced 2024-06-27 16:29:29 +00:00
136 lines
3.3 KiB
C++
136 lines
3.3 KiB
C++
/*
|
|
* prefs_unix.cpp - Preferences handling, Unix specific stuff
|
|
*
|
|
* Basilisk II (C) 1997-2008 Christian Bauer
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#include "sysdeps.h"
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <string>
|
|
using std::string;
|
|
|
|
#include "prefs.h"
|
|
|
|
|
|
// Platform-specific preferences items
|
|
prefs_desc platform_prefs_items[] = {
|
|
{"fbdevicefile", TYPE_STRING, false, "path of frame buffer device specification file"},
|
|
{"dsp", TYPE_STRING, false, "audio output (dsp) device name"},
|
|
{"mixer", TYPE_STRING, false, "audio mixer device name"},
|
|
{"idlewait", TYPE_BOOLEAN, false, "sleep when idle"},
|
|
#ifdef USE_SDL_VIDEO
|
|
{"sdlrender", TYPE_STRING, false, "SDL_Renderer driver (\"auto\", \"software\" (may be faster), etc.)"},
|
|
#endif
|
|
{NULL, TYPE_END, false, NULL} // End of list
|
|
};
|
|
|
|
|
|
// Prefs file name and path
|
|
const char PREFS_FILE_NAME[] = ".basilisk_ii_prefs";
|
|
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 {
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Add defaults of platform-specific prefs items
|
|
* You may also override the defaults set in PrefsInit()
|
|
*/
|
|
|
|
void AddPlatformPrefsDefaults(void)
|
|
{
|
|
PrefsAddBool("keycodes", false);
|
|
PrefsReplaceString("extfs", "/");
|
|
PrefsReplaceInt32("mousewheelmode", 1);
|
|
PrefsReplaceInt32("mousewheellines", 3);
|
|
#ifdef __linux__
|
|
if (access("/dev/sound/dsp", F_OK) == 0) {
|
|
PrefsReplaceString("dsp", "/dev/sound/dsp");
|
|
} else {
|
|
PrefsReplaceString("dsp", "/dev/dsp");
|
|
}
|
|
if (access("/dev/sound/mixer", F_OK) == 0) {
|
|
PrefsReplaceString("mixer", "/dev/sound/mixer");
|
|
} else {
|
|
PrefsReplaceString("mixer", "/dev/mixer");
|
|
}
|
|
#else
|
|
PrefsReplaceString("dsp", "/dev/dsp");
|
|
PrefsReplaceString("mixer", "/dev/mixer");
|
|
#endif
|
|
PrefsAddBool("idlewait", true);
|
|
}
|