root/core/conf.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. conf_change_dng
  2. cb_change_dng_usb_ext
  3. conf_update_prevent_shutdown
  4. clear_values
  5. user_menu_conf_info_func
  6. osd_conf_info_func
  7. conf_info_func
  8. memhash31
  9. config_update_last_saved
  10. config_has_changed
  11. config_load_defaults
  12. conf_load_defaults
  13. config_save
  14. conf_save
  15. save_config_file
  16. config_restore
  17. config_restore_1_2
  18. conf_restore
  19. load_config_file
  20. findConfInfo
  21. resetColors
  22. getValue
  23. conf_getValue
  24. setValue
  25. conf_setValue
  26. conf_setAutosave
  27. is_raw_exception
  28. is_raw_possible
  29. is_raw_enabled

   1 #include "platform.h"
   2 #include "conf.h"
   3 #include "histogram.h"
   4 #include "font.h"
   5 #include "raw.h"
   6 #include "gui.h"
   7 #include "gui_draw.h"
   8 #include "gui_osd.h"
   9 #include "gui_lang.h"
  10 #include "gui_menu.h"
  11 #include "gui_user_menu.h"
  12 #include "core.h"
  13 #include "fileutil.h"
  14 #include "lang.h"
  15 #include "usb_remote.h"
  16 
  17 #include "modules.h"
  18 #include "module_def.h"
  19 
  20 //-------------------------------------------------------------------
  21 Conf conf;
  22 
  23 // reyalp: putting these in conf, since the conf values are lookups for them
  24 // prefixes and extentions available for raw images (index with conf.raw_prefix etc)
  25 const char* img_folders[NUM_IMG_FOLDER_NAMES]={ "A/DCIM", "withJPG", "A/RAW" };
  26 const char* img_prefixes[NUM_IMG_PREFIXES]={ "IMG_", "CRW_", "SND_" /*, "AUT_", "ETC_","SDR_", "MVI_", "MRK_"*/};
  27 const char* img_exts[NUM_IMG_EXTS]={ ".JPG", ".CRW", ".CR2", ".THM", ".WAV"/*, ".AVI", ".MRK"*/};
  28 
  29 //-------------------------------------------------------------------
  30 
  31 void conf_change_dng(void)
  32 {
  33     if (conf.save_raw && conf.dng_raw && conf.dng_version)
  34     {
  35         if (!libdng->badpixel_list_loaded_b()) libdng->load_bad_pixels_list_b("A/CHDK/badpixel.bin");
  36         if (!libdng->badpixel_list_loaded_b()) conf.dng_version=0;
  37     }
  38 }
  39 
  40 #if defined (DNG_EXT_FROM)
  41 void cb_change_dng_usb_ext()
  42 {
  43     extern void change_ext_to_dng(void);
  44     extern void change_ext_to_default(void);
  45     if (conf.dng_usb_ext)
  46         change_ext_to_dng();
  47     else
  48         change_ext_to_default();
  49 }
  50 #endif
  51 
  52 /*
  53 update the prevent display off/prevent shutdown based on current state
  54 doesn't really belong in conf but not clear where else it should go
  55 */
  56 void conf_update_prevent_shutdown(void) {
  57     if(conf.alt_prevent_shutdown == ALT_PREVENT_SHUTDOWN_ALWAYS 
  58         || (conf.alt_prevent_shutdown == ALT_PREVENT_SHUTDOWN_ALT && !camera_info.state.gui_mode_none)
  59         || (conf.alt_prevent_shutdown == ALT_PREVENT_SHUTDOWN_ALT_SCRIPT && camera_info.state.state_kbd_script_run)) {
  60         disable_shutdown();
  61     } else {
  62         enable_shutdown();
  63     }
  64 }
  65 
  66 //-------------------------------------------------------------------
  67 void clear_values()
  68 {       
  69 
  70 #if CAM_ADJUSTABLE_ALT_BUTTON
  71     extern const char* gui_alt_mode_button_enum(int change, int arg);
  72     gui_alt_mode_button_enum(0,0); // will reset if not in list of valid alt buttons
  73 #else
  74     conf.alt_mode_button = CAM_DEFAULT_ALT_BUTTON; // if not adjustable, force to default
  75 #endif
  76 
  77     if (conf.platformid != PLATFORMID) // the following config entries will be resetted if you switch the camera using the same cfg
  78     {
  79         conf.fast_ev = 0;
  80         conf.fast_movie_control = 0;
  81         conf.fast_movie_quality_control = 0;
  82         conf.platformid = PLATFORMID;
  83         conf.flash_video_override = 0;
  84 
  85         // remote input channel - all cams assumed to support USB
  86         // TODO could reset only if invalid on current cam
  87         conf.remote_input_channel = REMOTE_INPUT_USB;
  88 
  89         // video related entries are interpreted differently on D6 cameras
  90         conf.video_mode = 0;
  91         conf.video_quality = VIDEO_DEFAULT_QUALITY;
  92         conf.video_bitrate = VIDEO_DEFAULT_BITRATE;
  93         shooting_video_bitrate_change(conf.video_bitrate);
  94 #ifdef CAM_MOVIEREC_NEWSTYLE
  95         shooting_video_minbitrate_change(conf.video_quality);
  96 #endif
  97     }
  98     if (conf.osd_platformid != PLATFORMID) // the following config entries will be resetted if you switch the camera using the same cfg
  99     {
 100         conf.zoom_scale = 100;
 101         // battery voltages are camera dependent
 102         conf.batt_volts_max = get_vbatt_max();
 103         conf.batt_volts_min = get_vbatt_min();
 104         conf.osd_platformid = PLATFORMID;
 105 
 106         conf.mem_view_addr_init = 0x1000;
 107 
 108     }
 109 
 110     if (conf.clear_override)
 111     {
 112         conf.av_override_enabled=0;
 113         conf.tv_override_enabled=0;
 114         conf.subj_dist_override_koef=SD_OVERRIDE_OFF;
 115         conf.iso_override_koef=0;
 116         conf.nd_filter_state=0;
 117     }
 118     if (conf.clear_bracket)
 119     {
 120         conf.av_bracket_value=0;
 121         conf.tv_bracket_value=0;
 122         conf.iso_bracket_koef=0;
 123         conf.subj_dist_bracket_koef=0;
 124     }
 125     if (conf.clear_video)
 126     {
 127         conf.video_mode = 0;
 128 #if CAM_CHDK_HAS_EXT_VIDEO_TIME
 129         conf.ext_video_time=0;
 130 #endif
 131         conf.video_quality = VIDEO_DEFAULT_QUALITY;
 132         conf.video_bitrate = VIDEO_DEFAULT_BITRATE;
 133         shooting_video_bitrate_change(conf.video_bitrate);
 134 #ifdef CAM_MOVIEREC_NEWSTYLE
 135         shooting_video_minbitrate_change(conf.video_quality);
 136 #endif
 137     }
 138     //conf.edge_overlay_pano = 0; // reset it because otherwise this feature cant be used at startup (when buffer is empty) - needs workaround other than this!
 139 }
 140 
 141 //-------------------------------------------------------------------
 142 static ConfInfo user_menu_conf_info[] = {
 143     CONF_INFO(  1, conf.user_menu_vars,         CONF_STRUCT_PTR,i:0),
 144     CONF_INFO(  2, conf.user_menu_as_root,      CONF_DEF_VALUE, i:0),
 145     CONF_INFO(  3, conf.user_menu_enable,       CONF_DEF_VALUE, i:0),
 146 
 147     {0,0,0,0,{0}}
 148 };
 149 
 150 void user_menu_conf_info_func(unsigned short id)
 151 {
 152     switch (id)
 153     {
 154     case 1: 
 155         user_menu_restore(); 
 156         break;
 157     }
 158 }
 159 
 160 // Range of entry IDs for user adjustable colors.
 161 // Used to reset colors. Adjust these if color entries changes
 162 #define COLOR_FIRST_OVERRIDE    50
 163 #define COLOR_LAST_OVERRIDE     63
 164 
 165 static ConfInfo osd_conf_info[] = {
 166 /* !!! Do NOT change ID for items defined already! Append a new one at the end! !!! */
 167 
 168     CONF_INFO(  1, conf.show_osd,                               CONF_DEF_VALUE, i:1),
 169     CONF_INFO(  2, conf.show_osd_in_review,                     CONF_DEF_VALUE, i:0),
 170     CONF_INFO(  3, conf.override_disable,                       CONF_DEF_VALUE, i:0),
 171     CONF_INFO(  4, conf.override_disable_all,                   CONF_DEF_VALUE, i:1),
 172     CONF_INFO(  5, conf.hide_osd,                               CONF_DEF_VALUE, i:1),
 173     CONF_INFO(  6, conf.rotate_osd,                             CONF_DEF_VALUE, i:0),
 174     CONF_INFO(  7, conf.show_hiddenfiles,                       CONF_DEF_VALUE, i:0),
 175 
 176     CONF_INFO2( 20, conf.histo_pos,                             CONF_OSD_POS,   45,CAM_SCREEN_HEIGHT-HISTO_HEIGHT-40),
 177     CONF_INFO2( 21, conf.dof_pos,                               CONF_OSD_POS,   90,45),
 178     CONF_INFO2( 22, conf.batt_icon_pos,                         CONF_OSD_POS,   178,0),
 179     CONF_INFO2( 23, conf.batt_txt_pos,                          CONF_OSD_POS,   178,FONT_HEIGHT),
 180     CONF_INFO2( 24, conf.mode_state_pos,                        CONF_OSD_POS,   35,0),
 181     CONF_INFO2( 25, conf.values_pos,                            CONF_OSD_POS,   CAM_SCREEN_WIDTH-9*FONT_WIDTH,30),
 182     CONF_INFO2( 26, conf.clock_pos,                             CONF_OSD_POS,   CAM_SCREEN_WIDTH-5*FONT_WIDTH-2,0),
 183     CONF_INFO2( 27, conf.space_icon_pos,                        CONF_OSD_POS,   CAM_SCREEN_WIDTH-100,0),
 184     CONF_INFO2( 28, conf.space_txt_pos,                         CONF_OSD_POS,   128,0),
 185     CONF_INFO2( 29, conf.mode_raw_pos,                          CONF_OSD_POS,   CAM_SCREEN_WIDTH-7*FONT_WIDTH-2,CAM_SCREEN_HEIGHT-3*FONT_HEIGHT-2),
 186     CONF_INFO2( 30, conf.space_ver_pos,                         CONF_OSD_POS,   CAM_SCREEN_WIDTH-7,0),
 187     CONF_INFO2( 31, conf.space_hor_pos,                         CONF_OSD_POS,   0,CAM_SCREEN_HEIGHT-7),   
 188     CONF_INFO2( 32, conf.mode_video_pos,                        CONF_OSD_POS,   CAM_SCREEN_WIDTH-25*FONT_WIDTH-2,CAM_SCREEN_HEIGHT-6*FONT_HEIGHT-2),
 189     CONF_INFO2( 33, conf.mode_ev_pos,                           CONF_OSD_POS,   CAM_SCREEN_WIDTH-40*FONT_WIDTH-2,CAM_SCREEN_HEIGHT-8*FONT_HEIGHT-2),
 190     CONF_INFO2( 34, conf.temp_pos,                              CONF_OSD_POS,   CAM_SCREEN_WIDTH-9*FONT_WIDTH-2,FONT_HEIGHT),
 191     CONF_INFO2( 35, conf.ev_video_pos,                          CONF_OSD_POS,   18,80),
 192     CONF_INFO2( 36, conf.usb_info_pos,                          CONF_OSD_POS,   95,0),
 193 
 194     // Keep these together
 195     CONF_INFOC( 50, conf.histo_color,                           CONF_DEF_VALUE, IDX_COLOR_GREY_DK,IDX_COLOR_WHITE,1,1),
 196     CONF_INFOC( 51, conf.histo_color2,                          CONF_DEF_VALUE, IDX_COLOR_RED,IDX_COLOR_WHITE,1,1),
 197     CONF_INFOC( 52, conf.osd_color,                             CONF_DEF_VALUE, IDX_COLOR_GREY_DK_TRANS,IDX_COLOR_WHITE,1,1),
 198     CONF_INFOC( 53, conf.osd_color_warn,                        CONF_DEF_VALUE, IDX_COLOR_GREY_DK_TRANS,IDX_COLOR_RED,1,1),
 199     CONF_INFOC( 54, conf.osd_color_override,                    CONF_DEF_VALUE, IDX_COLOR_GREY_DK_TRANS,IDX_COLOR_RED,1,1),
 200     CONF_INFOC( 55, conf.menu_color,                            CONF_DEF_VALUE, IDX_COLOR_GREY_DK,IDX_COLOR_WHITE,1,1),
 201     CONF_INFOC( 56, conf.menu_title_color,                      CONF_DEF_VALUE, IDX_COLOR_WHITE,IDX_COLOR_BLACK,1,1),
 202     CONF_INFOC( 57, conf.menu_cursor_color,                     CONF_DEF_VALUE, CAM_DEFAULT_MENU_CURSOR_BG,CAM_DEFAULT_MENU_CURSOR_FG,1,1),
 203     CONF_INFOC( 58, conf.menu_symbol_color,                     CONF_DEF_VALUE, IDX_COLOR_GREY_DK,IDX_COLOR_WHITE,1,1),
 204     CONF_INFOC( 59, conf.reader_color,                          CONF_DEF_VALUE, IDX_COLOR_GREY,IDX_COLOR_WHITE,1,1),
 205     CONF_INFOC( 60, conf.grid_color,                            CONF_DEF_VALUE, IDX_COLOR_GREY_DK,IDX_COLOR_WHITE,1,1),
 206     CONF_INFOC( 61, conf.space_color,                           CONF_DEF_VALUE, IDX_COLOR_GREY_DK_TRANS,IDX_COLOR_WHITE,1,1),
 207     CONF_INFOC( 62, conf.zebra_color,                           CONF_DEF_VALUE, IDX_COLOR_RED,IDX_COLOR_RED,1,1),
 208     CONF_INFOC( 63, conf.edge_overlay_color,                    CONF_DEF_VALUE, 0,IDX_COLOR_RED,0,1),
 209 
 210     CONF_INFO( 80, conf.show_clock,                             CONF_DEF_VALUE, i:2),
 211     CONF_INFO( 81, conf.clock_format,                           CONF_DEF_VALUE, i:0),
 212     CONF_INFO( 82, conf.clock_indicator,                        CONF_DEF_VALUE, i:0),
 213     CONF_INFO( 83, conf.clock_halfpress,                        CONF_DEF_VALUE, i:1),
 214 
 215     CONF_INFO( 90, conf.show_state,                             CONF_DEF_VALUE, i:1),
 216 
 217     CONF_INFO(100, conf.batt_volts_max,                         CONF_FUNC_PTR,  func:get_vbatt_max),
 218     CONF_INFO(101, conf.batt_volts_min,                         CONF_FUNC_PTR,  func:get_vbatt_min),
 219     CONF_INFO(102, conf.batt_perc_show,                         CONF_DEF_VALUE, i:1),
 220     CONF_INFO(103, conf.batt_volts_show,                        CONF_DEF_VALUE, i:0),
 221     CONF_INFO(104, conf.batt_icon_show,                         CONF_DEF_VALUE, i:1),
 222 
 223     CONF_INFO(110, conf.reader_file,                            CONF_CHAR_PTR,  ptr:"A/CHDK/BOOKS/README.TXT"),
 224     CONF_INFO(111, conf.reader_pos,                             CONF_DEF_VALUE, i:0),
 225     CONF_INFO(112, conf.reader_autoscroll,                      CONF_DEF_VALUE, i:0),
 226     CONF_INFO(113, conf.reader_autoscroll_delay,                CONF_DEF_VALUE, i:5),
 227     CONF_INFO(114, conf.reader_rbf_file,                        CONF_CHAR_PTR,  ptr:""),
 228     CONF_INFO(115, conf.reader_codepage,                        CONF_DEF_VALUE, i:FONT_CP_WIN),
 229     CONF_INFO(116, conf.reader_wrap_by_words,                   CONF_DEF_VALUE, i:1),
 230 
 231     CONF_INFO(120, conf.splash_show,                            CONF_DEF_VALUE, i:1),
 232         CONF_INFO(121, conf.start_sound,                            CONF_DEF_VALUE, i:0),
 233 
 234     CONF_INFO(130, conf.menu_symbol_enable,                     CONF_DEF_VALUE, i:1),
 235     CONF_INFO(131, conf.menu_rbf_file,                          CONF_CHAR_PTR,  ptr:""),
 236     CONF_INFO(132, conf.menu_symbol_rbf_file,                   CONF_CHAR_PTR,  ptr:DEFAULT_SYMBOL_FILE),
 237     CONF_INFO(133, conf.menu_select_first_entry,                CONF_DEF_VALUE, i:1),
 238     CONF_INFO(134, conf.menu_center,                            CONF_DEF_VALUE, i:1),
 239     CONF_INFO(135, conf.lang_file,                              CONF_CHAR_PTR,  ptr:""),
 240     CONF_INFO(136, conf.font_cp,                                CONF_DEF_VALUE, i:FONT_CP_WIN_1252),
 241     CONF_INFO(137, conf.tbox_char_map,                          CONF_DEF_VALUE, i:0),
 242 
 243     CONF_INFO(140, conf.show_grid_lines,                        CONF_DEF_VALUE, i:0),
 244     CONF_INFO(141, conf.grid_lines_file,                        CONF_CHAR_PTR,  ptr:""),
 245     CONF_INFO(142, conf.grid_force_color,                       CONF_DEF_VALUE, i:0),
 246 
 247     CONF_INFO(150, conf.show_dof,                               CONF_DEF_VALUE, i:DOF_DONT_SHOW),
 248     CONF_INFO(151, conf.dof_subj_dist_as_near_limit,            CONF_DEF_VALUE, i:0),
 249     CONF_INFO(152, conf.dof_use_exif_subj_dist,                 CONF_DEF_VALUE, i:0),
 250     CONF_INFO(153, conf.dof_subj_dist_in_misc,                  CONF_DEF_VALUE, i:1),
 251     CONF_INFO(154, conf.dof_near_limit_in_misc,                 CONF_DEF_VALUE, i:1),
 252     CONF_INFO(155, conf.dof_far_limit_in_misc,                  CONF_DEF_VALUE, i:1),
 253     CONF_INFO(156, conf.dof_hyperfocal_in_misc,                 CONF_DEF_VALUE, i:1),
 254     CONF_INFO(157, conf.dof_depth_in_misc,                      CONF_DEF_VALUE, i:0),
 255 
 256     CONF_INFO(160, conf.show_values,                            CONF_DEF_VALUE, i:0),
 257     CONF_INFO(161, conf.values_show_in_review,                  CONF_DEF_VALUE, i:0),
 258     CONF_INFO(162, conf.values_show_zoom,                       CONF_DEF_VALUE, i:1),
 259     CONF_INFO(163, conf.values_show_real_aperture,              CONF_DEF_VALUE, i:0),
 260     CONF_INFO(164, conf.values_show_real_iso,                   CONF_DEF_VALUE, i:1),
 261     CONF_INFO(165, conf.values_show_market_iso,                 CONF_DEF_VALUE, i:0),
 262     CONF_INFO(166, conf.values_show_iso_only_in_autoiso_mode,   CONF_DEF_VALUE, i:0),
 263     CONF_INFO(167, conf.values_show_ev_seted,                   CONF_DEF_VALUE, i:0),
 264     CONF_INFO(168, conf.values_show_ev_measured,                CONF_DEF_VALUE, i:0),
 265     CONF_INFO(169, conf.values_show_bv_measured,                CONF_DEF_VALUE, i:0),
 266     CONF_INFO(170, conf.values_show_bv_seted,                   CONF_DEF_VALUE, i:0),
 267     CONF_INFO(171, conf.values_show_overexposure,               CONF_DEF_VALUE, i:0),
 268     CONF_INFO(172, conf.values_show_luminance,                  CONF_DEF_VALUE, i:0),
 269     CONF_INFO(173, conf.values_show_canon_overexposure,         CONF_DEF_VALUE, i:0),
 270     CONF_INFO(174, conf.show_values_in_video,                   CONF_DEF_VALUE, i:0),
 271     CONF_INFO(175, conf.zoom_value,                             CONF_DEF_VALUE, i:ZOOM_SHOW_X),
 272     CONF_INFO(176, conf.zoom_scale,                             CONF_DEF_VALUE, i:100), 
 273     
 274     CONF_INFO(180, conf.space_icon_show,                        CONF_DEF_VALUE, i:0),
 275     CONF_INFO(181, conf.space_perc_show,                        CONF_DEF_VALUE, i:0),
 276     CONF_INFO(182, conf.space_mb_show,                          CONF_DEF_VALUE, i:1),
 277     CONF_INFO(183, conf.space_bar_show,                         CONF_DEF_VALUE, i:1), 
 278     CONF_INFO(184, conf.space_bar_size,                         CONF_DEF_VALUE, i:1), 
 279     CONF_INFO(185, conf.space_bar_width,                        CONF_DEF_VALUE, i:2), 
 280     CONF_INFO(186, conf.space_perc_warn,                        CONF_DEF_VALUE, i:10),
 281     CONF_INFO(187, conf.space_mb_warn,                          CONF_DEF_VALUE, i:20),
 282     CONF_INFO(188, conf.space_warn_type,                        CONF_DEF_VALUE, i:0),
 283     CONF_INFO(189, conf.show_partition_nr,                      CONF_DEF_VALUE, i:0),
 284 
 285     CONF_INFO(200, conf.show_remaining_raw,                     CONF_DEF_VALUE, i:1),
 286     CONF_INFO(201, conf.show_raw_state,                         CONF_DEF_VALUE, i:1),
 287     CONF_INFO(202, conf.remaining_raw_treshold,                 CONF_DEF_VALUE, i:0),
 288     CONF_INFO(203, conf.raw_exceptions_warn,                    CONF_DEF_VALUE, i:1),
 289 
 290     CONF_INFO(210, conf.show_movie_time,                        CONF_DEF_VALUE, i:3),
 291     CONF_INFO(211, conf.show_movie_refresh,                     CONF_DEF_VALUE, i:1),
 292 
 293     CONF_INFO(220, conf.show_temp,                              CONF_DEF_VALUE, i:1),
 294     CONF_INFO(221, conf.temperature_unit,                       CONF_DEF_VALUE, i:0),
 295 
 296     CONF_INFO(230, conf.debug_shortcut_action,                  CONF_DEF_VALUE, i:0), // backwards compatible
 297         CONF_INFO(231, conf.debug_display,                          CONF_DEF_VALUE, i:0),
 298     CONF_INFO(232, conf.debug_propcase_page,                    CONF_DEF_VALUE, i:0),
 299         CONF_INFO(233, conf.debug_misc_vals_show,                   CONF_DEF_VALUE, i:0),
 300     CONF_INFO(234, conf.mem_view_addr_init,                     CONF_DEF_VALUE, i:0x1000),
 301 
 302     // Touch screen U/I overrides
 303     CONF_INFO(240, conf.touchscreen_disable_video_controls,     CONF_DEF_VALUE, i:0),
 304     CONF_INFO(241, conf.touchscreen_disable_shortcut_controls,  CONF_DEF_VALUE, i:0),
 305 
 306     CONF_INFO(250, conf.usb_info_enable,                        CONF_DEF_VALUE, i:0),
 307 
 308     CONF_INFO(260, conf.show_alt_helper,                        CONF_DEF_VALUE, i:1),
 309     CONF_INFO(261, conf.show_alt_helper_delay,                  CONF_DEF_VALUE, i:3),
 310     CONF_INFO(262, conf.enable_shortcuts,                       CONF_DEF_VALUE, i:1),
 311     CONF_INFO(263, conf.extra_button,                           CONF_DEF_VALUE, i:0),
 312 
 313     // Console settings
 314     CONF_INFO(270, conf.console_show,                           CONF_DEF_VALUE, i:0),
 315     CONF_INFO(271, conf.console_timeout,                        CONF_DEF_VALUE, i:3),
 316  
 317     // OSD element scaling factor 
 318     CONF_INFO2( 280, conf.histo_scale,                             CONF_OSD_POS, 0,0  ),  // 0=no scale, 1=scale  (0 for future expansion)
 319     CONF_INFO2( 281, conf.dof_scale,                               CONF_OSD_POS, 1,1  ),
 320     CONF_INFO2( 282, conf.batt_icon_scale,                         CONF_OSD_POS, 0,0  ),
 321     CONF_INFO2( 283, conf.batt_txt_scale,                          CONF_OSD_POS, 1,1  ),
 322     CONF_INFO2( 284, conf.mode_state_scale,                        CONF_OSD_POS, 1,1  ),
 323     CONF_INFO2( 285, conf.values_scale,                            CONF_OSD_POS, 1,1  ),
 324     CONF_INFO2( 286, conf.clock_scale,                             CONF_OSD_POS, 1,1  ),
 325     CONF_INFO2( 287, conf.space_icon_scale,                        CONF_OSD_POS, 0,0  ),
 326     CONF_INFO2( 288, conf.space_txt_scale,                         CONF_OSD_POS, 1,1  ),
 327     CONF_INFO2( 289, conf.mode_raw_scale,                          CONF_OSD_POS, 1,1  ),
 328     CONF_INFO2( 290, conf.space_ver_scale,                         CONF_OSD_POS, 0,0  ),
 329     CONF_INFO2( 291, conf.space_hor_scale,                         CONF_OSD_POS, 0,0  ),   
 330     CONF_INFO2( 292, conf.mode_video_scale,                        CONF_OSD_POS, 1,1  ),
 331     CONF_INFO2( 293, conf.mode_ev_scale,                           CONF_OSD_POS, 1,1  ),
 332     CONF_INFO2( 294, conf.temp_scale,                              CONF_OSD_POS, 1,1  ),
 333     CONF_INFO2( 295, conf.ev_video_scale,                          CONF_OSD_POS, 1,1  ),
 334     CONF_INFO2( 296, conf.usb_info_scale,                          CONF_OSD_POS, 0,0  ),
 335 
 336     CONF_INFO( 297, conf.enable_raw_shortcut,                      CONF_DEF_VALUE, i:0),
 337 
 338     CONF_INFO( 298, conf.osd_platformid,                           CONF_DEF_VALUE, i:PLATFORMID),
 339 
 340     {0,0,0,0,{0}}
 341 };
 342 
 343 void osd_conf_info_func(unsigned short id)
 344 {
 345     switch (id)
 346     {
 347     case 6:
 348         update_draw_proc();
 349         break;
 350     case 131: 
 351         rbf_load_from_file(conf.menu_rbf_file, FONT_CP_WIN);
 352         break;
 353     case 132: 
 354         if (!rbf_load_symbol(conf.menu_symbol_rbf_file))
 355             conf.menu_symbol_enable=0;
 356         break;
 357     case 135: 
 358         gui_lang_init(); 
 359         break;
 360     case 136:
 361         font_set(conf.font_cp);
 362         break;
 363 #if CAM_OPTIONAL_EXTRA_BUTTON
 364     case 263: 
 365         kbd_set_extra_button((short)conf.extra_button);
 366         break;
 367 #endif
 368     }
 369 }
 370 
 371 static ConfInfo conf_info[] = {
 372 /* !!! Do NOT change ID for items defined already! Append a new one at the end! !!! */
 373 
 374     CONF_INFO(  1, conf.platformid,                             CONF_DEF_VALUE, i:PLATFORMID),
 375 
 376     CONF_INFO(  2, conf.fast_image_quality,                     CONF_DEF_VALUE, i:3),
 377 
 378     CONF_INFO(  3, conf.nd_filter_state,                        CONF_DEF_VALUE, i:0),
 379 
 380     CONF_INFO( 20, conf.save_raw,                               CONF_DEF_VALUE, i:0),
 381     CONF_INFO( 21, conf.raw_in_dir,                             CONF_DEF_VALUE, i:1),
 382     CONF_INFO( 22, conf.raw_prefix,                             CONF_DEF_VALUE, i:RAW_PREFIX_CRW),
 383     CONF_INFO( 23, conf.raw_ext,                                CONF_DEF_VALUE, i:DEFAULT_RAW_EXT),
 384     CONF_INFO( 24, conf.raw_save_first_only,                    CONF_DEF_VALUE, i:0),
 385     CONF_INFO( 25, conf.save_raw_in_video,                      CONF_DEF_VALUE, i:1),
 386     CONF_INFO( 26, conf.save_raw_in_sports,                     CONF_DEF_VALUE, i:0),
 387     CONF_INFO( 27, conf.save_raw_in_burst,                      CONF_DEF_VALUE, i:0),
 388     CONF_INFO( 28, conf.save_raw_in_ev_bracketing,              CONF_DEF_VALUE, i:0),
 389     CONF_INFO( 29, conf.save_raw_in_timer,                      CONF_DEF_VALUE, i:0),
 390     CONF_INFO( 30, conf.raw_cache,                              CONF_DEF_VALUE, i:1),
 391     CONF_INFO( 31, conf.save_raw_in_edgeoverlay,                CONF_DEF_VALUE, i:0),
 392     CONF_INFO( 32, conf.save_raw_in_auto,                       CONF_DEF_VALUE, i:0),
 393     CONF_INFO( 33, conf.bad_pixel_removal,                      CONF_DEF_VALUE, i:0),
 394     CONF_INFO( 34, conf.raw_timer,                              CONF_DEF_VALUE, i:0),
 395     CONF_INFO( 35, conf.raw_dng_ext,                            CONF_DEF_VALUE, i:1),
 396     CONF_INFO( 36, conf.dng_raw,                                CONF_DEF_VALUE, i:1),
 397     CONF_INFO( 37, conf.dng_version,                            CONF_DEF_VALUE, i:0),
 398     CONF_INFO( 38, conf.dng_usb_ext,                            CONF_DEF_VALUE, i:0),
 399     CONF_INFO( 39, conf.raw_nr,                                 CONF_DEF_VALUE, i:NOISE_REDUCTION_AUTO_CANON),
 400     CONF_INFO( 40, conf.bracketing_add_raw_suffix,              CONF_DEF_VALUE, i:0),                   
 401     CONF_INFO( 41, conf.sub_batch_prefix,                       CONF_DEF_VALUE, i:RAW_PREFIX_SND), // SND_
 402     CONF_INFO( 42, conf.sub_batch_ext,                          CONF_DEF_VALUE, i:DEFAULT_RAW_EXT), // .CRW
 403     CONF_INFO( 43, conf.dng_crop_size,                          CONF_DEF_VALUE, i:0),
 404 
 405     CONF_INFO( 50, conf.script_shoot_delay,                     CONF_DEF_VALUE, i:0),
 406     CONF_INFO( 52, conf.script_param_set,                       CONF_DEF_VALUE, i:0),
 407     CONF_INFO( 53, conf.script_startup,                         CONF_DEF_VALUE, i:SCRIPT_AUTOSTART_NONE),
 408     CONF_INFO( 54, conf.script_file,                            CONF_CHAR_PTR,  ptr:""),
 409     CONF_INFO( 55, conf.script_param_save,                      CONF_DEF_VALUE, i:1),
 410 
 411     CONF_INFO( 60, conf.show_histo,                             CONF_DEF_VALUE, i:0),
 412     CONF_INFO( 61, conf.show_overexp,                           CONF_DEF_VALUE, i:1),
 413     CONF_INFO( 62, conf.histo_mode,                             CONF_DEF_VALUE, i:0),
 414     CONF_INFO( 63, conf.histo_auto_ajust,                       CONF_DEF_VALUE, i:1),
 415     CONF_INFO( 64, conf.histo_ignore_boundary,                  CONF_DEF_VALUE, i:4),
 416     CONF_INFO( 65, conf.histo_layout,                           CONF_DEF_VALUE, i:0),
 417     CONF_INFO( 66, conf.histo_show_ev_grid,                     CONF_DEF_VALUE, i:0),
 418 
 419     CONF_INFO( 70, conf.zebra_draw,                             CONF_DEF_VALUE, i:0),
 420     CONF_INFO( 71, conf.zebra_mode,                             CONF_DEF_VALUE, i:ZEBRA_MODE_BLINKED_2),
 421     CONF_INFO( 72, conf.zebra_restore_screen,                   CONF_DEF_VALUE, i:1),
 422     CONF_INFO( 73, conf.zebra_restore_osd,                      CONF_DEF_VALUE, i:1),
 423     CONF_INFO( 74, conf.zebra_over,                             CONF_DEF_VALUE, i:1),
 424     CONF_INFO( 75, conf.zebra_under,                            CONF_DEF_VALUE, i:0),
 425     CONF_INFO( 76, conf.zebra_draw_osd,                         CONF_DEF_VALUE, i:ZEBRA_DRAW_HISTO),
 426     CONF_INFO( 77, conf.zebra_multichannel,                     CONF_DEF_VALUE, i:0),
 427 
 428     CONF_INFO( 80, conf.video_mode,                             CONF_DEF_VALUE, i:0),
 429     CONF_INFO( 81, conf.video_quality,                          CONF_DEF_VALUE, i:VIDEO_DEFAULT_QUALITY),
 430     CONF_INFO( 82, conf.video_bitrate,                          CONF_DEF_VALUE, i:VIDEO_DEFAULT_BITRATE),
 431     CONF_INFO( 83, conf.clear_video,                            CONF_DEF_VALUE, i:0),
 432     CONF_INFO( 84, conf.mute_on_zoom,                           CONF_DEF_VALUE, i:0), 
 433     CONF_INFO( 85, conf.video_af_key,                           CONF_DEF_VALUE, i:0),
 434     CONF_INFO( 86, conf.unlock_optical_zoom_for_video,          CONF_DEF_VALUE, i:1), 
 435     CONF_INFO( 87, conf.fast_ev,                                CONF_DEF_VALUE, i:0),
 436     CONF_INFO( 88, conf.fast_ev_step,                           CONF_DEF_VALUE, i:1),
 437     CONF_INFO( 89, conf.fast_movie_control,                     CONF_DEF_VALUE, i:0),
 438     CONF_INFO( 90, conf.fast_movie_quality_control,             CONF_DEF_VALUE, i:0),
 439     CONF_INFO( 91, conf.ext_video_time,                         CONF_DEF_VALUE, i:0),
 440 
 441     CONF_INFO(100, conf.clear_override,                         CONF_DEF_VALUE, i:1),
 442     
 443     CONF_INFO(110, conf.tv_override_enabled,                    CONF_DEF_VALUE, i:0),
 444     CONF_INFO(111, conf.tv_enum_type,                           CONF_DEF_VALUE, i:TV_OVERRIDE_EV_STEP),
 445     CONF_INFO(112, conf.tv_override_value,                      CONF_DEF_VALUE, i:0),
 446     CONF_INFO(113, conf.tv_override_long_exp,                   CONF_DEF_VALUE, i:0),
 447     CONF_INFO(114, conf.tv_override_short_exp,                  CONF_DEF_VALUE, i:0),
 448 
 449     CONF_INFO(120, conf.av_override_enabled,                    CONF_DEF_VALUE, i:0),
 450     CONF_INFO(121, conf.av_override_value,                      CONF_DEF_VALUE, i:0),
 451 
 452     CONF_INFO(130, conf.iso_override_value,                     CONF_DEF_VALUE, i:0),
 453     CONF_INFO(131, conf.iso_override_koef,                      CONF_DEF_VALUE, i:0),
 454     
 455     CONF_INFO(140, conf.subj_dist_override_value,               CONF_DEF_VALUE, i:0),
 456     CONF_INFO(141, conf.subj_dist_override_koef,                CONF_DEF_VALUE, i:SD_OVERRIDE_OFF),
 457     
 458     CONF_INFO(150, conf.tv_bracket_value,                       CONF_DEF_VALUE, i:0),
 459     CONF_INFO(151, conf.av_bracket_value,                       CONF_DEF_VALUE, i:0),
 460     CONF_INFO(152, conf.iso_bracket_value,                      CONF_DEF_VALUE, i:0),
 461     CONF_INFO(153, conf.iso_bracket_koef,                       CONF_DEF_VALUE, i:0),
 462     CONF_INFO(154, conf.subj_dist_bracket_value,                CONF_DEF_VALUE, i:0),
 463     CONF_INFO(155, conf.subj_dist_bracket_koef,                 CONF_DEF_VALUE, i:0),
 464     CONF_INFO(156, conf.bracket_type,                           CONF_DEF_VALUE, i:0),
 465     CONF_INFO(157, conf.clear_bracket,                          CONF_DEF_VALUE, i:1),
 466     
 467     CONF_INFO(160, conf.autoiso_enable,                         CONF_DEF_VALUE, i:0),
 468     CONF_INFO(161, conf.autoiso_shutter_enum,                   CONF_DEF_VALUE, i:5), // 5='1/125'
 469     CONF_INFO(162, conf.autoiso_user_factor,                    CONF_DEF_VALUE, i:5),
 470     CONF_INFO(163, conf.autoiso_is_factor,                      CONF_DEF_VALUE, i:2),
 471     CONF_INFO(164, conf.autoiso_max_iso_hi,                     CONF_DEF_VALUE, i:550),
 472     CONF_INFO(165, conf.autoiso_max_iso_auto,                   CONF_DEF_VALUE, i:320),
 473     CONF_INFO(166, conf.autoiso_min_iso,                        CONF_DEF_VALUE, i:50),
 474 
 475     // AutoISO2
 476     CONF_INFO(170, conf.autoiso2_shutter_enum,                  CONF_DEF_VALUE, i:0), // 0="off" 6='1/20'
 477     CONF_INFO(171, conf.autoiso2_max_iso_auto,                  CONF_DEF_VALUE, i:600),
 478     CONF_INFO(172, conf.autoiso2_over,                          CONF_DEF_VALUE, i:1),
 479     CONF_INFO(173, conf.overexp_threshold,                      CONF_DEF_VALUE, i:5),
 480     CONF_INFO(174, conf.overexp_ev_enum,                        CONF_DEF_VALUE, i:0), // 0="off"
 481 
 482     CONF_INFO(180, conf.curve_file,                             CONF_CHAR_PTR,  ptr:""),
 483     CONF_INFO(181, conf.curve_enable,                           CONF_DEF_VALUE, i:0),
 484 
 485     CONF_INFO(190, conf.edge_overlay_enable,                    CONF_DEF_VALUE, i:0),
 486     CONF_INFO(191, conf.edge_overlay_thresh,                    CONF_DEF_VALUE, i:60),
 487     CONF_INFO(192, conf.edge_overlay_play,                      CONF_DEF_VALUE, i:0),
 488     CONF_INFO(193, conf.edge_overlay_pano,                      CONF_DEF_VALUE, i:0),
 489     CONF_INFO(194, conf.edge_overlay_zoom,                      CONF_DEF_VALUE, i:1),
 490         CONF_INFO(195, conf.edge_overlay_filter,                    CONF_DEF_VALUE, i:0),
 491         CONF_INFO(196, conf.edge_overlay_show,                      CONF_DEF_VALUE, i:0),
 492     CONF_INFO(197, conf.edge_overlay_pano_overlap,              CONF_DEF_VALUE, i:30),
 493     
 494     CONF_INFO(200, conf.remote_enable,                          CONF_DEF_VALUE, i:0),
 495     CONF_INFO(201, conf.synch_enable,                           CONF_DEF_VALUE, i:0),
 496     CONF_INFO(202, conf.synch_delay_enable,                     CONF_DEF_VALUE, i:0),
 497     CONF_INFO(203, conf.synch_delay_value,                      CONF_DEF_VALUE, i:100),
 498     CONF_INFO(204, conf.remote_switch_type,                     CONF_DEF_VALUE, i:0),
 499     CONF_INFO(205, conf.remote_control_mode,                    CONF_DEF_VALUE, i:0),
 500     CONF_INFO(206, conf.remote_enable_scripts,                  CONF_DEF_VALUE, i:0),
 501     CONF_INFO(207, conf.ricoh_ca1_mode,                         CONF_DEF_VALUE, i:0),
 502     CONF_INFO(208, conf.remote_input_channel,                   CONF_DEF_VALUE, i:0),
 503 
 504     CONF_INFO(210, conf.flash_sync_curtain,                     CONF_DEF_VALUE, i:0),
 505     CONF_INFO(211, conf.flash_video_override,                   CONF_DEF_VALUE, i:0),
 506     CONF_INFO(212, conf.flash_video_override_power,             CONF_DEF_VALUE, i:0),
 507     CONF_INFO(213, conf.flash_manual_override,                  CONF_DEF_VALUE, i:0),
 508     CONF_INFO(214, conf.flash_exp_comp,                         CONF_DEF_VALUE, i:9),
 509     CONF_INFO(215, conf.flash_enable_exp_comp,                  CONF_DEF_VALUE, i:0),
 510     CONF_INFO(216, conf.hotshoe_override,                       CONF_DEF_VALUE, i:0),
 511 
 512     CONF_INFO(220, conf.alt_mode_button,                        CONF_DEF_VALUE, i:KEY_PRINT),
 513     CONF_INFO(221, conf.alt_prevent_shutdown,                   CONF_DEF_VALUE, i:ALT_PREVENT_SHUTDOWN_ALT),
 514     CONF_INFO(222, conf.use_zoom_mf,                            CONF_DEF_VALUE, i:0),
 515     CONF_INFO(223, conf.zoom_assist_button_disable,             CONF_DEF_VALUE, i:0),
 516     CONF_INFO(224, conf.debug_lua_restart_on_error,             CONF_DEF_VALUE, i:0),
 517     CONF_INFO(225, conf.module_logging,                         CONF_DEF_VALUE, i:0),
 518     CONF_INFO(226, conf.flashlight,                             CONF_DEF_VALUE, i:0),
 519 
 520     CONF_INFO(230, conf.memdmp_start,                           CONF_DEF_VALUE, i:0),
 521     CONF_INFO(231, conf.memdmp_size,                            CONF_DEF_VALUE, i:0),
 522 
 523     CONF_INFO(240, conf.allow_unsafe_io,                        CONF_DEF_VALUE, i:0),
 524 
 525     CONF_INFO(250, conf.disable_lfn_parser_ui,                  CONF_DEF_VALUE, i:0),
 526 
 527     CONF_INFO(251, conf.save_raw_in_canon_raw,                  CONF_DEF_VALUE, i:1),
 528 
 529     CONF_INFO(999, conf.script_allow_lua_native_calls,          CONF_DEF_VALUE, i:0),
 530 
 531     {0,0,0,0,{0}}
 532 };
 533 
 534 void conf_info_func(unsigned short id)
 535 {
 536     switch (id)
 537     {
 538     case  20:
 539     case  36: 
 540     case  37: 
 541         conf_change_dng(); 
 542         break;
 543 #if defined (DNG_EXT_FROM)
 544     case  38: 
 545         {
 546         extern void save_ext_for_dng(void);
 547         save_ext_for_dng();
 548         cb_change_dng_usb_ext();
 549         }
 550         break;
 551 #endif 
 552     case  54:
 553         script_load(conf.script_file);
 554         break;
 555 #ifdef CAM_MOVIEREC_NEWSTYLE
 556     case  81:
 557         shooting_video_minbitrate_change(conf.video_quality);
 558         break;
 559 #endif
 560     case  82: 
 561         shooting_video_bitrate_change(conf.video_bitrate);
 562         break;
 563     case 200:
 564     case 204:
 565     case 205:   // USB Remote
 566     case 208:
 567         set_usb_remote_state();
 568         break;
 569     case 220:
 570 #ifndef CAM_ADJUSTABLE_ALT_BUTTON
 571         conf.alt_mode_button = KEY_PRINT;
 572 #endif
 573         break;
 574     case 221: 
 575         conf_update_prevent_shutdown(); 
 576         break;
 577     }
 578 }
 579 
 580 #ifdef CAM_HAS_GPS
 581 static ConfInfo gps_conf_info[] = {
 582     // GPS
 583     CONF_INFO(  1, conf.gps_record,                 CONF_DEF_VALUE,     i:0),
 584     CONF_INFO(  2, conf.gps_navi_show,              CONF_DEF_VALUE,     i:0),
 585     CONF_INFO(  3, conf.gps_compass_show,           CONF_DEF_VALUE,     i:0),
 586     CONF_INFO(  4, conf.gps_coordinates_show,       CONF_DEF_VALUE,     i:0),
 587     CONF_INFO(  5, conf.gps_height_show,            CONF_DEF_VALUE,     i:0),
 588     CONF_INFO(  6, conf.gps_waypoint_save,          CONF_DEF_VALUE,     i:0),
 589     CONF_INFO(  7, conf.gps_track_time,             CONF_DEF_VALUE,     i:1),
 590     CONF_INFO(  8, conf.gps_compass_hide,           CONF_DEF_VALUE,     i:0),
 591 
 592     CONF_INFO(  9, conf.gps_wait_for_signal,        CONF_DEF_VALUE,     i:300),
 593     CONF_INFO( 10, conf.gps_compass_time,           CONF_DEF_VALUE,     i:1),
 594     CONF_INFO( 11, conf.gps_navi_time,              CONF_DEF_VALUE,     i:1),
 595     CONF_INFO( 12, conf.gps_wait_for_signal_time,   CONF_DEF_VALUE,     i:5),
 596     CONF_INFO( 13, conf.gps_compass_smooth,         CONF_DEF_VALUE,     i:7),
 597     CONF_INFO( 14, conf.gps_batt,                   CONF_DEF_VALUE,     i:25),
 598     CONF_INFO( 15, conf.gps_countdown,              CONF_DEF_VALUE,     i:0),
 599     CONF_INFO( 16, conf.gps_2D_3D_fix,              CONF_DEF_VALUE,     i:2),
 600     CONF_INFO( 17, conf.gps_countdown_blink,        CONF_DEF_VALUE,     i:1),
 601     
 602     CONF_INFO( 18, conf.gps_rec_play_set,           CONF_DEF_VALUE,     i:0),
 603     CONF_INFO( 19, conf.gps_play_dark_set,          CONF_DEF_VALUE,     i:0),
 604     CONF_INFO( 20, conf.gps_rec_play_time,          CONF_DEF_VALUE,     i:30),
 605     CONF_INFO( 21, conf.gps_play_dark_time,         CONF_DEF_VALUE,     i:45),
 606 
 607     CONF_INFO( 22, conf.gps_rec_play_set_1,         CONF_DEF_VALUE,     i:0),
 608     CONF_INFO( 23, conf.gps_play_dark_set_1,        CONF_DEF_VALUE,     i:0),
 609     CONF_INFO( 24, conf.gps_rec_play_time_1,        CONF_DEF_VALUE,     i:10),
 610     CONF_INFO( 25, conf.gps_play_dark_time_1,       CONF_DEF_VALUE,     i:15),
 611     CONF_INFO( 26, conf.gps_show_symbol,            CONF_DEF_VALUE,     i:0),
 612     CONF_INFO( 27, conf.gps_batt_warn,              CONF_DEF_VALUE,     i:0),
 613     CONF_INFO( 28, conf.gps_track_symbol,           CONF_DEF_VALUE,     i:0),
 614     CONF_INFO( 29, conf.gps_test_timezone,          CONF_DEF_VALUE,     i:0),
 615     CONF_INFO( 30, conf.gps_beep_warn,              CONF_DEF_VALUE,     i:0),
 616     CONF_INFO( 31, conf.gps_on_off,                 CONF_DEF_VALUE,     i:0),
 617 
 618     {0,0,0,0,{0}}
 619 };
 620 #endif
 621 
 622 //-------------------------------------------------------------------
 623 // ID offsets for ConfInfo mapping from Lua libraries
 624 #define CONF_CORE   1000
 625 #define CONF_OSD    2000
 626 #define CONF_USER   3000
 627 #define CONF_GPS    4000
 628 
 629 #define CONF_FILE           "A/CHDK/CCHDK4.CFG"
 630 #define OSD_CONF_FILE       "A/CHDK/OSD__4.CFG"
 631 #define USER_MENU_CONF_FILE "A/CHDK/UMENU4.CFG"
 632 #define GPS_CONF_FILE       "A/CHDK/GPS__4.CFG"
 633 #define CONF_MAGICK_VALUE   (0x33204741)
 634 
 635 typedef struct
 636 {
 637     int         start_id, end_id;
 638     ConfInfo    *ci;
 639     char        *filename;
 640     void        (*info_func)(unsigned short id);
 641 } confinfo_handler;
 642 
 643 static const confinfo_handler confinfo_handlers[] = {
 644     { CONF_CORE, CONF_CORE+999, conf_info,           CONF_FILE,           conf_info_func },
 645     { CONF_OSD,  CONF_OSD +999, osd_conf_info,       OSD_CONF_FILE,       osd_conf_info_func },
 646     { CONF_USER, CONF_USER+999, user_menu_conf_info, USER_MENU_CONF_FILE, user_menu_conf_info_func },
 647 #ifdef CAM_HAS_GPS
 648     { CONF_GPS,  CONF_GPS +999, gps_conf_info,       GPS_CONF_FILE,       0 },
 649 #endif
 650     { 0,0,0,0,0 }
 651 };
 652 
 653 // mapping table to convert previous version (1.2) ConfInfo ID's to new version
 654 static short conf_map_1_2[] =
 655 {
 656     0,
 657     2001, // 1 conf.show_osd
 658     1020, // 2 conf.save_raw
 659     1050, // 3 conf.script_shoot_delay
 660     1060, // 4 conf.show_histo
 661     2006, // 5 conf.rotate_osd
 662     1052, // 6 conf.script_param_set
 663     2150, // 7 conf.show_dof
 664     2100, // 8 conf.batt_volts_max
 665     2101, // 9 conf.batt_volts_min
 666     0,
 667     2102, // 11 conf.batt_perc_show
 668     2103, // 12 conf.batt_volts_show
 669     2104, // 13 conf.batt_icon_show
 670     2090, // 14 conf.show_state
 671     2160, // 15 conf.show_values
 672     1061, // 16 conf.show_overexp
 673     1062, // 17 conf.histo_mode
 674     1063, // 18 conf.histo_auto_ajust
 675     1064, // 19 conf.histo_ignore_boundary
 676     1065, // 20 conf.histo_layout
 677     2020, // 21 conf.histo_pos
 678     2021, // 22 conf.dof_pos
 679     2022, // 23 conf.batt_icon_pos
 680     2023, // 24 conf.batt_txt_pos
 681     2024, // 25 conf.mode_state_pos
 682     2025, // 26 conf.values_pos
 683     2050, // 27 conf.histo_color
 684     2052, // 28 conf.osd_color
 685     0,
 686     2055, // 30 conf.menu_color
 687     2059, // 31 conf.reader_color
 688     1207, // 32 conf.ricoh_ca1_mode
 689     1226, // 33 conf.flashlight
 690     2230, // 34 conf.debug_shortcut_action
 691     1021, // 35 conf.raw_in_dir
 692     1022, // 36 conf.raw_prefix
 693     1023, // 37 conf.raw_ext
 694     2110, // 38 conf.reader_file
 695     2111, // 39 conf.reader_pos
 696     0,
 697     2080, // 41 conf.show_clock
 698     2026, // 42 conf.clock_pos
 699     2112, // 43 conf.reader_autoscroll
 700     2113, // 44 conf.reader_autoscroll_delay
 701     2114, // 45 conf.reader_rbf_file
 702     2115, // 46 conf.reader_codepage
 703     2120, // 47 conf.splash_show
 704     2051, // 48 conf.histo_color2
 705     1070, // 49 conf.zebra_draw
 706     1071, // 50 conf.zebra_mode
 707     1072, // 51 conf.zebra_restore_screen
 708     1073, // 52 conf.zebra_restore_osd
 709     1074, // 53 conf.zebra_over
 710     1075, // 54 conf.zebra_under
 711     2062, // 55 conf.zebra_color
 712     1076, // 56 conf.zebra_draw_osd
 713     3002, // 57 conf.user_menu_as_root
 714     2175, // 58 conf.zoom_value
 715     1222, // 59 conf.use_zoom_mf
 716     1024, // 60 conf.raw_save_first_only
 717     2116, // 61 conf.reader_wrap_by_words
 718     2130, // 62 conf.menu_symbol_enable
 719     1220, // 63 conf.alt_mode_button
 720     2135, // 64 conf.lang_file
 721     2136, // 65 conf.font_cp
 722     2131, // 66 conf.menu_rbf_file
 723     1221, // 67 conf.alt_prevent_shutdown
 724     2140, // 68 conf.show_grid_lines
 725     2141, // 69 conf.grid_lines_file
 726     1039, // 70 conf.raw_nr
 727     2142, // 71 conf.grid_force_color
 728     2060, // 72 conf.grid_color
 729     0,
 730     0,
 731     0,
 732     0,
 733     0,
 734     0,
 735     0,
 736     2151, // 80 conf.dof_subj_dist_as_near_limit
 737     2152, // 81 conf.dof_use_exif_subj_dist
 738     2153, // 82 conf.dof_subj_dist_in_misc
 739     2154, // 83 conf.dof_near_limit_in_misc
 740     2155, // 84 conf.dof_far_limit_in_misc
 741     2156, // 85 conf.dof_hyperfocal_in_misc
 742     2157, // 86 conf.dof_depth_in_misc
 743     2161, // 87 conf.values_show_in_review
 744     2162, // 88 conf.values_show_zoom
 745     2163, // 89 conf.values_show_real_aperture
 746     2164, // 90 conf.values_show_real_iso
 747     2165, // 91 conf.values_show_market_iso
 748     2166, // 92 conf.values_show_iso_only_in_autoiso_mode
 749     2167, // 93 conf.values_show_ev_seted
 750     2168, // 94 conf.values_show_ev_measured
 751     2169, // 95 conf.values_show_bv_measured
 752     2170, // 96 conf.values_show_bv_seted
 753     2171, // 97 conf.values_show_overexposure
 754     2172, // 98 conf.values_show_luminance
 755     1080, // 99 conf.video_mode
 756     1081, // 100 conf.video_quality
 757     1082, // 101 conf.video_bitrate
 758     1112, // 102 conf.tv_override_value
 759     1110, // 103 conf.tv_override_enabled
 760     1121, // 104 conf.av_override_value
 761     1130, // 105 conf.iso_override_value
 762     1131, // 106 conf.iso_override_koef
 763     1140, // 107 conf.subj_dist_override_value
 764     1141, // 108 conf.subj_dist_override_koef
 765     1150, // 109 conf.tv_bracket_value
 766     1151, // 110 conf.av_bracket_value
 767     1152, // 111 conf.iso_bracket_value
 768     1153, // 112 conf.iso_bracket_koef
 769     1154, // 113 conf.subj_dist_bracket_value
 770     1155, // 114 conf.subj_dist_bracket_koef
 771     1156, // 115 conf.bracket_type
 772     1113, // 116 conf.tv_override_long_exp
 773     1114, // 117 conf.tv_override_short_exp
 774     1120, // 118 conf.av_override_enabled
 775     1999, // 119 conf.script_allow_lua_native_calls
 776     1053, // 120 conf.script_startup
 777     1200, // 121 conf.remote_enable
 778     2173, // 122 conf.values_show_canon_overexposure
 779     1100, // 123 conf.clear_override
 780     2002, // 124 conf.show_osd_in_review
 781     0,
 782     1157, // 126 conf.clear_bracket
 783     1077, // 127 conf.zebra_multichannel
 784     1003, // 128 conf.nd_filter_state
 785     1066, // 129 conf.histo_show_ev_grid
 786     2053, // 130 conf.osd_color_warn
 787     2061, // 131 conf.space_color
 788     2180, // 132 conf.space_icon_show
 789     2027, // 133 conf.space_icon_pos
 790     2181, // 134 conf.space_perc_show
 791     2182, // 135 conf.space_mb_show
 792     2028, // 136 conf.space_txt_pos
 793     2200, // 137 conf.show_remaining_raw
 794     2029, // 138 conf.mode_raw_pos
 795     2201, // 139 conf.show_raw_state
 796     2174, // 140 conf.show_values_in_video
 797     1111, // 141 conf.tv_enum_type
 798     3003, // 142 conf.user_menu_enable
 799     3001, // 143 conf.user_menu_vars
 800     2176, // 144 conf.zoom_scale
 801     2183, // 145 conf.space_bar_show
 802     2184, // 146 conf.space_bar_size
 803     2030, // 147 conf.space_ver_pos
 804     2031, // 148 conf.space_hor_pos
 805     2185, // 149 conf.space_bar_width
 806     2186, // 150 conf.space_perc_warn
 807     2187, // 151 conf.space_mb_warn
 808     2188, // 152 conf.space_warn_type
 809     2202, // 153 conf.remaining_raw_treshold
 810     1086, // 154 conf.unlock_optical_zoom_for_video
 811     2081, // 155 conf.clock_format
 812     2082, // 156 conf.clock_indicator
 813     2083, // 157 conf.clock_halfpress
 814     1160, // 158 conf.autoiso_enable
 815     1161, // 159 conf.autoiso_shutter_enum
 816     1162, // 160 conf.autoiso_user_factor
 817     1163, // 161 conf.autoiso_is_factor
 818     1164, // 162 conf.autoiso_max_iso_hi
 819     1165, // 163 conf.autoiso_max_iso_auto
 820     1166, // 164 conf.autoiso_min_iso
 821     2056, // 165 conf.menu_title_color
 822     2057, // 166 conf.menu_cursor_color
 823     2134, // 167 conf.menu_center
 824     1084, // 168 conf.mute_on_zoom
 825     1033, // 169 conf.bad_pixel_removal
 826     1085, // 170 conf.video_af_key
 827     2054, // 171 conf.osd_color_override
 828     2003, // 172 conf.override_disable
 829     2004, // 173 conf.override_disable_all
 830     2005, // 174 conf.hide_osd
 831     1025, // 175 conf.save_raw_in_video
 832     2210, // 176 conf.show_movie_time
 833     2211, // 177 conf.show_movie_refresh
 834     2032, // 178 conf.mode_video_pos
 835     1083, // 179 conf.clear_video
 836     1087, // 180 conf.fast_ev
 837     1088, // 181 conf.fast_ev_step
 838     2033, // 182 conf.mode_ev_pos
 839     2132, // 183 conf.menu_symbol_rbf_file
 840     2058, // 184 conf.menu_symbol_color
 841     1180, // 185 conf.curve_file
 842     1181, // 186 conf.curve_enable
 843     1190, // 187 conf.edge_overlay_enable
 844     1191, // 188 conf.edge_overlay_thresh
 845     2063, // 189 conf.edge_overlay_color
 846     1201, // 190 conf.synch_enable
 847     1202, // 191 conf.synch_delay_enable
 848     1203, // 192 conf.synch_delay_value
 849     0,
 850     1054, // 194 conf.script_file
 851     2234, // 195 conf.mem_view_addr_init
 852     1026, // 196 conf.save_raw_in_sports
 853     1027, // 197 conf.save_raw_in_burst
 854     1028, // 198 conf.save_raw_in_ev_bracketing
 855     1029, // 199 conf.save_raw_in_timer
 856     2203, // 200 conf.raw_exceptions_warn
 857     2133, // 201 conf.menu_select_first_entry
 858     1089, // 202 conf.fast_movie_control
 859     2220, // 203 conf.show_temp
 860     2034, // 204 conf.temp_pos
 861     1090, // 205 conf.fast_movie_quality_control
 862     0,
 863     0,
 864     2121, // 208 conf.start_sound
 865     1041, // 209 conf.sub_batch_prefix
 866     1042, // 210 conf.sub_batch_ext
 867     0,
 868     0,
 869     2231, // 213 conf.debug_display
 870     1055, // 214 conf.script_param_save
 871     2035, // 215 conf.ev_video_pos
 872     0,
 873     0,
 874     0,
 875     1040, // 219 conf.bracketing_add_raw_suffix
 876     2221, // 220 conf.temperature_unit
 877     0,
 878     1192, // 222 conf.edge_overlay_play
 879     1193, // 223 conf.edge_overlay_pano
 880     1194, // 224 conf.edge_overlay_zoom
 881     1030, // 225 conf.raw_cache
 882     1036, // 226 conf.dng_raw
 883     1210, // 227 conf.flash_sync_curtain
 884     1034, // 228 conf.raw_timer
 885     1001, // 229 conf.platformid
 886     1031, // 230 conf.save_raw_in_edgeoverlay
 887     1032, // 231 conf.save_raw_in_auto
 888     1211, // 232 conf.flash_video_override
 889     1212, // 233 conf.flash_video_override_power
 890     1035, // 234 conf.raw_dng_ext
 891     1038, // 235 conf.dng_usb_ext
 892     1213, // 236 conf.flash_manual_override
 893     1002, // 237 conf.fast_image_quality
 894     1224, // 238 conf.debug_lua_restart_on_error
 895     2232, // 239 conf.debug_propcase_page
 896     2233, // 240 conf.debug_misc_vals_show
 897     1195, // 241 conf.edge_overlay_filter
 898     1196, // 242 conf.edge_overlay_show
 899     1197, // 243 conf.edge_overlay_pano_overlap
 900     2240, // 244 conf.touchscreen_disable_video_controls
 901     2241, // 245 conf.touchscreen_disable_shortcut_controls
 902     2250, // 246 conf.usb_info_enable
 903     2036, // 247 conf.usb_info_pos
 904     1204, // 248 conf.remote_switch_type
 905     1205, // 249 conf.remote_control_mode
 906     1206, // 250 conf.remote_enable_scripts
 907     2189, // 251 conf.show_partition_nr
 908     1091, // 252 conf.ext_video_time
 909     4001, // 253 conf.gps_record
 910     4002, // 254 conf.gps_navi_show
 911     4003, // 255 conf.gps_compass_show
 912     4004, // 256 conf.gps_coordinates_show
 913     4005, // 257 conf.gps_height_show
 914     4006, // 258 conf.gps_waypoint_save
 915     4007, // 259 conf.gps_track_time
 916     4008, // 260 conf.gps_compass_hide
 917     4009, // 261 conf.gps_wait_for_signal
 918     4010, // 262 conf.gps_compass_time
 919     4011, // 263 conf.gps_navi_time
 920     4012, // 264 conf.gps_wait_for_signal_time
 921     4013, // 265 conf.gps_compass_smooth
 922     4014, // 266 conf.gps_batt
 923     4015, // 267 conf.gps_countdown
 924     4016, // 268 conf.gps_2D_3D_fix
 925     4017, // 269 conf.gps_countdown_blink
 926     4018, // 270 conf.gps_rec_play_set
 927     4019, // 271 conf.gps_play_dark_set
 928     4020, // 272 conf.gps_rec_play_time
 929     4021, // 273 conf.gps_play_dark_time
 930     4022, // 274 conf.gps_rec_play_set_1
 931     4023, // 275 conf.gps_play_dark_set_1
 932     4024, // 276 conf.gps_rec_play_time_1
 933     4025, // 277 conf.gps_play_dark_time_1
 934     4026, // 278 conf.gps_show_symbol
 935     4027, // 279 conf.gps_batt_warn
 936     4029, // 280 conf.gps_test_timezone
 937     4030, // 281 conf.gps_beep_warn
 938     4031, // 282 conf.gps_on_off
 939     1170, // 283 conf.autoiso2_shutter_enum
 940     1171, // 284 conf.autoiso2_max_iso_auto
 941     1172, // 285 conf.autoiso2_over
 942     1173, // 286 conf.overexp_threshold
 943     1174, // 287 conf.overexp_ev_enum
 944     1223, // 288 conf.zoom_assist_button_disable
 945     1037, // 289 conf.dng_version
 946     2137, // 290 conf.tbox_char_map
 947     2260, // 291 conf.show_alt_helper
 948     2261, // 292 conf.show_alt_helper_delay
 949     2263, // 293 conf.extra_button
 950     1225, // 294 conf.module_logging
 951     2262, // 295 conf.enable_shortcuts
 952     2270, // 296 conf.console_show
 953     2271, // 297 conf.console_timeout
 954     1230, // 298 conf.memdmp_start
 955     1231, // 299 conf.memdmp_size
 956     1214, // 300 conf.flash_exp_comp
 957     1215, // 301 conf.flash_enable_exp_comp
 958     2297, // 302 conf.enable_raw_shortcut
 959 };
 960 
 961 //-------------------------------------------------------------------
 962 // make hash of memory block
 963 unsigned int memhash31(unsigned char *mem, int len)
 964 {
 965         unsigned hash=0;
 966         for (; len > 0; mem++, len-- )
 967                 hash = *mem ^ (hash<<6) ^ (hash>>25);
 968         return hash;
 969 }
 970 
 971 static void config_update_last_saved(ConfInfo *ci)
 972 {
 973     int i;
 974     for (i=0; ci[i].id > 0; ++i)
 975     {
 976         switch (ci[i].type)
 977         {
 978             case CONF_OSD_POS:
 979             case CONF_DEF_VALUE:
 980             case CONF_FUNC_PTR:
 981                 switch (ci[i].size)
 982                 {
 983                     case sizeof(int):
 984                         ci[i].last_saved = (unsigned int)*((int*)ci[i].var);
 985                         break;
 986                     case sizeof(short):
 987                         ci[i].last_saved = (unsigned int)*((short*)ci[i].var);
 988                         break;
 989                     case sizeof(char):
 990                         ci[i].last_saved = (unsigned int)*((char*)ci[i].var);
 991                         break;
 992                 }
 993                 break;
 994             case CONF_INT_PTR:
 995                 ci[i].last_saved = memhash31((unsigned char*)ci[i].var, ci[i].size);
 996                 break;
 997             case CONF_CHAR_PTR:
 998                 ci[i].last_saved = lang_strhash31((int)ci[i].var);
 999                 break;
1000         }
1001     }
1002 }
1003 
1004 static int config_has_changed(ConfInfo *ci)
1005 {
1006     int i;
1007     for (i=0; ci[i].id > 0; ++i)
1008     {
1009         switch (ci[i].type)
1010         {
1011             case CONF_OSD_POS:
1012             case CONF_DEF_VALUE:
1013             case CONF_FUNC_PTR:
1014                 switch (ci[i].size)
1015                 {
1016                     case sizeof(int):
1017                         if (ci[i].last_saved != (unsigned int)*((int*)ci[i].var))
1018                             return 1;
1019                         break;
1020                     case sizeof(short):
1021                         if (ci[i].last_saved != (unsigned int)*((short*)ci[i].var))
1022                             return 1;
1023                         break;
1024                     case sizeof(char):
1025                         if (ci[i].last_saved != (unsigned int)*((char*)ci[i].var))
1026                             return 1;
1027                         break;
1028                 }
1029                 break;
1030             case CONF_INT_PTR:
1031                 if (ci[i].last_saved != memhash31((unsigned char*)ci[i].var, ci[i].size))
1032                     return 1;
1033                 break;
1034             case CONF_CHAR_PTR:
1035                 if (ci[i].last_saved != lang_strhash31((int)ci[i].var))
1036                     return 1;
1037                 break;
1038         }
1039     }
1040 
1041     return 0;
1042 }
1043 
1044 //-------------------------------------------------------------------
1045 static void config_load_defaults(ConfInfo *ci, void (*info_func)(unsigned short id))
1046 {
1047     register int i;
1048 
1049     for (i=0; ci[i].id > 0; ++i) {
1050         switch (ci[i].type) {
1051             case CONF_OSD_POS:
1052             case CONF_DEF_VALUE:
1053                 memcpy(ci[i].var, &(ci[i].i), ci[i].size);
1054                 break;
1055             case CONF_INT_PTR:
1056                 memset(ci[i].var, 0, ci[i].size);
1057                 break;
1058             case CONF_FUNC_PTR:
1059                 *((int*)ci[i].var) = ci[i].func();
1060                 break;
1061             case CONF_CHAR_PTR:
1062                 memcpy(ci[i].var, ci[i].ptr, ci[i].size);
1063                 break;
1064         }
1065         if (info_func) info_func(ci[i].id);
1066     }
1067 }
1068 
1069 void conf_load_defaults()
1070 {
1071     int i;
1072     for (i=0; confinfo_handlers[i].ci != 0; i++)
1073         config_load_defaults(confinfo_handlers[i].ci, confinfo_handlers[i].info_func);
1074 }
1075 
1076 //-------------------------------------------------------------------
1077 
1078 // Structure for saved conf info (allows for changes to ConfInfo without affecting saved configurations
1079 typedef struct
1080 {
1081     unsigned short id;
1082     unsigned short size;
1083 } ConfInfoSave;
1084 
1085 void config_save(ConfInfo *ci, const char *filename, int config_base)
1086 {
1087 // if Lua native calls are forced on, don't save state to config file since user did not select it
1088 #if defined(OPT_FORCE_LUA_CALL_NATIVE)
1089     conf.script_allow_lua_native_calls = 0;
1090 #endif
1091 
1092     register int i;
1093     
1094     for (i=0; ci[i].id > 0; i++);   // Find # of items
1095 
1096     int size = 2 * sizeof(int) + i * sizeof(ConfInfoSave);
1097 
1098     for (i=0; ci[i].id > 0; i++)
1099     {
1100         if (ci[i].type == CONF_STRUCT_PTR)
1101         {
1102             tVarArrayConfig *cfg = (tVarArrayConfig*)(ci[i].var);
1103             size += cfg->saved_size();
1104         }
1105         else
1106         {
1107             size += ci[i].size;
1108         }
1109     }
1110 
1111     char *buf = umalloc(size);
1112     char *p = buf;
1113 
1114     int fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0777); 
1115     if (fd >= 0)
1116     {
1117         int t = CONF_MAGICK_VALUE;
1118         memcpy(p, &t, sizeof(t));
1119         p += sizeof(t);
1120 
1121         t = config_base;
1122         memcpy(p, &t, sizeof(t));
1123         p += sizeof(t);
1124 
1125         for (i=0; ci[i].id > 0; ++i)
1126         {
1127             ((ConfInfoSave*)p)->id   = ci[i].id;
1128             ((ConfInfoSave*)p)->size = ci[i].size;
1129             p += sizeof(ConfInfoSave);
1130             if (ci[i].type == CONF_STRUCT_PTR)
1131             {
1132                 tVarArrayConfig *cfg = (tVarArrayConfig*)(ci[i].var);
1133                 p = cfg->save(p);
1134             }
1135             else
1136             {
1137                 memcpy(p, ci[i].var, ci[i].size);
1138                 // Clear out unused space after string config item value
1139                 if ((ci[i].size == CONF_STR_LEN) && (strlen(ci[i].var) < CONF_STR_LEN))
1140                     memset(p+strlen(ci[i].var), 0, CONF_STR_LEN-strlen(ci[i].var));
1141                 p += ci[i].size;
1142             }
1143         }
1144 
1145         write(fd, buf, p-buf);
1146         close(fd);
1147     }
1148     ufree(buf);
1149 
1150 // if Lua native calls are forced on, re-enable native calls
1151 #if defined(OPT_FORCE_LUA_CALL_NATIVE)
1152     conf.script_allow_lua_native_calls = 1;
1153 #endif
1154 }
1155 
1156 void conf_save()
1157 {
1158     int i;
1159     for (i=0; confinfo_handlers[i].ci != 0; i++)
1160     {
1161         if (config_has_changed(confinfo_handlers[i].ci) || ((confinfo_handlers[i].start_id == CONF_USER) && camera_info.state.user_menu_has_changed))
1162         {
1163             if (confinfo_handlers[i].start_id == CONF_USER)
1164                         user_menu_save();
1165 
1166             config_save(confinfo_handlers[i].ci, confinfo_handlers[i].filename, confinfo_handlers[i].start_id);
1167             config_update_last_saved(confinfo_handlers[i].ci);
1168         }
1169     }
1170     // Save current script parameters if they have changed.
1171     save_params_values(0);
1172 }
1173 
1174 int save_config_file(int config_base, const char *filename)
1175 {
1176     int i;
1177     for (i=0; confinfo_handlers[i].ci != 0; i++)
1178     {
1179         if ((config_base >= confinfo_handlers[i].start_id) && (config_base <= confinfo_handlers[i].end_id))
1180         {
1181             config_save(confinfo_handlers[i].ci, (filename != 0) ? filename : confinfo_handlers[i].filename, confinfo_handlers[i].start_id);
1182             if (filename == 0)  // Reset 'last_saved' values after saving default file
1183                 config_update_last_saved(confinfo_handlers[i].ci);
1184             return 1;
1185         }
1186     }
1187     return 0;
1188 }
1189 
1190 //-------------------------------------------------------------------
1191 void config_restore(ConfInfo *ci, const char *filename, void (*info_func)(unsigned short id))
1192 {
1193     int rcnt, i, offs;
1194     unsigned short id, size;
1195 
1196     char* buf = load_file(filename, &rcnt, 0);
1197 
1198     if (buf)
1199     {
1200         if (*(int*)buf == CONF_MAGICK_VALUE)
1201         {
1202             offs = 2 * sizeof(int);
1203             while (1)
1204             {
1205                 if (offs + sizeof(short) > rcnt)
1206                     break;
1207                 id = *((short*)(buf + offs));
1208                 offs += sizeof(short);
1209 
1210                 if (offs + sizeof(short) > rcnt)
1211                     break;
1212                 size = *((short*)(buf + offs));
1213                 offs += sizeof(short);
1214 
1215                 for (i=0; ci[i].id > 0; ++i)
1216                 {
1217                     if (ci[i].id==id && ci[i].size==size)
1218                     {
1219                         if (offs + size <= rcnt)
1220                         {
1221                             if (ci[i].type == CONF_STRUCT_PTR)
1222                             {
1223                                 tVarArrayConfig *cfg = (tVarArrayConfig*)(ci[i].var);
1224                                 size = cfg->load(buf+offs);
1225                             }
1226                             else if (ci[i].size == size)    // only restore if size matches
1227                             {
1228                                 memcpy(ci[i].var, buf+offs, size);
1229                             }
1230                             if (info_func) info_func(ci[i].id);
1231                         }
1232                         break;
1233                     }
1234                 }
1235 
1236                 offs += size;
1237             }
1238         }
1239         free(buf);
1240     }
1241 }
1242 
1243 // Try loading old config file
1244 static int config_restore_1_2(const char *filename)
1245 {
1246     int rv = 0;
1247     int rcnt, i, offs;
1248     unsigned short id, size;
1249 
1250     char* buf = load_file(filename, &rcnt, 0);
1251 
1252     if (buf)
1253     {
1254         if (*(int*)buf == CONF_MAGICK_VALUE)
1255         {
1256             rv = 1;
1257             offs = sizeof(int);
1258             while (1)
1259             {
1260                 if (offs + sizeof(short) > rcnt)
1261                     break;
1262                 id = conf_map_1_2[*((short*)(buf + offs))];
1263                 offs += sizeof(short);
1264 
1265                 if (offs + sizeof(short) > rcnt)
1266                     break;
1267                 size = *((short*)(buf + offs));
1268                 offs += sizeof(short);
1269 
1270                 ConfInfo *ci = 0;
1271                 void (*info_func)(unsigned short id) = 0;
1272                 for (i=0; confinfo_handlers[i].ci != 0; i++)
1273                 {
1274                     if ((id >= confinfo_handlers[i].start_id) && (id <= confinfo_handlers[i].end_id))
1275                     {
1276                         ci = confinfo_handlers[i].ci;
1277                         info_func = confinfo_handlers[i].info_func;
1278                         id -= confinfo_handlers[i].start_id;
1279                         break;
1280                     }
1281                 }
1282 
1283                 if (ci != 0)
1284                 {
1285                     for (i=0; ci[i].id > 0; ++i)
1286                     {
1287                         if (ci[i].id==id && ci[i].size==size)
1288                         {
1289                             if (offs + size <= rcnt)
1290                             {
1291                                 if (ci[i].type == CONF_STRUCT_PTR)
1292                                 {
1293                                     tVarArrayConfig *cfg = (tVarArrayConfig*)(ci[i].var);
1294                                     size = cfg->load(buf+offs);
1295                                 }
1296                                 else
1297                                 {
1298                                     memcpy(ci[i].var, buf+offs, size);
1299                                 }
1300                                 if (info_func) info_func(ci[i].id);
1301                             }
1302                             break;
1303                         }
1304                     }
1305                 }
1306 
1307                 offs += size;
1308             }
1309         }
1310         free(buf);
1311     }
1312 
1313     return rv;
1314 }
1315 
1316 void conf_restore()
1317 {
1318     int i;
1319     int old_config_loaded = 0;
1320 
1321     // init some defaults values
1322     init_user_menu(USER_MENU_ITEMS);
1323 
1324     // Load all defaults first, in case we end up loading old file
1325     conf_load_defaults();
1326 
1327     // Check if CORE config file exists, if not try loading old (1.2) file
1328     if (stat(confinfo_handlers[0].filename,0) != 0)
1329         old_config_loaded = config_restore_1_2("A/CHDK/CCHDK3.CFG");
1330 
1331     // Load all new files (that exist)
1332     for (i=0; confinfo_handlers[i].ci != 0; i++)
1333     {
1334         config_restore(confinfo_handlers[i].ci, confinfo_handlers[i].filename, confinfo_handlers[i].info_func);
1335         if (old_config_loaded == 0)
1336             config_update_last_saved(confinfo_handlers[i].ci);
1337     }
1338 
1339     // clear any "clear on restart" values
1340     clear_values();
1341 
1342 // Enable Lua native calls if builder wants them forced on
1343 #if defined(OPT_FORCE_LUA_CALL_NATIVE)
1344     conf.script_allow_lua_native_calls = 1;
1345 #endif
1346 
1347 // If curves not compiled in force option off
1348 #if !defined(OPT_CURVES)
1349     conf.curve_enable = 0;
1350 #endif
1351 }
1352 
1353 int load_config_file(int config_base, const char *filename)
1354 {
1355     int i;
1356     for (i=0; confinfo_handlers[i].ci != 0; i++)
1357     {
1358         if ((config_base >= confinfo_handlers[i].start_id) && (config_base <= confinfo_handlers[i].end_id))
1359         {
1360             config_restore(confinfo_handlers[i].ci, (filename != 0) ? filename : confinfo_handlers[i].filename, confinfo_handlers[i].info_func);
1361             if (filename == 0)  // Reset 'last_saved' values if loading default file
1362                 config_update_last_saved(confinfo_handlers[i].ci);
1363             return 1;
1364         }
1365     }
1366     return 0;
1367 }
1368 
1369 //-------------------------------------------------------------------
1370 // Find ConfInfo entry index for given ID
1371 static int findConfInfo(ConfInfo *ci, unsigned short id)
1372 {
1373     int i;
1374     for( i=0; ci[i].id > 0; ++i )
1375         if( ci[i].id==id )
1376             return i;
1377     return -1;
1378 }
1379 
1380 // Reset all user adjustable color settings to default values
1381 void resetColors()
1382 {
1383     int i, n;
1384 
1385     // Iterate over color override ID's
1386     for (n=COLOR_FIRST_OVERRIDE; n<=COLOR_LAST_OVERRIDE; n++)
1387     {
1388         i = findConfInfo(osd_conf_info, n);
1389         if (i != -1)
1390         {
1391             *((confColor*)osd_conf_info[i].var) = osd_conf_info[i].cl;
1392         }
1393     }
1394 }
1395 
1396 //-------------------------------------------------------------------
1397 static int getValue(ConfInfo *ci, unsigned short id, tConfigVal* configVal)
1398 {
1399     int i;
1400     int ret = CONF_EMPTY;
1401     OSD_pos* pos;
1402     
1403     if (id == 0)
1404     {
1405         configVal->numb = 0;
1406         for ( i=0; ci[i].id > 0; ++i )
1407             if ( configVal->numb<ci[i].id )
1408                 configVal->numb = ci[i].id;
1409         ret = CONF_VALUE;
1410     }
1411     else
1412     {
1413         i = findConfInfo(ci, id);
1414         if (i != -1)
1415         {
1416             switch( ci[i].type )
1417             {
1418                 case CONF_VALUE:
1419                 case CONF_FUNC_PTR:
1420                     switch( ci[i].size )
1421                     {
1422                         case sizeof(int):
1423                             configVal->numb = *(int*)ci[i].var;
1424                             ret = CONF_VALUE;
1425                             break;
1426                         case sizeof(short):
1427                             configVal->numb = *(short*)ci[i].var;
1428                             ret = CONF_VALUE;
1429                             break;
1430                         case sizeof(char):
1431                             configVal->numb = *(char*)ci[i].var;
1432                             ret = CONF_VALUE;
1433                             break;
1434                     }
1435                     configVal->pInt = (int*)ci[i].var;
1436                     break;
1437                 case CONF_INT_PTR:
1438                     configVal->numb = ci[i].size/sizeof(int);
1439                     configVal->pInt = (int*)ci[i].var;
1440                     ret = CONF_INT_PTR;
1441                     break;
1442                 case CONF_CHAR_PTR:
1443                     configVal->str = ci[i].var;
1444                     ret = CONF_CHAR_PTR;
1445                     break;
1446                 case CONF_OSD_POS:
1447                     pos = (OSD_pos*)ci[i].var;
1448                     configVal->pos.x = pos->x;
1449                     configVal->pos.y = pos->y;
1450                     ret = CONF_OSD_POS;
1451                     configVal->pInt = (int*)ci[i].var;
1452                     break;
1453             }
1454         }
1455     }
1456     return ret;
1457 }
1458 
1459 int conf_getValue(unsigned short id, tConfigVal* configVal)
1460 {
1461     int i;
1462 
1463     if (id < CONF_CORE)
1464         id = conf_map_1_2[id];  // Convert old ID to new ID
1465 
1466     for (i=0; confinfo_handlers[i].ci != 0; i++)
1467         if ((id >= confinfo_handlers[i].start_id) && (id <= confinfo_handlers[i].end_id))
1468             return getValue(confinfo_handlers[i].ci, id - confinfo_handlers[i].start_id, configVal);
1469 
1470     return CONF_EMPTY;
1471 }
1472 
1473 //-------------------------------------------------------------------
1474 static int config_autosave = 1;
1475 
1476 static int setValue(ConfInfo *ci, unsigned short id, tConfigVal configVal, void (*info_func)(unsigned short id))
1477 {
1478     int i;
1479     int ret = CONF_EMPTY, len, len2;
1480     OSD_pos* pos;
1481     
1482     // Don't allow scripts to enable Lua native calls.
1483     if (id == 999) return ret;
1484 
1485     i = findConfInfo(ci, id);
1486     if (i != -1)
1487     {
1488         switch( ci[i].type )
1489         {
1490             case CONF_VALUE:
1491             case CONF_FUNC_PTR:
1492                 if( configVal.isNumb )
1493                 {
1494                     switch( ci[i].size )
1495                     {
1496                         case sizeof(int):
1497                             *(int*)ci[i].var = (int)configVal.numb;
1498                             ret = CONF_VALUE;
1499                             break;
1500                         case sizeof(short):
1501                             *(short*)ci[i].var = (short)configVal.numb;
1502                             ret = CONF_VALUE;
1503                             break;
1504                         case sizeof(char):
1505                             *(char*)ci[i].var = (char)configVal.numb;
1506                             ret = CONF_VALUE;
1507                             break;
1508                     }
1509                 }
1510                 break;
1511             case CONF_INT_PTR:
1512                 if( configVal.isPInt )
1513                 {
1514                     len = ci[i].size;
1515                     len2 = configVal.numb*sizeof(int);
1516                     if( len2<len ) len = len2;
1517                     memcpy(ci[i].var, configVal.pInt, len);
1518                     ret = CONF_INT_PTR;
1519                 }
1520                 break;
1521             case CONF_CHAR_PTR:
1522                 if( configVal.isStr )
1523                 {
1524                     len = strlen(configVal.str);
1525                     if (len<CONF_STR_LEN)
1526                     {
1527                         strncpy(ci[i].var, configVal.str ,len+1);
1528                     }
1529                     ret = CONF_CHAR_PTR;
1530                 }
1531                 break;
1532             case CONF_OSD_POS:
1533                 if( configVal.isPos )
1534                 {
1535                     pos = (OSD_pos*)ci[i].var;
1536                     pos->x = configVal.pos.x;
1537                     pos->y = configVal.pos.y;
1538                     ret = CONF_OSD_POS;
1539                 }
1540                 break;
1541         }
1542     }
1543 
1544     if (ret != CONF_EMPTY)
1545     {
1546         // Perform an updates required on change of value
1547         if (info_func)
1548             info_func(id);
1549         // Save config file is autosave enabled
1550         if (config_autosave)
1551             conf_save();
1552     }
1553 
1554     return ret;
1555 }
1556 
1557 int conf_setValue(unsigned short id, tConfigVal configVal)
1558 {
1559     int i;
1560 
1561     if (id < CONF_CORE)
1562         id = conf_map_1_2[id];  // Convert old ID to new ID
1563 
1564     for (i=0; confinfo_handlers[i].ci != 0; i++)
1565         if ((id >= confinfo_handlers[i].start_id) && (id <= confinfo_handlers[i].end_id))
1566             return setValue(confinfo_handlers[i].ci, id - confinfo_handlers[i].start_id, configVal, confinfo_handlers[i].info_func);
1567 
1568     return CONF_EMPTY;
1569 }
1570 
1571 void conf_setAutosave(int n)
1572 {
1573     config_autosave = (n == 0) ? 0 : 1;
1574 }
1575 
1576 //-------------------------------------------------------------------
1577 // Common code extracted from raw.c (raw_savefile) and gui_osd.c (gui_osd_draw_raw_info)
1578 // returns 0 if RAW save is disabled due to mode settings, etc, return 1 if RAW save OK
1579 /*
1580 is raw disabled by exceptions
1581 */
1582 int is_raw_exception() {
1583     int m = camera_info.state.mode_shooting;
1584     // NOTE: the conf.save_raw_in variables are negative logic
1585     //       1 = disable saving raw in this mode, 0 = allow saving raw
1586     //       variables should be named conf.disable_save_raw_in_XXX
1587     return (
1588         (is_video_recording() && conf.save_raw_in_video) ||                                 // True is movie mode and save_raw_in_video is disabled
1589 #ifdef CAM_HAS_CANON_RAW
1590         (shooting_get_canon_raw_enabled() && conf.save_raw_in_canon_raw) ||                                                   // True if Canon RAW enabled, for cams that treat it as a resolution setting (g9, g10, s90, sx1? not g12, g1x)
1591 #endif
1592 #ifdef CAM_HAS_SPORTS_MODE
1593         ((m==MODE_SPORTS) && conf.save_raw_in_sports) ||                                    // True if sports mode and save_raw_in_sports is disabled
1594 #endif
1595         ((m==MODE_AUTO) && conf.save_raw_in_auto) ||                                        // True if auto mode and save_raw_in_auto is disabled
1596         (conf.edge_overlay_enable && conf.save_raw_in_edgeoverlay) ||                       // True if edge overlay on and save_raw_in_edgeoverlay is disabled
1597         ((shooting_get_drive_mode()==1) && conf.save_raw_in_burst && !(m==MODE_SPORTS)) ||  // True if drive mode is continuous and save_raw_in_burst is disabled and not sports mode
1598         ((shooting_get_drive_mode()>=2) && conf.save_raw_in_timer) ||                       // True if drive mode is timer and save_raw_in_timer is disabled
1599         ((shooting_get_prop(PROPCASE_BRACKET_MODE)==1) && conf.save_raw_in_ev_bracketing)   // True if bracketing enabled and save_raw_in_ev_bracketing is disabled
1600     );
1601 }
1602 
1603 /*
1604 is raw possible (i.e. valid raw buffer exists in current mode)
1605 TODO this might be better as a platform lib.c function rather than a bunch of camera.h ifdefs
1606 */
1607 int is_raw_possible() {
1608     int m = camera_info.state.mode_shooting;
1609     return !(0   // Return false if any of these tests are true
1610 #ifdef CAM_DISABLE_RAW_IN_AUTO
1611        || (m == MODE_AUTO)                   // some cameras don't have valid raw in auto mode
1612 #endif
1613 #ifdef CAM_DISABLE_RAW_IN_ISO_3200
1614        || (m == MODE_ISO_3200)           // some cameras don't have valid raw in ISO3200 binned mode, not the same as low light
1615 #endif
1616 #ifdef CAM_DISABLE_RAW_IN_LOW_LIGHT_MODE
1617        || (shooting_get_resolution()==7)     // True if shooting resolution is 'low light'
1618 #endif
1619 #if defined(CAM_DISABLE_RAW_IN_HQ_BURST)
1620        || (m == MODE_HIGHSPEED_BURST)    // True if HQ Burst mode (SX40HS corrupts JPEG images if RAW enabled in this mode)
1621 #endif
1622 #if defined(CAM_DISABLE_RAW_IN_HANDHELD_NIGHT_SCN)
1623        || (m == MODE_NIGHT_SCENE)            // True if HandHeld Night Scene (SX40HS corrupts JPEG images if RAW enabled in this mode)
1624 #endif
1625 #if defined(CAM_DISABLE_RAW_IN_DIGITAL_IS)
1626        || (m == MODE_DIGITAL_IS)            // True if Digital IS mode (ixus160_elph160 crashes if RAW enabled in this mode)
1627 #endif
1628 #if defined(CAM_DISABLE_RAW_IN_HYBRID_AUTO)
1629        || (m == MODE_HYBRID_AUTO)            // True if Hybrid Auto mode (SX280HS raw hook conflicts with the saving of digest movie)
1630 #endif
1631 #if defined(CAM_DISABLE_RAW_IN_MOVIE_DIGEST) 
1632        || (m == MODE_VIDEO_MOVIE_DIGEST)     // True if Movie Digest mode (SX510HS raw hook conflicts with the saving of digest movie)
1633 #endif
1634 #if defined(CAM_DISABLE_RAW_IN_SPORTS)
1635        || (m == MODE_SPORTS)            // True if Sports mode (SX280HS, multiple issues with raw buffer; storing raw makes little sense in this mode anyway)
1636 #endif
1637 #if defined(CAM_DISABLE_RAW_IN_HDR)
1638        || (m == MODE_HDR)            // True if HDR mode (G7X)
1639 #endif
1640     );
1641 }
1642 
1643 int is_raw_enabled()
1644 {
1645     return is_raw_possible() && !is_raw_exception();
1646 }
1647 
1648 //-------------------------------------------------------------------

/* [<][>][^][v][top][bottom][index][help] */