Home | History | Annotate | Line # | Download | only in menu
menu.cpp revision 1.1
      1  1.1  uch /* -*-C++-*-	$NetBSD: menu.cpp,v 1.1 2001/04/24 19:28:00 uch Exp $	*/
      2  1.1  uch 
      3  1.1  uch /*-
      4  1.1  uch  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.1  uch  * All rights reserved.
      6  1.1  uch  *
      7  1.1  uch  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  uch  * by UCHIYAMA Yasushi.
      9  1.1  uch  *
     10  1.1  uch  * Redistribution and use in source and binary forms, with or without
     11  1.1  uch  * modification, are permitted provided that the following conditions
     12  1.1  uch  * are met:
     13  1.1  uch  * 1. Redistributions of source code must retain the above copyright
     14  1.1  uch  *    notice, this list of conditions and the following disclaimer.
     15  1.1  uch  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  uch  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  uch  *    documentation and/or other materials provided with the distribution.
     18  1.1  uch  * 3. All advertising materials mentioning features or use of this software
     19  1.1  uch  *    must display the following acknowledgement:
     20  1.1  uch  *        This product includes software developed by the NetBSD
     21  1.1  uch  *        Foundation, Inc. and its contributors.
     22  1.1  uch  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  uch  *    contributors may be used to endorse or promote products derived
     24  1.1  uch  *    from this software without specific prior written permission.
     25  1.1  uch  *
     26  1.1  uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  uch  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  uch  */
     38  1.1  uch 
     39  1.1  uch #include <hpcmenu.h>
     40  1.1  uch #include <hpcboot.h>
     41  1.1  uch #include <res/resource.h>
     42  1.1  uch #include <menu/window.h>
     43  1.1  uch #include <menu/tabwindow.h>
     44  1.1  uch #include <menu/rootwindow.h>
     45  1.1  uch #include <machine/bootinfo.h>
     46  1.1  uch #include <framebuffer.h>
     47  1.1  uch #include <console.h>
     48  1.1  uch 
     49  1.1  uch #include <menu/menu.h>
     50  1.1  uch 
     51  1.1  uch TabWindow *
     52  1.1  uch TabWindowBase::boot(int id)
     53  1.1  uch {
     54  1.1  uch 	TabWindow *w = NULL;
     55  1.1  uch 	HpcMenuInterface &menu = HPC_MENU;
     56  1.1  uch 
     57  1.1  uch 	switch(id) {
     58  1.1  uch 	default:
     59  1.1  uch 		break;
     60  1.1  uch 	case IDC_BASE_MAIN:
     61  1.1  uch 		menu._main = new MainTabWindow(*this, IDC_BASE_MAIN);
     62  1.1  uch 		w = menu._main;
     63  1.1  uch 		break;
     64  1.1  uch 	case IDC_BASE_OPTION:
     65  1.1  uch 		menu._option = new OptionTabWindow(*this, IDC_BASE_OPTION);
     66  1.1  uch 		w = menu._option;
     67  1.1  uch 		break;
     68  1.1  uch 	case IDC_BASE_CONSOLE:
     69  1.1  uch 		menu._console = new ConsoleTabWindow(*this, IDC_BASE_CONSOLE);
     70  1.1  uch 		w = menu._console;
     71  1.1  uch 		break;
     72  1.1  uch 	}
     73  1.1  uch 
     74  1.1  uch 	if (w)
     75  1.1  uch 		w->create(0);
     76  1.1  uch 
     77  1.1  uch 	return w;
     78  1.1  uch }
     79  1.1  uch 
     80  1.1  uch //
     81  1.1  uch // Main window
     82  1.1  uch //
     83  1.1  uch void
     84  1.1  uch MainTabWindow::_insert_item(HWND w, TCHAR *name, int id)
     85  1.1  uch {
     86  1.1  uch 	int idx = SendDlgItemMessage(w, id, CB_ADDSTRING, 0,
     87  1.1  uch 				     reinterpret_cast <LPARAM>(name));
     88  1.1  uch 	if (idx != CB_ERR)
     89  1.1  uch 		SendDlgItemMessage(w, IDC_MAIN_DIR, CB_SETITEMDATA,
     90  1.1  uch 				   idx, _item_idx++);
     91  1.1  uch }
     92  1.1  uch 
     93  1.1  uch void
     94  1.1  uch MainTabWindow::init(HWND w)
     95  1.1  uch {
     96  1.1  uch 	HpcMenuInterface &menu = HPC_MENU;
     97  1.1  uch 	struct HpcMenuInterface::HpcMenuPreferences &pref = HPC_PREFERENCE;
     98  1.1  uch 
     99  1.1  uch 	_window = w;
    100  1.1  uch 	// insert myself to tab-control
    101  1.1  uch 	TabWindow::init(w);
    102  1.1  uch 
    103  1.1  uch 	// setup child.
    104  1.1  uch 	TCHAR *entry;
    105  1.1  uch 	int i;
    106  1.1  uch 	// kernel directory path
    107  1.1  uch 	for (i = 0; entry = menu.dir(i); i++)
    108  1.1  uch 		_insert_item(w, entry, IDC_MAIN_DIR);
    109  1.1  uch 	SendDlgItemMessage(w, IDC_MAIN_DIR, CB_SETCURSEL, menu.dir_default(),
    110  1.1  uch 			   0);
    111  1.1  uch 	// platform
    112  1.1  uch 	for (i = 0; entry = menu.platform_get(i); i++)
    113  1.1  uch 		_insert_item(w, entry, IDC_MAIN_PLATFORM);
    114  1.1  uch 	SendDlgItemMessage(w, IDC_MAIN_PLATFORM, CB_SETCURSEL,
    115  1.1  uch 			   menu.platform_default(), 0);
    116  1.1  uch 	// kernel file name.
    117  1.1  uch 	Edit_SetText(GetDlgItem(w, IDC_MAIN_KERNEL), pref.kernel_user ?
    118  1.1  uch 		     pref.kernel_user_file : TEXT("netbsd.gz"));
    119  1.1  uch 
    120  1.1  uch 	// root file system.
    121  1.1  uch 	int fs = pref.rootfs + IDC_MAIN_ROOT_;
    122  1.1  uch 	_set_check(fs, TRUE);
    123  1.1  uch 
    124  1.1  uch 	_edit_md_root = GetDlgItem(w, IDC_MAIN_ROOT_MD_OPS);
    125  1.1  uch 	Edit_SetText(_edit_md_root, pref.rootfs_file);
    126  1.1  uch 	EnableWindow(_edit_md_root, fs == IDC_MAIN_ROOT_MD ? TRUE : FALSE);
    127  1.1  uch 
    128  1.1  uch 	// kernel boot options.
    129  1.1  uch 	_set_check(IDC_MAIN_OPTION_A, pref.boot_ask_for_name);
    130  1.1  uch 	_set_check(IDC_MAIN_OPTION_S, pref.boot_single_user);
    131  1.1  uch 	_set_check(IDC_MAIN_OPTION_V, pref.boot_verbose);
    132  1.1  uch 	_set_check(IDC_MAIN_OPTION_H, pref.boot_serial);
    133  1.1  uch 
    134  1.1  uch 	// serial console speed.
    135  1.1  uch 	TCHAR *speed_tab[] = { L"9600", L"19200", L"115200", 0 };
    136  1.1  uch 	int sel = 0;
    137  1.1  uch 	i = 0;
    138  1.1  uch 	for (TCHAR **speed = speed_tab; *speed; speed++, i++) {
    139  1.1  uch 		_insert_item(w, *speed, IDC_MAIN_OPTION_H_SPEED);
    140  1.1  uch 		if (_wtoi(*speed) == pref.serial_speed)
    141  1.1  uch 			sel = i;
    142  1.1  uch 	}
    143  1.1  uch 	_combobox_serial_speed = GetDlgItem(_window, IDC_MAIN_OPTION_H_SPEED);
    144  1.1  uch 	SendDlgItemMessage(w, IDC_MAIN_OPTION_H_SPEED, CB_SETCURSEL, sel, 0);
    145  1.1  uch 	EnableWindow(_combobox_serial_speed, pref.boot_serial);
    146  1.1  uch }
    147  1.1  uch 
    148  1.1  uch void
    149  1.1  uch MainTabWindow::get()
    150  1.1  uch {
    151  1.1  uch 	HpcMenuInterface &menu = HPC_MENU;
    152  1.1  uch 	struct HpcMenuInterface::HpcMenuPreferences &pref = HPC_PREFERENCE;
    153  1.1  uch 
    154  1.1  uch 	HWND w = GetDlgItem(_window, IDC_MAIN_DIR);
    155  1.1  uch 	ComboBox_GetText(w, pref.dir_user_path, MAX_PATH);
    156  1.1  uch 	pref.dir_user = TRUE;
    157  1.1  uch 	w = GetDlgItem(_window, IDC_MAIN_KERNEL);
    158  1.1  uch 	Edit_GetText(w, pref.kernel_user_file, MAX_PATH);
    159  1.1  uch 	pref.kernel_user = TRUE;
    160  1.1  uch 
    161  1.1  uch 	int i = ComboBox_GetCurSel(GetDlgItem(_window, IDC_MAIN_PLATFORM));
    162  1.1  uch 	menu.platform_set(i);
    163  1.1  uch 
    164  1.1  uch 	if (_is_checked(IDC_MAIN_ROOT_WD))
    165  1.1  uch 		pref.rootfs = 0;
    166  1.1  uch 	else if (_is_checked(IDC_MAIN_ROOT_SD))
    167  1.1  uch 		pref.rootfs = 1;
    168  1.1  uch 	else if (_is_checked(IDC_MAIN_ROOT_MD))
    169  1.1  uch 		pref.rootfs = 2;
    170  1.1  uch 	else if (_is_checked(IDC_MAIN_ROOT_NFS))
    171  1.1  uch 		pref.rootfs = 3;
    172  1.1  uch 
    173  1.1  uch 	pref.boot_ask_for_name	= _is_checked(IDC_MAIN_OPTION_A);
    174  1.1  uch 	pref.boot_verbose	= _is_checked(IDC_MAIN_OPTION_V);
    175  1.1  uch 	pref.boot_single_user	= _is_checked(IDC_MAIN_OPTION_S);
    176  1.1  uch 	pref.boot_serial	= _is_checked(IDC_MAIN_OPTION_H);
    177  1.1  uch 	Edit_GetText(_edit_md_root, pref.rootfs_file, MAX_PATH);
    178  1.1  uch 
    179  1.1  uch 	TCHAR tmpbuf[8];
    180  1.1  uch 	ComboBox_GetText(_combobox_serial_speed, tmpbuf, 8);
    181  1.1  uch 	pref.serial_speed = _wtoi(tmpbuf);
    182  1.1  uch }
    183  1.1  uch 
    184  1.1  uch void
    185  1.1  uch MainTabWindow::command(int id, int msg)
    186  1.1  uch {
    187  1.1  uch 	switch (id) {
    188  1.1  uch 	case IDC_MAIN_OPTION_H:
    189  1.1  uch 		EnableWindow(_combobox_serial_speed,
    190  1.1  uch 			     _is_checked(IDC_MAIN_OPTION_H));
    191  1.1  uch 		break;
    192  1.1  uch 	case IDC_MAIN_ROOT_WD:
    193  1.1  uch 		/* FALLTHROUGH */
    194  1.1  uch 	case IDC_MAIN_ROOT_SD:
    195  1.1  uch 		/* FALLTHROUGH */
    196  1.1  uch 	case IDC_MAIN_ROOT_MD:
    197  1.1  uch 		/* FALLTHROUGH */
    198  1.1  uch 	case IDC_MAIN_ROOT_NFS:
    199  1.1  uch 		EnableWindow(_edit_md_root, _is_checked(IDC_MAIN_ROOT_MD));
    200  1.1  uch 	}
    201  1.1  uch }
    202  1.1  uch 
    203  1.1  uch //
    204  1.1  uch // Option window
    205  1.1  uch //
    206  1.1  uch void
    207  1.1  uch OptionTabWindow::init(HWND w)
    208  1.1  uch {
    209  1.1  uch 	struct HpcMenuInterface::HpcMenuPreferences &pref = HPC_PREFERENCE;
    210  1.1  uch 
    211  1.1  uch 	_window = w;
    212  1.1  uch 
    213  1.1  uch 	TabWindow::init(_window);
    214  1.1  uch 	_spin_edit = GetDlgItem(_window, IDC_OPT_AUTO_INPUT);
    215  1.1  uch 	_spin = CreateUpDownControl(WS_CHILD | WS_BORDER | WS_VISIBLE |
    216  1.1  uch 				    UDS_SETBUDDYINT | UDS_ALIGNRIGHT,
    217  1.1  uch 				    80, 0, 50, 50, _window,
    218  1.1  uch 				    IDC_OPT_AUTO_UPDOWN,
    219  1.1  uch 				    _app._instance, _spin_edit,
    220  1.1  uch 				    60, 1, 30);
    221  1.1  uch 	BOOL onoff = pref.auto_boot ? TRUE : FALSE;
    222  1.1  uch 	EnableWindow(_spin_edit, onoff);
    223  1.1  uch 	EnableWindow(_spin, onoff);
    224  1.1  uch 
    225  1.1  uch 	SET_CHECK(AUTO, pref.auto_boot);
    226  1.1  uch 	if (pref.auto_boot) {
    227  1.1  uch 		TCHAR tmp[32];
    228  1.1  uch 		wsprintf(tmp, TEXT("%d"), pref.auto_boot);
    229  1.1  uch 		Edit_SetText(_spin_edit, tmp);
    230  1.1  uch 	}
    231  1.1  uch 	SET_CHECK(VIDEO,	pref.reverse_video);
    232  1.1  uch 	SET_CHECK(PAUSE,	pref.pause_before_boot);
    233  1.1  uch 	SET_CHECK(DEBUG,	pref.load_debug_info);
    234  1.1  uch 	SET_CHECK(SAFETY,	pref.safety_message);
    235  1.1  uch }
    236  1.1  uch 
    237  1.1  uch void
    238  1.1  uch OptionTabWindow::command(int id, int msg)
    239  1.1  uch {
    240  1.1  uch 	switch (id) {
    241  1.1  uch 	case IDC_OPT_AUTO:
    242  1.1  uch 		if (IS_CHECKED(AUTO)) {
    243  1.1  uch 			EnableWindow(_spin_edit, TRUE);
    244  1.1  uch 			EnableWindow(_spin, TRUE);
    245  1.1  uch 		} else {
    246  1.1  uch 			EnableWindow(_spin_edit, FALSE);
    247  1.1  uch 			EnableWindow(_spin, FALSE);
    248  1.1  uch 		}
    249  1.1  uch 		break;
    250  1.1  uch 	}
    251  1.1  uch }
    252  1.1  uch 
    253  1.1  uch void
    254  1.1  uch OptionTabWindow::get()
    255  1.1  uch {
    256  1.1  uch 	struct HpcMenuInterface::HpcMenuPreferences &pref = HPC_PREFERENCE;
    257  1.1  uch 	if (IS_CHECKED(AUTO)) {
    258  1.1  uch 		TCHAR tmp[32];
    259  1.1  uch 		Edit_GetText(_spin_edit, tmp, 32);
    260  1.1  uch 		pref.auto_boot = _wtoi(tmp);
    261  1.1  uch 	} else
    262  1.1  uch 		pref.auto_boot = 0;
    263  1.1  uch 	pref.reverse_video	= IS_CHECKED(VIDEO);
    264  1.1  uch 	pref.pause_before_boot	= IS_CHECKED(PAUSE);
    265  1.1  uch 	pref.load_debug_info	= IS_CHECKED(DEBUG);
    266  1.1  uch 	pref.safety_message	= IS_CHECKED(SAFETY);
    267  1.1  uch }
    268  1.1  uch #undef IS_CHECKED
    269  1.1  uch #undef SET_CHECK
    270  1.1  uch 
    271  1.1  uch 
    272  1.1  uch //
    273  1.1  uch // Console window
    274  1.1  uch //
    275  1.1  uch void
    276  1.1  uch ConsoleTabWindow::print(TCHAR *buf, BOOL force_display)
    277  1.1  uch {
    278  1.1  uch 	int cr;
    279  1.1  uch 	TCHAR *p;
    280  1.1  uch 
    281  1.1  uch 	if (force_display)
    282  1.1  uch 		goto display;
    283  1.1  uch 
    284  1.1  uch 	if (_filesave) {
    285  1.1  uch 		if (_logfile == INVALID_HANDLE_VALUE && !_open_log_file()) {
    286  1.1  uch 			_filesave = FALSE;
    287  1.1  uch 			_set_check(IDC_CONS_FILESAVE, _filesave);
    288  1.1  uch 			EnableWindow(_filename_edit, _filesave);
    289  1.1  uch 			goto display;
    290  1.1  uch 		}
    291  1.1  uch 		DWORD cnt;
    292  1.1  uch 		char c;
    293  1.1  uch 		for (int i = 0; *buf != TEXT('\0'); buf++) {
    294  1.1  uch 			c = *buf & 0x7f;
    295  1.1  uch 			WriteFile(_logfile, &c, 1, &cnt, 0);
    296  1.1  uch 		}
    297  1.1  uch 		FlushFileBuffers(_logfile);
    298  1.1  uch 		return;
    299  1.1  uch 	}
    300  1.1  uch 
    301  1.1  uch  display:
    302  1.1  uch 	// count # of '\n'
    303  1.1  uch 	for (cr = 0, p = buf; p = wcschr(p, TEXT('\n')); cr++, p++)
    304  1.1  uch 		;
    305  1.1  uch 	// total length of new buffer('\n' -> "\r\n" + '\0')
    306  1.1  uch 	int ln = wcslen(buf) + cr + 1;
    307  1.1  uch 
    308  1.1  uch 	// get old buffer.
    309  1.1  uch 	int lo = Edit_GetTextLength(_edit);
    310  1.1  uch 	size_t sz =(lo  + ln) * sizeof(TCHAR);
    311  1.1  uch 
    312  1.1  uch 	p = reinterpret_cast <TCHAR *>(malloc(sz));
    313  1.1  uch 	if (p == NULL)
    314  1.1  uch 		return;
    315  1.1  uch 
    316  1.1  uch 	memset(p, 0, sz);
    317  1.1  uch 	Edit_GetText(_edit, p, lo + 1);
    318  1.1  uch 
    319  1.1  uch 	// put new buffer to end of old buffer.
    320  1.1  uch 	TCHAR *d = p + lo;
    321  1.1  uch 	while (*buf != TEXT('\0')) {
    322  1.1  uch 		TCHAR c = *buf++;
    323  1.1  uch 		if (c == TEXT('\n'))
    324  1.1  uch 			*d++ = TEXT('\r');
    325  1.1  uch 		*d++ = c;
    326  1.1  uch 	}
    327  1.1  uch 	*d = TEXT('\0');
    328  1.1  uch 
    329  1.1  uch 	// display total buffer.
    330  1.1  uch 	Edit_SetText(_edit, p);
    331  1.1  uch //  Edit_Scroll(_edit, Edit_GetLineCount(_edit), 0);
    332  1.1  uch 	UpdateWindow(_edit);
    333  1.1  uch 
    334  1.1  uch 	free(p);
    335  1.1  uch }
    336  1.1  uch 
    337  1.1  uch void
    338  1.1  uch ConsoleTabWindow::init(HWND w)
    339  1.1  uch {
    340  1.1  uch 	// at this time _window is NULL.
    341  1.1  uch 	// use argument of window procedure.
    342  1.1  uch 	TabWindow::init(w);
    343  1.1  uch 	_edit = GetDlgItem(w, IDC_CONS_EDIT);
    344  1.1  uch 	MoveWindow(_edit, 5, 60, _rect.right - _rect.left - 10,
    345  1.1  uch 		   _rect.bottom - _rect.top - 60, TRUE);
    346  1.1  uch 	Edit_FmtLines(_edit, TRUE);
    347  1.1  uch 
    348  1.1  uch 	// log file.
    349  1.1  uch 	_filename_edit = GetDlgItem(w, IDC_CONS_FILENAME);
    350  1.1  uch 	_filesave = FALSE;
    351  1.1  uch 	Edit_SetText(_filename_edit, L"bootlog.txt");
    352  1.1  uch 	EnableWindow(_filename_edit, _filesave);
    353  1.1  uch }
    354  1.1  uch 
    355  1.1  uch void
    356  1.1  uch ConsoleTabWindow::command(int id, int msg)
    357  1.1  uch {
    358  1.1  uch 	HpcMenuInterface &menu = HPC_MENU;
    359  1.1  uch 	struct HpcMenuInterface::cons_hook_args *hook = 0;
    360  1.1  uch 	int bit;
    361  1.1  uch 
    362  1.1  uch 	switch(id) {
    363  1.1  uch 	case IDC_CONS_FILESAVE:
    364  1.1  uch 		_filesave = _is_checked(IDC_CONS_FILESAVE);
    365  1.1  uch 		EnableWindow(_filename_edit, _filesave);
    366  1.1  uch 		break;
    367  1.1  uch 	case IDC_CONS_CHK0:
    368  1.1  uch 		/* FALLTHROUGH */
    369  1.1  uch 	case IDC_CONS_CHK1:
    370  1.1  uch 		/* FALLTHROUGH */
    371  1.1  uch 	case IDC_CONS_CHK2:
    372  1.1  uch 		/* FALLTHROUGH */
    373  1.1  uch 	case IDC_CONS_CHK3:
    374  1.1  uch 		/* FALLTHROUGH */
    375  1.1  uch 	case IDC_CONS_CHK4:
    376  1.1  uch 		/* FALLTHROUGH */
    377  1.1  uch 	case IDC_CONS_CHK5:
    378  1.1  uch 		/* FALLTHROUGH */
    379  1.1  uch 	case IDC_CONS_CHK6:
    380  1.1  uch 		/* FALLTHROUGH */
    381  1.1  uch 	case IDC_CONS_CHK7:
    382  1.1  uch 		bit = 1 << (id - IDC_CONS_CHK_);
    383  1.1  uch 		if (SendDlgItemMessage(_window, id, BM_GETCHECK, 0, 0))
    384  1.1  uch 			menu._cons_parameter |= bit;
    385  1.1  uch 		else
    386  1.1  uch 			menu._cons_parameter &= ~bit;
    387  1.1  uch 		break;
    388  1.1  uch 	case IDC_CONS_BTN0:
    389  1.1  uch 		/* FALLTHROUGH */
    390  1.1  uch 	case IDC_CONS_BTN1:
    391  1.1  uch 		/* FALLTHROUGH */
    392  1.1  uch 	case IDC_CONS_BTN2:
    393  1.1  uch 		/* FALLTHROUGH */
    394  1.1  uch 	case IDC_CONS_BTN3:
    395  1.1  uch 		hook = &menu._cons_hook[id - IDC_CONS_BTN_];
    396  1.1  uch 		if (hook->func)
    397  1.1  uch 			hook->func(hook->arg, menu._cons_parameter);
    398  1.1  uch 
    399  1.1  uch 		break;
    400  1.1  uch 	}
    401  1.1  uch }
    402  1.1  uch 
    403  1.1  uch BOOL
    404  1.1  uch ConsoleTabWindow::_open_log_file()
    405  1.1  uch {
    406  1.1  uch 	TCHAR path[MAX_PATH];
    407  1.1  uch 	TCHAR filename[MAX_PATH];
    408  1.1  uch 	TCHAR filepath[MAX_PATH];
    409  1.1  uch 
    410  1.1  uch 	if (!_find_pref_dir(path)) {
    411  1.1  uch 		print(L"couldn't find temporary directory.\n", TRUE);
    412  1.1  uch 		return FALSE;
    413  1.1  uch 	}
    414  1.1  uch 
    415  1.1  uch 	Edit_GetText(_filename_edit, filename, MAX_PATH);
    416  1.1  uch 	wsprintf(filepath, TEXT("\\%s\\%s"), path, filename);
    417  1.1  uch 	_logfile = CreateFile(filepath, GENERIC_WRITE, 0, 0,
    418  1.1  uch 			      CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
    419  1.1  uch 	if (_logfile == INVALID_HANDLE_VALUE)
    420  1.1  uch 		return FALSE;
    421  1.1  uch 
    422  1.1  uch 	wsprintf(path, TEXT("log file is %s\n"), filepath);
    423  1.1  uch 	print(path, TRUE);
    424  1.1  uch 
    425  1.1  uch 	return TRUE;
    426  1.1  uch }
    427  1.1  uch 
    428  1.1  uch //
    429  1.1  uch // Common utility
    430  1.1  uch //
    431  1.1  uch BOOL
    432  1.1  uch _find_pref_dir(TCHAR *path)
    433  1.1  uch {
    434  1.1  uch 	WIN32_FIND_DATA fd;
    435  1.1  uch 	HANDLE find;
    436  1.1  uch 
    437  1.1  uch 	lstrcpy(path, TEXT("\\*.*"));
    438  1.1  uch 	find = FindFirstFile(path, &fd);
    439  1.1  uch 
    440  1.1  uch 	if (find != INVALID_HANDLE_VALUE) {
    441  1.1  uch 		do {
    442  1.1  uch 			int attr = fd.dwFileAttributes;
    443  1.1  uch 			if ((attr & FILE_ATTRIBUTE_DIRECTORY) &&
    444  1.1  uch 			    (attr & FILE_ATTRIBUTE_TEMPORARY)) {
    445  1.1  uch 				wcscpy(path, fd.cFileName);
    446  1.1  uch 				FindClose(find);
    447  1.1  uch 				return TRUE;
    448  1.1  uch 			}
    449  1.1  uch 		} while (FindNextFile(find, &fd));
    450  1.1  uch 	}
    451  1.1  uch 	FindClose(find);
    452  1.1  uch 
    453  1.1  uch 	return FALSE;
    454  1.1  uch }
    455