ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Windows/prefs_windows.cpp
Revision: 1.3
Committed: 2005-11-27T22:29:32Z (19 years ago) by gbeauche
Branch: MAIN
Changes since 1.2: +16 -0 lines
Log Message:
Ethernet and Serial support (merge from Basilisk II tree)

File Contents

# User Rev Content
1 gbeauche 1.1 /*
2     * prefs_windows.cpp - Preferences handling, Windows specific stuff
3     *
4 gbeauche 1.2 * SheepShaver (C) 1997-2005 Christian Bauer
5 gbeauche 1.1 *
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 gbeauche 1.3 {"etherpermanentaddress", TYPE_BOOLEAN, false, "use permanent NIC address to identify itself"},
52     {"ethermulticastmode", TYPE_INT32, false, "how to multicast packets"},
53     {"etherfakeaddress", TYPE_STRING, false, "optional fake hardware address"},
54     {"routerenabled", TYPE_BOOLEAN, false, "enable NAT/Router module"},
55     {"ftp_port_list", TYPE_STRING, false, "FTP ports list"},
56     {"tcp_port", TYPE_STRING, false, "TCP ports list"},
57     {"portfile0", TYPE_STRING, false, "output file for serial port 0"},
58     {"portfile1", TYPE_STRING, false, "output file for serial port 1"},
59 gbeauche 1.1
60     {NULL, TYPE_END, false, NULL} // End of list
61     };
62    
63    
64     // Prefs file name and path
65     const char PREFS_FILE_NAME[] = "SheepShaver_prefs";
66     string UserPrefsPath;
67     static string prefs_path;
68    
69    
70     /*
71     * Load preferences from settings file
72     */
73    
74     void LoadPrefs(void)
75     {
76     // Construct prefs path
77     if (UserPrefsPath.empty()) {
78     int pwd_len = GetCurrentDirectory(0, NULL);
79     char *pwd = new char[pwd_len];
80     if (GetCurrentDirectory(pwd_len, pwd) == pwd_len - 1)
81     prefs_path = string(pwd) + '\\';
82     delete[] pwd;
83     prefs_path += PREFS_FILE_NAME;
84     } else
85     prefs_path = UserPrefsPath;
86    
87     // Read preferences from settings file
88     FILE *f = fopen(prefs_path.c_str(), "r");
89     if (f != NULL) {
90    
91     // Prefs file found, load settings
92     LoadPrefsFromStream(f);
93     fclose(f);
94    
95     } else {
96    
97     // No prefs file, save defaults
98     SavePrefs();
99     }
100     }
101    
102    
103     /*
104     * Save preferences to settings file
105     */
106    
107     void SavePrefs(void)
108     {
109     FILE *f;
110     if ((f = fopen(prefs_path.c_str(), "w")) != NULL) {
111     SavePrefsToStream(f);
112     fclose(f);
113     }
114     }
115    
116    
117     /*
118     * Add defaults of platform-specific prefs items
119     * You may also override the defaults set in PrefsInit()
120     */
121    
122     void AddPlatformPrefsDefaults(void)
123     {
124     PrefsAddBool("keycodes", false);
125     PrefsReplaceBool("pollmedia", true);
126     PrefsReplaceBool("enableextfs", false);
127     PrefsReplaceString("extfs", "");
128     PrefsReplaceString("extdrives", "CDEFGHIJKLMNOPQRSTUVWXYZ");
129     PrefsReplaceInt32("mousewheelmode", 1);
130     PrefsReplaceInt32("mousewheellines", 3);
131     PrefsAddInt32("windowmodes", 3);
132     PrefsAddInt32("screenmodes", 0x3f);
133     #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
134     PrefsAddBool("ignoresegv", false);
135     #endif
136     PrefsAddBool("idlewait", true);
137 gbeauche 1.3 PrefsReplaceBool("etherpermanentaddress", true);
138     PrefsReplaceInt32("ethermulticastmode", 0);
139     PrefsReplaceBool("routerenabled", false);
140     PrefsReplaceString("ftp_port_list", "21");
141     PrefsReplaceString("seriala", "COM1");
142     PrefsReplaceString("serialb", "COM2");
143     PrefsReplaceString("portfile0", "C:\\B2TEMP0.OUT");
144     PrefsReplaceString("portfile1", "C:\\B2TEMP1.OUT");
145 gbeauche 1.1 }