8b5037a6 |
1 | /** |
2 | * @section LICENSE |
3 | * |
4 | * PickleLauncher |
5 | * Copyright (C) 2010-2011 Scott Smith |
6 | * |
7 | * This program is free software: you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation, either version 3 of the License, or |
10 | * (at your option) any later version. |
11 | * |
12 | * This program is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * |
20 | * @section LOCATION |
21 | */ |
22 | |
23 | #include "cconfig.h" |
24 | |
25 | CConfig::CConfig() : CBase(), |
26 | ResetGUI (false), |
27 | #if defined(DEBUG) |
28 | Fullscreen (false), |
29 | #else |
30 | Fullscreen (true), |
31 | #endif |
32 | ScreenFlip (false), |
33 | UseZipSupport (true), |
34 | ShowExts (true), |
35 | ShowHidden (false), |
36 | #if defined(X86) |
37 | ShowPointer (true), |
38 | #else |
39 | ShowPointer (false), |
40 | #endif |
41 | ShowLabels (true), |
42 | UnusedKeysLaunch (false), |
43 | UnusedJoysLaunch (false), |
44 | ReloadLauncher (true), |
45 | TextScrollOption (true), |
46 | AutoLayout (true), |
47 | FilenameArgNoExt (false), |
48 | FilenameAbsPath (true), |
49 | EntryFastMode (ENTRY_FAST_MODE_FILTER), |
50 | MaxEntries (MAX_ENTRIES), |
51 | ColorButton (COLOR_BLUE), |
52 | ColorFontButton (COLOR_WHITE), |
53 | ColorBackground (COLOR_WHITE), |
54 | ColorFontFiles (COLOR_BLACK), |
55 | ColorFontFolders (COLOR_RED), |
56 | AnalogDeadZone (DEAD_ZONE), |
57 | ScreenWidth (SCREEN_WIDTH), |
58 | ScreenHeight (SCREEN_HEIGHT), |
59 | ScreenDepth (SCREEN_DEPTH), |
60 | CPUClock (CPU_CLOCK_DEF), |
61 | ScrollSpeed (SCROLL_SPEED), |
62 | ScrollPauseSpeed (SCROLL_PAUSE_SPEED), |
63 | EntryYDelta (0), |
64 | EntryXOffset (0), |
65 | EntryYOffset (0), |
66 | ButtonWidthLeft (0), |
67 | ButtonHeightLeft (0), |
68 | ButtonWidthRight (0), |
69 | ButtonHeightRight (0), |
70 | PreviewWidth (0), |
71 | PreviewHeight (0), |
72 | DisplayListMaxWidth (0), |
73 | FilePathMaxWidth (0), |
74 | PosX_Title (0), |
75 | PosY_Title (0), |
76 | PosX_ButtonLeft (0), |
77 | PosY_ButtonLeft (0), |
78 | PosX_ButtonRight (0), |
79 | PosY_ButtonRight (0), |
80 | PosX_ListNames (0), |
81 | PosY_ListNames (0), |
82 | ScreenRatioW ((float)ScreenWidth/(float)BASE_WIDTH), |
83 | ScreenRatioH ((float)ScreenHeight/(float)BASE_HEIGHT), |
84 | ZipPath ("ziptemp"), |
85 | PreviewsPath ("previews"), |
86 | PathFont ("DejaVuSansMono-Bold.ttf"), |
87 | PathBackground ("images/background.png"), |
88 | PathPointer ("images/pointer.png"), |
89 | PathSelectPointer ("images/selectpointer.png"), |
90 | Delimiter (DELIMITER), |
91 | ButtonModesLeftEnable (), |
92 | ButtonModesRightEnable (), |
93 | PathButtons (), |
94 | KeyMaps (), |
95 | JoyMaps (), |
96 | FontSizes (), |
97 | Colors (), |
98 | ColorNames () |
99 | { |
100 | SetDefaults(); |
101 | } |
102 | |
103 | CConfig::~CConfig() |
104 | { |
105 | } |
106 | |
107 | void CConfig::SetDefaults( void ) |
108 | { |
109 | ButtonModesLeftEnable.resize( BUTTONS_MAX_LEFT, true ); |
110 | ButtonModesRightEnable.resize( BUTTONS_MAX_RIGHT, true ); |
111 | |
112 | KeyMaps.resize(EVENT_TOTAL); |
113 | KeyMaps.at(EVENT_ONE_UP) = SDLK_UP; |
114 | KeyMaps.at(EVENT_ONE_DOWN) = SDLK_DOWN; |
115 | KeyMaps.at(EVENT_PAGE_UP) = SDLK_LEFT; |
116 | KeyMaps.at(EVENT_PAGE_DOWN) = SDLK_RIGHT; |
117 | KeyMaps.at(EVENT_DIR_UP) = SDLK_LCTRL; |
118 | KeyMaps.at(EVENT_DIR_DOWN) = SDLK_RSHIFT; |
119 | KeyMaps.at(EVENT_CFG_APP) = SDLK_1; |
120 | KeyMaps.at(EVENT_CFG_ITEM) = SDLK_2; |
121 | KeyMaps.at(EVENT_SET_ONE) = SDLK_3; |
122 | KeyMaps.at(EVENT_SET_ALL) = SDLK_4; |
123 | KeyMaps.at(EVENT_SELECT) = SDLK_RETURN; |
124 | KeyMaps.at(EVENT_BACK) = SDLK_LCTRL; |
125 | KeyMaps.at(EVENT_QUIT) = SDLK_ESCAPE; |
126 | |
127 | JoyMaps.resize(EVENT_TOTAL); |
128 | JoyMaps.at(EVENT_ONE_UP) = 0; |
129 | JoyMaps.at(EVENT_ONE_DOWN) = 1; |
130 | JoyMaps.at(EVENT_PAGE_UP) = 2; |
131 | JoyMaps.at(EVENT_PAGE_DOWN) = 3; |
132 | JoyMaps.at(EVENT_DIR_UP) = 4; |
133 | JoyMaps.at(EVENT_DIR_DOWN) = 5; |
134 | JoyMaps.at(EVENT_CFG_APP) = 6; |
135 | JoyMaps.at(EVENT_CFG_ITEM) = 7; |
136 | JoyMaps.at(EVENT_SET_ONE) = 8; |
137 | JoyMaps.at(EVENT_SET_ALL) = 9; |
138 | JoyMaps.at(EVENT_SELECT) = 10; |
139 | JoyMaps.at(EVENT_BACK) = 11; |
140 | JoyMaps.at(EVENT_QUIT) = 12; |
141 | |
142 | PathButtons.resize(EVENT_TOTAL); |
143 | PathButtons.at(EVENT_ONE_UP) = "images/button_oneup.png"; |
144 | PathButtons.at(EVENT_ONE_DOWN) = "images/button_onedn.png"; |
145 | PathButtons.at(EVENT_PAGE_UP) = "images/button_pageup.png"; |
146 | PathButtons.at(EVENT_PAGE_DOWN) = "images/button_pagedn.png"; |
147 | PathButtons.at(EVENT_DIR_UP) = "images/button_dirup.png"; |
148 | PathButtons.at(EVENT_DIR_DOWN) = "images/button_dirdn.png"; |
149 | PathButtons.at(EVENT_ZIP_MODE) = "images/button_zipmode.png"; |
150 | PathButtons.at(EVENT_CFG_APP) = "images/button_cfg_app.png"; |
151 | PathButtons.at(EVENT_CFG_ITEM) = "images/button_cfg_item.png"; |
152 | PathButtons.at(EVENT_SET_ONE) = "images/button_set_one.png"; |
153 | PathButtons.at(EVENT_SET_ALL) = "images/button_set_all.png"; |
154 | PathButtons.at(EVENT_BACK) = "images/button_back.png"; |
155 | PathButtons.at(EVENT_SELECT) = "images/button_select.png"; |
156 | PathButtons.at(EVENT_QUIT) = "images/button_quit.png"; |
157 | |
158 | Colors.resize(COLOR_TOTAL); |
159 | ColorNames.resize(COLOR_TOTAL); |
160 | ColorNames.at(COLOR_WHITE) = "white"; Colors.at(COLOR_WHITE).r = 255; Colors.at(COLOR_WHITE).g = 255; Colors.at(COLOR_WHITE).b = 255; |
161 | ColorNames.at(COLOR_YELLOW) = "yellow"; Colors.at(COLOR_YELLOW).r = 255; Colors.at(COLOR_YELLOW).g = 255; Colors.at(COLOR_YELLOW).b = 0; |
162 | ColorNames.at(COLOR_FUCHSIA) = "fushsia"; Colors.at(COLOR_FUCHSIA).r = 255; Colors.at(COLOR_FUCHSIA).g = 0; Colors.at(COLOR_FUCHSIA).b = 255; |
163 | ColorNames.at(COLOR_RED) = "red"; Colors.at(COLOR_RED).r = 255; Colors.at(COLOR_RED).g = 0; Colors.at(COLOR_RED).b = 0; |
164 | ColorNames.at(COLOR_SILVER) = "silver"; Colors.at(COLOR_SILVER).r = 192; Colors.at(COLOR_SILVER).g = 192; Colors.at(COLOR_SILVER).b = 192; |
165 | ColorNames.at(COLOR_GRAY) = "gray"; Colors.at(COLOR_GRAY).r = 128; Colors.at(COLOR_GRAY).g = 128; Colors.at(COLOR_GRAY).b = 128; |
166 | ColorNames.at(COLOR_OLIVE) = "olive"; Colors.at(COLOR_OLIVE).r = 128; Colors.at(COLOR_OLIVE).g = 128; Colors.at(COLOR_OLIVE).b = 0; |
167 | ColorNames.at(COLOR_PURPLE) = "purple"; Colors.at(COLOR_PURPLE).r = 128; Colors.at(COLOR_PURPLE).g = 0; Colors.at(COLOR_PURPLE).b = 128; |
168 | ColorNames.at(COLOR_MAROON) = "maroon"; Colors.at(COLOR_MAROON).r = 128; Colors.at(COLOR_MAROON).g = 0; Colors.at(COLOR_MAROON).b = 0; |
169 | ColorNames.at(COLOR_AQUA) = "aqua"; Colors.at(COLOR_AQUA).r = 0; Colors.at(COLOR_AQUA).g = 255; Colors.at(COLOR_AQUA).b = 255; |
170 | ColorNames.at(COLOR_LIME) = "lime"; Colors.at(COLOR_LIME).r = 0; Colors.at(COLOR_LIME).g = 255; Colors.at(COLOR_LIME).b = 0; |
171 | ColorNames.at(COLOR_TEAL) = "teal"; Colors.at(COLOR_TEAL).r = 0; Colors.at(COLOR_TEAL).g = 128; Colors.at(COLOR_TEAL).b = 128; |
172 | ColorNames.at(COLOR_GREEN) = "green"; Colors.at(COLOR_GREEN).r = 0; Colors.at(COLOR_GREEN).g = 128; Colors.at(COLOR_GREEN).b = 0; |
173 | ColorNames.at(COLOR_BLUE) = "blue"; Colors.at(COLOR_BLUE).r = 0; Colors.at(COLOR_BLUE).g = 0; Colors.at(COLOR_BLUE).b = 255; |
174 | ColorNames.at(COLOR_NAVY) = "navy"; Colors.at(COLOR_NAVY).r = 0; Colors.at(COLOR_NAVY).g = 0; Colors.at(COLOR_NAVY).b = 128; |
175 | ColorNames.at(COLOR_BLACK) = "black"; Colors.at(COLOR_BLACK).r = 0; Colors.at(COLOR_BLACK).g = 0; Colors.at(COLOR_BLACK).b = 0; |
176 | |
177 | FontSizes.resize(FONT_SIZE_TOTAL, 0); |
178 | FontSizes.at(FONT_SIZE_SMALL) = (int16_t)( 8*ScreenRatioH); |
179 | FontSizes.at(FONT_SIZE_MEDIUM) = (int16_t)(12*ScreenRatioH); |
180 | FontSizes.at(FONT_SIZE_LARGE) = (int16_t)(14*ScreenRatioH); |
181 | |
182 | EntryYDelta = ENTRY_Y_DELTA; |
183 | EntryXOffset = ENTRY_X_OFFSET; |
184 | EntryYOffset = ENTRY_Y_OFFSET; |
185 | ButtonWidthLeft = BUTTON_W_LEFT; |
186 | ButtonHeightLeft = BUTTON_H_LEFT; |
187 | ButtonWidthRight = BUTTON_W_RIGHT; |
188 | ButtonHeightRight = BUTTON_H_RIGHT; |
189 | PreviewWidth = PREVIEW_W; |
190 | PreviewHeight = PREVIEW_H; |
191 | DisplayListMaxWidth = ENTRY_MAX_W; |
192 | FilePathMaxWidth = FILEPATH_MAX_W; |
193 | } |
194 | |
195 | #define LOAD_INT(X,Y) if (UnprefixString( line, line, X ) == true) { Y = a_to_i(line); } |
196 | #define LOAD_KEY(X,Y) if (UnprefixString( line, line, X ) == true) { Y = (SDLKey)a_to_i(line); } |
197 | #define LOAD_STR(X,Y) if (UnprefixString( Y, line, X ) == true) {} |
198 | |
199 | int8_t CConfig::Load( const string& location ) |
200 | { |
201 | uint16_t i; |
202 | string line; |
203 | string label; |
204 | ifstream fin; |
205 | |
206 | fin.open(location.c_str(), ios_base::in); |
207 | |
208 | if (!fin) |
209 | { |
210 | Log( "Failed to open config\n" ); |
211 | return 0; // Dont stop the app if it cant be opened, default values will be used and then save to file. |
212 | } |
213 | |
214 | // Read in the profile |
215 | if (fin.is_open()) |
216 | { |
217 | while (!fin.eof()) |
218 | { |
219 | getline(fin,line); |
220 | |
221 | #if defined(DEBUG) |
222 | Log( "%s\n", line.c_str() ); |
223 | #endif |
224 | |
225 | if (line.length() > 0) |
226 | { |
227 | LOAD_INT( OPT_SCREEN_WIDTH, ScreenWidth ); |
228 | LOAD_INT( OPT_SCREEN_HEIGHT, ScreenHeight ); |
229 | LOAD_INT( OPT_SCREEN_DEPTH, ScreenDepth ); |
230 | LOAD_INT( OPT_FULLSCREEN, Fullscreen ); |
231 | LOAD_INT( OPT_CPU_CLOCK, CPUClock ); |
232 | LOAD_INT( OPT_USEZIPSUPPORT, UseZipSupport ); |
233 | LOAD_INT( OPT_SHOWEXTS, ShowExts ); |
234 | LOAD_INT( OPT_SHOWHIDDEN, ShowHidden ); |
235 | LOAD_INT( OPT_SHOWPOINTER, ShowPointer ); |
236 | LOAD_INT( OPT_SHOWLABELS, ShowLabels ); |
237 | LOAD_INT( OPT_UNUSED_KEYS_SELECT, UnusedKeysLaunch ); |
238 | LOAD_INT( OPT_UNUSED_JOYS_SELECT, UnusedJoysLaunch ); |
239 | LOAD_INT( OPT_RELOAD_LAUNCHER, ReloadLauncher ); |
240 | LOAD_INT( OPT_TEXT_SCROLL_OPTION, TextScrollOption ); |
241 | LOAD_INT( OPT_FILENAMEARGNOEXT, FilenameArgNoExt ); |
242 | LOAD_INT( OPT_FILEABSPATH, FilenameAbsPath ); |
243 | LOAD_INT( OPT_FONT_SIZE_SMALL, FontSizes.at(FONT_SIZE_SMALL) ); |
244 | LOAD_INT( OPT_FONT_SIZE_MEDIUM, FontSizes.at(FONT_SIZE_MEDIUM) ); |
245 | LOAD_INT( OPT_FONT_SIZE_LARGE, FontSizes.at(FONT_SIZE_LARGE) ); |
246 | LOAD_INT( OPT_ENTRY_FAST_MODE, EntryFastMode ); |
247 | LOAD_INT( OPT_MAX_ENTRIES, MaxEntries ); |
248 | LOAD_INT( OPT_SCROLL_SPEED, ScrollSpeed ); |
249 | LOAD_INT( OPT_SCROLL_PAUSE_SPEED, ScrollPauseSpeed ); |
250 | LOAD_STR( OPT_PROFILE_DELIMITER, Delimiter ); |
251 | // GUI Positions |
252 | LOAD_INT( OPT_AUTOLAYOUT, AutoLayout ); |
253 | LOAD_INT( OPT_POSX_TITLE, PosX_Title ); |
254 | LOAD_INT( OPT_POSY_TITLE, PosY_Title ); |
255 | LOAD_INT( OPT_POSX_BTNLEFT, PosX_ButtonLeft ); |
256 | LOAD_INT( OPT_POSY_BTNLEFT, PosY_ButtonLeft ); |
257 | LOAD_INT( OPT_POSX_BTNRIGHT, PosX_ButtonRight ); |
258 | LOAD_INT( OPT_POSY_BTNRIGHT, PosY_ButtonRight ); |
259 | LOAD_INT( OPT_POSX_LISTNAMES, PosX_ListNames ); |
260 | LOAD_INT( OPT_POSY_LISTNAMES, PosY_ListNames ); |
261 | // GUI Options |
262 | LOAD_INT( OPT_ENTRY_Y_DELTA, EntryYDelta ); |
263 | LOAD_INT( OPT_ENTRY_X_OFFSET, EntryXOffset ); |
264 | LOAD_INT( OPT_ENTRY_Y_OFFSET, EntryYOffset ); |
265 | LOAD_INT( OPT_BUTTON_W_LEFT, ButtonWidthLeft ); |
266 | LOAD_INT( OPT_BUTTON_H_LEFT, ButtonHeightLeft ); |
267 | LOAD_INT( OPT_BUTTON_W_RIGHT, ButtonWidthRight ); |
268 | LOAD_INT( OPT_BUTTON_H_RIGHT, ButtonHeightRight ); |
269 | LOAD_INT( OPT_PREVIEW_W, PreviewWidth ); |
270 | LOAD_INT( OPT_PREVIEW_H, PreviewHeight ); |
271 | LOAD_INT( OPT_ENTRY_MAX_W, DisplayListMaxWidth ); |
272 | LOAD_INT( OPT_FILEPATH_MAX_W, FilePathMaxWidth ); |
273 | // GUI Buttons |
274 | for (i=0; i<ButtonModesLeftEnable.size(); i++) |
275 | { |
276 | label = string(OPT_BUTTONLEFT_ENABLED) + "_"+ i_to_a(i); |
277 | LOAD_INT( label, ButtonModesLeftEnable.at(i) ); |
278 | } |
279 | for (i=0; i<ButtonModesRightEnable.size(); i++) |
280 | { |
281 | label = string(OPT_BUTTONRIGHT_ENABLED) + "_"+ i_to_a(i); |
282 | LOAD_INT( label, ButtonModesRightEnable.at(i) ); |
283 | } |
284 | // Paths |
285 | LOAD_STR( OPT_PATH_ZIPTEMP, ZipPath ); |
286 | LOAD_STR( OPT_PATH_PREVIEWS, PreviewsPath ); |
287 | LOAD_STR( OPT_PATH_FONT, PathFont ); |
288 | LOAD_STR( OPT_PATH_BACKGND, PathBackground ); |
289 | LOAD_STR( OPT_PATH_POINTER, PathPointer ); |
290 | LOAD_STR( OPT_PATH_POINTER, PathPointer ); |
291 | LOAD_STR( OPT_PATH_ONEUP, PathButtons.at(EVENT_ONE_UP) ); |
292 | LOAD_STR( OPT_PATH_ONEDN, PathButtons.at(EVENT_ONE_DOWN) ); |
293 | LOAD_STR( OPT_PATH_PGUP, PathButtons.at(EVENT_PAGE_UP) ); |
294 | LOAD_STR( OPT_PATH_PGDN, PathButtons.at(EVENT_PAGE_DOWN) ); |
295 | LOAD_STR( OPT_PATH_DIRUP, PathButtons.at(EVENT_DIR_UP) ); |
296 | LOAD_STR( OPT_PATH_DIRDN, PathButtons.at(EVENT_DIR_DOWN) ); |
297 | LOAD_STR( OPT_PATH_CFG_APP, PathButtons.at(EVENT_CFG_APP) ); |
298 | LOAD_STR( OPT_PATH_CFG_ITEM, PathButtons.at(EVENT_CFG_ITEM) ); |
299 | LOAD_STR( OPT_PATH_SELECT, PathButtons.at(EVENT_SELECT) ); |
300 | LOAD_STR( OPT_PATH_QUIT, PathButtons.at(EVENT_QUIT) ); |
301 | // Color mappings |
302 | LOAD_INT( OPT_COLOR_BUTTON, ColorButton ); |
303 | LOAD_INT( OPT_COLOR_FONTBUTTON, ColorFontButton ); |
304 | LOAD_INT( OPT_COLOR_BACKGND, ColorBackground ); |
305 | LOAD_INT( OPT_COLOR_FONTFILES, ColorFontFiles ); |
306 | LOAD_INT( OPT_COLOR_FONTFOLDERS, ColorFontFolders ); |
307 | // Keyboard mappings |
308 | LOAD_KEY( OPT_KEYUP, KeyMaps.at(EVENT_ONE_UP) ); |
309 | LOAD_KEY( OPT_KEYDOWN, KeyMaps.at(EVENT_ONE_DOWN) ); |
310 | LOAD_KEY( OPT_KEYLEFT , KeyMaps.at(EVENT_PAGE_UP) ); |
311 | LOAD_KEY( OPT_KEYRIGHT, KeyMaps.at(EVENT_PAGE_DOWN) ); |
312 | LOAD_KEY( OPT_KEYDIRUP, KeyMaps.at(EVENT_DIR_UP) ); |
313 | LOAD_KEY( OPT_KEYDIRDOWN, KeyMaps.at(EVENT_DIR_DOWN) ); |
314 | LOAD_KEY( OPT_KEYCFGAPP, KeyMaps.at(EVENT_CFG_APP) ); |
315 | LOAD_KEY( OPT_KEYCFGENTRY, KeyMaps.at(EVENT_CFG_ITEM) ); |
316 | LOAD_KEY( OPT_KEYSETONE, KeyMaps.at(EVENT_SET_ONE) ); |
317 | LOAD_KEY( OPT_KEYSETALL, KeyMaps.at(EVENT_SET_ALL) ); |
318 | LOAD_KEY( OPT_KEYSELECT, KeyMaps.at(EVENT_SELECT) ); |
319 | LOAD_KEY( OPT_KEYBACK, KeyMaps.at(EVENT_BACK) ); |
320 | LOAD_KEY( OPT_KEYQUIT, KeyMaps.at(EVENT_QUIT) ); |
321 | // Joystick mappings |
322 | LOAD_INT( OPT_JOYUP, JoyMaps.at(EVENT_ONE_UP) ); |
323 | LOAD_INT( OPT_JOYDOWN, JoyMaps.at(EVENT_ONE_DOWN) ); |
324 | LOAD_INT( OPT_JOYLEFT, JoyMaps.at(EVENT_PAGE_UP) ); |
325 | LOAD_INT( OPT_JOYRIGHT, JoyMaps.at(EVENT_PAGE_DOWN) ); |
326 | LOAD_INT( OPT_JOYDIRUP, JoyMaps.at(EVENT_DIR_UP) ); |
327 | LOAD_INT( OPT_JOYDIRDOWN, JoyMaps.at(EVENT_DIR_DOWN) ); |
328 | LOAD_INT( OPT_JOYCFGAPP, JoyMaps.at(EVENT_CFG_APP) ); |
329 | LOAD_INT( OPT_JOYCFGENTRY, JoyMaps.at(EVENT_CFG_ITEM) ); |
330 | LOAD_INT( OPT_JOYSETONE, JoyMaps.at(EVENT_SET_ONE) ); |
331 | LOAD_INT( OPT_JOYSETALL, JoyMaps.at(EVENT_SET_ALL) ); |
332 | LOAD_INT( OPT_JOYSELECT, JoyMaps.at(EVENT_SELECT) ); |
333 | LOAD_INT( OPT_JOYBACK, JoyMaps.at(EVENT_BACK) ); |
334 | LOAD_INT( OPT_JOYQUIT, JoyMaps.at(EVENT_QUIT) ); |
335 | // Analog joystick mappings |
336 | LOAD_INT( OPT_DEADZONE, AnalogDeadZone ); |
337 | } |
338 | } |
339 | fin.close(); |
340 | } |
341 | else |
342 | { |
343 | Log( "Failed to open config\n" ); |
344 | return 1; |
345 | } |
346 | |
347 | ScreenRatioW = (float)ScreenWidth/(float)BASE_WIDTH; |
348 | ScreenRatioH = (float)ScreenHeight/(float)BASE_HEIGHT; |
349 | |
350 | if (ResetGUI == true) |
351 | { |
352 | SetDefaults(); |
353 | } |
354 | |
355 | return 0; |
356 | } |
357 | |
358 | #define SAVE_LBL(X) fout << endl << X << endl; |
359 | #define SAVE_INT(X,H,V) fout << setw(CFG_LBL_W) << X << "= " << setw(CFG_VAL_W) << i_to_a(V) << "# " << H << endl |
360 | #define SAVE_STR(X,H,V) fout << setw(CFG_LBL_W) << X << "= " << setw(CFG_VAL_W) << V << "# " << H << endl |
361 | #define GET_KEY_NAME(X) SDL_GetKeyName(KeyMaps.at(X)) |
362 | |
363 | int8_t CConfig::Save( const string& location ) |
364 | { |
365 | uint8_t i; |
366 | ofstream fout; |
367 | string label; |
368 | |
369 | fout.open(location.c_str(), ios_base::trunc); |
370 | |
371 | if (!fout) |
372 | { |
373 | Log( "Failed to open profile\n" ); |
374 | return 1; |
375 | } |
376 | |
377 | // Write out the profile |
378 | if (fout.is_open()) |
379 | { |
380 | fout.setf( ios::left, ios::adjustfield ); |
381 | SAVE_LBL( "# General Settings" ); |
382 | SAVE_INT( OPT_SCREEN_WIDTH, HELP_SCREEN_WIDTH, ScreenWidth ); |
383 | SAVE_INT( OPT_SCREEN_HEIGHT, HELP_SCREEN_HEIGHT, ScreenHeight ); |
384 | SAVE_INT( OPT_SCREEN_DEPTH, HELP_SCREEN_DEPTH, ScreenDepth ); |
385 | SAVE_INT( OPT_FULLSCREEN, HELP_FULLSCREEN, Fullscreen ); |
386 | SAVE_INT( OPT_CPU_CLOCK, HELP_CPU_CLOCK, CPUClock ); |
387 | SAVE_INT( OPT_USEZIPSUPPORT, HELP_USEZIPSUPPORT, UseZipSupport ); |
388 | SAVE_INT( OPT_SHOWEXTS, HELP_SHOWEXTS, ShowExts ); |
389 | SAVE_INT( OPT_SHOWHIDDEN, HELP_SHOWHIDDEN, ShowHidden ); |
390 | SAVE_INT( OPT_SHOWPOINTER, HELP_SHOWPOINTER, ShowPointer ); |
391 | SAVE_INT( OPT_SHOWLABELS, HELP_SHOWLABELS, ShowLabels ); |
392 | SAVE_INT( OPT_UNUSED_KEYS_SELECT, HELP_UNUSED_KEYS_SELECT, UnusedKeysLaunch ); |
393 | SAVE_INT( OPT_UNUSED_JOYS_SELECT, HELP_UNUSED_JOYS_SELECT, UnusedJoysLaunch ); |
394 | SAVE_INT( OPT_RELOAD_LAUNCHER, HELP_RELOAD_LAUNCHER, ReloadLauncher ); |
395 | SAVE_INT( OPT_TEXT_SCROLL_OPTION, HELP_TEXT_SCROLL_OPTION, TextScrollOption ); |
396 | SAVE_INT( OPT_FILENAMEARGNOEXT, HELP_FILENAMEARGNOEXT, FilenameArgNoExt ); |
397 | SAVE_INT( OPT_FILEABSPATH, HELP_FILEABSPATH, FilenameAbsPath ); |
398 | SAVE_INT( OPT_FONT_SIZE_SMALL, HELP_FONT_SIZE_SMALL, FontSizes.at(FONT_SIZE_SMALL) ); |
399 | SAVE_INT( OPT_FONT_SIZE_MEDIUM, HELP_FONT_SIZE_MEDIUM, FontSizes.at(FONT_SIZE_MEDIUM) ); |
400 | SAVE_INT( OPT_FONT_SIZE_LARGE, HELP_FONT_SIZE_LARGE, FontSizes.at(FONT_SIZE_LARGE) ); |
401 | SAVE_INT( OPT_ENTRY_FAST_MODE, HELP_ENTRY_FAST_MODE, EntryFastMode ); |
402 | SAVE_INT( OPT_MAX_ENTRIES, HELP_MAX_ENTRIES, MaxEntries ); |
403 | SAVE_INT( OPT_SCROLL_SPEED, HELP_SCROLL_SPEED, ScrollSpeed ); |
404 | SAVE_INT( OPT_SCROLL_PAUSE_SPEED, HELP_SCROLL_PAUSE_SPEED, ScrollPauseSpeed ); |
405 | SAVE_STR( OPT_PROFILE_DELIMITER, HELP_PROFILE_DELIMITER, Delimiter ); |
406 | SAVE_LBL( "# GUI Positions" ); |
407 | SAVE_INT( OPT_AUTOLAYOUT, HELP_AUTOLAYOUT, AutoLayout ); |
408 | SAVE_INT( OPT_POSX_TITLE, HELP_POSX_TITLE, PosX_Title ); |
409 | SAVE_INT( OPT_POSY_TITLE, HELP_POSY_TITLE, PosY_Title ); |
410 | SAVE_INT( OPT_POSX_BTNLEFT, HELP_POSX_BTNLEFT, PosX_ButtonLeft ); |
411 | SAVE_INT( OPT_POSY_BTNLEFT, HELP_POSY_BTNLEFT, PosY_ButtonLeft ); |
412 | SAVE_INT( OPT_POSX_BTNRIGHT, HELP_POSX_BTNRIGHT, PosX_ButtonRight ); |
413 | SAVE_INT( OPT_POSY_BTNRIGHT, HELP_POSY_BTNRIGHT, PosY_ButtonRight ); |
414 | SAVE_INT( OPT_POSX_LISTNAMES, HELP_POSX_LISTNAMES, PosX_ListNames ); |
415 | SAVE_INT( OPT_POSY_LISTNAMES, HELP_POSY_LISTNAMES, PosY_ListNames ); |
416 | SAVE_LBL( "# GUI Options" ); |
417 | SAVE_INT( OPT_ENTRY_Y_DELTA, HELP_ENTRY_Y_DELTA, EntryYDelta ); |
418 | SAVE_INT( OPT_ENTRY_X_OFFSET, HELP_ENTRY_X_OFFSET, EntryXOffset ); |
419 | SAVE_INT( OPT_ENTRY_Y_OFFSET, HELP_ENTRY_Y_OFFSET, EntryYOffset ); |
420 | SAVE_INT( OPT_BUTTON_W_LEFT, HELP_BUTTON_W_LEFT, ButtonWidthLeft ); |
421 | SAVE_INT( OPT_BUTTON_H_LEFT, HELP_BUTTON_H_LEFT, ButtonHeightLeft ); |
422 | SAVE_INT( OPT_BUTTON_W_RIGHT, HELP_BUTTON_W_RIGHT, ButtonWidthRight ); |
423 | SAVE_INT( OPT_BUTTON_H_RIGHT, HELP_BUTTON_H_RIGHT, ButtonHeightRight ); |
424 | SAVE_INT( OPT_PREVIEW_W, HELP_PREVIEW_W, PreviewWidth ); |
425 | SAVE_INT( OPT_PREVIEW_H, HELP_PREVIEW_H, PreviewHeight ); |
426 | SAVE_INT( OPT_ENTRY_MAX_W, HELP_ENTRY_MAX_W, DisplayListMaxWidth ); |
427 | SAVE_INT( OPT_FILEPATH_MAX_W, HELP_FILEPATH_MAX_W, FilePathMaxWidth ); |
428 | SAVE_LBL( "# Button Enable Options" ); |
429 | for (i=0; i<ButtonModesLeftEnable.size(); i++) |
430 | { |
431 | label = string(OPT_BUTTONLEFT_ENABLED) + "_"+ i_to_a(i); |
432 | SAVE_INT( label, HELP_DEFAULT, ButtonModesLeftEnable.at(i) ); |
433 | } |
434 | for (i=0; i<ButtonModesRightEnable.size(); i++) |
435 | { |
436 | label = string(OPT_BUTTONRIGHT_ENABLED) + "_"+ i_to_a(i); |
437 | SAVE_INT( label, HELP_DEFAULT, ButtonModesRightEnable.at(i) ); |
438 | } |
439 | SAVE_LBL( "# Paths" ); |
440 | SAVE_STR( OPT_PATH_ZIPTEMP, HELP_PATH_ZIPTEMP, ZipPath ); |
441 | SAVE_STR( OPT_PATH_PREVIEWS, HELP_PATH_PREVIEWS, PreviewsPath ); |
442 | SAVE_STR( OPT_PATH_FONT, HELP_PATH_FONT, PathFont ); |
443 | SAVE_STR( OPT_PATH_BACKGND, HELP_PATH_BACKGND, PathBackground ); |
444 | SAVE_STR( OPT_PATH_POINTER, HELP_PATH_POINTER, PathPointer ); |
445 | SAVE_STR( OPT_PATH_SELECTPOINTER, HELP_PATH_SELECTPOINTER, PathSelectPointer ); |
446 | SAVE_STR( OPT_PATH_ONEUP, HELP_PATH_ONEUP, PathButtons.at(EVENT_ONE_UP) ); |
447 | SAVE_STR( OPT_PATH_ONEDN, HELP_PATH_ONEDN, PathButtons.at(EVENT_ONE_DOWN) ); |
448 | SAVE_STR( OPT_PATH_PGUP, HELP_PATH_PGUP, PathButtons.at(EVENT_PAGE_UP) ); |
449 | SAVE_STR( OPT_PATH_PGDN, HELP_PATH_PGDN, PathButtons.at(EVENT_PAGE_DOWN) ); |
450 | SAVE_STR( OPT_PATH_DIRUP, HELP_PATH_DIRUP, PathButtons.at(EVENT_DIR_UP) ); |
451 | SAVE_STR( OPT_PATH_DIRDN, HELP_PATH_DIRDN, PathButtons.at(EVENT_DIR_DOWN) ); |
452 | SAVE_STR( OPT_PATH_CFG_APP, HELP_PATH_CFG_APP, PathButtons.at(EVENT_CFG_APP) ); |
453 | SAVE_STR( OPT_PATH_CFG_ITEM, HELP_PATH_CFG_ITEM, PathButtons.at(EVENT_CFG_ITEM) ); |
454 | SAVE_STR( OPT_PATH_SELECT, HELP_PATH_SELECT, PathButtons.at(EVENT_SELECT) ); |
455 | SAVE_STR( OPT_PATH_QUIT, HELP_PATH_QUIT, PathButtons.at(EVENT_QUIT) ); |
456 | SAVE_LBL( "# Colors" ); |
457 | fout << "# "; |
458 | for (i=0; i<ColorNames.size(); i++) |
459 | { |
460 | fout << setw(4) << i_to_a(i) << setw(20) << ColorNames.at(i); |
461 | if ((i+1) % 3 == 0) |
462 | { |
463 | fout << endl << "# "; |
464 | } |
465 | } |
466 | fout << endl; |
467 | SAVE_INT( OPT_COLOR_BUTTON, HELP_COLOR_BUTTON, ColorButton ); |
468 | SAVE_INT( OPT_COLOR_FONTBUTTON, HELP_COLOR_FONTBUTTON, ColorFontButton ); |
469 | SAVE_INT( OPT_COLOR_BACKGND, HELP_COLOR_BACKGND, ColorBackground ); |
470 | SAVE_INT( OPT_COLOR_FONTFILES, HELP_COLOR_FONTFILES, ColorFontFiles ); |
471 | SAVE_INT( OPT_COLOR_FONTFOLDERS, HELP_COLOR_FONTFOLDERS, ColorFontFolders ); |
472 | SAVE_LBL( "# Controls" ); |
473 | SAVE_LBL( "# Keyboard" ); |
474 | SAVE_STR( OPT_KEYUP, GET_KEY_NAME(EVENT_ONE_UP), KeyMaps.at(EVENT_ONE_UP) ); |
475 | SAVE_STR( OPT_KEYDOWN, GET_KEY_NAME(EVENT_ONE_DOWN), KeyMaps.at(EVENT_ONE_DOWN) ); |
476 | SAVE_STR( OPT_KEYLEFT, GET_KEY_NAME(EVENT_PAGE_UP), KeyMaps.at(EVENT_PAGE_UP) ); |
477 | SAVE_STR( OPT_KEYRIGHT, GET_KEY_NAME(EVENT_PAGE_DOWN), KeyMaps.at(EVENT_PAGE_DOWN) ); |
478 | SAVE_STR( OPT_KEYDIRUP, GET_KEY_NAME(EVENT_DIR_UP), KeyMaps.at(EVENT_DIR_UP) ); |
479 | SAVE_STR( OPT_KEYDIRDOWN, GET_KEY_NAME(EVENT_DIR_DOWN), KeyMaps.at(EVENT_DIR_DOWN) ); |
480 | SAVE_STR( OPT_KEYCFGAPP, GET_KEY_NAME(EVENT_CFG_APP), KeyMaps.at(EVENT_CFG_APP) ); |
481 | SAVE_STR( OPT_KEYCFGENTRY, GET_KEY_NAME(EVENT_CFG_ITEM), KeyMaps.at(EVENT_CFG_ITEM) ); |
482 | SAVE_STR( OPT_KEYSETONE, GET_KEY_NAME(EVENT_SET_ONE), KeyMaps.at(EVENT_SET_ONE) ); |
483 | SAVE_STR( OPT_KEYSETALL, GET_KEY_NAME(EVENT_SET_ALL), KeyMaps.at(EVENT_SET_ALL) ); |
484 | SAVE_STR( OPT_KEYSELECT, GET_KEY_NAME(EVENT_SELECT), KeyMaps.at(EVENT_SELECT) ); |
485 | SAVE_STR( OPT_KEYBACK, GET_KEY_NAME(EVENT_BACK), KeyMaps.at(EVENT_BACK) ); |
486 | SAVE_STR( OPT_KEYQUIT, GET_KEY_NAME(EVENT_QUIT), KeyMaps.at(EVENT_QUIT) ); |
487 | SAVE_LBL( "# Joystick" ); |
488 | SAVE_INT( OPT_JOYUP, HELP_DEFAULT, JoyMaps.at(EVENT_ONE_UP) ); |
489 | SAVE_INT( OPT_JOYDOWN, HELP_DEFAULT, JoyMaps.at(EVENT_ONE_DOWN) ); |
490 | SAVE_INT( OPT_JOYLEFT, HELP_DEFAULT, JoyMaps.at(EVENT_PAGE_UP) ); |
491 | SAVE_INT( OPT_JOYRIGHT, HELP_DEFAULT, JoyMaps.at(EVENT_PAGE_DOWN) ); |
492 | SAVE_INT( OPT_JOYDIRUP, HELP_DEFAULT, JoyMaps.at(EVENT_DIR_UP) ); |
493 | SAVE_INT( OPT_JOYDIRDOWN, HELP_DEFAULT, JoyMaps.at(EVENT_DIR_DOWN) ); |
494 | SAVE_INT( OPT_JOYCFGAPP, HELP_DEFAULT, JoyMaps.at(EVENT_CFG_APP) ); |
495 | SAVE_INT( OPT_JOYCFGENTRY, HELP_DEFAULT, JoyMaps.at(EVENT_CFG_ITEM) ); |
496 | SAVE_INT( OPT_JOYSETONE, HELP_DEFAULT, JoyMaps.at(EVENT_SET_ONE) ); |
497 | SAVE_INT( OPT_JOYSETALL, HELP_DEFAULT, JoyMaps.at(EVENT_SET_ALL) ); |
498 | SAVE_INT( OPT_JOYSELECT, HELP_DEFAULT, JoyMaps.at(EVENT_SELECT) ); |
499 | SAVE_INT( OPT_JOYBACK, HELP_DEFAULT, JoyMaps.at(EVENT_BACK) ); |
500 | SAVE_INT( OPT_JOYQUIT, HELP_DEFAULT, JoyMaps.at(EVENT_QUIT) ); |
501 | SAVE_INT( OPT_DEADZONE, HELP_DEADZONE, AnalogDeadZone ); |
502 | fout.close(); |
503 | } |
504 | else |
505 | { |
506 | Log( "Failed to open profile\n" ); |
507 | return 1; |
508 | } |
509 | return 0; |
510 | } |