ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Windows/prefs_windows.cpp
Revision: 1.1
Committed: 2004-12-07T22:43:21Z (19 years, 11 months ago) by gbeauche
Branch: MAIN
Log Message:
Windows-specific prefs items

File Contents

# User Rev Content
1 gbeauche 1.1 /*
2     * prefs_windows.cpp - Preferences handling, Windows specific stuff
3     *
4     * SheepShaver (C) 1997-2004 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    
52     {NULL, TYPE_END, false, NULL} // End of list
53     };
54    
55    
56     // Prefs file name and path
57     const char PREFS_FILE_NAME[] = "SheepShaver_prefs";
58     string UserPrefsPath;
59     static string prefs_path;
60    
61    
62     /*
63     * Load preferences from settings file
64     */
65    
66     void LoadPrefs(void)
67     {
68     // Construct prefs path
69     if (UserPrefsPath.empty()) {
70     int pwd_len = GetCurrentDirectory(0, NULL);
71     char *pwd = new char[pwd_len];
72     if (GetCurrentDirectory(pwd_len, pwd) == pwd_len - 1)
73     prefs_path = string(pwd) + '\\';
74     delete[] pwd;
75     prefs_path += PREFS_FILE_NAME;
76     } else
77     prefs_path = UserPrefsPath;
78    
79     // Read preferences from settings file
80     FILE *f = fopen(prefs_path.c_str(), "r");
81     if (f != NULL) {
82    
83     // Prefs file found, load settings
84     LoadPrefsFromStream(f);
85     fclose(f);
86    
87     } else {
88    
89     // No prefs file, save defaults
90     SavePrefs();
91     }
92     }
93    
94    
95     /*
96     * Save preferences to settings file
97     */
98    
99     void SavePrefs(void)
100     {
101     FILE *f;
102     if ((f = fopen(prefs_path.c_str(), "w")) != NULL) {
103     SavePrefsToStream(f);
104     fclose(f);
105     }
106     }
107    
108    
109     /*
110     * Add defaults of platform-specific prefs items
111     * You may also override the defaults set in PrefsInit()
112     */
113    
114     void AddPlatformPrefsDefaults(void)
115     {
116     PrefsAddBool("keycodes", false);
117     PrefsReplaceBool("pollmedia", true);
118     PrefsReplaceBool("enableextfs", false);
119     PrefsReplaceString("extfs", "");
120     PrefsReplaceString("extdrives", "CDEFGHIJKLMNOPQRSTUVWXYZ");
121     PrefsReplaceInt32("mousewheelmode", 1);
122     PrefsReplaceInt32("mousewheellines", 3);
123     PrefsAddInt32("windowmodes", 3);
124     PrefsAddInt32("screenmodes", 0x3f);
125     #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
126     PrefsAddBool("ignoresegv", false);
127     #endif
128     PrefsAddBool("idlewait", true);
129     }