aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/sdl/win32
diff options
context:
space:
mode:
Diffstat (limited to 'backends/platform/sdl/win32')
-rw-r--r--backends/platform/sdl/win32/win32.cpp118
-rw-r--r--backends/platform/sdl/win32/win32.h2
2 files changed, 75 insertions, 45 deletions
diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp
index 5b14be4417..a2c8e43424 100644
--- a/backends/platform/sdl/win32/win32.cpp
+++ b/backends/platform/sdl/win32/win32.cpp
@@ -23,10 +23,6 @@
// Disable symbol overrides so that we can use system headers.
#define FORBIDDEN_SYMBOL_ALLOW_ALL
-#include "common/scummsys.h"
-#include "common/error.h"
-#include "common/textconsole.h"
-
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
@@ -34,58 +30,52 @@
#undef ARRAYSIZE // winnt.h defines ARRAYSIZE, but we want our own one...
#include <shellapi.h>
+#include "common/scummsys.h"
+#include "common/config-manager.h"
+#include "common/error.h"
+#include "common/textconsole.h"
+
+#include <SDL_syswm.h> // For setting the icon
+
#include "backends/platform/sdl/win32/win32.h"
#include "backends/fs/windows/windows-fs-factory.h"
+#include "backends/taskbar/win32/win32-taskbar.h"
#include "common/memstream.h"
#define DEFAULT_CONFIG_FILE "scummvm.ini"
-//#define HIDE_CONSOLE
+void OSystem_Win32::init() {
+ // Initialize File System Factory
+ _fsFactory = new WindowsFilesystemFactory();
-#ifdef HIDE_CONSOLE
-struct SdlConsoleHidingWin32 {
- DWORD myPid;
- DWORD myTid;
- HWND consoleHandle;
-};
+#if defined(USE_TASKBAR)
+ // Initialize taskbar manager
+ _taskbarManager = new Win32TaskbarManager();
+#endif
-// console hiding for win32
-static BOOL CALLBACK initBackendFindConsoleWin32Proc(HWND hWnd, LPARAM lParam) {
- DWORD pid, tid;
- SdlConsoleHidingWin32 *variables = (SdlConsoleHidingWin32 *)lParam;
- tid = GetWindowThreadProcessId(hWnd, &pid);
- if ((tid == variables->myTid) && (pid == variables->myPid)) {
- variables->consoleHandle = hWnd;
- return FALSE;
- }
- return TRUE;
+ // Invoke parent implementation of this method
+ OSystem_SDL::init();
}
-#endif
+void OSystem_Win32::initBackend() {
+ // Console window is enabled by default on Windows
+ ConfMan.registerDefault("console", true);
-void OSystem_Win32::init() {
-#ifdef HIDE_CONSOLE
- // console hiding for win32
- SdlConsoleHidingWin32 consoleHidingWin32;
- consoleHidingWin32.consoleHandle = 0;
- consoleHidingWin32.myPid = GetCurrentProcessId();
- consoleHidingWin32.myTid = GetCurrentThreadId();
- EnumWindows (initBackendFindConsoleWin32Proc, (LPARAM)&consoleHidingWin32);
-
- if (!ConfMan.getBool("show_console")) {
- if (consoleHidingWin32.consoleHandle) {
- // We won't find a window with our TID/PID in case we were started from command-line
- ShowWindow(consoleHidingWin32.consoleHandle, SW_HIDE);
+ // Enable or disable the window console window
+ if (ConfMan.getBool("console")) {
+ if (AllocConsole()) {
+ freopen("CONIN$","r",stdin);
+ freopen("CONOUT$","w",stdout);
+ freopen("CONOUT$","w",stderr);
}
+ SetConsoleTitle("ScummVM Status Window");
+ } else {
+ FreeConsole();
}
-#endif
-
- // Initialze File System Factory
- _fsFactory = new WindowsFilesystemFactory();
// Invoke parent implementation of this method
- OSystem_SDL::init();
+ OSystem_SDL::initBackend();
}
@@ -131,6 +121,28 @@ bool OSystem_Win32::displayLogFile() {
return false;
}
+void OSystem_Win32::setupIcon() {
+ HMODULE handle = GetModuleHandle(NULL);
+ HICON ico = LoadIcon(handle, MAKEINTRESOURCE(1001 /* IDI_ICON */));
+ if (ico) {
+ SDL_SysWMinfo wminfo;
+ SDL_VERSION(&wminfo.version);
+ if (SDL_GetWMInfo(&wminfo)) {
+ // Replace the handle to the icon associated with the window class by our custom icon
+ SetClassLongPtr(wminfo.window, GCLP_HICON, (ULONG_PTR)ico);
+
+ // Since there wasn't any default icon, we can't use the return value from SetClassLong
+ // to check for errors (it would be 0 in both cases: error or no previous value for the
+ // icon handle). Instead we check for the last-error code value.
+ if (GetLastError() == ERROR_SUCCESS)
+ return;
+ }
+ }
+
+ // If no icon has been set, fallback to default path
+ OSystem_SDL::setupIcon();
+}
+
Common::String OSystem_Win32::getDefaultConfigFileName() {
char configFile[MAXPATHLEN];
@@ -149,18 +161,31 @@ Common::String OSystem_Win32::getDefaultConfigFileName() {
error("Unable to access user profile directory");
strcat(configFile, "\\Application Data");
- CreateDirectory(configFile, NULL);
+
+ // If the directory already exists (as it should in most cases),
+ // we don't want to fail, but we need to stop on other errors (such as ERROR_PATH_NOT_FOUND)
+ if (!CreateDirectory(configFile, NULL)) {
+ if (GetLastError() != ERROR_ALREADY_EXISTS)
+ error("Cannot create Application data folder");
+ }
}
strcat(configFile, "\\ScummVM");
- CreateDirectory(configFile, NULL);
+ if (!CreateDirectory(configFile, NULL)) {
+ if (GetLastError() != ERROR_ALREADY_EXISTS)
+ error("Cannot create ScummVM application data folder");
+ }
+
strcat(configFile, "\\" DEFAULT_CONFIG_FILE);
FILE *tmp = NULL;
if ((tmp = fopen(configFile, "r")) == NULL) {
// Check windows directory
char oldConfigFile[MAXPATHLEN];
- GetWindowsDirectory(oldConfigFile, MAXPATHLEN);
+ uint ret = GetWindowsDirectory(oldConfigFile, MAXPATHLEN);
+ if (ret == 0 || ret > MAXPATHLEN)
+ error("Cannot retrieve the path of the Windows directory");
+
strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE);
if ((tmp = fopen(oldConfigFile, "r"))) {
strcpy(configFile, oldConfigFile);
@@ -172,7 +197,10 @@ Common::String OSystem_Win32::getDefaultConfigFileName() {
}
} else {
// Check windows directory
- GetWindowsDirectory(configFile, MAXPATHLEN);
+ uint ret = GetWindowsDirectory(configFile, MAXPATHLEN);
+ if (ret == 0 || ret > MAXPATHLEN)
+ error("Cannot retrieve the path of the Windows directory");
+
strcat(configFile, "\\" DEFAULT_CONFIG_FILE);
}
@@ -300,7 +328,7 @@ Common::SeekableReadStream *Win32ResourceArchive::createReadStreamForMember(cons
} // End of anonymous namespace
void OSystem_Win32::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
- s.add("Win32Res", new Win32ResourceArchive());
+ s.add("Win32Res", new Win32ResourceArchive(), priority);
OSystem_SDL::addSysArchivesToSearchSet(s, priority);
}
diff --git a/backends/platform/sdl/win32/win32.h b/backends/platform/sdl/win32/win32.h
index ef7b6af3f1..b56997a63b 100644
--- a/backends/platform/sdl/win32/win32.h
+++ b/backends/platform/sdl/win32/win32.h
@@ -28,6 +28,7 @@
class OSystem_Win32 : public OSystem_SDL {
public:
virtual void init();
+ virtual void initBackend();
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0);
@@ -46,6 +47,7 @@ protected:
*/
Common::String _logFilePath;
+ virtual void setupIcon();
virtual Common::String getDefaultConfigFileName();
virtual Common::WriteStream *createLogFile();
};