SS: append --config command line option

This commit is contained in:
kanjitalk755 2022-01-26 13:43:08 +09:00
parent c359aabc2d
commit 33c3419b08
3 changed files with 29 additions and 10 deletions

View File

@ -796,6 +796,13 @@ int main(int argc, char **argv)
gui_connection_path = argv[i];
argv[i] = NULL;
}
} else if (strcmp(argv[i], "--config") == 0) {
argv[i++] = NULL;
if (i < argc) {
extern std::string UserPrefsPath;
UserPrefsPath = argv[i];
argv[i] = NULL;
}
} else if (valid_vmdir(argv[i])) {
vmdir = argv[i];
argv[i] = NULL;

View File

@ -23,6 +23,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include "prefs.h"
@ -49,6 +50,7 @@ prefs_desc platform_prefs_items[] = {
const char PREFS_FILE_NAME[] = ".sheepshaver_prefs";
static char prefs_path[1024];
std::string UserPrefsPath;
/*
* Load preferences from settings file
@ -68,14 +70,17 @@ void LoadPrefs(const char *vmdir)
return;
}
// Construct prefs path
prefs_path[0] = 0;
char *home = getenv("HOME");
if (home != NULL && strlen(home) < 1000) {
strncpy(prefs_path, home, 1000);
strcat(prefs_path, "/");
if (!UserPrefsPath.empty()) strncpy(prefs_path, UserPrefsPath.c_str(), 1000);
else {
// Construct prefs path
prefs_path[0] = 0;
char *home = getenv("HOME");
if (home != NULL && strlen(home) < 1000) {
strncpy(prefs_path, home, 1000);
strcat(prefs_path, "/");
}
strcat(prefs_path, PREFS_FILE_NAME);
}
strcat(prefs_path, PREFS_FILE_NAME);
// Read preferences from settings file
FILE *f = fopen(prefs_path, "r");

View File

@ -178,19 +178,26 @@ int main(int argc, char **argv)
printf(GetString(STR_ABOUT_TEXT1), VERSION_MAJOR, VERSION_MINOR);
printf(" %s\n", GetString(STR_ABOUT_TEXT2));
// Read preferences
PrefsInit(NULL, argc, argv);
// Parse command line arguments
for (int i=1; i<argc; i++) {
if (strcmp(argv[i], "--help") == 0) {
usage(argv[0]);
} else if (strcmp(argv[i], "--config") == 0) {
argv[i++] = NULL;
if (i < argc) {
extern std::string UserPrefsPath; // from prefs_windows.cpp
UserPrefsPath = to_tstring(argv[i]);
argv[i] = NULL;
}
} else if (argv[i][0] == '-') {
fprintf(stderr, "Unrecognized option '%s'\n", argv[i]);
usage(argv[0]);
}
}
// Read preferences
PrefsInit(NULL, argc, argv);
// Check we are using a Windows NT kernel >= 4.0
OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));