Ticket #7792: console.diff

File console.diff, 6.1 KB (added by Kirben, 14 years ago)

Patch using FreeConsole()

  • README

     
    924924  -z, --list-games         Display list of supported games and exit
    925925  -t, --list-targets       Display list of configured targets and exit
    926926  --list-saves=TARGET      Display a list of savegames for the game (TARGET) specified
     927  --no-console             Disable the console window (Windows only)
    927928
    928929  -c, --config=CONFIG      Use alternate configuration file
    929930  -p, --path=PATH          Path to where the game is installed
     
    19551956
    19561957    confirm_exit    bool     Ask for confirmation by the user before quitting
    19571958                             (SDL backend only).
     1959    no_console      bool     Disable the console window (Windows only).
    19581960    cdrom           number   Number of CD-ROM unit to use for audio. If
    19591961                             negative, don't even try to access the CD-ROM.
    19601962    joystick_num    number   Number of joystick device to use for input
  • backends/platform/sdl/sdl.cpp

     
    116116}
    117117#endif
    118118
    119 #if defined(WIN32)
    120         struct SdlConsoleHidingWin32 {
    121                 DWORD myPid;
    122                 DWORD myTid;
    123                 HWND consoleHandle;
    124         };
     119#if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
     120static Common::String getLogPath() {
     121        char appDataPath[MAXPATHLEN];
     122        OSVERSIONINFO win32OsVersion;
     123        ZeroMemory(&win32OsVersion, sizeof(OSVERSIONINFO));
     124        win32OsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
     125        GetVersionEx(&win32OsVersion);
     126        // Check for non-9X version of Windows.
     127        if (win32OsVersion.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) {
     128                // Use the Application Data directory of the user profile.
     129                if (win32OsVersion.dwMajorVersion >= 5) {
     130                        if (!GetEnvironmentVariable("APPDATA", appDataPath, sizeof(appDataPath)))
     131                                error("Unable to access application data directory");
     132                } else {
     133                        if (!GetEnvironmentVariable("USERPROFILE", appDataPath, sizeof(appDataPath)))
     134                                error("Unable to access user profile directory");
    125135
    126         // console hiding for win32
    127         static BOOL CALLBACK initBackendFindConsoleWin32Proc(HWND hWnd, LPARAM lParam) {
    128                 DWORD pid, tid;
    129                 SdlConsoleHidingWin32 *variables = (SdlConsoleHidingWin32 *)lParam;
    130                 tid = GetWindowThreadProcessId(hWnd, &pid);
    131                 if ((tid == variables->myTid) && (pid == variables->myPid)) {
    132                         variables->consoleHandle = hWnd;
    133                         return FALSE;
     136                        strcat(appDataPath, "\\Application Data");
     137                        CreateDirectory(appDataPath, NULL);
    134138                }
    135                 return TRUE;
     139
     140                strcat(appDataPath, "\\ScummVM");
     141                CreateDirectory(appDataPath, NULL);
     142        } else {
     143                // Use current working directory
     144                GetCurrentDirectory(MAXPATHLEN, appDataPath);
    136145        }
     146
     147        return appDataPath;
     148}
    137149#endif
    138150
    139151void OSystem_SDL::initBackend() {
     
    155167        if (joystick_num > -1)
    156168                sdlFlags |= SDL_INIT_JOYSTICK;
    157169
    158 #if 0
    159         // NEW CODE TO HIDE CONSOLE FOR WIN32
    160 #if defined(WIN32)
    161         // console hiding for win32
    162         SdlConsoleHidingWin32 consoleHidingWin32;
    163         consoleHidingWin32.consoleHandle = 0;
    164         consoleHidingWin32.myPid = GetCurrentProcessId();
    165         consoleHidingWin32.myTid = GetCurrentThreadId();
    166         EnumWindows (initBackendFindConsoleWin32Proc, (LPARAM)&consoleHidingWin32);
     170#if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
     171        if (ConfMan.getBool("no_console")) {
     172                FreeConsole();
     173                /* Redirect standard input and standard output */
     174                char STDOUT_FILE[MAX_PATH], STDERR_FILE[MAX_PATH];
    167175
    168         if (!ConfMan.getBool("show_console")) {
    169                 if (consoleHidingWin32.consoleHandle) {
    170                         // We won't find a window with our TID/PID in case we were started from command-line
    171                         ShowWindow(consoleHidingWin32.consoleHandle, SW_HIDE);
     176                strcpy(STDOUT_FILE, getLogPath().c_str());
     177                strcpy(STDERR_FILE, getLogPath().c_str());
     178                strcat(STDOUT_FILE, "\\scummvm.stdout.txt");
     179                strcat(STDERR_FILE, "\\scummvm.stderr.txt");
     180
     181                freopen(STDOUT_FILE, "w", stdout);
     182                freopen(STDERR_FILE, "w", stderr);
     183                setbuf(stdout, NULL);   /* No buffering */
     184                setbuf(stderr, NULL);   /* No buffering */
     185        } else {
     186                if (AllocConsole()) {
     187                        freopen("CONIN$","r",stdin);
     188                        freopen("CONOUT$","w",stdout);
     189                        freopen("CONOUT$","w",stderr);
    172190                }
     191                SetConsoleTitle("ScummVM Status Window");
    173192        }
    174193#endif
    175 #endif
    176194
    177195        if (SDL_Init(sdlFlags) == -1) {
    178196                error("Could not initialize SDL: %s", SDL_GetError());
  • base/commandLine.cpp

     
    6060        "  -z, --list-games         Display list of supported games and exit\n"
    6161        "  -t, --list-targets       Display list of configured targets and exit\n"
    6262        "  --list-saves=TARGET      Display a list of savegames for the game (TARGET) specified\n"
     63#if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
     64        "  --no-console             Disable the console window\n"
     65#endif
    6366        "\n"
    6467        "  -c, --config=CONFIG      Use alternate configuration file\n"
    6568        "  -p, --path=PATH          Path to where the game is installed\n"
     
    220223        ConfMan.registerDefault("record_temp_file_name", "record.tmp");
    221224        ConfMan.registerDefault("record_time_file_name", "record.time");
    222225
    223 #if 0
    224         // NEW CODE TO HIDE CONSOLE FOR WIN32
    225 #ifdef WIN32
    226         // console hiding for win32
    227         ConfMan.registerDefault("show_console", false);
     226#if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
     227        // Console window is enabled by default on Windows
     228        ConfMan.registerDefault("no_console", false);
    228229#endif
    229 #endif
    230230}
    231231
    232232//
     
    554554                        END_OPTION
    555555#endif
    556556
    557 #if 0
    558         // NEW CODE TO HIDE CONSOLE FOR WIN32
    559 #ifdef WIN32
    560                         // console hiding for win32
    561                         DO_LONG_OPTION_BOOL("show-console")
     557#if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
     558                        // Optional disabling of console window on Windows
     559                        DO_LONG_OPTION_BOOL("no-console")
    562560                        END_OPTION
    563561#endif
    564 #endif
    565562
    566563unknownOption:
    567564                        // If we get till here, the option is unhandled and hence unknown.