1 |
/* |
2 |
* prefs_windows.cpp - Preferences handling, Windows specific stuff |
3 |
* |
4 |
* SheepShaver (C) 1997-2008 Christian Bauer |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
*/ |
20 |
|
21 |
#include "sysdeps.h" |
22 |
|
23 |
#include <stdio.h> |
24 |
#include <stdlib.h> |
25 |
|
26 |
#include <string> |
27 |
using std::string; |
28 |
|
29 |
#include "prefs.h" |
30 |
|
31 |
|
32 |
// Platform-specific preferences items |
33 |
prefs_desc platform_prefs_items[] = { |
34 |
{"ether", TYPE_STRING, false, "device name of Mac ethernet adapter"}, |
35 |
{"keycodes", TYPE_BOOLEAN, false, "use keycodes rather than keysyms to decode keyboard"}, |
36 |
{"keycodefile", TYPE_STRING, false, "path of keycode translation file"}, |
37 |
{"mousewheelmode", TYPE_INT32, false, "mouse wheel support mode (0=page up/down, 1=cursor up/down)"}, |
38 |
{"mousewheellines", TYPE_INT32, false, "number of lines to scroll in mouse wheel mode 1"}, |
39 |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
40 |
{"ignoresegv", TYPE_BOOLEAN, false, "ignore illegal memory accesses"}, |
41 |
#endif |
42 |
{"idlewait", TYPE_BOOLEAN, false, "sleep when idle"}, |
43 |
{"keycodes", TYPE_BOOLEAN, false, "use keycodes rather than keysyms to decode keyboard"}, |
44 |
{"keycodefile", TYPE_STRING, false, "path of keycode translation file"}, |
45 |
{"mousewheelmode", TYPE_INT32, false, "mouse wheel support mode (0=page up/down, 1=cursor up/down)"}, |
46 |
{"mousewheellines", TYPE_INT32, false, "number of lines to scroll in mouse wheel mode 1"}, |
47 |
{"enableextfs", TYPE_BOOLEAN, false, "enable extfs system"}, |
48 |
{"debugextfs", TYPE_BOOLEAN, false, "debug extfs system"}, |
49 |
{"extdrives", TYPE_STRING, false, "define allowed extfs drives"}, |
50 |
{"pollmedia", TYPE_BOOLEAN, false, "poll for new media (e.g. cd, floppy)"}, |
51 |
{"etherguid", TYPE_STRING, false, "GUID of the ethernet device to use"}, |
52 |
{"etherpermanentaddress", TYPE_BOOLEAN, false, "use permanent NIC address to identify itself"}, |
53 |
{"ethermulticastmode", TYPE_INT32, false, "how to multicast packets"}, |
54 |
{"etherfakeaddress", TYPE_STRING, false, "optional fake hardware address"}, |
55 |
{"routerenabled", TYPE_BOOLEAN, false, "enable NAT/Router module"}, |
56 |
{"ftp_port_list", TYPE_STRING, false, "FTP ports list"}, |
57 |
{"tcp_port", TYPE_STRING, false, "TCP ports list"}, |
58 |
{"portfile0", TYPE_STRING, false, "output file for serial port 0"}, |
59 |
{"portfile1", TYPE_STRING, false, "output file for serial port 1"}, |
60 |
|
61 |
{NULL, TYPE_END, false, NULL} // End of list |
62 |
}; |
63 |
|
64 |
|
65 |
// Prefs file name and path |
66 |
const char PREFS_FILE_NAME[] = "SheepShaver_prefs"; |
67 |
string UserPrefsPath; |
68 |
static string prefs_path; |
69 |
|
70 |
|
71 |
/* |
72 |
* Load preferences from settings file |
73 |
*/ |
74 |
|
75 |
void LoadPrefs(const char *vmdir) |
76 |
{ |
77 |
// Construct prefs path |
78 |
if (UserPrefsPath.empty()) { |
79 |
int pwd_len = GetCurrentDirectory(0, NULL); |
80 |
char *pwd = new char[pwd_len]; |
81 |
if (GetCurrentDirectory(pwd_len, pwd) == pwd_len - 1) |
82 |
prefs_path = string(pwd) + '\\'; |
83 |
delete[] pwd; |
84 |
prefs_path += PREFS_FILE_NAME; |
85 |
} else |
86 |
prefs_path = UserPrefsPath; |
87 |
|
88 |
// Read preferences from settings file |
89 |
FILE *f = fopen(prefs_path.c_str(), "r"); |
90 |
if (f != NULL) { |
91 |
|
92 |
// Prefs file found, load settings |
93 |
LoadPrefsFromStream(f); |
94 |
fclose(f); |
95 |
|
96 |
} else { |
97 |
|
98 |
// No prefs file, save defaults |
99 |
SavePrefs(); |
100 |
} |
101 |
} |
102 |
|
103 |
|
104 |
/* |
105 |
* Save preferences to settings file |
106 |
*/ |
107 |
|
108 |
void SavePrefs(void) |
109 |
{ |
110 |
FILE *f; |
111 |
if ((f = fopen(prefs_path.c_str(), "w")) != NULL) { |
112 |
SavePrefsToStream(f); |
113 |
fclose(f); |
114 |
} |
115 |
} |
116 |
|
117 |
|
118 |
/* |
119 |
* Add defaults of platform-specific prefs items |
120 |
* You may also override the defaults set in PrefsInit() |
121 |
*/ |
122 |
|
123 |
void AddPlatformPrefsDefaults(void) |
124 |
{ |
125 |
PrefsAddBool("keycodes", false); |
126 |
PrefsReplaceBool("pollmedia", true); |
127 |
PrefsReplaceBool("enableextfs", false); |
128 |
PrefsReplaceString("extfs", ""); |
129 |
PrefsReplaceString("extdrives", "CDEFGHIJKLMNOPQRSTUVWXYZ"); |
130 |
PrefsReplaceInt32("mousewheelmode", 1); |
131 |
PrefsReplaceInt32("mousewheellines", 3); |
132 |
PrefsAddInt32("windowmodes", 3); |
133 |
PrefsAddInt32("screenmodes", 0x3f); |
134 |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
135 |
PrefsAddBool("ignoresegv", false); |
136 |
#endif |
137 |
PrefsAddBool("idlewait", true); |
138 |
PrefsReplaceBool("etherpermanentaddress", true); |
139 |
PrefsReplaceInt32("ethermulticastmode", 0); |
140 |
PrefsReplaceBool("routerenabled", false); |
141 |
PrefsReplaceString("ftp_port_list", "21"); |
142 |
PrefsReplaceString("seriala", "COM1"); |
143 |
PrefsReplaceString("serialb", "COM2"); |
144 |
PrefsReplaceString("portfile0", "C:\\B2TEMP0.OUT"); |
145 |
PrefsReplaceString("portfile1", "C:\\B2TEMP1.OUT"); |
146 |
} |