2001-11-24 00:04:58 +01:00
|
|
|
/*
|
|
|
|
* an application for displaying Win32 console
|
|
|
|
*
|
2002-09-04 20:41:52 +02:00
|
|
|
* Copyright 2001, 2002 Eric Pouech
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-11-24 00:04:58 +01:00
|
|
|
*/
|
|
|
|
|
2002-04-26 21:05:15 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
#include <stdio.h>
|
2006-10-19 19:21:17 +02:00
|
|
|
#include <stdarg.h>
|
2001-11-30 19:46:42 +01:00
|
|
|
#include "wine/server.h"
|
2001-11-24 00:04:58 +01:00
|
|
|
#include "winecon_private.h"
|
2002-12-14 00:37:06 +01:00
|
|
|
#include "winnls.h"
|
2006-10-19 19:21:17 +02:00
|
|
|
#include "winuser.h"
|
2015-10-29 13:17:17 +01:00
|
|
|
#include "wine/unicode.h"
|
2002-05-14 23:45:13 +02:00
|
|
|
#include "wine/debug.h"
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2002-05-14 23:45:13 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wineconsole);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2002-09-04 20:41:52 +02:00
|
|
|
void WINECON_Fatal(const char* msg)
|
|
|
|
{
|
|
|
|
WINE_ERR("%s\n", msg);
|
|
|
|
ExitProcess(0);
|
|
|
|
}
|
|
|
|
|
2006-10-19 19:21:17 +02:00
|
|
|
static void printf_res(UINT uResId, ...)
|
|
|
|
{
|
|
|
|
WCHAR buffer[1024];
|
|
|
|
CHAR ansi[1024];
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, uResId);
|
2018-07-13 19:01:25 +02:00
|
|
|
LoadStringW(GetModuleHandleW(NULL), uResId, buffer, ARRAY_SIZE(buffer));
|
2006-10-19 19:21:17 +02:00
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, buffer, -1, ansi, sizeof(ansi), NULL, NULL);
|
|
|
|
vprintf(ansi, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2007-03-10 22:00:47 +01:00
|
|
|
static void WINECON_Usage(void)
|
2006-10-19 19:21:17 +02:00
|
|
|
{
|
|
|
|
printf_res(IDS_USAGE_HEADER);
|
|
|
|
printf_res(IDS_USAGE_BACKEND);
|
|
|
|
printf_res(IDS_USAGE_COMMAND);
|
|
|
|
printf_res(IDS_USAGE_FOOTER);
|
|
|
|
}
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
/******************************************************************
|
|
|
|
* WINECON_FetchCells
|
|
|
|
*
|
|
|
|
* updates the local copy of cells (band to update)
|
|
|
|
*/
|
2009-01-20 09:15:26 +01:00
|
|
|
static void WINECON_FetchCells(struct inner_data* data, int upd_tp, int upd_bm)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2020-07-24 20:39:58 +02:00
|
|
|
SMALL_RECT region = { 0, upd_tp, data->curcfg.sb_width - 1, upd_bm };
|
|
|
|
COORD size = { data->curcfg.sb_width, data->curcfg.sb_height };
|
|
|
|
COORD coord = { 0, upd_tp };
|
|
|
|
|
2020-07-29 12:37:47 +02:00
|
|
|
if (ReadConsoleOutputW(data->console, data->cells, size, coord, ®ion))
|
2020-07-24 20:39:58 +02:00
|
|
|
data->fnRefresh(data, upd_tp, upd_bm);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
2010-11-15 21:36:02 +01:00
|
|
|
/******************************************************************
|
|
|
|
* WINECON_ResizeWithContainer
|
|
|
|
*
|
|
|
|
* For console embedded in a container (e.g. user in a win32 window, or (n)curses
|
|
|
|
* in a TERM, perform resize of console (screen buffer and window) to fit in
|
|
|
|
* (new) container size.
|
|
|
|
*/
|
|
|
|
void WINECON_ResizeWithContainer(struct inner_data* data, int width, int height)
|
|
|
|
{
|
|
|
|
struct config_data cfg;
|
|
|
|
|
2020-04-21 22:09:55 +02:00
|
|
|
if (data->in_set_config || data->in_grab_changes) return;
|
2010-11-15 21:36:02 +01:00
|
|
|
|
|
|
|
cfg = data->curcfg;
|
|
|
|
cfg.win_width = width;
|
|
|
|
cfg.win_height = height;
|
|
|
|
|
|
|
|
/* auto size screen-buffer if it's now smaller than window */
|
|
|
|
if (cfg.sb_width < cfg.win_width) cfg.sb_width = cfg.win_width;
|
|
|
|
if (cfg.sb_height < cfg.win_height) cfg.sb_height = cfg.win_height;
|
|
|
|
|
|
|
|
/* and reset window pos so that we don't display outside of the screen-buffer */
|
|
|
|
if (cfg.win_pos.X + cfg.win_width > cfg.sb_width) cfg.win_pos.X = cfg.sb_width - cfg.win_width;
|
|
|
|
if (cfg.win_pos.Y + cfg.win_height > cfg.sb_height) cfg.win_pos.Y = cfg.sb_height - cfg.win_height;
|
|
|
|
|
|
|
|
WINECON_SetConfig(data, &cfg);
|
|
|
|
}
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
/******************************************************************
|
|
|
|
* WINECON_SetHistorySize
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2009-01-20 09:16:20 +01:00
|
|
|
static BOOL WINECON_SetHistorySize(HANDLE hConIn, int size)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2020-07-20 15:38:11 +02:00
|
|
|
struct condrv_input_info_params params = { SET_CONSOLE_INPUT_INFO_HISTORY_SIZE };
|
|
|
|
params.info.history_size = size;
|
|
|
|
return DeviceIoControl(hConIn, IOCTL_CONDRV_SET_INPUT_INFO, ¶ms, sizeof(params), NULL, 0, NULL, NULL);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WINECON_SetHistoryMode
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2009-01-20 09:16:20 +01:00
|
|
|
static BOOL WINECON_SetHistoryMode(HANDLE hConIn, int mode)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2020-07-20 15:38:18 +02:00
|
|
|
struct condrv_input_info_params params = { SET_CONSOLE_INPUT_INFO_HISTORY_MODE };
|
|
|
|
params.info.history_mode = mode;
|
|
|
|
return DeviceIoControl(hConIn, IOCTL_CONDRV_SET_INPUT_INFO, ¶ms, sizeof(params), NULL, 0, NULL, NULL);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
2015-07-13 15:18:37 +02:00
|
|
|
/******************************************************************
|
|
|
|
* WINECON_SetInsertMode
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void WINECON_SetInsertMode(HANDLE hConIn, unsigned int enable)
|
|
|
|
{
|
|
|
|
DWORD mode;
|
|
|
|
|
|
|
|
GetConsoleMode(hConIn, &mode);
|
|
|
|
if (enable)
|
|
|
|
mode |= ENABLE_INSERT_MODE|ENABLE_EXTENDED_FLAGS;
|
|
|
|
else
|
|
|
|
mode &= ~ENABLE_INSERT_MODE;
|
|
|
|
SetConsoleMode(hConIn, mode);
|
|
|
|
}
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
/******************************************************************
|
|
|
|
* WINECON_GetConsoleTitle
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2001-11-30 19:46:42 +01:00
|
|
|
BOOL WINECON_GetConsoleTitle(HANDLE hConIn, WCHAR* buffer, size_t len)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2020-07-15 17:34:34 +02:00
|
|
|
DWORD size;
|
2001-11-30 19:46:42 +01:00
|
|
|
|
2020-07-15 17:34:34 +02:00
|
|
|
if (!DeviceIoControl(hConIn, IOCTL_CONDRV_GET_TITLE, NULL, 0, buffer, len - sizeof(WCHAR), &size, NULL))
|
|
|
|
return FALSE;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2020-07-15 17:34:34 +02:00
|
|
|
buffer[size / sizeof(WCHAR)] = 0;
|
|
|
|
return TRUE;
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
2003-01-09 07:01:51 +01:00
|
|
|
/******************************************************************
|
|
|
|
* WINECON_SetEditionMode
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static BOOL WINECON_SetEditionMode(HANDLE hConIn, int edition_mode)
|
|
|
|
{
|
2020-07-20 15:38:26 +02:00
|
|
|
struct condrv_input_info_params params = { SET_CONSOLE_INPUT_INFO_EDITION_MODE };
|
|
|
|
params.info.edition_mode = edition_mode;
|
|
|
|
return DeviceIoControl(hConIn, IOCTL_CONDRV_SET_INPUT_INFO, ¶ms, sizeof(params), NULL, 0, NULL, NULL);
|
2003-01-09 07:01:51 +01:00
|
|
|
}
|
|
|
|
|
2016-08-10 12:01:34 +02:00
|
|
|
/******************************************************************
|
|
|
|
* WINECON_SetColors
|
|
|
|
*
|
2016-08-10 12:01:45 +02:00
|
|
|
* Sets ColorTable and Pop-up menu colors
|
2016-08-10 12:01:34 +02:00
|
|
|
*/
|
|
|
|
static void WINECON_SetColors(struct inner_data *data, const struct config_data* cfg)
|
|
|
|
{
|
2020-07-10 17:08:15 +02:00
|
|
|
struct condrv_output_info_params params =
|
|
|
|
{ SET_CONSOLE_OUTPUT_INFO_COLORTABLE | SET_CONSOLE_OUTPUT_INFO_POPUP_ATTR };
|
2016-08-10 12:01:34 +02:00
|
|
|
|
2020-07-10 17:08:15 +02:00
|
|
|
memcpy(data->curcfg.color_map, cfg->color_map, sizeof(data->curcfg.color_map));
|
2016-08-10 12:01:45 +02:00
|
|
|
data->curcfg.popup_attr = cfg->popup_attr;
|
2016-08-10 12:01:34 +02:00
|
|
|
|
2020-07-10 17:08:15 +02:00
|
|
|
params.info.popup_attr = cfg->popup_attr;
|
|
|
|
memcpy(params.info.color_map, cfg->color_map, sizeof(cfg->color_map));
|
2020-07-29 12:37:47 +02:00
|
|
|
DeviceIoControl(data->console, IOCTL_CONDRV_SET_OUTPUT_INFO, ¶ms, sizeof(params), NULL, 0, NULL, NULL);
|
2016-08-10 12:01:34 +02:00
|
|
|
}
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
/******************************************************************
|
|
|
|
* WINECON_GrabChanges
|
|
|
|
*
|
|
|
|
* A change occurs, try to figure out which
|
|
|
|
*/
|
2011-03-20 09:18:10 +01:00
|
|
|
void WINECON_GrabChanges(struct inner_data* data)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2020-07-08 16:31:55 +02:00
|
|
|
struct condrv_renderer_event *evts = data->events;
|
2020-07-08 16:29:49 +02:00
|
|
|
int i, ev_found;
|
|
|
|
DWORD num;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2011-09-08 22:27:41 +02:00
|
|
|
if (data->in_grab_changes) return;
|
|
|
|
|
2020-07-29 12:37:28 +02:00
|
|
|
if (!GetOverlappedResult(data->console, &data->overlapped, &num, FALSE))
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2020-07-24 20:39:53 +02:00
|
|
|
if (GetLastError() == ERROR_IO_INCOMPLETE) return;
|
2020-07-08 16:29:49 +02:00
|
|
|
ERR( "failed to get renderer events: %u\n", GetLastError() );
|
|
|
|
data->dying = TRUE;
|
|
|
|
return;
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
2020-07-08 16:31:55 +02:00
|
|
|
num /= sizeof(data->events[0]);
|
2011-09-08 22:27:11 +02:00
|
|
|
WINE_TRACE( "got %u events\n", num );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
/* FIXME: should do some event compression here (cursor pos, update) */
|
2002-03-23 19:45:57 +01:00
|
|
|
/* step 1: keep only last cursor pos event */
|
2003-10-09 06:27:08 +02:00
|
|
|
ev_found = -1;
|
2002-03-23 19:45:57 +01:00
|
|
|
for (i = num - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if (evts[i].event == CONSOLE_RENDERER_CURSOR_POS_EVENT)
|
|
|
|
{
|
2004-03-17 21:48:30 +01:00
|
|
|
if (ev_found != -1)
|
2011-09-08 22:27:11 +02:00
|
|
|
{
|
|
|
|
WINE_TRACE("%u/%u: curs-pos(%d,%d) ignoring\n", i+1, num, evts[i].u.cursor_pos.x, evts[i].u.cursor_pos.y);
|
2004-03-17 21:48:30 +01:00
|
|
|
evts[i].event = CONSOLE_RENDERER_NONE_EVENT;
|
2011-09-08 22:27:11 +02:00
|
|
|
}
|
2003-10-09 06:27:08 +02:00
|
|
|
ev_found = i;
|
2002-03-23 19:45:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* step 2: manage update events */
|
2003-10-09 06:27:08 +02:00
|
|
|
ev_found = -1;
|
2003-12-02 04:52:35 +01:00
|
|
|
for (i = 0; i < num; i++)
|
2002-03-23 19:45:57 +01:00
|
|
|
{
|
2003-12-02 04:52:35 +01:00
|
|
|
if (evts[i].event == CONSOLE_RENDERER_NONE_EVENT ||
|
|
|
|
evts[i].event == CONSOLE_RENDERER_CURSOR_POS_EVENT ||
|
|
|
|
evts[i].event == CONSOLE_RENDERER_CURSOR_GEOM_EVENT) continue;
|
2003-10-09 06:27:08 +02:00
|
|
|
if (evts[i].event != CONSOLE_RENDERER_UPDATE_EVENT)
|
2002-03-23 19:45:57 +01:00
|
|
|
{
|
2003-10-09 06:27:08 +02:00
|
|
|
ev_found = -1;
|
|
|
|
continue;
|
2003-12-02 04:52:35 +01:00
|
|
|
}
|
2003-10-09 06:27:08 +02:00
|
|
|
|
2005-05-06 17:44:31 +02:00
|
|
|
if (ev_found != -1 && /* Only 2 cases where they CANNOT merge */
|
2003-10-09 06:27:08 +02:00
|
|
|
!(evts[i ].u.update.bottom + 1 < evts[ev_found].u.update.top ||
|
|
|
|
evts[ev_found].u.update.bottom + 1 < evts[i ].u.update.top))
|
|
|
|
{
|
2011-09-08 22:27:11 +02:00
|
|
|
WINE_TRACE("%u/%u: update(%d,%d) merging with %u\n", ev_found+1, num, evts[i].u.update.top, evts[i].u.update.bottom, i+1);
|
2003-10-09 06:27:08 +02:00
|
|
|
evts[i].u.update.top = min(evts[i ].u.update.top,
|
|
|
|
evts[ev_found].u.update.top);
|
|
|
|
evts[i].u.update.bottom = max(evts[i ].u.update.bottom,
|
|
|
|
evts[ev_found].u.update.bottom);
|
|
|
|
evts[ev_found].event = CONSOLE_RENDERER_NONE_EVENT;
|
2002-03-23 19:45:57 +01:00
|
|
|
}
|
2003-10-09 06:27:08 +02:00
|
|
|
ev_found = i;
|
2002-03-23 19:45:57 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2011-09-08 22:27:41 +02:00
|
|
|
data->in_grab_changes = TRUE;
|
2001-11-24 00:04:58 +01:00
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
switch (evts[i].event)
|
|
|
|
{
|
2003-10-09 06:27:08 +02:00
|
|
|
case CONSOLE_RENDERER_NONE_EVENT:
|
2011-09-08 22:27:11 +02:00
|
|
|
WINE_TRACE("%u/%u: NOP\n", i+1, num);
|
2003-10-09 06:27:08 +02:00
|
|
|
break;
|
2001-11-24 00:04:58 +01:00
|
|
|
case CONSOLE_RENDERER_TITLE_EVENT:
|
2011-09-08 22:27:11 +02:00
|
|
|
WINE_TRACE("%u/%u: title()\n", i+1, num);
|
2001-11-24 00:04:58 +01:00
|
|
|
data->fnSetTitle(data);
|
|
|
|
break;
|
|
|
|
case CONSOLE_RENDERER_SB_RESIZE_EVENT:
|
2002-06-01 01:06:46 +02:00
|
|
|
if (data->curcfg.sb_width != evts[i].u.resize.width ||
|
2005-12-03 18:04:07 +01:00
|
|
|
data->curcfg.sb_height != evts[i].u.resize.height)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2011-09-08 22:27:11 +02:00
|
|
|
WINE_TRACE("%u/%u: resize(%d,%d)\n", i+1, num, evts[i].u.resize.width, evts[i].u.resize.height);
|
2001-12-04 21:46:54 +01:00
|
|
|
data->curcfg.sb_width = evts[i].u.resize.width;
|
|
|
|
data->curcfg.sb_height = evts[i].u.resize.height;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-12-03 18:04:07 +01:00
|
|
|
data->cells = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, data->cells,
|
2003-10-15 23:01:05 +02:00
|
|
|
data->curcfg.sb_width * data->curcfg.sb_height * sizeof(CHAR_INFO));
|
|
|
|
|
2017-05-17 22:20:51 +02:00
|
|
|
if (!data->cells) WINECON_Fatal("OOM");
|
2001-11-24 00:04:58 +01:00
|
|
|
data->fnResizeScreenBuffer(data);
|
|
|
|
data->fnComputePositions(data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CONSOLE_RENDERER_UPDATE_EVENT:
|
2011-09-08 22:27:11 +02:00
|
|
|
WINE_TRACE("%u/%u: update(%d,%d)\n", i+1, num, evts[i].u.update.top, evts[i].u.update.bottom);
|
2001-11-24 00:04:58 +01:00
|
|
|
WINECON_FetchCells(data, evts[i].u.update.top, evts[i].u.update.bottom);
|
|
|
|
break;
|
|
|
|
case CONSOLE_RENDERER_CURSOR_POS_EVENT:
|
|
|
|
if (evts[i].u.cursor_pos.x != data->cursor.X || evts[i].u.cursor_pos.y != data->cursor.Y)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2011-09-08 22:27:11 +02:00
|
|
|
WINE_TRACE("%u/%u: curs-pos(%d,%d)\n", i+1, num, evts[i].u.cursor_pos.x, evts[i].u.cursor_pos.y);
|
2001-11-24 00:04:58 +01:00
|
|
|
data->cursor.X = evts[i].u.cursor_pos.x;
|
|
|
|
data->cursor.Y = evts[i].u.cursor_pos.y;
|
|
|
|
data->fnPosCursor(data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CONSOLE_RENDERER_CURSOR_GEOM_EVENT:
|
2002-06-01 01:06:46 +02:00
|
|
|
if (evts[i].u.cursor_geom.size != data->curcfg.cursor_size ||
|
2001-12-04 21:46:54 +01:00
|
|
|
evts[i].u.cursor_geom.visible != data->curcfg.cursor_visible)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2011-09-08 22:27:11 +02:00
|
|
|
WINE_TRACE("%u/%u: curs-geom(%d,%d)\n", i+1, num,
|
2003-10-08 21:20:11 +02:00
|
|
|
evts[i].u.cursor_geom.size, evts[i].u.cursor_geom.visible);
|
2003-10-08 21:18:33 +02:00
|
|
|
data->fnShapeCursor(data, evts[i].u.cursor_geom.size,
|
|
|
|
evts[i].u.cursor_geom.visible, FALSE);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CONSOLE_RENDERER_DISPLAY_EVENT:
|
2001-12-04 21:46:54 +01:00
|
|
|
if (evts[i].u.display.left != data->curcfg.win_pos.X)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2011-09-08 22:27:11 +02:00
|
|
|
WINE_TRACE("%u/%u: h-scroll(%d)\n", i+1, num, evts[i].u.display.left);
|
2003-10-08 21:18:33 +02:00
|
|
|
data->fnScroll(data, evts[i].u.display.left, TRUE);
|
|
|
|
data->fnPosCursor(data);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
2001-12-04 21:46:54 +01:00
|
|
|
if (evts[i].u.display.top != data->curcfg.win_pos.Y)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2011-09-08 22:27:11 +02:00
|
|
|
WINE_TRACE("%u/%u: v-scroll(%d)\n", i+1, num, evts[i].u.display.top);
|
2003-10-08 21:18:33 +02:00
|
|
|
data->fnScroll(data, evts[i].u.display.top, FALSE);
|
|
|
|
data->fnPosCursor(data);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
if (evts[i].u.display.width != data->curcfg.win_width ||
|
2001-12-04 21:46:54 +01:00
|
|
|
evts[i].u.display.height != data->curcfg.win_height)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2011-09-08 22:27:11 +02:00
|
|
|
WINE_TRACE("%u/%u: win-size(%d,%d)\n", i+1, num, evts[i].u.display.width, evts[i].u.display.height);
|
2001-12-04 21:46:54 +01:00
|
|
|
data->curcfg.win_width = evts[i].u.display.width;
|
|
|
|
data->curcfg.win_height = evts[i].u.display.height;
|
2001-11-24 00:04:58 +01:00
|
|
|
data->fnComputePositions(data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CONSOLE_RENDERER_EXIT_EVENT:
|
2011-03-20 09:18:10 +01:00
|
|
|
data->dying = TRUE;
|
2011-09-08 22:27:11 +02:00
|
|
|
WINE_TRACE("%u/%u: Exit!!\n", i+1, num);
|
2011-03-20 09:18:10 +01:00
|
|
|
return;
|
2001-11-24 00:04:58 +01:00
|
|
|
default:
|
2002-05-14 23:45:13 +02:00
|
|
|
WINE_FIXME("Unknown event type (%d)\n", evts[i].event);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
}
|
2011-09-08 22:27:41 +02:00
|
|
|
data->in_grab_changes = FALSE;
|
2020-07-08 16:31:55 +02:00
|
|
|
|
2020-07-29 12:37:28 +02:00
|
|
|
if (!DeviceIoControl(data->console, IOCTL_CONDRV_GET_RENDERER_EVENTS, NULL, 0, data->events,
|
2020-07-08 16:31:55 +02:00
|
|
|
sizeof(data->events), NULL, &data->overlapped) && GetLastError() != ERROR_IO_PENDING)
|
|
|
|
{
|
|
|
|
ERR("failed to get renderer events: %u\n", GetLastError());
|
|
|
|
data->dying = TRUE;
|
|
|
|
}
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
2002-09-04 20:41:52 +02:00
|
|
|
/******************************************************************
|
|
|
|
* WINECON_SetConfig
|
|
|
|
*
|
|
|
|
* Apply to data all the configuration elements from cfg. This includes modification
|
|
|
|
* of server side equivalent and visual parts.
|
|
|
|
* If force is FALSE, only the changed items are modified.
|
|
|
|
*/
|
2005-11-03 12:32:52 +01:00
|
|
|
void WINECON_SetConfig(struct inner_data* data, const struct config_data* cfg)
|
2002-09-04 20:41:52 +02:00
|
|
|
{
|
2010-11-15 21:36:02 +01:00
|
|
|
if (data->in_set_config) return;
|
|
|
|
data->in_set_config = TRUE;
|
2005-11-03 12:32:52 +01:00
|
|
|
if (data->curcfg.cursor_size != cfg->cursor_size ||
|
2002-09-04 20:41:52 +02:00
|
|
|
data->curcfg.cursor_visible != cfg->cursor_visible)
|
|
|
|
{
|
|
|
|
CONSOLE_CURSOR_INFO cinfo;
|
|
|
|
cinfo.dwSize = cfg->cursor_size;
|
2012-05-15 10:15:32 +02:00
|
|
|
/* <FIXME>: this hack is needed to pass through the invariant test operation on the server side
|
|
|
|
* (no notification is sent when invariant operation is requested)
|
2002-09-04 20:41:52 +02:00
|
|
|
*/
|
|
|
|
cinfo.bVisible = !cfg->cursor_visible;
|
2020-07-29 12:37:47 +02:00
|
|
|
SetConsoleCursorInfo(data->console, &cinfo);
|
2002-09-04 20:41:52 +02:00
|
|
|
/* </FIXME> */
|
|
|
|
cinfo.bVisible = cfg->cursor_visible;
|
|
|
|
/* this shall update (through notif) curcfg */
|
2020-07-29 12:37:47 +02:00
|
|
|
SetConsoleCursorInfo(data->console, &cinfo);
|
2002-09-04 20:41:52 +02:00
|
|
|
}
|
2005-11-03 12:32:52 +01:00
|
|
|
if (data->curcfg.history_size != cfg->history_size)
|
2002-09-04 20:41:52 +02:00
|
|
|
{
|
|
|
|
data->curcfg.history_size = cfg->history_size;
|
2020-07-30 17:15:08 +02:00
|
|
|
WINECON_SetHistorySize(data->console, cfg->history_size);
|
2002-09-04 20:41:52 +02:00
|
|
|
}
|
2005-11-03 12:32:52 +01:00
|
|
|
if (data->curcfg.history_nodup != cfg->history_nodup)
|
2002-09-04 20:41:52 +02:00
|
|
|
{
|
|
|
|
data->curcfg.history_nodup = cfg->history_nodup;
|
2020-07-30 17:15:08 +02:00
|
|
|
WINECON_SetHistoryMode(data->console, cfg->history_nodup);
|
2002-09-04 20:41:52 +02:00
|
|
|
}
|
2015-07-13 15:18:37 +02:00
|
|
|
if (data->curcfg.insert_mode != cfg->insert_mode)
|
|
|
|
{
|
|
|
|
data->curcfg.insert_mode = cfg->insert_mode;
|
2020-07-30 17:15:08 +02:00
|
|
|
WINECON_SetInsertMode(data->console, cfg->insert_mode);
|
2015-07-13 15:18:37 +02:00
|
|
|
}
|
2002-09-04 20:41:52 +02:00
|
|
|
data->curcfg.menu_mask = cfg->menu_mask;
|
|
|
|
data->curcfg.quick_edit = cfg->quick_edit;
|
2015-10-29 13:17:17 +01:00
|
|
|
if (strcmpiW(data->curcfg.face_name, cfg->face_name) || data->curcfg.cell_width != cfg->cell_width ||
|
2019-11-20 11:45:31 +01:00
|
|
|
data->curcfg.cell_height != cfg->cell_height || data->curcfg.font_pitch_family != cfg->font_pitch_family ||
|
|
|
|
data->curcfg.font_weight != cfg->font_weight)
|
2002-09-04 20:41:52 +02:00
|
|
|
{
|
2020-07-10 17:08:04 +02:00
|
|
|
struct condrv_output_info_params *params;
|
|
|
|
size_t len = lstrlenW(cfg->face_name);
|
2016-01-05 08:59:31 +01:00
|
|
|
RECT r;
|
2002-09-04 20:41:52 +02:00
|
|
|
data->fnSetFont(data, cfg->face_name, cfg->cell_height, cfg->font_weight);
|
2016-01-05 08:59:31 +01:00
|
|
|
SystemParametersInfoW(SPI_GETWORKAREA, 0, &r, 0);
|
2020-07-10 17:08:04 +02:00
|
|
|
if ((params = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*params) + len * sizeof(WCHAR))))
|
2015-10-29 13:17:19 +01:00
|
|
|
{
|
2020-07-10 17:08:04 +02:00
|
|
|
params->mask = SET_CONSOLE_OUTPUT_INFO_MAX_SIZE | SET_CONSOLE_OUTPUT_INFO_FONT;
|
|
|
|
params->info.max_width = (r.right - r.left) / cfg->cell_width;
|
|
|
|
params->info.max_height = (r.bottom - r.top - GetSystemMetrics(SM_CYCAPTION)) / cfg->cell_height;
|
|
|
|
params->info.font_width = cfg->cell_width;
|
|
|
|
params->info.font_height = cfg->cell_height;
|
|
|
|
params->info.font_weight = cfg->font_weight;
|
|
|
|
params->info.font_pitch_family = cfg->font_pitch_family;
|
|
|
|
memcpy(params + 1, cfg->face_name, len * sizeof(WCHAR));
|
2020-07-29 12:37:47 +02:00
|
|
|
DeviceIoControl(data->console, IOCTL_CONDRV_SET_OUTPUT_INFO, params, sizeof(*params) + len * sizeof(WCHAR),
|
2020-07-10 17:08:04 +02:00
|
|
|
NULL, 0, NULL, NULL);
|
2015-10-29 13:17:19 +01:00
|
|
|
}
|
2002-09-04 20:41:52 +02:00
|
|
|
}
|
2005-11-03 12:32:52 +01:00
|
|
|
if (data->curcfg.def_attr != cfg->def_attr)
|
2002-09-04 20:41:52 +02:00
|
|
|
{
|
2016-01-25 11:01:00 +01:00
|
|
|
DWORD screen_size, written;
|
|
|
|
COORD top_left = {0,0};
|
|
|
|
|
2002-09-04 20:41:52 +02:00
|
|
|
data->curcfg.def_attr = cfg->def_attr;
|
2016-01-25 11:01:00 +01:00
|
|
|
screen_size = cfg->win_width * (cfg->win_height + 1);
|
2020-07-29 12:37:47 +02:00
|
|
|
FillConsoleOutputAttribute(data->console, cfg->def_attr, screen_size, top_left, &written);
|
|
|
|
SetConsoleTextAttribute(data->console, cfg->def_attr);
|
2002-09-04 20:41:52 +02:00
|
|
|
}
|
2016-08-10 12:01:34 +02:00
|
|
|
WINECON_SetColors(data, cfg);
|
2003-02-26 05:37:15 +01:00
|
|
|
/* now let's look at the window / sb size changes...
|
|
|
|
* since the server checks that sb is always bigger than window,
|
|
|
|
* we have to take care of doing the operations in the right order
|
|
|
|
*/
|
|
|
|
/* a set of macros to make things easier to read
|
|
|
|
* The Test<A><B> macros test if the <A> (width/height) needs to be changed
|
|
|
|
* for <B> (window / ScreenBuffer)
|
|
|
|
* The Change<A><B> actually modify the <B> dimension of <A>.
|
|
|
|
*/
|
2005-11-03 12:32:52 +01:00
|
|
|
#define TstSBfWidth() (data->curcfg.sb_width != cfg->sb_width)
|
2010-11-15 21:35:55 +01:00
|
|
|
#define TstWinHPos() (data->curcfg.win_width != cfg->win_width || data->curcfg.win_pos.X != cfg->win_pos.X)
|
2003-02-26 05:37:15 +01:00
|
|
|
|
|
|
|
#define ChgSBfWidth() do {c.X = cfg->sb_width; \
|
|
|
|
c.Y = data->curcfg.sb_height;\
|
2020-07-29 12:37:47 +02:00
|
|
|
SetConsoleScreenBufferSize(data->console, c);\
|
2003-02-26 05:37:15 +01:00
|
|
|
} while (0)
|
2010-11-15 21:35:55 +01:00
|
|
|
#define ChgWinHPos() do {pos.Left = cfg->win_pos.X - data->curcfg.win_pos.X; \
|
|
|
|
pos.Top = 0; \
|
|
|
|
pos.Right = pos.Left + cfg->win_width - data->curcfg.win_width; \
|
2005-10-10 13:18:46 +02:00
|
|
|
pos.Bottom = 0; \
|
2020-07-29 12:37:47 +02:00
|
|
|
SetConsoleWindowInfo(data->console, FALSE, &pos);\
|
2003-02-26 05:37:15 +01:00
|
|
|
} while (0)
|
2005-11-03 12:32:52 +01:00
|
|
|
#define TstSBfHeight() (data->curcfg.sb_height != cfg->sb_height)
|
2010-11-15 21:35:55 +01:00
|
|
|
#define TstWinVPos() (data->curcfg.win_height != cfg->win_height || data->curcfg.win_pos.Y != cfg->win_pos.Y)
|
2003-02-26 05:37:15 +01:00
|
|
|
|
|
|
|
/* since we're going to apply height after width is done, we use width as defined
|
|
|
|
* in cfg, and not in data->curcfg because if won't be updated yet */
|
|
|
|
#define ChgSBfHeight() do {c.X = cfg->sb_width; c.Y = cfg->sb_height; \
|
2020-07-29 12:37:47 +02:00
|
|
|
SetConsoleScreenBufferSize(data->console, c); \
|
2003-02-26 05:37:15 +01:00
|
|
|
} while (0)
|
2010-11-15 21:35:55 +01:00
|
|
|
#define ChgWinVPos() do {pos.Left = 0; \
|
|
|
|
pos.Top = cfg->win_pos.Y - data->curcfg.win_pos.Y; \
|
2005-10-10 13:18:46 +02:00
|
|
|
pos.Right = 0; \
|
2010-11-15 21:35:55 +01:00
|
|
|
pos.Bottom = pos.Top + cfg->win_height - data->curcfg.win_height; \
|
2020-07-29 12:37:47 +02:00
|
|
|
SetConsoleWindowInfo(data->console, FALSE, &pos);\
|
2003-02-26 05:37:15 +01:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
do
|
2002-09-04 20:41:52 +02:00
|
|
|
{
|
|
|
|
COORD c;
|
|
|
|
SMALL_RECT pos;
|
|
|
|
|
2003-02-26 05:37:15 +01:00
|
|
|
if (TstSBfWidth())
|
|
|
|
{
|
2010-11-15 21:35:55 +01:00
|
|
|
if (TstWinHPos())
|
2003-02-26 05:37:15 +01:00
|
|
|
{
|
|
|
|
/* we're changing both at the same time, do it in the right order */
|
|
|
|
if (cfg->sb_width >= data->curcfg.win_width)
|
|
|
|
{
|
2010-11-15 21:35:55 +01:00
|
|
|
ChgSBfWidth(); ChgWinHPos();
|
2003-02-26 05:37:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-15 21:35:55 +01:00
|
|
|
ChgWinHPos(); ChgSBfWidth();
|
2003-02-26 05:37:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else ChgSBfWidth();
|
|
|
|
}
|
2010-11-15 21:35:55 +01:00
|
|
|
else if (TstWinHPos()) ChgWinHPos();
|
2003-02-26 05:37:15 +01:00
|
|
|
if (TstSBfHeight())
|
|
|
|
{
|
2010-11-15 21:35:55 +01:00
|
|
|
if (TstWinVPos())
|
2003-02-26 05:37:15 +01:00
|
|
|
{
|
|
|
|
if (cfg->sb_height >= data->curcfg.win_height)
|
|
|
|
{
|
2010-11-15 21:35:55 +01:00
|
|
|
ChgSBfHeight(); ChgWinVPos();
|
2003-02-26 05:37:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-15 21:35:55 +01:00
|
|
|
ChgWinVPos(); ChgSBfHeight();
|
2003-02-26 05:37:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else ChgSBfHeight();
|
|
|
|
}
|
2010-11-15 21:35:55 +01:00
|
|
|
else if (TstWinVPos()) ChgWinVPos();
|
2003-02-26 05:37:15 +01:00
|
|
|
} while (0);
|
|
|
|
#undef TstSBfWidth
|
2010-11-15 21:35:55 +01:00
|
|
|
#undef TstWinHPos
|
2003-02-26 05:37:15 +01:00
|
|
|
#undef ChgSBfWidth
|
2010-11-15 21:35:55 +01:00
|
|
|
#undef ChgWinHPos
|
2003-02-26 05:37:15 +01:00
|
|
|
#undef TstSBfHeight
|
2010-11-15 21:35:55 +01:00
|
|
|
#undef TstWinVPos
|
2003-02-26 05:37:15 +01:00
|
|
|
#undef ChgSBfHeight
|
2010-11-15 21:35:55 +01:00
|
|
|
#undef ChgWinVPos
|
2003-02-26 05:37:15 +01:00
|
|
|
|
2002-09-04 20:41:52 +02:00
|
|
|
data->curcfg.exit_on_die = cfg->exit_on_die;
|
2005-11-03 12:32:52 +01:00
|
|
|
if (data->curcfg.edition_mode != cfg->edition_mode)
|
2003-01-09 07:01:51 +01:00
|
|
|
{
|
|
|
|
data->curcfg.edition_mode = cfg->edition_mode;
|
2020-07-30 17:15:08 +02:00
|
|
|
WINECON_SetEditionMode(data->console, cfg->edition_mode);
|
2003-01-09 07:01:51 +01:00
|
|
|
}
|
2002-09-04 20:41:52 +02:00
|
|
|
/* we now need to gather all events we got from the operations above,
|
|
|
|
* in order to get data correctly updated
|
|
|
|
*/
|
|
|
|
WINECON_GrabChanges(data);
|
2010-11-15 21:36:02 +01:00
|
|
|
data->in_set_config = FALSE;
|
2002-09-04 20:41:52 +02:00
|
|
|
}
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
/******************************************************************
|
|
|
|
* WINECON_Delete
|
|
|
|
*
|
|
|
|
* Destroy wineconsole internal data
|
|
|
|
*/
|
|
|
|
static void WINECON_Delete(struct inner_data* data)
|
|
|
|
{
|
|
|
|
if (!data) return;
|
|
|
|
|
2002-12-14 00:37:06 +01:00
|
|
|
if (data->fnDeleteBackend) data->fnDeleteBackend(data);
|
2020-07-29 12:37:28 +02:00
|
|
|
if (data->console) CloseHandle(data->console);
|
2015-09-24 04:34:57 +02:00
|
|
|
if (data->hProcess) CloseHandle(data->hProcess);
|
2020-07-08 16:31:55 +02:00
|
|
|
if (data->overlapped.hEvent) CloseHandle(data->overlapped.hEvent);
|
2014-07-12 21:02:13 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, data->curcfg.registry);
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, data->cells);
|
2001-11-24 00:04:58 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, data);
|
|
|
|
}
|
|
|
|
|
2005-11-03 12:32:52 +01:00
|
|
|
/******************************************************************
|
|
|
|
* WINECON_GetServerConfig
|
|
|
|
*
|
|
|
|
* Fills data->curcfg with the actual configuration running in the server
|
|
|
|
* (getting real information on the server, and not relying on cached
|
|
|
|
* information in data)
|
|
|
|
*/
|
|
|
|
static BOOL WINECON_GetServerConfig(struct inner_data* data)
|
|
|
|
{
|
2020-07-07 16:07:02 +02:00
|
|
|
struct condrv_input_info input_info;
|
2020-07-09 19:29:12 +02:00
|
|
|
struct condrv_output_info output_info;
|
2015-07-13 15:18:37 +02:00
|
|
|
DWORD mode;
|
2005-11-03 12:32:52 +01:00
|
|
|
|
2020-07-30 17:15:08 +02:00
|
|
|
if (!DeviceIoControl(data->console, IOCTL_CONDRV_GET_INPUT_INFO, NULL, 0,
|
2020-07-07 16:07:02 +02:00
|
|
|
&input_info, sizeof(input_info), NULL, NULL))
|
|
|
|
return FALSE;
|
|
|
|
data->curcfg.history_size = input_info.history_size;
|
|
|
|
data->curcfg.history_nodup = input_info.history_mode;
|
|
|
|
data->curcfg.edition_mode = input_info.edition_mode;
|
2015-07-13 15:18:37 +02:00
|
|
|
|
2020-07-30 17:15:08 +02:00
|
|
|
GetConsoleMode(data->console, &mode);
|
2015-07-13 15:18:37 +02:00
|
|
|
data->curcfg.insert_mode = (mode & (ENABLE_INSERT_MODE|ENABLE_EXTENDED_FLAGS)) ==
|
|
|
|
(ENABLE_INSERT_MODE|ENABLE_EXTENDED_FLAGS);
|
|
|
|
|
2020-07-29 12:37:47 +02:00
|
|
|
if (!DeviceIoControl(data->console, IOCTL_CONDRV_GET_OUTPUT_INFO, NULL, 0,
|
2020-07-09 19:29:12 +02:00
|
|
|
&output_info, sizeof(output_info), NULL, NULL))
|
|
|
|
return FALSE;
|
|
|
|
data->curcfg.cursor_size = output_info.cursor_size;
|
|
|
|
data->curcfg.cursor_visible = output_info.cursor_visible;
|
|
|
|
data->curcfg.def_attr = output_info.attr;
|
|
|
|
data->curcfg.sb_width = output_info.width;
|
|
|
|
data->curcfg.sb_height = output_info.height;
|
|
|
|
data->curcfg.win_width = output_info.win_right - output_info.win_left + 1;
|
|
|
|
data->curcfg.win_height = output_info.win_bottom - output_info.win_top + 1;
|
2005-11-03 12:32:52 +01:00
|
|
|
|
2020-07-09 19:29:12 +02:00
|
|
|
WINECON_DumpConfig("first cfg: ", &data->curcfg);
|
|
|
|
return TRUE;
|
2005-11-03 12:32:52 +01:00
|
|
|
}
|
|
|
|
|
2020-07-30 17:15:19 +02:00
|
|
|
/******************************************************************
|
|
|
|
* WINECON_Spawn
|
|
|
|
*
|
|
|
|
* Spawn the child process when invoked with wineconsole foo bar
|
|
|
|
*/
|
2020-07-30 17:15:35 +02:00
|
|
|
static BOOL WINECON_Spawn(struct inner_data* data, LPWSTR cmdLine, HANDLE con_in, HANDLE con_out)
|
2020-07-30 17:15:19 +02:00
|
|
|
{
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
STARTUPINFOW startup;
|
|
|
|
BOOL done;
|
|
|
|
|
|
|
|
/* we're in the case wineconsole <exe> <options>... spawn the new process */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESTDHANDLES;
|
|
|
|
|
|
|
|
/* the attributes of wineconsole's handles are not adequate for inheritance, so
|
|
|
|
* get them with the correct attributes before process creation
|
|
|
|
*/
|
2020-07-30 17:15:35 +02:00
|
|
|
if (!DuplicateHandle(GetCurrentProcess(), con_in, GetCurrentProcess(),
|
2020-07-30 17:15:19 +02:00
|
|
|
&startup.hStdInput, GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE, TRUE, 0) ||
|
2020-07-30 17:15:35 +02:00
|
|
|
!DuplicateHandle(GetCurrentProcess(), con_out, GetCurrentProcess(),
|
2020-07-30 17:15:19 +02:00
|
|
|
&startup.hStdOutput, GENERIC_READ|GENERIC_WRITE, TRUE, 0) ||
|
2020-07-30 17:15:35 +02:00
|
|
|
!DuplicateHandle(GetCurrentProcess(), con_out, GetCurrentProcess(),
|
2020-07-30 17:15:19 +02:00
|
|
|
&startup.hStdError, GENERIC_READ|GENERIC_WRITE, TRUE, 0))
|
|
|
|
{
|
|
|
|
WINE_ERR("Can't dup handles\n");
|
|
|
|
/* no need to delete handles, we're exiting the program anyway */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
done = CreateProcessW(NULL, cmdLine, NULL, NULL, TRUE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
if (done)
|
|
|
|
{
|
|
|
|
data->hProcess = info.hProcess;
|
|
|
|
CloseHandle(info.hThread);
|
|
|
|
}
|
|
|
|
else printf_res(IDS_CMD_LAUNCH_FAILED, wine_dbgstr_w(cmdLine));
|
|
|
|
|
|
|
|
/* we no longer need the handles passed to the child for the console */
|
|
|
|
CloseHandle(startup.hStdInput);
|
|
|
|
CloseHandle(startup.hStdOutput);
|
|
|
|
CloseHandle(startup.hStdError);
|
|
|
|
|
|
|
|
return done;
|
|
|
|
}
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
/******************************************************************
|
|
|
|
* WINECON_Init
|
|
|
|
*
|
|
|
|
* Initialisation part I. Creation of server object (console input and
|
|
|
|
* active screen buffer)
|
|
|
|
*/
|
2002-10-03 21:54:57 +02:00
|
|
|
static struct inner_data* WINECON_Init(HINSTANCE hInst, DWORD pid, LPCWSTR appname,
|
2005-04-14 13:30:09 +02:00
|
|
|
enum init_return (*backend)(struct inner_data*),
|
2020-07-30 17:15:19 +02:00
|
|
|
INT nCmdShow, WCHAR *cmdline)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2020-07-20 15:38:50 +02:00
|
|
|
struct condrv_input_info_params input_params;
|
2020-07-16 17:50:33 +02:00
|
|
|
OBJECT_ATTRIBUTES attr = {sizeof(attr)};
|
2001-11-24 00:04:58 +01:00
|
|
|
struct inner_data* data = NULL;
|
|
|
|
DWORD ret;
|
2002-09-04 20:41:52 +02:00
|
|
|
struct config_data cfg;
|
|
|
|
STARTUPINFOW si;
|
2020-07-16 17:50:33 +02:00
|
|
|
UNICODE_STRING string;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
condrv_handle_t h;
|
2020-07-30 17:15:35 +02:00
|
|
|
HANDLE con_in;
|
|
|
|
HANDLE con_out;
|
2020-07-16 17:50:33 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
static const WCHAR renderer_pathW[] = {'\\','D','e','v','i','c','e','\\','C','o','n','D','r','v',
|
|
|
|
'\\','R','e','n','d','e','r','e','r',0};
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
|
|
data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data));
|
|
|
|
if (!data) return 0;
|
|
|
|
|
2010-04-28 01:10:42 +02:00
|
|
|
GetStartupInfoW(&si);
|
2002-09-04 20:41:52 +02:00
|
|
|
|
2017-05-17 22:20:40 +02:00
|
|
|
if (pid == 0) appname = si.lpTitle;
|
2002-09-04 20:41:52 +02:00
|
|
|
|
2005-04-14 13:30:09 +02:00
|
|
|
data->nCmdShow = nCmdShow;
|
2002-09-04 20:41:52 +02:00
|
|
|
/* load settings */
|
|
|
|
WINECON_RegLoad(appname, &cfg);
|
|
|
|
|
|
|
|
/* some overrides */
|
|
|
|
if (pid == 0)
|
|
|
|
{
|
|
|
|
if (si.dwFlags & STARTF_USECOUNTCHARS)
|
|
|
|
{
|
|
|
|
cfg.sb_width = si.dwXCountChars;
|
|
|
|
cfg.sb_height = si.dwYCountChars;
|
|
|
|
}
|
|
|
|
if (si.dwFlags & STARTF_USEFILLATTRIBUTE)
|
|
|
|
cfg.def_attr = si.dwFillAttribute;
|
|
|
|
/* should always be defined */
|
|
|
|
}
|
2001-12-04 21:46:54 +01:00
|
|
|
|
2020-07-08 16:31:55 +02:00
|
|
|
if (!(data->overlapped.hEvent = CreateEventW(NULL, TRUE, TRUE, NULL))) goto error;
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
/* the handles here are created without the whistles and bells required by console
|
|
|
|
* (mainly because wineconsole doesn't need it)
|
2002-07-02 01:22:48 +02:00
|
|
|
* - they are not inheritable
|
2001-11-24 00:04:58 +01:00
|
|
|
* - hConIn is not synchronizable
|
|
|
|
*/
|
|
|
|
SERVER_START_REQ(alloc_console)
|
|
|
|
{
|
2003-06-21 04:07:10 +02:00
|
|
|
req->access = GENERIC_READ | GENERIC_WRITE;
|
2005-12-09 12:05:20 +01:00
|
|
|
req->attributes = 0;
|
2003-06-23 05:37:14 +02:00
|
|
|
req->pid = pid;
|
2010-08-30 22:18:44 +02:00
|
|
|
req->input_fd = -1;
|
2003-06-21 04:07:10 +02:00
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
ret = !wine_server_call_err( req );
|
2020-07-30 17:15:35 +02:00
|
|
|
con_in = wine_server_ptr_handle( reply->handle_in );
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
if (!ret) goto error;
|
2020-07-30 17:15:35 +02:00
|
|
|
WINE_TRACE("using con_in %p, renderer %p\n", con_in, data->console);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2020-07-16 17:50:33 +02:00
|
|
|
RtlInitUnicodeString(&string, renderer_pathW);
|
|
|
|
attr.ObjectName = &string;
|
2020-07-29 12:37:28 +02:00
|
|
|
status = NtCreateFile(&data->console, FILE_READ_DATA | FILE_WRITE_DATA | FILE_WRITE_PROPERTIES
|
2020-07-16 17:50:33 +02:00
|
|
|
| FILE_READ_PROPERTIES | SYNCHRONIZE, &attr, &io, NULL, FILE_ATTRIBUTE_NORMAL,
|
|
|
|
0, FILE_OPEN, FILE_NON_DIRECTORY_FILE, NULL, 0);
|
|
|
|
if (status) goto error;
|
|
|
|
|
2020-07-30 17:15:35 +02:00
|
|
|
h = condrv_handle(con_in);
|
2020-07-29 12:37:28 +02:00
|
|
|
if (!DeviceIoControl(data->console, IOCTL_CONDRV_ATTACH_RENDERER, &h, sizeof(h), NULL, 0, NULL, NULL))
|
2020-07-16 17:50:33 +02:00
|
|
|
goto error;
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
SERVER_START_REQ(create_console_output)
|
|
|
|
{
|
2020-07-30 17:15:35 +02:00
|
|
|
req->handle_in = wine_server_obj_handle( con_in );
|
2005-12-09 12:05:20 +01:00
|
|
|
req->access = GENERIC_WRITE|GENERIC_READ;
|
|
|
|
req->attributes = 0;
|
|
|
|
req->share = FILE_SHARE_READ|FILE_SHARE_WRITE;
|
2010-08-30 22:18:52 +02:00
|
|
|
req->fd = -1;
|
2002-09-04 20:41:52 +02:00
|
|
|
ret = !wine_server_call_err( req );
|
2020-07-30 17:15:35 +02:00
|
|
|
con_out = wine_server_ptr_handle( reply->handle_out );
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
2001-12-04 21:46:54 +01:00
|
|
|
SERVER_END_REQ;
|
2002-09-04 20:41:52 +02:00
|
|
|
if (!ret) goto error;
|
2020-07-30 17:15:35 +02:00
|
|
|
WINE_TRACE("using con_out %p\n", con_out);
|
2002-09-04 20:41:52 +02:00
|
|
|
|
|
|
|
/* filling data->curcfg from cfg */
|
2003-06-13 18:32:52 +02:00
|
|
|
switch ((*backend)(data))
|
2002-09-04 20:41:52 +02:00
|
|
|
{
|
2007-09-26 14:21:46 +02:00
|
|
|
case init_not_supported:
|
|
|
|
if (backend == WCCURSES_InitBackend)
|
|
|
|
{
|
|
|
|
if (WCUSER_InitBackend( data ) != init_success) break;
|
|
|
|
}
|
|
|
|
else if (backend == WCUSER_InitBackend)
|
|
|
|
{
|
|
|
|
if (WCCURSES_InitBackend( data ) != init_success) break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
2003-06-13 18:32:52 +02:00
|
|
|
case init_success:
|
2005-11-03 12:32:52 +01:00
|
|
|
WINECON_GetServerConfig(data);
|
2005-12-03 18:04:07 +01:00
|
|
|
data->cells = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
data->curcfg.sb_width * data->curcfg.sb_height * sizeof(CHAR_INFO));
|
2017-05-17 22:20:40 +02:00
|
|
|
if (!data->cells) goto error;
|
2005-12-03 18:04:07 +01:00
|
|
|
data->fnResizeScreenBuffer(data);
|
|
|
|
data->fnComputePositions(data);
|
2005-11-03 12:32:52 +01:00
|
|
|
WINECON_SetConfig(data, &cfg);
|
2002-09-04 20:41:52 +02:00
|
|
|
data->curcfg.registry = cfg.registry;
|
|
|
|
WINECON_DumpConfig("fint", &data->curcfg);
|
2020-07-20 15:38:50 +02:00
|
|
|
|
|
|
|
memset(&input_params, 0, sizeof(input_params));
|
|
|
|
input_params.mask = SET_CONSOLE_INPUT_INFO_WIN;
|
|
|
|
input_params.info.win = condrv_handle(data->hWnd);
|
2020-07-30 17:15:08 +02:00
|
|
|
ret = DeviceIoControl(data->console, IOCTL_CONDRV_SET_INPUT_INFO, &input_params, sizeof(input_params),
|
2020-07-20 15:38:50 +02:00
|
|
|
NULL, 0, NULL, NULL);
|
|
|
|
if (!ret) goto error;
|
|
|
|
|
2020-07-30 17:15:08 +02:00
|
|
|
ret = DeviceIoControl(data->console, IOCTL_CONDRV_SET_TITLE, (void *)appname,
|
2020-07-21 14:56:48 +02:00
|
|
|
lstrlenW(appname) * sizeof(WCHAR), NULL, 0, NULL, NULL);
|
2007-08-23 17:17:17 +02:00
|
|
|
if (!ret) goto error;
|
|
|
|
|
2020-07-30 17:15:35 +02:00
|
|
|
if (cmdline && !WINECON_Spawn(data, cmdline, con_in, con_out)) goto error;
|
|
|
|
|
|
|
|
CloseHandle(con_in);
|
|
|
|
CloseHandle(con_out);
|
2002-09-04 20:41:52 +02:00
|
|
|
return data;
|
2020-07-30 17:15:19 +02:00
|
|
|
|
2003-06-13 18:32:52 +02:00
|
|
|
case init_failed:
|
|
|
|
break;
|
2002-09-04 20:41:52 +02:00
|
|
|
}
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
|
|
error:
|
2002-09-04 20:41:52 +02:00
|
|
|
WINE_ERR("failed to init.\n");
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
WINECON_Delete(data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-03-04 03:13:25 +01:00
|
|
|
struct wc_init {
|
2003-06-13 18:32:52 +02:00
|
|
|
LPCSTR ptr;
|
2003-03-04 03:13:25 +01:00
|
|
|
enum {from_event, from_process_name} mode;
|
2003-06-13 18:32:52 +02:00
|
|
|
enum init_return (*backend)(struct inner_data*);
|
|
|
|
HANDLE event;
|
2003-03-04 03:13:25 +01:00
|
|
|
};
|
|
|
|
|
2006-10-19 19:21:17 +02:00
|
|
|
#define WINECON_CMD_SHOW_USAGE 0x10000
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
/******************************************************************
|
2003-03-04 03:13:25 +01:00
|
|
|
* WINECON_ParseOptions
|
2001-12-04 21:46:54 +01:00
|
|
|
*
|
2006-10-19 19:21:17 +02:00
|
|
|
* RETURNS
|
|
|
|
* On success: 0
|
2006-11-07 00:37:42 +01:00
|
|
|
* On error: error string id optionally with the CMD_SHOW_USAGE flag
|
2001-12-04 21:46:54 +01:00
|
|
|
*/
|
2006-10-19 19:21:17 +02:00
|
|
|
static UINT WINECON_ParseOptions(const char* lpCmdLine, struct wc_init* wci)
|
2001-11-25 01:49:36 +01:00
|
|
|
{
|
2003-03-04 03:13:25 +01:00
|
|
|
memset(wci, 0, sizeof(*wci));
|
|
|
|
wci->ptr = lpCmdLine;
|
|
|
|
wci->mode = from_process_name;
|
2007-09-26 14:21:46 +02:00
|
|
|
wci->backend = WCUSER_InitBackend;
|
2003-03-04 03:13:25 +01:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
while (*wci->ptr == ' ' || *wci->ptr == '\t') wci->ptr++;
|
|
|
|
if (wci->ptr[0] != '-') break;
|
|
|
|
if (strncmp(wci->ptr, "--use-event=", 12) == 0)
|
|
|
|
{
|
|
|
|
char* end;
|
2013-04-09 14:41:33 +02:00
|
|
|
wci->event = ULongToHandle( strtoul(wci->ptr + 12, &end, 10) );
|
2006-10-19 19:21:17 +02:00
|
|
|
if (end == wci->ptr + 12) return IDS_CMD_INVALID_EVENT_ID;
|
2003-03-04 03:13:25 +01:00
|
|
|
wci->mode = from_event;
|
|
|
|
wci->ptr = end;
|
|
|
|
}
|
|
|
|
else if (strncmp(wci->ptr, "--backend=", 10) == 0)
|
|
|
|
{
|
|
|
|
if (strncmp(wci->ptr + 10, "user", 4) == 0)
|
|
|
|
{
|
|
|
|
wci->backend = WCUSER_InitBackend;
|
|
|
|
wci->ptr += 14;
|
|
|
|
}
|
|
|
|
else if (strncmp(wci->ptr + 10, "curses", 6) == 0)
|
|
|
|
{
|
2007-09-26 14:21:46 +02:00
|
|
|
wci->backend = WCCURSES_InitBackend;
|
2003-03-04 03:13:25 +01:00
|
|
|
wci->ptr += 16;
|
|
|
|
}
|
|
|
|
else
|
2006-10-19 19:21:17 +02:00
|
|
|
return IDS_CMD_INVALID_BACKEND;
|
2003-03-04 03:13:25 +01:00
|
|
|
}
|
2013-09-30 14:31:23 +02:00
|
|
|
else if (!strncmp(wci->ptr, "--help", 6) &&
|
|
|
|
(!wci->ptr[6] || wci->ptr[6] == ' ' || wci->ptr[6] == '\t'))
|
|
|
|
return IDS_CMD_ABOUT|WINECON_CMD_SHOW_USAGE;
|
2003-03-10 20:03:33 +01:00
|
|
|
else
|
2006-10-19 19:21:17 +02:00
|
|
|
return IDS_CMD_INVALID_OPTION|WINECON_CMD_SHOW_USAGE;
|
2003-03-04 03:13:25 +01:00
|
|
|
}
|
|
|
|
|
2006-10-19 19:21:17 +02:00
|
|
|
if (wci->mode == from_event)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (*wci->ptr == ' ' || *wci->ptr == '\t') wci->ptr++;
|
2013-09-30 14:31:23 +02:00
|
|
|
if (*wci->ptr == 0) wci->ptr = "cmd";
|
2006-10-19 19:21:17 +02:00
|
|
|
|
|
|
|
return 0;
|
2001-11-25 01:49:36 +01:00
|
|
|
}
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
/******************************************************************
|
2002-05-12 01:06:32 +02:00
|
|
|
* WinMain
|
2001-11-24 00:04:58 +01:00
|
|
|
*
|
|
|
|
* wineconsole can either be started as:
|
2001-11-25 01:49:36 +01:00
|
|
|
* wineconsole --use-event=<int> used when a new console is created (AllocConsole)
|
2001-11-24 00:04:58 +01:00
|
|
|
* wineconsole <pgm> <arguments> used to start the program <pgm> from the command line in
|
|
|
|
* a freshly created console
|
2003-03-04 03:13:25 +01:00
|
|
|
* --backend=(curses|user) can also be used to select the desired backend
|
2001-11-24 00:04:58 +01:00
|
|
|
*/
|
2002-05-12 01:06:32 +02:00
|
|
|
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, INT nCmdShow)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
|
|
|
struct inner_data* data;
|
|
|
|
int ret = 1;
|
2003-03-04 03:13:25 +01:00
|
|
|
struct wc_init wci;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2020-08-17 15:08:11 +02:00
|
|
|
/* make sure we're not connected to inherited console */
|
|
|
|
FreeConsole();
|
|
|
|
|
2006-10-19 19:21:17 +02:00
|
|
|
if ((ret = WINECON_ParseOptions(lpCmdLine, &wci)) != 0)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2006-10-19 19:21:17 +02:00
|
|
|
printf_res(ret & 0xffff);
|
|
|
|
if (ret & WINECON_CMD_SHOW_USAGE)
|
|
|
|
WINECON_Usage();
|
2003-03-04 03:13:25 +01:00
|
|
|
return 0;
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
2002-09-04 20:41:52 +02:00
|
|
|
|
2003-03-04 03:13:25 +01:00
|
|
|
switch (wci.mode)
|
|
|
|
{
|
|
|
|
case from_event:
|
|
|
|
/* case of wineconsole <evt>, signal process that created us that we're up and running */
|
2020-07-30 17:15:19 +02:00
|
|
|
if (!(data = WINECON_Init(hInst, 0, NULL, wci.backend, nCmdShow, NULL))) return 1;
|
2015-07-30 07:34:34 +02:00
|
|
|
ret = !SetEvent(wci.event);
|
|
|
|
if (ret != 0) WINE_ERR("SetEvent failed.\n");
|
2003-03-04 03:13:25 +01:00
|
|
|
break;
|
|
|
|
case from_process_name:
|
|
|
|
{
|
2015-04-08 08:08:08 +02:00
|
|
|
int len;
|
|
|
|
WCHAR *buffer;
|
2003-03-04 03:13:25 +01:00
|
|
|
|
2015-04-08 08:08:08 +02:00
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, wci.ptr, -1, NULL, 0);
|
|
|
|
|
|
|
|
buffer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!buffer)
|
2015-07-30 07:34:34 +02:00
|
|
|
return 1;
|
2015-04-08 08:08:08 +02:00
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, wci.ptr, -1, buffer, len);
|
2003-03-04 03:13:25 +01:00
|
|
|
|
2020-07-30 17:15:19 +02:00
|
|
|
data = WINECON_Init(hInst, GetCurrentProcessId(), buffer, wci.backend, nCmdShow, buffer);
|
2015-04-08 08:08:08 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
2020-07-30 17:15:19 +02:00
|
|
|
if (!data) return 1;
|
2003-03-04 03:13:25 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2015-07-30 07:34:34 +02:00
|
|
|
return 1;
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
2015-07-30 07:34:34 +02:00
|
|
|
if (!ret)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2015-09-24 04:34:57 +02:00
|
|
|
DWORD exitcode;
|
|
|
|
|
|
|
|
WINE_TRACE("calling MainLoop.\n");
|
|
|
|
ret = data->fnMainLoop(data);
|
|
|
|
|
|
|
|
if (!ret && data->hProcess &&
|
|
|
|
WaitForSingleObject(data->hProcess, INFINITE) == WAIT_OBJECT_0 &&
|
|
|
|
GetExitCodeProcess(data->hProcess, &exitcode))
|
|
|
|
{
|
|
|
|
WINE_TRACE("forwarding exitcode %u from child process\n", exitcode);
|
|
|
|
ret = exitcode;
|
|
|
|
}
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
2002-06-25 01:00:47 +02:00
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
WINECON_Delete(data);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|