ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Windows/prefs_windows.cpp
Revision: 1.10
Committed: 2006-04-23T15:40:23Z (18 years, 2 months ago) by gbeauche
Branch: MAIN
Changes since 1.9: +1 -1 lines
Log Message:
Update the GUI with the new ethernet configuration changes. Handle migrations
from the GUI. Also move from a combo to a fixed popdown menu with pretty
printed ethernet interfaces.

File Contents

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