ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Windows/prefs_windows.cpp
Revision: 1.7
Committed: 2005-01-30T21:42:15Z (19 years, 4 months ago) by gbeauche
Branch: MAIN
Changes since 1.6: +1 -1 lines
Log Message:
Happy New Year!

File Contents

# Content
1 /*
2 * prefs_windows.cpp - Preferences handling, Windows specific stuff
3 *
4 * Basilisk II (C) 1997-2005 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 {"enableextfs", TYPE_BOOLEAN, false, "enable extfs system"},
45 {"debugextfs", TYPE_BOOLEAN, false, "debug extfs system"},
46 {"extdrives", TYPE_STRING, false, "define allowed extfs drives"},
47 {"pollmedia", TYPE_BOOLEAN, false, "poll for new media (e.g. cd, floppy)"},
48 {"etherpermanentaddress", TYPE_BOOLEAN, false, "use permanent NIC address to identify itself"},
49 {"ethermulticastmode", TYPE_INT32, false, "how to multicast packets"},
50 {"etherfakeaddress", TYPE_STRING, false, "optional fake hardware address"},
51 {"routerenabled", TYPE_BOOLEAN, false, "enable NAT/Router module"},
52 {"ftp_port_list", TYPE_STRING, false, "FTP ports list"},
53 {"tcp_port", TYPE_STRING, false, "TCP ports list"},
54
55 {NULL, TYPE_END, false, NULL} // End of list
56 };
57
58
59 // Prefs file name and path
60 const char PREFS_FILE_NAME[] = "BasiliskII_prefs";
61 string UserPrefsPath;
62 static string prefs_path;
63
64
65 /*
66 * Load preferences from settings file
67 */
68
69 void LoadPrefs(void)
70 {
71 // Construct prefs path
72 if (UserPrefsPath.empty()) {
73 int pwd_len = GetCurrentDirectory(0, NULL);
74 char *pwd = new char[pwd_len];
75 if (GetCurrentDirectory(pwd_len, pwd) == pwd_len - 1)
76 prefs_path = string(pwd) + '\\';
77 delete[] pwd;
78 prefs_path += PREFS_FILE_NAME;
79 } else
80 prefs_path = UserPrefsPath;
81
82 // Read preferences from settings file
83 FILE *f = fopen(prefs_path.c_str(), "r");
84 if (f != NULL) {
85
86 // Prefs file found, load settings
87 LoadPrefsFromStream(f);
88 fclose(f);
89
90 } else {
91
92 // No prefs file, save defaults
93 SavePrefs();
94 }
95 }
96
97
98 /*
99 * Save preferences to settings file
100 */
101
102 void SavePrefs(void)
103 {
104 FILE *f;
105 if ((f = fopen(prefs_path.c_str(), "w")) != NULL) {
106 SavePrefsToStream(f);
107 fclose(f);
108 }
109 }
110
111
112 /*
113 * Add defaults of platform-specific prefs items
114 * You may also override the defaults set in PrefsInit()
115 */
116
117 void AddPlatformPrefsDefaults(void)
118 {
119 PrefsAddBool("keycodes", false);
120 PrefsReplaceBool("pollmedia", true);
121 PrefsReplaceBool("enableextfs", false);
122 PrefsReplaceString("extfs", "");
123 PrefsReplaceString("extdrives", "CDEFGHIJKLMNOPQRSTUVWXYZ");
124 PrefsReplaceInt32("mousewheelmode", 1);
125 PrefsReplaceInt32("mousewheellines", 3);
126 #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
127 PrefsAddBool("ignoresegv", false);
128 #endif
129 PrefsReplaceBool("etherpermanentaddress", true);
130 PrefsReplaceInt32("ethermulticastmode", 0);
131 PrefsReplaceBool("routerenabled", false);
132 PrefsReplaceString("ftp_port_list", "21");
133 }