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. reset_alt_button
  5. clear_values
  6. user_menu_conf_info_func
  7. osd_conf_info_func
  8. conf_info_func
  9. memhash31
  10. config_update_last_saved
  11. config_has_changed
  12. config_load_defaults
  13. conf_load_defaults
  14. config_save
  15. conf_save
  16. save_config_file
  17. config_restore
  18. config_restore_1_2
  19. conf_restore
  20. load_config_file
  21. findConfInfo
  22. resetColors
  23. getValue
  24. conf_getValue
  25. setValue
  26. conf_setValue
  27. conf_setAutosave
  28. is_raw_exception
  29. is_raw_possible
  30. is_raw_enabled

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

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