/*********************************************************************** * start_dosbox */ static void start_dosbox( const char *appname, const char *args ) { static const WCHAR cfgW[] = {'c','f','g',0}; const char *config_dir = wine_get_config_dir(); WCHAR path[MAX_PATH], config[MAX_PATH]; HANDLE file; char *p, *buffer, app[MAX_PATH]; int i; int ret = 1; DWORD written, drives = GetLogicalDrives(); char *dosbox = find_dosbox(); if (!dosbox) return; if (!GetTempPathW( MAX_PATH, path )) return; if (!GetTempFileNameW( path, cfgW, 0, config )) return; if (!GetCurrentDirectoryW( MAX_PATH, path )) return; if (!GetShortPathNameA( appname, app, MAX_PATH )) return; GetShortPathNameW( path, path, MAX_PATH ); file = CreateFileW( config, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 ); if (file == INVALID_HANDLE_VALUE) return; buffer = HeapAlloc( GetProcessHeap(), 0, sizeof("[autoexec]") + sizeof("mount -z c") + sizeof("config -securemode") + 25 * (strlen(config_dir) + sizeof("mount c /dosdevices/c:")) + 4 * strlenW( path ) + 6 + strlen( app ) + strlen( args ) + 20 ); p = buffer; p += sprintf( p, "[autoexec]\n" ); for (i = 25; i >= 0; i--) if (!(drives & (1 << i))) { p += sprintf( p, "mount -z %c\n", 'a' + i ); break; } for (i = 0; i <= 25; i++) if (drives & (1 << i)) p += sprintf( p, "mount %c %s/dosdevices/%c:\n", 'a' + i, config_dir, 'a' + i ); p += sprintf( p, "%c:\ncd ", path[0] ); p += WideCharToMultiByte( CP_UNIXCP, 0, path + 2, -1, p, 4 * strlenW(path), NULL, NULL ) - 1; p += sprintf( p, "\nconfig -securemode\n" ); p += sprintf( p, "%s %s\n", app, args ); p += sprintf( p, "exit\n" ); if (WriteFile( file, buffer, strlen(buffer), &written, NULL ) && written == strlen(buffer)) { const char *args[5]; char *config_file = wine_get_unix_file_name( config ); args[0] = dosbox; args[1] = "-userconf"; args[2] = "-conf"; args[3] = config_file; args[4] = NULL; ret = _spawnvp( _P_WAIT, args[0], args ); } CloseHandle( file ); DeleteFileW( config ); HeapFree( GetProcessHeap(), 0, buffer ); ExitProcess( ret ); }
/*********************************************************************** * start_dosbox */ static void start_dosbox( const char *appname, const char *args ) { static const WCHAR cfgW[] = {'c','f','g',0}; const char *config_dir = wine_get_config_dir(); WCHAR path[MAX_PATH], config[MAX_PATH]; HANDLE file; char *p, *buffer; int i; int ret = 1; DWORD written, drives = GetLogicalDrives(); char *dosbox = find_dosbox(); if (!dosbox) return; if (tolower(appname[0]) == 'z') { WINE_MESSAGE( "winevdm: Cannot start DOS application %s\n", appname ); WINE_MESSAGE( " because DOSBox doesn't support running from the Z: drive.\n" ); ExitProcess(1); } if (!GetTempPathW( MAX_PATH, path )) return; if (!GetTempFileNameW( path, cfgW, 0, config )) return; if (!GetCurrentDirectoryW( MAX_PATH, path )) return; file = CreateFileW( config, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 ); if (file == INVALID_HANDLE_VALUE) return; buffer = HeapAlloc( GetProcessHeap(), 0, sizeof("[autoexec]") + 25 * (strlen(config_dir) + sizeof("mount c /dosdevices/c:")) + 4 * strlenW( path ) + 6 + strlen( appname ) + strlen( args ) + 20 ); p = buffer; p += sprintf( p, "[autoexec]\n" ); for (i = 0; i < 25; i++) if (drives & (1 << i)) p += sprintf( p, "mount %c %s/dosdevices/%c:\n", 'a' + i, config_dir, 'a' + i ); p += sprintf( p, "%c:\ncd ", path[0] ); p += WideCharToMultiByte( CP_UNIXCP, 0, path + 2, -1, p, 4 * strlenW(path), NULL, NULL ) - 1; p += sprintf( p, "\n%s %s\n", appname, args ); p += sprintf( p, "exit\n" ); if (WriteFile( file, buffer, strlen(buffer), &written, NULL ) && written == strlen(buffer)) { const char *args[4]; char *config_file = wine_get_unix_file_name( config ); args[0] = dosbox; args[1] = "-conf"; args[2] = config_file; args[3] = NULL; ret = spawnvp( _P_WAIT, args[0], args ); } CloseHandle( file ); DeleteFileW( config ); HeapFree( GetProcessHeap(), 0, buffer ); ExitProcess( ret ); }