1 |
/* |
2 |
* prefs_windows.cpp - Preferences handling, Windows specific stuff |
3 |
* |
4 |
* Basilisk II (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 |
#define WIN32_LEAN_AND_MEAN |
24 |
#include <windows.h> |
25 |
|
26 |
#include <stdio.h> |
27 |
#include <stdlib.h> |
28 |
|
29 |
#include <string> |
30 |
using std::string; |
31 |
|
32 |
#include "prefs.h" |
33 |
|
34 |
|
35 |
// Platform-specific preferences items |
36 |
prefs_desc platform_prefs_items[] = { |
37 |
{"keycodes", TYPE_BOOLEAN, false, "use keycodes rather than keysyms to decode keyboard"}, |
38 |
{"keycodefile", TYPE_STRING, false, "path of keycode translation file"}, |
39 |
{"mousewheelmode", TYPE_INT32, false, "mouse wheel support mode (0=page up/down, 1=cursor up/down)"}, |
40 |
{"mousewheellines", TYPE_INT32, false, "number of lines to scroll in mouse wheel mode 1"}, |
41 |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
42 |
{"ignoresegv", TYPE_BOOLEAN, false, "ignore illegal memory accesses"}, |
43 |
#endif |
44 |
{"idlewait", TYPE_BOOLEAN, false, "sleep when idle"}, |
45 |
{"enableextfs", TYPE_BOOLEAN, false, "enable extfs system"}, |
46 |
{"debugextfs", TYPE_BOOLEAN, false, "debug extfs system"}, |
47 |
{"extdrives", TYPE_STRING, false, "define allowed extfs drives"}, |
48 |
{"pollmedia", TYPE_BOOLEAN, false, "poll for new media (e.g. cd, floppy)"}, |
49 |
{"etherguid", TYPE_STRING, false, "GUID of the ethernet device to use"}, |
50 |
{"etherpermanentaddress", TYPE_BOOLEAN, false, "use permanent NIC address to identify itself"}, |
51 |
{"ethermulticastmode", TYPE_INT32, false, "how to multicast packets"}, |
52 |
{"etherfakeaddress", TYPE_STRING, false, "optional fake hardware address"}, |
53 |
{"routerenabled", TYPE_BOOLEAN, false, "enable NAT/Router module"}, |
54 |
{"ftp_port_list", TYPE_STRING, false, "FTP ports list"}, |
55 |
{"tcp_port", TYPE_STRING, false, "TCP ports list"}, |
56 |
{"portfile0", TYPE_STRING, false, "output file for serial port 0"}, |
57 |
{"portfile1", TYPE_STRING, false, "output file for serial port 1"}, |
58 |
|
59 |
{NULL, TYPE_END, false, NULL} // End of list |
60 |
}; |
61 |
|
62 |
|
63 |
// Prefs file name and path |
64 |
const char PREFS_FILE_NAME[] = "BasiliskII_prefs"; |
65 |
string UserPrefsPath; |
66 |
static string prefs_path; |
67 |
|
68 |
|
69 |
/* |
70 |
* Load preferences from settings file |
71 |
*/ |
72 |
|
73 |
void LoadPrefs(const char *vmdir) |
74 |
{ |
75 |
// Construct prefs path |
76 |
if (UserPrefsPath.empty()) { |
77 |
int pwd_len = GetCurrentDirectory(0, NULL); |
78 |
char *pwd = new char[pwd_len]; |
79 |
if (GetCurrentDirectory(pwd_len, pwd) == pwd_len - 1) |
80 |
prefs_path = string(pwd) + '\\'; |
81 |
delete[] pwd; |
82 |
prefs_path += PREFS_FILE_NAME; |
83 |
} else |
84 |
prefs_path = UserPrefsPath; |
85 |
|
86 |
// Read preferences from settings file |
87 |
FILE *f = fopen(prefs_path.c_str(), "r"); |
88 |
if (f != NULL) { |
89 |
|
90 |
// Prefs file found, load settings |
91 |
LoadPrefsFromStream(f); |
92 |
fclose(f); |
93 |
|
94 |
} else { |
95 |
|
96 |
// No prefs file, save defaults |
97 |
SavePrefs(); |
98 |
} |
99 |
} |
100 |
|
101 |
|
102 |
/* |
103 |
* Save preferences to settings file |
104 |
*/ |
105 |
|
106 |
void SavePrefs(void) |
107 |
{ |
108 |
FILE *f; |
109 |
if ((f = fopen(prefs_path.c_str(), "w")) != NULL) { |
110 |
SavePrefsToStream(f); |
111 |
fclose(f); |
112 |
} |
113 |
} |
114 |
|
115 |
|
116 |
/* |
117 |
* Add defaults of platform-specific prefs items |
118 |
* You may also override the defaults set in PrefsInit() |
119 |
*/ |
120 |
|
121 |
void AddPlatformPrefsDefaults(void) |
122 |
{ |
123 |
PrefsAddBool("keycodes", false); |
124 |
PrefsReplaceBool("pollmedia", true); |
125 |
PrefsReplaceBool("enableextfs", false); |
126 |
PrefsReplaceString("extfs", ""); |
127 |
PrefsReplaceString("extdrives", "CDEFGHIJKLMNOPQRSTUVWXYZ"); |
128 |
PrefsReplaceInt32("mousewheelmode", 1); |
129 |
PrefsReplaceInt32("mousewheellines", 3); |
130 |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
131 |
PrefsAddBool("ignoresegv", false); |
132 |
#endif |
133 |
PrefsAddBool("idlewait", true); |
134 |
PrefsReplaceBool("etherpermanentaddress", true); |
135 |
PrefsReplaceInt32("ethermulticastmode", 0); |
136 |
PrefsReplaceString("ftp_port_list", "21"); |
137 |
PrefsReplaceString("seriala", "COM1"); |
138 |
PrefsReplaceString("serialb", "COM2"); |
139 |
PrefsReplaceString("portfile0", "C:\\B2TEMP0.OUT"); |
140 |
PrefsReplaceString("portfile1", "C:\\B2TEMP1.OUT"); |
141 |
} |