winevdm: Build with msvcrt.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2021-09-27 12:31:50 +02:00
parent c1b3d6eb10
commit cd3e6db5a5
2 changed files with 18 additions and 80 deletions

View file

@ -1,7 +1,7 @@
MODULE = winevdm.exe MODULE = winevdm.exe
IMPORTS = user32 kernel comctl32 IMPORTS = user32 kernel comctl32
EXTRADLLFLAGS = -mwindows -mcygwin EXTRADLLFLAGS = -mwindows
C_SRCS = \ C_SRCS = \
winevdm.c winevdm.c

View file

@ -18,20 +18,18 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include "config.h"
#include "wine/port.h"
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "wine/winbase16.h" #include "wine/winbase16.h"
#include "winuser.h" #include "winuser.h"
#include "wincon.h" #include "wincon.h"
#include "commctrl.h" #include "commctrl.h"
#include "wine/unicode.h"
#include "wine/debug.h" #include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(winevdm); WINE_DEFAULT_DEBUG_CHANNEL(winevdm);
@ -106,75 +104,32 @@ typedef struct {
#include "poppack.h" #include "poppack.h"
/***********************************************************************
* find_dosbox
*/
static char *find_dosbox(void)
{
const char *envpath = getenv( "PATH" );
struct stat st;
char *path, *p, *buffer, *dir;
size_t envpath_len;
if (!envpath) return NULL;
envpath_len = strlen( envpath );
path = HeapAlloc( GetProcessHeap(), 0, envpath_len + 1 );
buffer = HeapAlloc( GetProcessHeap(), 0, envpath_len + strlen(DOSBOX) + 2 );
strcpy( path, envpath );
p = path;
while (*p)
{
while (*p == ':') p++;
if (!*p) break;
dir = p;
while (*p && *p != ':') p++;
if (*p == ':') *p++ = 0;
strcpy( buffer, dir );
strcat( buffer, "/" DOSBOX );
if (!stat( buffer, &st ))
{
HeapFree( GetProcessHeap(), 0, path );
return buffer;
}
}
HeapFree( GetProcessHeap(), 0, buffer );
HeapFree( GetProcessHeap(), 0, path );
return NULL;
}
/*********************************************************************** /***********************************************************************
* start_dosbox * start_dosbox
*/ */
static void start_dosbox( const char *appname, const char *args ) static void start_dosbox( const char *appname, const char *args )
{ {
static const WCHAR cfgW[] = {'c','f','g',0}; const WCHAR *config_dir = _wgetenv( L"WINECONFIGDIR" );
const char *home = getenv( "HOME" );
const char *prefix = getenv( "WINEPREFIX" );
WCHAR path[MAX_PATH], config[MAX_PATH]; WCHAR path[MAX_PATH], config[MAX_PATH];
HANDLE file; HANDLE file;
char *p, *buffer, app[MAX_PATH]; char *p, *prefix, *buffer, app[MAX_PATH];
int i, len; int i;
int ret = 1; NTSTATUS ret = STATUS_OBJECT_NAME_NOT_FOUND;
DWORD written, drives = GetLogicalDrives(); DWORD written, drives = GetLogicalDrives();
char *dosbox = find_dosbox();
if (!dosbox) return; if (!config_dir || !(prefix = wine_get_unix_file_name( config_dir ))) return;
if (!GetTempPathW( MAX_PATH, path )) return; if (!GetTempPathW( MAX_PATH, path )) return;
if (!GetTempFileNameW( path, cfgW, 0, config )) return; if (!GetTempFileNameW( path, L"cfg", 0, config )) return;
if (!GetCurrentDirectoryW( MAX_PATH, path )) return; if (!GetCurrentDirectoryW( MAX_PATH, path )) return;
if (!GetShortPathNameA( appname, app, MAX_PATH )) return; if (!GetShortPathNameA( appname, app, MAX_PATH )) return;
GetShortPathNameW( path, path, MAX_PATH ); GetShortPathNameW( path, path, MAX_PATH );
file = CreateFileW( config, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 ); file = CreateFileW( config, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
if (file == INVALID_HANDLE_VALUE) return; if (file == INVALID_HANDLE_VALUE) return;
len = prefix ? strlen(prefix) : strlen(home) + strlen("/.wine");
buffer = HeapAlloc( GetProcessHeap(), 0, sizeof("[autoexec]") + buffer = HeapAlloc( GetProcessHeap(), 0, sizeof("[autoexec]") +
sizeof("mount -z c") + sizeof("config -securemode") + sizeof("mount -z c") + sizeof("config -securemode") +
25 * (len + sizeof("mount c /dosdevices/c:")) + 26 * (strlen(prefix) + sizeof("mount c /dosdevices/c:")) +
4 * strlenW( path ) + 4 * lstrlenW( path ) +
6 + strlen( app ) + strlen( args ) + 20 ); 6 + strlen( app ) + strlen( args ) + 20 );
p = buffer; p = buffer;
p += sprintf( p, "[autoexec]\n" ); p += sprintf( p, "[autoexec]\n" );
@ -187,13 +142,10 @@ static void start_dosbox( const char *appname, const char *args )
for (i = 0; i <= 25; i++) for (i = 0; i <= 25; i++)
{ {
if (!(drives & (1 << i))) continue; if (!(drives & (1 << i))) continue;
if (prefix) p += sprintf( p, "mount %c %s/dosdevices/%c:\n", 'a' + i, prefix, 'a' + i );
p += sprintf( p, "mount %c %s/dosdevices/%c:\n", 'a' + i, prefix, 'a' + i );
else
p += sprintf( p, "mount %c %s/.wine/dosdevices/%c:\n", 'a' + i, home, 'a' + i );
} }
p += sprintf( p, "%c:\ncd ", path[0] ); p += sprintf( p, "%c:\ncd ", path[0] );
p += WideCharToMultiByte( CP_UNIXCP, 0, path + 2, -1, p, 4 * strlenW(path), NULL, NULL ) - 1; p += WideCharToMultiByte( CP_UNIXCP, 0, path + 2, -1, p, 4 * lstrlenW(path), NULL, NULL ) - 1;
p += sprintf( p, "\nconfig -securemode\n" ); p += sprintf( p, "\nconfig -securemode\n" );
p += sprintf( p, "%s %s\n", app, args ); p += sprintf( p, "%s %s\n", app, args );
p += sprintf( p, "exit\n" ); p += sprintf( p, "exit\n" );
@ -201,30 +153,21 @@ static void start_dosbox( const char *appname, const char *args )
{ {
const char *args[5]; const char *args[5];
char *config_file = wine_get_unix_file_name( config ); char *config_file = wine_get_unix_file_name( config );
args[0] = dosbox; args[0] = DOSBOX;
args[1] = "-userconf"; args[1] = "-userconf";
args[2] = "-conf"; args[2] = "-conf";
args[3] = config_file; args[3] = config_file;
args[4] = NULL; args[4] = NULL;
ret = _spawnvp( _P_WAIT, args[0], args ); ret = __wine_unix_spawnvp( (char **)args, TRUE );
} }
CloseHandle( file ); CloseHandle( file );
DeleteFileW( config ); DeleteFileW( config );
HeapFree( GetProcessHeap(), 0, buffer ); HeapFree( GetProcessHeap(), 0, buffer );
if (FAILED(ret)) MESSAGE( "winevdm: %s is a DOS application, you need to install DOSBox.\n", appname );
ExitProcess( ret ); ExitProcess( ret );
} }
/***********************************************************************
* start_dos_exe
*/
static void start_dos_exe( LPCSTR filename, LPCSTR cmdline )
{
start_dosbox( filename, cmdline );
WINE_MESSAGE( "winevdm: %s is a DOS application, you need to install DOSBox.\n", filename );
ExitProcess(1);
}
/*********************************************************************** /***********************************************************************
* read_pif_file * read_pif_file
*pif386rec_tu *pif386rec_tu
@ -367,7 +310,7 @@ static VOID pif_cmd( char *filename, char *cmdline)
* - hot key's * - hot key's
* - etc. * - etc.
*/ */
start_dos_exe( progpath, cmdline ); start_dosbox( progpath, cmdline );
} }
/*********************************************************************** /***********************************************************************
@ -561,13 +504,8 @@ int main( int argc, char *argv[] )
if( ( p = strrchr( appname, '.' )) && !strcasecmp( p, ".pif")) if( ( p = strrchr( appname, '.' )) && !strcasecmp( p, ".pif"))
pif_cmd( appname, cmdline + 1); pif_cmd( appname, cmdline + 1);
else else
{
/* try DOS format */ /* try DOS format */
/* loader expects arguments to be regular C strings */ start_dosbox( appname, cmdline + 1 );
start_dos_exe( appname, cmdline + 1 );
}
/* if we get back here it failed */
instance = GetLastError();
} }
WINE_MESSAGE( "winevdm: can't exec '%s': ", appname ); WINE_MESSAGE( "winevdm: can't exec '%s': ", appname );