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

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