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]; gui_connection_path = argv[i];
argv[i] = NULL; 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])) { } else if (valid_vmdir(argv[i])) {
vmdir = argv[i]; vmdir = argv[i];
argv[i] = NULL; argv[i] = NULL;

View File

@ -23,6 +23,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string>
#include "prefs.h" #include "prefs.h"
@ -49,6 +50,7 @@ prefs_desc platform_prefs_items[] = {
const char PREFS_FILE_NAME[] = ".sheepshaver_prefs"; const char PREFS_FILE_NAME[] = ".sheepshaver_prefs";
static char prefs_path[1024]; static char prefs_path[1024];
std::string UserPrefsPath;
/* /*
* Load preferences from settings file * Load preferences from settings file
@ -68,14 +70,17 @@ void LoadPrefs(const char *vmdir)
return; return;
} }
// Construct prefs path if (!UserPrefsPath.empty()) strncpy(prefs_path, UserPrefsPath.c_str(), 1000);
prefs_path[0] = 0; else {
char *home = getenv("HOME"); // Construct prefs path
if (home != NULL && strlen(home) < 1000) { prefs_path[0] = 0;
strncpy(prefs_path, home, 1000); char *home = getenv("HOME");
strcat(prefs_path, "/"); 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 // Read preferences from settings file
FILE *f = fopen(prefs_path, "r"); 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(GetString(STR_ABOUT_TEXT1), VERSION_MAJOR, VERSION_MINOR);
printf(" %s\n", GetString(STR_ABOUT_TEXT2)); printf(" %s\n", GetString(STR_ABOUT_TEXT2));
// Read preferences
PrefsInit(NULL, argc, argv);
// Parse command line arguments // Parse command line arguments
for (int i=1; i<argc; i++) { for (int i=1; i<argc; i++) {
if (strcmp(argv[i], "--help") == 0) { if (strcmp(argv[i], "--help") == 0) {
usage(argv[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] == '-') { } else if (argv[i][0] == '-') {
fprintf(stderr, "Unrecognized option '%s'\n", argv[i]); fprintf(stderr, "Unrecognized option '%s'\n", argv[i]);
usage(argv[0]); usage(argv[0]);
} }
} }
// Read preferences
PrefsInit(NULL, argc, argv);
// Check we are using a Windows NT kernel >= 4.0 // Check we are using a Windows NT kernel >= 4.0
OSVERSIONINFO osvi; OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); ZeroMemory(&osvi, sizeof(OSVERSIONINFO));