support for .sheepvm bundles on macosx, containing "prefs" and "nvram" files

This commit is contained in:
asvitkine 2009-07-23 19:12:51 +00:00
parent 581ff8d86f
commit 5b958defa7
9 changed files with 63 additions and 10 deletions

View File

@ -318,7 +318,7 @@ void SheepShaver::ReadyToRun(void)
// Read preferences
int argc = 0;
char **argv = NULL;
PrefsInit(argc, argv);
PrefsInit(NULL, argc, argv);
// Init system routines
SysInit();

View File

@ -49,7 +49,7 @@ time_t PrefsFileDate = 0;
* Load preferences from settings file
*/
void LoadPrefs(void)
void LoadPrefs(const char *vmdir)
{
// Construct prefs path
find_directory(B_USER_SETTINGS_DIRECTORY, &prefs_path, true);

View File

@ -18,5 +18,22 @@
<string>SheepShaver.icns</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>sheepvm</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>SheepShaver.icns</string>
<key>CFBundleTypeName</key>
<string>SheepShaver VM</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSTypeIsPackage</key>
<true/>
</dict>
</array>
</dict>
</plist>

View File

@ -89,6 +89,7 @@
#include <sys/mman.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <signal.h>
#include "sysdeps.h"
@ -360,6 +361,19 @@ static void usage(const char *prg_name)
exit(0);
}
static bool valid_vmdir(const char *path)
{
const int suffix_len = sizeof(".sheepvm") - 1;
int len = strlen(path);
if (len > suffix_len && !strcmp(path + len - suffix_len, ".sheepvm")) {
struct stat d;
if (!stat(path, &d) && S_ISDIR(d.st_mode)) {
return true;
}
}
return false;
}
int main(int argc, char **argv)
{
char str[256];
@ -370,6 +384,7 @@ int main(int argc, char **argv)
uint8 *rom_tmp;
time_t now, expire;
bool memory_mapped_from_zero;
const char *vmdir = NULL;
#ifdef USE_SDL_VIDEO
// Don't let SDL block the screensaver
@ -414,6 +429,15 @@ int main(int argc, char **argv)
gui_connection_path = argv[i];
argv[i] = NULL;
}
} else if (valid_vmdir(argv[i])) {
vmdir = argv[i];
argv[i] = NULL;
printf("Using %s as vmdir.\n", vmdir);
if (chdir(vmdir)) {
printf("Failed to chdir to %s. Good bye.", vmdir);
exit(1);
}
break;
}
}
@ -448,7 +472,7 @@ int main(int argc, char **argv)
#endif
// Read preferences
PrefsInit(argc, argv);
PrefsInit(vmdir, argc, argv);
// Any command line arguments left?
for (int i=1; i<argc; i++) {
@ -895,7 +919,7 @@ int main(int argc, char **argv)
delete[] rom_tmp;
// Initialize everything
if (!InitAll())
if (!InitAll(vmdir))
goto quit;
D(bug("Initialization complete\n"));

View File

@ -54,8 +54,20 @@ static char prefs_path[1024];
* Load preferences from settings file
*/
void LoadPrefs(void)
void LoadPrefs(const char *vmdir)
{
if (vmdir) {
snprintf(prefs_path, sizeof(prefs_path), "%s/prefs", vmdir);
FILE *prefs = fopen(prefs_path, "r");
if (!prefs) {
printf("No file at %s found.\n", prefs_path);
exit(1);
}
LoadPrefsFromStream(prefs);
fclose(prefs);
return;
}
// Construct prefs path
prefs_path[0] = 0;
char *home = getenv("HOME");

View File

@ -173,7 +173,7 @@ int main(int argc, char **argv)
printf(" %s\n", GetString(STR_ABOUT_TEXT2));
// Read preferences
PrefsInit(argc, argv);
PrefsInit(NULL, argc, argv);
// Parse command line arguments
for (int i=1; i<argc; i++) {

View File

@ -72,7 +72,7 @@ static string prefs_path;
* Load preferences from settings file
*/
void LoadPrefs(void)
void LoadPrefs(const char *vmdir)
{
// Construct prefs path
if (UserPrefsPath.empty()) {

View File

@ -43,7 +43,7 @@ struct M68kRegisters {
// Functions
extern bool InitAll(void);
extern bool InitAll(const char *vmdir);
extern void ExitAll(void);
extern void Dump68kRegs(M68kRegisters *r); // Dump 68k registers
extern void MakeExecutable(int dummy, uint32 start, uint32 length); // Make code executable

View File

@ -70,10 +70,10 @@ static void sheepshaver_write_byte(uintptr adr, uint32 b)
* Initialize everything, returns false on error
*/
bool InitAll(void)
bool InitAll(const char *vmdir)
{
// Load NVRAM
XPRAMInit();
XPRAMInit(vmdir);
// Load XPRAM default values if signature not found
if (XPRAM[0x130c] != 0x4e || XPRAM[0x130d] != 0x75