// // Console window // void ConsoleTabWindow::print(TCHAR *buf, BOOL force_display) { int cr; TCHAR *p; if (force_display) goto display; if (_filesave) { if (_logfile == INVALID_HANDLE_VALUE && !_open_log_file()) { _filesave = FALSE; _set_check(IDC_CONS_FILESAVE, _filesave); EnableWindow(_filename_edit, _filesave); goto display; } DWORD cnt; char c; for (int i = 0; *buf != TEXT('\0'); buf++) { c = *buf & 0x7f; WriteFile(_logfile, &c, 1, &cnt, 0); } FlushFileBuffers(_logfile); return; } display: // count number of '\n' for (cr = 0, p = buf; p = wcschr(p, TEXT('\n')); cr++, p++) continue; // total length of new buffer ('\n' -> "\r\n" + '\0') size_t sz = (wcslen(buf) + cr + 1) * sizeof(TCHAR); p = reinterpret_cast <TCHAR *>(malloc(sz)); if (p == NULL) return; // convert newlines TCHAR *d = p; while (*buf != TEXT('\0')) { TCHAR c = *buf++; if (c == TEXT('\n')) *d++ = TEXT('\r'); *d++ = c; } *d = TEXT('\0'); // append the text and scroll int end = Edit_GetTextLength(_edit); Edit_SetSel(_edit, end, end); Edit_ReplaceSel(_edit, p); Edit_ScrollCaret(_edit); UpdateWindow(_edit); free(p); }
bool set_del(struct set *s, void *p) { ssize_t i; _set_check(s); i = _set_find(s, p); if (i < 0) return FALSE; /* overwrite elem i with the last elem, drop the size of the set * if the elem to delete is the last elem, this is a noop */ s->elems[i] = s->elems[--s->filled]; return TRUE; }
void MainTabWindow::init(HWND w) { HpcMenuInterface &menu = HPC_MENU; struct HpcMenuInterface::HpcMenuPreferences &pref = HPC_PREFERENCE; _window = w; // insert myself to tab-control TabWindow::init(w); // setup child. TCHAR *entry; int i; // kernel directory path for (i = 0; entry = menu.dir(i); i++) _insert_item(w, entry, IDC_MAIN_DIR); SendDlgItemMessage(w, IDC_MAIN_DIR, CB_SETCURSEL, menu.dir_default(), 0); // platform _sort_platids(w); // kernel file name. Edit_SetText(GetDlgItem(w, IDC_MAIN_KERNEL), pref.kernel_user ? pref.kernel_user_file : TEXT("netbsd.gz")); // root file system. int fs = pref.rootfs + IDC_MAIN_ROOT_; _set_check(fs, TRUE); _edit_md_root = GetDlgItem(w, IDC_MAIN_ROOT_MD_OPS); Edit_SetText(_edit_md_root, pref.rootfs_file); EnableWindow(_edit_md_root, fs == IDC_MAIN_ROOT_MD ? TRUE : FALSE); // layout checkbox and editbox. layout(); // set default kernel boot options. _set_check(IDC_MAIN_OPTION_A, pref.boot_ask_for_name); _set_check(IDC_MAIN_OPTION_D, pref.boot_debugger); _set_check(IDC_MAIN_OPTION_S, pref.boot_single_user); _set_check(IDC_MAIN_OPTION_V, pref.boot_verbose); _set_check(IDC_MAIN_OPTION_H, pref.boot_serial); // serial console speed. TCHAR *speed_tab[] = { L"9600", L"19200", L"115200", 0 }; int sel = 0; i = 0; for (TCHAR **speed = speed_tab; *speed; speed++, i++) { _insert_item(w, *speed, IDC_MAIN_OPTION_H_SPEED); if (_wtoi(*speed) == pref.serial_speed) sel = i; } _combobox_serial_speed = GetDlgItem(_window, IDC_MAIN_OPTION_H_SPEED); SendDlgItemMessage(w, IDC_MAIN_OPTION_H_SPEED, CB_SETCURSEL, sel, 0); EnableWindow(_combobox_serial_speed, pref.boot_serial); }
void *set_get(struct set *s, size_t index) { _set_check(s); if (index >= s->filled) return NULL; return s->elems[index]; }
void *set_choose(struct set *s) { _set_check(s); if (!s->filled) return NULL; return s->elems[randint0(s->filled)]; }
void set_add(struct set *s, void *p) { _set_check(s); if (s->allocated == s->filled) _set_grow(s); s->elems[s->filled++] = p; }
void set_free(struct set *s) { _set_check(s); mem_free(s->elems); mem_free(s); }
int _init_wizard_encrypt_pages( HWND parent, _wz_sheets *sheets, _dnode *node ) { wchar_t *static_head[ ] = { L"# Choice iso-file", L"# Format Options", L"# Encryption Settings", L"# Boot Settings", L"# Volume Password", L"# Encryption Progress" }; HWND hwnd; dc_conf dcfg; int k; int count = 0; BOOL boot_device = ( _is_boot_device( &node->mnt.info ) ); BOOL force_small = ( boot_device && ( dc_get_conf_flags(&dcfg) == ST_OK ) && ( dcfg.load_flags & DST_SMALL_MEM ) ); while ( sheets[count].id != -1 ) { HWND hwnd; sheets[count].hwnd = CreateDialog( __hinst, MAKEINTRESOURCE(sheets[count].id), GetDlgItem(parent, IDC_TAB), _tab_proc ); hwnd = sheets[count].hwnd; EnumChildWindows( hwnd, __sub_enum, (LPARAM)NULL ); SetWindowText( GetDlgItem( hwnd, IDC_HEAD ), static_head[count] ); SendMessage( GetDlgItem( hwnd, IDC_HEAD ), (UINT)WM_SETFONT, (WPARAM)__font_bold, 0 ); sheets[count].first_tab_hwnd = ( ( sheets[count].first_tab_id != -1 ) ? GetDlgItem( hwnd, sheets[count].first_tab_id ) : HWND_NULL ); count++; } /////////////////////////////////////////////////////////////// hwnd = sheets[WPAGE_ENC_FRMT].hwnd; /////////////////////////////////////////////////////////////// /////// FORMAT OPTIONS PAGE /////////////////////////////////// { HWND h_fs = GetDlgItem(hwnd, IDC_COMBO_FS_LIST); _sub_class( GetDlgItem(hwnd, IDC_CHECK_QUICK_FORMAT), SUB_STATIC_PROC, HWND_NULL ); _set_check( hwnd, IDC_CHECK_QUICK_FORMAT, FALSE ); for ( k = 0; k < array_num(fs_names); k++ ) { SendMessage( h_fs, (UINT)CB_ADDSTRING, 0, (LPARAM)fs_names[k] ); } SendMessage( h_fs, CB_SETCURSEL, 2, 0 ); } /////////////////////////////////////////////////////////////// hwnd = sheets[WPAGE_ENC_CONF].hwnd; /////////////////////////////////////////////////////////////// /////// ENCRYPTION SETTINGS PAGE ////////////////////////////// { HWND h_combo_wipe = GetDlgItem(hwnd, IDC_COMBO_PASSES); _init_combo( h_combo_wipe, wipe_modes, WP_NONE, FALSE, -1 ); EnableWindow( h_combo_wipe, node->dlg.act_type != ACT_ENCRYPT_CD); EnableWindow( GetDlgItem(hwnd, IDC_STATIC_PASSES_LIST), node->dlg.act_type != ACT_ENCRYPT_CD ); _init_combo( GetDlgItem(hwnd, IDC_COMBO_ALGORT), cipher_names, CF_AES, FALSE, -1 ); if ( force_small ) { EnableWindow( GetDlgItem(hwnd, IDC_COMBO_ALGORT), FALSE ); SendMessage( GetDlgItem(hwnd, IDC_WIZ_CONF_WARNING), (UINT)WM_SETFONT, (WPARAM)__font_bold, 0 ); SetWindowText( GetDlgItem(hwnd, IDC_WIZ_CONF_WARNING), L"Your BIOS does not provide enough base memory,\n" L"you can only use AES to encrypt the boot partition!" ); } for ( k = 0; k < array_num(combo_sel); k++ ) { SendMessage( GetDlgItem(hwnd, combo_sel[k]), CB_SETCURSEL, 0, 0 ); } } /////////////////////////////////////////////////////////////// hwnd = sheets[WPAGE_ENC_BOOT].hwnd; /////////////////////////////////////////////////////////////// /////// BOOT SETTINGS PAGE //////////////////////////////////// { int dsk_num = -1; int rlt = _get_info_install_boot_page( &node->mnt.info, sheets, &dsk_num ); __lists[HENC_WIZARD_BOOT_DEVS] = GetDlgItem(hwnd, IDC_BOOT_DEVS); _list_devices( __lists[HENC_WIZARD_BOOT_DEVS], TRUE, dsk_num ); SendMessage( GetDlgItem(hwnd, IDC_COMBO_BOOT_INST), (UINT)CB_ADDSTRING, 0, (LPARAM)L"Use external bootloader" ); if ( rlt != ST_OK ) { SetWindowText( GetDlgItem(hwnd, IDC_WARNING), L"Bootable HDD not found!" ); SendMessage( GetDlgItem(hwnd, IDC_COMBO_BOOT_INST), CB_SETCURSEL, 0, 0 ); SendMessage( GetDlgItem(hwnd, IDC_WARNING), (UINT)WM_SETFONT, (WPARAM)__font_bold, 0 ); EnableWindow( GetDlgItem(hwnd, IDB_BOOT_PREF), TRUE ); } else { SendMessage( GetDlgItem(hwnd, IDC_COMBO_BOOT_INST), (UINT)CB_ADDSTRING, 0, (LPARAM)L"Install to HDD" ); SendMessage( GetDlgItem(hwnd, IDC_COMBO_BOOT_INST), CB_SETCURSEL, 1, 0 ); } } /////////////////////////////////////////////////////////////// hwnd = sheets[WPAGE_ENC_PASS].hwnd; /////////////////////////////////////////////////////////////// /////// VOLUME PASSWORD PAGE ////////////////////////////////// { int kbd_layout; _update_layout( node, -1, &kbd_layout ); _init_combo( GetDlgItem(hwnd, IDC_COMBO_KBLAYOUT), kb_layouts, kbd_layout, FALSE, -1 ); SetWindowText(GetDlgItem( hwnd, IDC_USE_KEYFILES), boot_device ? IDS_USE_KEYFILE : IDS_USE_KEYFILES ); _sub_class( GetDlgItem(hwnd, IDC_CHECK_SHOW), SUB_STATIC_PROC, HWND_NULL ); _set_check( hwnd, IDC_CHECK_SHOW, FALSE ); _sub_class( GetDlgItem(hwnd, IDC_USE_KEYFILES), SUB_STATIC_PROC, HWND_NULL ); _set_check( hwnd, IDC_USE_KEYFILES, FALSE ); SendMessage( GetDlgItem( hwnd, IDP_BREAKABLE ), PBM_SETBARCOLOR, 0, _cl( COLOR_BTNSHADOW, DARK_CLR-20 ) ); SendMessage( GetDlgItem(hwnd, IDP_BREAKABLE), PBM_SETRANGE, 0, MAKELPARAM(0, 193) ); SetWindowText( GetDlgItem(hwnd, IDC_HEAD2), L"# Password Rating" ); SendMessage( GetDlgItem(hwnd, IDC_HEAD2), (UINT)WM_SETFONT, (WPARAM)__font_bold, 0 ); SendMessage( GetDlgItem(hwnd, IDE_PASS), EM_LIMITTEXT, MAX_PASSWORD, 0 ); SendMessage( GetDlgItem(hwnd, IDE_CONFIRM), EM_LIMITTEXT, MAX_PASSWORD, 0 ); } /////////////////////////////////////////////////////////////// hwnd = sheets[WPAGE_ENC_PROGRESS].hwnd; /////////////////////////////////////////////////////////////// /////// ENCRYPTION PROGRESS PAGE ////////////////////////////// { _colinfo _progress_iso_crypt_headers[ ] = { { STR_HEAD_NO_ICONS, 100, LVCFMT_LEFT, FALSE }, { STR_HEAD_NO_ICONS, 120, LVCFMT_LEFT, FALSE }, { STR_NULL } }; HWND h_list = GetDlgItem( hwnd, IDC_ISO_PROGRESS ); int rlt = ST_OK; int j = 0; ListView_SetBkColor( h_list, GetSysColor(COLOR_BTNFACE) ); _init_list_headers( h_list, _progress_iso_crypt_headers ); while ( wcslen(_act_table_items[j]) > 0 ) { _list_insert_item( h_list, j, 0, _act_table_items[j], 0 ); if ( j != 2 ) ListView_SetItemText( h_list, j, 1, STR_EMPTY ); j++; } SendMessage( GetDlgItem( hwnd, IDC_PROGRESS_ISO ), PBM_SETBARCOLOR, 0, _cl(COLOR_BTNSHADOW, DARK_CLR-20) ); SendMessage( GetDlgItem( hwnd, IDC_PROGRESS_ISO ), PBM_SETRANGE, 0, MAKELPARAM(0, PRG_STEP) ); } return count; }
INT_PTR CALLBACK _password_dlg_proc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam ) { WORD code = HIWORD(wparam); WORD id = LOWORD(wparam); wchar_t display[MAX_PATH] = { 0 }; static dlgpass *info; static RECT rc_left = { 0, 0, 0, 0 }; static RECT rc_right = { 0, 0, 0, 0 }; static cut; switch ( message ) { case WM_DRAWITEM : { DRAWITEMSTRUCT *draw = pv(lparam); static RECT left; static RECT right; switch ( draw->CtlID ) { case IDC_FRAME_LEFT: { if ( !rc_left.right ) { _relative_rect( draw->hwndItem, &rc_left ); rc_left.bottom -= cut; } MoveWindow( draw->hwndItem, rc_left.left, rc_left.top, rc_left.right, rc_left.bottom, TRUE ); } break; case IDC_FRAME_RIGHT: { if ( !rc_right.right ) { _relative_rect( draw->hwndItem, &rc_right ); rc_right.bottom -= cut; } MoveWindow( draw->hwndItem, rc_right.left, rc_right.top, rc_right.right, rc_right.bottom, TRUE ); } break; } _draw_static( draw ); return 1L; } break; case WM_CTLCOLOREDIT : { return ( _ctl_color( wparam, _cl(COLOR_BTNFACE, LGHT_CLR) ) ); } break; case WM_INITDIALOG : { int ctl_resize[ ] = { IDC_FRAME_LEFT, IDC_FRAME_RIGHT, -1 }; info = (dlgpass *)lparam; _init_mount_points( GetDlgItem(hwnd, IDC_COMBO_MNPOINT) ); SendMessage( GetDlgItem(hwnd, IDC_COMBO_MNPOINT), CB_SETCURSEL, 1, 0 ); SendMessage( GetDlgItem(hwnd, IDE_PASS), EM_LIMITTEXT, MAX_PASSWORD, 0 ); if ( info->node ) { _snwprintf( display, sizeof_w(display), L"[%s] - %s", info->node->mnt.info.status.mnt_point, info->node->mnt.info.device ); } else { wcscpy(display, L"Enter password"); } SetWindowText( hwnd, display ); SetWindowText( GetDlgItem(hwnd, IDC_HEAD_PASS), L"# Current Password" ); SendMessage( GetDlgItem(hwnd, IDC_HEAD_PASS), WM_SETFONT, (WPARAM)__font_bold, 0 ); SetWindowText( GetDlgItem(hwnd, IDC_HEAD_MOUNT_OPTIONS), L"# Mount Options" ); SendMessage( GetDlgItem(hwnd, IDC_HEAD_MOUNT_OPTIONS), WM_SETFONT, (WPARAM)__font_bold, 0 ); _sub_class( GetDlgItem(hwnd, IDC_CHECK_SHOW), SUB_STATIC_PROC, HWND_NULL ); _set_check( hwnd, IDC_CHECK_SHOW, FALSE ); _sub_class( GetDlgItem(hwnd, IDC_USE_KEYFILES), SUB_STATIC_PROC, HWND_NULL ); _set_check( hwnd, IDC_USE_KEYFILES, FALSE ); { HWND mnt_combo = GetDlgItem( hwnd, IDC_COMBO_MNPOINT ); HWND mnt_check = GetDlgItem( hwnd, IDC_CHECK_MNT_SET ); HWND mnt_label = GetDlgItem( hwnd, IDC_MNT_POINT ); BOOL enable; RECT rc_main; GetWindowRect(hwnd, &rc_main); enable = info->node && ( info->node->mnt.info.status.mnt_point[0] == L'\\' ); EnableWindow( mnt_combo, enable ); EnableWindow( mnt_check, enable ); EnableWindow( mnt_label, enable ); _sub_class( GetDlgItem(hwnd, IDC_CHECK_MNT_SET), SUB_STATIC_PROC, HWND_NULL ); _set_check( hwnd, IDC_CHECK_MNT_SET, enable ); } SendMessage( hwnd, WM_COMMAND, MAKELONG(IDE_PASS, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS) ); SetForegroundWindow(hwnd); return 1L; } break; case WM_USER_CLICK : { if ( (HWND)wparam == GetDlgItem(hwnd, IDC_CHECK_MNT_SET) ) { EnableWindow( GetDlgItem(hwnd, IDC_COMBO_MNPOINT), _get_check(hwnd, IDC_CHECK_MNT_SET) ); EnableWindow( GetDlgItem(hwnd, IDC_MNT_POINT), _get_check(hwnd, IDC_CHECK_MNT_SET) ); return 1L; } if ( (HWND)wparam == GetDlgItem(hwnd, IDC_CHECK_SHOW) ) { int mask = _get_check(hwnd, IDC_CHECK_SHOW) ? 0 : '*'; SendMessage(GetDlgItem(hwnd, IDE_PASS), EM_SETPASSWORDCHAR, mask, 0 ); InvalidateRect(GetDlgItem(hwnd, IDE_PASS), NULL, TRUE); return 1L; } if ( (HWND)wparam == GetDlgItem(hwnd, IDC_USE_KEYFILES) ) { SendMessage( hwnd, WM_COMMAND, MAKELONG(IDE_PASS, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS) ); EnableWindow(GetDlgItem(hwnd, IDB_USE_KEYFILES), _get_check(hwnd, IDC_USE_KEYFILES)); return 1L; } } break; case WM_COMMAND : if ( id == IDB_USE_KEYFILES ) { _dlg_keyfiles(hwnd, KEYLIST_CURRENT); SendMessage( hwnd, WM_COMMAND, MAKELONG(IDE_PASS, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS) ); } if ( code == CBN_SELCHANGE && id == IDC_COMBO_MNPOINT ) { if ( SendMessage((HWND)lparam, CB_GETCURSEL, 0, 0) == 0 ) { HWND h_combo = GetDlgItem(hwnd, IDC_COMBO_MNPOINT); int sel_item = 1; wchar_t path[MAX_PATH]; if ( _folder_choice(hwnd, path, L"Choice folder for mount point") ) { sel_item = (int)SendMessage(h_combo, CB_GETCOUNT, 0, 0); SendMessage(h_combo, CB_ADDSTRING, 0, (LPARAM)path); } SendMessage(h_combo, CB_SETCURSEL, sel_item, 0); } } if (code == EN_CHANGE) { BOOL correct; int idx_status; dc_pass *pass = _get_pass(hwnd, IDE_PASS); int keylist = _get_check(hwnd, IDC_USE_KEYFILES) ? KEYLIST_CURRENT : KEYLIST_NONE; correct = _input_verify(pass, NULL, keylist, -1, &idx_status ); secure_free(pass); SetWindowText(GetDlgItem(hwnd, IDC_PASS_STATUS), _get_text_name(idx_status, pass_status)); EnableWindow(GetDlgItem(hwnd, IDOK), correct); return 1L; } if ((id == IDCANCEL) || (id == IDOK)) { if (id == IDOK) { info->pass = _get_pass_keyfiles(hwnd, IDE_PASS, IDC_USE_KEYFILES, KEYLIST_CURRENT); if (IsWindowEnabled(GetDlgItem(hwnd, IDC_COMBO_MNPOINT)) && info->mnt_point) { GetWindowText( GetDlgItem(hwnd, IDC_COMBO_MNPOINT), (wchar_t *)info->mnt_point, MAX_PATH ); } } EndDialog (hwnd, id); return 1L; } break; case WM_DESTROY: { _wipe_pass_control(hwnd, IDE_PASS); _keyfiles_wipe(KEYLIST_CURRENT); memset(&rc_right, 0, sizeof(rc_right)); memset(&rc_left, 0, sizeof(rc_left)); cut = 0; return 0L; } break; case WM_MEASUREITEM: { MEASUREITEMSTRUCT *item = pv(lparam); if (item->CtlType != ODT_LISTVIEW) item->itemHeight -= 3; } break; } return 0L; }
INT_PTR CALLBACK _password_change_dlg_proc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam ) { WORD code = HIWORD(wparam); WORD id = LOWORD(wparam); wchar_t display[MAX_PATH] = { 0 }; static dlgpass *info; int k; int check_init[ ] = { IDC_CHECK_SHOW_CURRENT, IDC_USE_KEYFILES_CURRENT, IDC_CHECK_SHOW_NEW, IDC_USE_KEYFILES_NEW, -1 }; _ctl_init static_head[ ] = { { L"# Current Password", IDC_HEAD_PASS_CURRENT, 0 }, { L"# New Password", IDC_HEAD_PASS_NEW, 0 }, { L"# Password Rating", IDC_HEAD_RATING, 0 }, { STR_NULL, -1, -1 } }; switch (message) { case WM_CTLCOLOREDIT : return _ctl_color(wparam, _cl(COLOR_BTNFACE, LGHT_CLR)); break; case WM_CTLCOLORSTATIC : { HDC dc = (HDC)wparam; COLORREF bgcolor, fn = 0; SetBkMode(dc, TRANSPARENT); k = 0; while (pass_gr_ctls[k].id != -1) { if (pass_gr_ctls[k].hwnd == (HWND)lparam) fn = pass_gr_ctls[k].color; if (pass_pe_ctls[k].hwnd == (HWND)lparam) fn = pass_pe_ctls[k].color; k++; } SetTextColor(dc, fn); bgcolor = GetSysColor(COLOR_BTNFACE); SetDCBrushColor(dc, bgcolor); return (INT_PTR)GetStockObject(DC_BRUSH); } break; case WM_INITDIALOG : { info = (dlgpass *)lparam; SendMessage(GetDlgItem(hwnd, IDE_PASS_NEW_CONFIRM), EM_LIMITTEXT, MAX_PASSWORD, 0); SendMessage(GetDlgItem(hwnd, IDE_PASS_CURRENT), EM_LIMITTEXT, MAX_PASSWORD, 0); SendMessage(GetDlgItem(hwnd, IDE_PASS_NEW), EM_LIMITTEXT, MAX_PASSWORD, 0); SendMessage(hwnd, WM_COMMAND, MAKELONG(IDE_PASS_NEW, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS_NEW)); if (info->node) { _snwprintf(display, sizeof_w(display), L"[%s] - %s", info->node->mnt.info.status.mnt_point, info->node->mnt.info.device); } else { wcscpy(display, L"Change password"); } SetWindowText(hwnd, display); SendMessage( GetDlgItem(hwnd, IDP_BREAKABLE), PBM_SETBARCOLOR, 0, _cl(COLOR_BTNSHADOW, DARK_CLR-20) ); SendMessage( GetDlgItem(hwnd, IDP_BREAKABLE), PBM_SETRANGE, 0, MAKELPARAM(0, 193) ); k = 0; while (static_head[k].id != -1) { SetWindowText(GetDlgItem(hwnd, static_head[k].id), static_head[k].display); SendMessage(GetDlgItem(hwnd, static_head[k].id), (UINT)WM_SETFONT, (WPARAM)__font_bold, 0); k++; } k = 0; while (check_init[k] != -1) { _sub_class(GetDlgItem(hwnd, check_init[k]), SUB_STATIC_PROC, HWND_NULL); _set_check(hwnd, check_init[k], FALSE); k++; } SetForegroundWindow(hwnd); return 1L; } break; case WM_USER_CLICK : { if ( (HWND)wparam == GetDlgItem(hwnd, IDC_CHECK_SHOW_CURRENT) ) { SendMessage(GetDlgItem(hwnd, IDE_PASS_CURRENT), EM_SETPASSWORDCHAR, _get_check(hwnd, IDC_CHECK_SHOW_CURRENT) ? 0 : '*', 0 ); InvalidateRect(GetDlgItem(hwnd, IDE_PASS_CURRENT), NULL, TRUE); return 1L; } if ( (HWND)wparam == GetDlgItem(hwnd, IDC_CHECK_SHOW_NEW) ) { int mask = _get_check(hwnd, IDC_CHECK_SHOW_NEW) ? 0 : '*'; SendMessage(GetDlgItem(hwnd, IDE_PASS_NEW), EM_SETPASSWORDCHAR, mask, 0); SendMessage(GetDlgItem(hwnd, IDE_PASS_NEW_CONFIRM), EM_SETPASSWORDCHAR, mask, 0); InvalidateRect(GetDlgItem(hwnd, IDE_PASS_NEW), NULL, TRUE); InvalidateRect(GetDlgItem(hwnd, IDE_PASS_NEW_CONFIRM), NULL, TRUE); return 1L; } if ( (HWND)wparam == GetDlgItem(hwnd, IDC_USE_KEYFILES_CURRENT) ) { SendMessage( hwnd, WM_COMMAND, MAKELONG(IDE_PASS_CURRENT, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS_CURRENT) ); EnableWindow( GetDlgItem(hwnd, IDB_USE_KEYFILES_CURRENT), _get_check(hwnd, IDC_USE_KEYFILES_CURRENT) ); return 1L; } if ( (HWND)wparam == GetDlgItem(hwnd, IDC_USE_KEYFILES_NEW) ) { SendMessage( hwnd, WM_COMMAND, MAKELONG(IDE_PASS_NEW, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS_NEW) ); EnableWindow( GetDlgItem(hwnd, IDB_USE_KEYFILES_NEW), _get_check(hwnd, IDC_USE_KEYFILES_NEW )); return 1L; } } break; case WM_COMMAND : if ( id == IDB_USE_KEYFILES_CURRENT ) { _dlg_keyfiles( hwnd, KEYLIST_CURRENT ); SendMessage( hwnd, WM_COMMAND, MAKELONG(IDE_PASS_CURRENT, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS_CURRENT) ); } if ( id == IDB_USE_KEYFILES_NEW ) { _dlg_keyfiles( hwnd, KEYLIST_CHANGE_PASS ); SendMessage( hwnd, WM_COMMAND, MAKELONG(IDE_PASS_NEW, EN_CHANGE), (LPARAM)GetDlgItem(hwnd, IDE_PASS_NEW) ); } if ( code == EN_CHANGE ) { BOOL correct_current, correct_new; int id_stat_current, id_stat_new; dc_pass *pass; dc_pass *verify; ldr_config conf; int kb_layout = -1; int keylist; if ( info->node && _is_boot_device(&info->node->mnt.info) ) { if (dc_get_mbr_config( -1, NULL, &conf ) == ST_OK) { kb_layout = conf.kbd_layout; } } if ( id == IDE_PASS_NEW ) { int entropy; dc_pass *pass; pass = _get_pass(hwnd, IDE_PASS_NEW); _draw_pass_rating(hwnd, pass, kb_layout, &entropy); secure_free(pass); SendMessage( GetDlgItem(hwnd, IDP_BREAKABLE), PBM_SETPOS, (WPARAM)entropy, 0 ); } pass = _get_pass(hwnd, IDE_PASS_CURRENT); keylist = _get_check(hwnd, IDC_USE_KEYFILES_CURRENT) ? KEYLIST_CURRENT : KEYLIST_NONE; correct_current = _input_verify(pass, NULL, keylist, -1, &id_stat_current ); secure_free(pass); pass = _get_pass(hwnd, IDE_PASS_NEW); verify = _get_pass(hwnd, IDE_PASS_NEW_CONFIRM); keylist = _get_check(hwnd, IDC_USE_KEYFILES_NEW) ? KEYLIST_CHANGE_PASS : KEYLIST_NONE; correct_new = _input_verify(pass, verify, keylist, kb_layout, &id_stat_new ); secure_free(pass); secure_free(verify); SetWindowText(GetDlgItem(hwnd, IDC_PASS_STATUS_CURRENT), _get_text_name(id_stat_current, pass_status)); SetWindowText(GetDlgItem(hwnd, IDC_PASS_STATUS_NEW), _get_text_name(id_stat_new, pass_status)); EnableWindow(GetDlgItem(hwnd, IDOK), correct_current && correct_new); return 1L; } if ( (id == IDCANCEL) || (id == IDOK) ) { if ( id == IDOK ) { info->pass = _get_pass_keyfiles(hwnd, IDE_PASS_CURRENT, IDC_USE_KEYFILES_CURRENT, KEYLIST_CURRENT); info->new_pass = _get_pass_keyfiles(hwnd, IDE_PASS_NEW, IDC_USE_KEYFILES_NEW, KEYLIST_CHANGE_PASS); if ( IsWindowEnabled(GetDlgItem(hwnd, IDC_COMBO_MNPOINT)) && info->mnt_point ) { GetWindowText( GetDlgItem(hwnd, IDC_COMBO_MNPOINT), (wchar_t *)info->mnt_point, MAX_PATH ); } } EndDialog (hwnd, id); return 1L; } break; case WM_DESTROY: { _wipe_pass_control(hwnd, IDE_PASS_NEW_CONFIRM); _wipe_pass_control(hwnd, IDE_PASS_CURRENT); _wipe_pass_control(hwnd, IDE_PASS_NEW); _keyfiles_wipe(KEYLIST_CURRENT); _keyfiles_wipe(KEYLIST_CHANGE_PASS); return 0L; } break; default: { int rlt = _draw_proc(message, lparam); if (rlt != -1) return rlt; } } return 0L; }
INT_PTR CALLBACK _options_dlg_proc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam ) { _ctl_init ctl_chk_general[ ] = { { STR_NULL, IDC_AUTO_MOUNT_ON_BOOT, CONF_AUTOMOUNT_BOOT }, { STR_NULL, IDC_EXPLORER_ON_MOUNT, CONF_EXPLORER_MOUNT }, { STR_NULL, IDC_CACHE_PASSWORDS, CONF_CACHE_PASSWORD }, { STR_NULL, IDC_UNMOUNT_LOGOFF, CONF_DISMOUNT_LOGOFF }, { STR_NULL, IDC_FORCE_UNMOUNT, CONF_FORCE_DISMOUNT }, { STR_NULL, IDC_WIPE_LOGOFF, CONF_WIPEPAS_LOGOFF }, { STR_NULL, IDC_AUTO_START, CONF_AUTO_START } }; _ctl_init ctl_chk_extended[ ] = { { STR_NULL, IDC_HARD_CRYPTO_SUPPORT, CONF_HW_CRYPTO }, { STR_NULL, IDC_HIDE_FILES, CONF_HIDE_DCSYS }, { STR_NULL, IDC_DISABLE_TRIM, CONF_DISABLE_TRIM }, { STR_NULL, IDC_SSD_OPTIMIZATION, CONF_ENABLE_SSD_OPT } }; _ctl_init static_head_general[ ] = { { L"# Mount Settings", IDC_HEAD1, 0 }, { L"# Password Caching", IDC_HEAD2, 0 }, { L"# Boot Options", IDC_HEAD3, 0 } }; _ctl_init static_head_extended[ ] = { { L"# Extended Settings", IDC_HEAD1, 0 } }; WORD code = LOWORD(wparam); WORD id = LOWORD(wparam); DWORD _flags = 0; DWORD _hotkeys[HOTKEYS] = { 0 }; _wnd_data *wnd; int check = 0; int k = 0; switch ( message ) { case WM_INITDIALOG : { TCITEM tab_item = { TCIF_TEXT }; HWND h_tab = GetDlgItem( hwnd, IDT_TAB ); _tab_data *d_tab = malloc(sizeof(_tab_data)); wnd = _sub_class( h_tab, SUB_NONE, CreateDialog( __hinst, MAKEINTRESOURCE(DLG_CONF_GENERAL), GetDlgItem(hwnd, IDC_TAB), _tab_proc ), CreateDialog( __hinst, MAKEINTRESOURCE(DLG_CONF_EXTNDED), GetDlgItem(hwnd, IDC_TAB), _tab_proc ), CreateDialog( __hinst, MAKEINTRESOURCE(DLG_CONF_HOTKEYS), GetDlgItem(hwnd, IDC_TAB), _tab_proc ), HWND_NULL ); memset(d_tab, 0, sizeof(_tab_data)); d_tab->active = wnd->dlg[0]; wnd_set_long(hwnd, GWL_USERDATA, d_tab); { for ( k = 0; k < array_num(ctl_chk_general); k++ ) { _sub_class( GetDlgItem( wnd->dlg[0], ctl_chk_general[k].id ), SUB_STATIC_PROC, HWND_NULL ); _set_check( wnd->dlg[0], ctl_chk_general[k].id, __config.conf_flags & ctl_chk_general[k].val ); } for ( k = 0; k < array_num(ctl_chk_extended); k++ ) { _sub_class( GetDlgItem( wnd->dlg[1], ctl_chk_extended[k].id ), SUB_STATIC_PROC, HWND_NULL ); _set_check( wnd->dlg[1], ctl_chk_extended[k].id, __config.conf_flags & ctl_chk_extended[k].val ); } if ( ! (__config.load_flags & DST_HW_CRYPTO) ) { wchar_t s_ch_label[MAX_PATH] = { 0 }; HWND h_check = GetDlgItem( wnd->dlg[1], IDC_HARD_CRYPTO_SUPPORT ); EnableWindow( h_check, FALSE ); GetWindowText( h_check, s_ch_label, sizeof_w(s_ch_label) ); wcscat( s_ch_label, L" (not supported)" ); SetWindowText( h_check, s_ch_label ); } for ( k = 0; k < array_num(static_head_general); k++ ) { SetWindowText(GetDlgItem(wnd->dlg[0], static_head_general[k].id), static_head_general[k].display); SendMessage(GetDlgItem(wnd->dlg[0], static_head_general[k].id), (UINT)WM_SETFONT, (WPARAM)__font_bold, 0); } for ( k = 0; k < array_num(static_head_extended); k++ ) { SetWindowText(GetDlgItem(wnd->dlg[1], static_head_extended[k].id), static_head_extended[k].display); SendMessage(GetDlgItem(wnd->dlg[1], static_head_extended[k].id), (UINT)WM_SETFONT, (WPARAM)__font_bold, 0); } SendMessage( wnd->dlg[0], WM_USER_CLICK, (WPARAM)GetDlgItem(wnd->dlg[0], IDC_AUTO_START), 0 ); _sub_class( GetDlgItem(wnd->dlg[2], IDC_KEY_USEEXT), SUB_STATIC_PROC, HWND_NULL ); k = 0; while ( hotks_edit[k].id != -1 ) { wchar_t key[200] = { 0 }; _sub_class( GetDlgItem(wnd->dlg[2], hotks_edit[k].id), SUB_KEY_PROC, HWND_NULL ); _sub_class( GetDlgItem(wnd->dlg[2], hotks_chk[k].id), SUB_STATIC_PROC, HWND_NULL ); _set_check( wnd->dlg[2], hotks_chk[k].id, __config.hotkeys[k] ); SendMessage( wnd->dlg[2], WM_USER_CLICK, (WPARAM)GetDlgItem(wnd->dlg[2], hotks_chk[k].id), 0 ); _key_name(HIWORD( __config.hotkeys[k]), LOWORD(__config.hotkeys[k]), key ); SetWindowText(GetDlgItem(wnd->dlg[2], hotks_edit[k].id), key); ((_wnd_data *)wnd_get_long( GetDlgItem(wnd->dlg[2], hotks_edit[k].id), GWL_USERDATA) )->vk = __config.hotkeys[k]; k++; } } tab_item.pszText = L"General"; TabCtrl_InsertItem(h_tab, 0, &tab_item); tab_item.pszText = L"Extended"; TabCtrl_InsertItem(h_tab, 1, &tab_item); tab_item.pszText = L"Hot Keys"; TabCtrl_InsertItem(h_tab, 2, &tab_item); { k = 1; while ( wnd->dlg[k] != 0 ) { ShowWindow( wnd->dlg[k], SW_HIDE ); k++; } } SetForegroundWindow( hwnd ); return 1L; } break; case WM_NOTIFY : { if ( wparam == IDT_TAB ) { if ( ((NMHDR *)lparam)->code == TCN_SELCHANGE ) { HWND h_tab = GetDlgItem(hwnd, IDT_TAB); if ( !_is_curr_in_group(h_tab) ) { _change_page( h_tab, TabCtrl_GetCurSel(h_tab) ); } } } } break; case WM_COMMAND : { /* switch (id) { case ID_SHIFT_TAB : case ID_TAB : { HWND h_current = GetFocus( ); HWND h_next = GetNextDlgTabItem( sheets[index].hwnd, h_current, id == ID_SHIFT_TAB ); SetFocus( h_next ); } break; */ if ( (id == IDOK) || (id == IDCANCEL) ) { wnd = wnd_get_long( GetDlgItem(hwnd, IDT_TAB), GWL_USERDATA ); if ( wnd ) { for ( k = 0; k < array_num(ctl_chk_general); k++ ) { _flags |= _get_check(wnd->dlg[0], ctl_chk_general[k].id) ? ctl_chk_general[k].val : FALSE; } for ( k = 0; k < array_num(ctl_chk_extended); k++ ) { _flags |= _get_check(wnd->dlg[1], ctl_chk_extended[k].id) ? ctl_chk_extended[k].val : FALSE; } k = 0; while ( hotks_edit[k].id != -1 ) { if ( _get_check(wnd->dlg[2], hotks_chk[k].id) ) { _hotkeys[k] = ( (_wnd_data *)wnd_get_long(GetDlgItem(wnd->dlg[2], hotks_edit[k].id), GWL_USERDATA) )->vk; } k++; } } if ( id == IDCANCEL ) check = TRUE; if ( id == IDOK ) { _unset_hotkeys(__config.hotkeys); check = _check_hotkeys(wnd->dlg[0], _hotkeys); if ( check ) { if ( _hotkeys[3] && !__config.hotkeys[3] ) { if (! __msg_w( hwnd, L"Set Hotkey for call BSOD?" ) ) { _hotkeys[3] = 0; } } if ( (_flags & CONF_AUTO_START) != (__config.conf_flags & CONF_AUTO_START) ) { autorun_set(_flags & CONF_AUTO_START); } __config.conf_flags = _flags; memcpy(&__config.hotkeys, &_hotkeys, sizeof(DWORD)*HOTKEYS); dc_save_conf(&__config); } _set_hotkeys(hwnd, __config.hotkeys, FALSE); } if ( check ) { EndDialog (hwnd, id); } return 1L; } } break; case WM_DESTROY : { wnd = wnd_get_long( GetDlgItem(hwnd, IDT_TAB), GWL_USERDATA ); if ( wnd ) { for ( k = 0; k < array_num(ctl_chk_general); k++ ) { __unsub_class(GetDlgItem(wnd->dlg[0], ctl_chk_general[k].id)); } for ( k = 0; k < array_num(ctl_chk_extended); k++ ) { __unsub_class(GetDlgItem(wnd->dlg[1], ctl_chk_extended[k].id)); } __unsub_class(GetDlgItem(wnd->dlg[1], IDC_KEY_USEEXT)); k = 0; while ( hotks_edit[k].id != -1 ) { __unsub_class(GetDlgItem(wnd->dlg[2], hotks_edit[k].id)); __unsub_class(GetDlgItem(wnd->dlg[2], hotks_chk[k].id)); k++; } } __unsub_class(GetDlgItem(hwnd, IDT_TAB)); } break; default : { int rlt = _draw_proc(message, lparam); if ( rlt != -1 ) { return rlt; } } } return 0L; }