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

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