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