[Scummvm-git-logs] scummvm master -> 1071f48be31a7b5d3ff0b254520c4499c1a004a0
sluicebox
22204938+sluicebox at users.noreply.github.com
Tue Jun 29 17:38:14 UTC 2021
This automated email contains information about 14 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
4cf7f1fc80 CONFIGURE: Add --enable-windows-unicode
1f253b805c CREATE_PROJECT: Add --use-windows-unicode
863747bc96 WIN32: Use MAX_PATH (260) instead of MAXPATHLEN (256)
fbf16c5a58 WIN32: Make WindowsFilesystemNode UNICODE compatible
ee5162078e WIN32: Make OSystem_Win32 UNICODE compatible
7deb79efab WIN32: Make Win32Plugin UNICODE compatible
abc3c36c37 WIN32: Make WindowsSaveFileManager UNICODE compatible
e592afe160 WIN32: Make StdioStream UNICODE compatible
544ab5a25b WIN32: Make MidiDriver_WIN UNICODE compatible
c5604b20e4 WIN32: Make WindowsTextToSpeechManager UNICODE compatible
eda2cc6b71 WIN32: Make Win32ResourceArchive UNICODE compatible
d9df1919d5 WIN32: Make Win32AudioCDManager UNICODE compatible
8b9bc17334 WIN32: Make Win32TaskbarManager UNICODE compatible
1071f48be3 WIN32: Make main() arguments UNICODE compatible
Commit: 4cf7f1fc8095600f0ea4217e1b8b42a478e933f8
https://github.com/scummvm/scummvm/commit/4cf7f1fc8095600f0ea4217e1b8b42a478e933f8
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2021-06-29T12:38:01-05:00
Commit Message:
CONFIGURE: Add --enable-windows-unicode
Changed paths:
configure
diff --git a/configure b/configure
index 2a5ebf04b7..803cf56692 100755
--- a/configure
+++ b/configure
@@ -221,6 +221,7 @@ _optimization_level=
_default_optimization_level=-O2
_nuked_opl=yes
_builtin_resources=yes
+_windows_unicode=no
# Default commands
_ranlib=ranlib
_strip=strip
@@ -906,6 +907,8 @@ Optional Features:
you are doing!
--no-builtin-resources do not include additional resources (e.g. engine data, fonts)
into the ScummVM binary
+ --enable-windows-unicode use Windows Unicode APIs
+ --disable-windows-unicode use Windows ANSI APIs (default)
Optional Libraries:
--with-alsa-prefix=DIR prefix where alsa is installed (optional)
@@ -1376,6 +1379,12 @@ for ac_option in $@; do
--no-builtin-resources)
_builtin_resources=no
;;
+ --enable-windows-unicode)
+ _windows_unicode=yes
+ ;;
+ --disable-windows-unicode)
+ _windows_unicode=no
+ ;;
--with-sdl-prefix=*)
arg=`echo $ac_option | cut -d '=' -f 2`
_sdlpath="$arg:$arg/bin"
@@ -6024,6 +6033,11 @@ case $_host_os in
# append_var LDFLAGS "-Wl,--retain-symbols-file,ds.syms"
fi
;;
+ mingw*)
+ if test "$_windows_unicode" = yes; then
+ append_var DEFINES "-DUNICODE -D_UNICODE"
+ fi
+ ;;
riscos)
append_var CXXFLAGS "-mno-poke-function-name"
append_var CXXFLAGS "-ffunction-sections"
Commit: 1f253b805cc76559e060d086ba3f3f63831bf850
https://github.com/scummvm/scummvm/commit/1f253b805cc76559e060d086ba3f3f63831bf850
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2021-06-29T12:38:01-05:00
Commit Message:
CREATE_PROJECT: Add --use-windows-unicode
Changed paths:
devtools/create_project/create_project.cpp
devtools/create_project/create_project.h
devtools/create_project/msbuild.cpp
diff --git a/devtools/create_project/create_project.cpp b/devtools/create_project/create_project.cpp
index 015d739efc..895ec1b99e 100644
--- a/devtools/create_project/create_project.cpp
+++ b/devtools/create_project/create_project.cpp
@@ -289,6 +289,10 @@ int main(int argc, char *argv[]) {
setup.useSDL2 = false;
} else if (!std::strcmp(argv[i], "--use-canonical-lib-names")) {
setup.useCanonicalLibNames = true;
+ } else if (!std::strcmp(argv[i], "--use-windows-unicode")) {
+ setup.useWindowsUnicode = true;
+ } else if (!std::strcmp(argv[i], "--use-windows-ansi")) {
+ setup.useWindowsUnicode = false;
} else {
std::cerr << "ERROR: Unknown parameter \"" << argv[i] << "\"\n";
return -1;
@@ -724,6 +728,10 @@ void displayHelp(const char *exe) {
" --use-canonical-lib-names Use canonical library names for linking. This makes it easy to use\n"
" e.g. vcpkg-provided libraries\n"
" (default: false)\n"
+ " --use-windows-unicode Use Windows Unicode APIs\n"
+ " (default: false)\n"
+ " --use-windows-ansi Use Windows ANSI APIs\n"
+ " (default: true)\n"
"\n"
"Engines settings:\n"
" --list-engines list all available engines and their default state\n"
diff --git a/devtools/create_project/create_project.h b/devtools/create_project/create_project.h
index f58eddb08a..75e96ab1aa 100644
--- a/devtools/create_project/create_project.h
+++ b/devtools/create_project/create_project.h
@@ -245,6 +245,7 @@ struct BuildSetup {
bool useSDL2; ///< Whether to use SDL2 or not.
bool useCanonicalLibNames; ///< Whether to use canonical libraries names or default ones
bool useStaticDetection; ///< Whether to link detection features inside the executable or not.
+ bool useWindowsUnicode; ///< Whether to use Windows Unicode APIs or ANSI APIs.
BuildSetup() {
devTools = false;
@@ -254,6 +255,7 @@ struct BuildSetup {
useSDL2 = true;
useCanonicalLibNames = false;
useStaticDetection = true;
+ useWindowsUnicode = false;
}
bool featureEnabled(std::string feature) const;
diff --git a/devtools/create_project/msbuild.cpp b/devtools/create_project/msbuild.cpp
index 9ca46568fd..4db49eab31 100644
--- a/devtools/create_project/msbuild.cpp
+++ b/devtools/create_project/msbuild.cpp
@@ -65,6 +65,7 @@ inline void outputConfigurationType(const BuildSetup &setup, std::ostream &proje
project << "\t\t<ConfigurationType>StaticLibrary</ConfigurationType>\n";
}
project << "\t\t<PlatformToolset>" << (config == "LLVM" ? msvc.toolsetLLVM : msvc.toolsetMSVC ) << "</PlatformToolset>\n";
+ project << "\t\t<CharacterSet>" << (setup.useWindowsUnicode ? "Unicode" : "NotSet") << "</CharacterSet>\n";
if (msvc.version >= 16 && config == "Analysis") {
project << "\t\t<EnableASAN>true</EnableASAN>\n";
}
Commit: 863747bc9696c721c0a1d03807b28a632cc679a0
https://github.com/scummvm/scummvm/commit/863747bc9696c721c0a1d03807b28a632cc679a0
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2021-06-29T12:38:01-05:00
Commit Message:
WIN32: Use MAX_PATH (260) instead of MAXPATHLEN (256)
Changed paths:
backends/platform/sdl/win32/win32.cpp
backends/saves/windows/windows-saves.cpp
engines/engine.cpp
diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp
index 3116617ab6..da806681d4 100644
--- a/backends/platform/sdl/win32/win32.cpp
+++ b/backends/platform/sdl/win32/win32.cpp
@@ -232,7 +232,7 @@ Common::String OSystem_Win32::getScreenshotsPath() {
}
// Use the My Pictures folder.
- char picturesPath[MAXPATHLEN];
+ char picturesPath[MAX_PATH];
if (SHGetFolderPathFunc(NULL, CSIDL_MYPICTURES, NULL, SHGFP_TYPE_CURRENT, picturesPath) != S_OK) {
warning("Unable to access My Pictures directory");
@@ -252,7 +252,7 @@ Common::String OSystem_Win32::getScreenshotsPath() {
}
Common::String OSystem_Win32::getDefaultConfigFileName() {
- char configFile[MAXPATHLEN];
+ char configFile[MAX_PATH];
// Use the Application Data directory of the user profile.
if (SHGetFolderPathFunc(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, configFile) == S_OK) {
@@ -267,9 +267,9 @@ Common::String OSystem_Win32::getDefaultConfigFileName() {
FILE *tmp = NULL;
if ((tmp = fopen(configFile, "r")) == NULL) {
// Check windows directory
- char oldConfigFile[MAXPATHLEN];
- uint ret = GetWindowsDirectory(oldConfigFile, MAXPATHLEN);
- if (ret == 0 || ret > MAXPATHLEN)
+ char oldConfigFile[MAX_PATH];
+ uint ret = GetWindowsDirectory(oldConfigFile, MAX_PATH);
+ if (ret == 0 || ret > MAX_PATH)
error("Cannot retrieve the path of the Windows directory");
strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE);
@@ -284,8 +284,8 @@ Common::String OSystem_Win32::getDefaultConfigFileName() {
} else {
warning("Unable to access application data directory");
// Check windows directory
- uint ret = GetWindowsDirectory(configFile, MAXPATHLEN);
- if (ret == 0 || ret > MAXPATHLEN)
+ uint ret = GetWindowsDirectory(configFile, MAX_PATH);
+ if (ret == 0 || ret > MAX_PATH)
error("Cannot retrieve the path of the Windows directory");
strcat(configFile, "\\" DEFAULT_CONFIG_FILE);
@@ -295,7 +295,7 @@ Common::String OSystem_Win32::getDefaultConfigFileName() {
}
Common::String OSystem_Win32::getDefaultLogFileName() {
- char logFile[MAXPATHLEN];
+ char logFile[MAX_PATH];
// Use the Application Data directory of the user profile.
if (SHGetFolderPathFunc(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, logFile) != S_OK) {
diff --git a/backends/saves/windows/windows-saves.cpp b/backends/saves/windows/windows-saves.cpp
index b206fa5e99..8528ed544e 100644
--- a/backends/saves/windows/windows-saves.cpp
+++ b/backends/saves/windows/windows-saves.cpp
@@ -36,7 +36,7 @@
#include "backends/platform/sdl/win32/win32_wrapper.h"
WindowsSaveFileManager::WindowsSaveFileManager() {
- char defaultSavepath[MAXPATHLEN];
+ char defaultSavepath[MAX_PATH];
// Use the Application Data directory of the user profile.
diff --git a/engines/engine.cpp b/engines/engine.cpp
index 45d69a4012..19c6ca1d74 100644
--- a/engines/engine.cpp
+++ b/engines/engine.cpp
@@ -483,19 +483,19 @@ void Engine::checkCD() {
// If we can find a compressed audio track, then it should be ok even
// if it's running from CD.
- char buffer[MAXPATHLEN];
+ char buffer[MAX_PATH];
int i;
const Common::FSNode gameDataDir(ConfMan.get("path"));
if (gameDataDir.getPath().empty()) {
// That's it! I give up!
- if (getcwd(buffer, MAXPATHLEN) == NULL)
+ if (getcwd(buffer, MAX_PATH) == NULL)
return;
} else
Common::strlcpy(buffer, gameDataDir.getPath().c_str(), sizeof(buffer));
- for (i = 0; i < MAXPATHLEN - 1; i++) {
+ for (i = 0; i < MAX_PATH - 1; i++) {
if (buffer[i] == '\\')
break;
}
Commit: fbf16c5a58eee1e2449ab1aac73bd6706d9bbfb2
https://github.com/scummvm/scummvm/commit/fbf16c5a58eee1e2449ab1aac73bd6706d9bbfb2
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2021-06-29T12:38:01-05:00
Commit Message:
WIN32: Make WindowsFilesystemNode UNICODE compatible
Changed paths:
backends/fs/windows/windows-fs.cpp
backends/fs/windows/windows-fs.h
diff --git a/backends/fs/windows/windows-fs.cpp b/backends/fs/windows/windows-fs.cpp
index face198430..b12af4018d 100644
--- a/backends/fs/windows/windows-fs.cpp
+++ b/backends/fs/windows/windows-fs.cpp
@@ -44,40 +44,40 @@
#endif
bool WindowsFilesystemNode::exists() const {
- return _access(_path.c_str(), F_OK) == 0;
+ return _taccess(charToTchar(_path.c_str()), F_OK) == 0;
}
bool WindowsFilesystemNode::isReadable() const {
- return _access(_path.c_str(), R_OK) == 0;
+ return _taccess(charToTchar(_path.c_str()), R_OK) == 0;
}
bool WindowsFilesystemNode::isWritable() const {
- return _access(_path.c_str(), W_OK) == 0;
+ return _taccess(charToTchar(_path.c_str()), W_OK) == 0;
}
void WindowsFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const char *base, bool hidden, WIN32_FIND_DATA* find_data) {
- WindowsFilesystemNode entry;
- char *asciiName = toAscii(find_data->cFileName);
- bool isDirectory;
-
// Skip local directory (.) and parent (..)
- if (!strcmp(asciiName, ".") || !strcmp(asciiName, ".."))
+ if (!_tcscmp(find_data->cFileName, TEXT(".")) ||
+ !_tcscmp(find_data->cFileName, TEXT("..")))
return;
// Skip hidden files if asked
if ((find_data->dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) && !hidden)
return;
- isDirectory = (find_data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? true : false);
+ bool isDirectory = ((find_data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? true : false);
if ((!isDirectory && mode == Common::FSNode::kListDirectoriesOnly) ||
(isDirectory && mode == Common::FSNode::kListFilesOnly))
return;
+ const char *fileName = tcharToChar(find_data->cFileName);
+
+ WindowsFilesystemNode entry;
entry._isDirectory = isDirectory;
- entry._displayName = asciiName;
+ entry._displayName = fileName;
entry._path = base;
- entry._path += asciiName;
+ entry._path += fileName;
if (entry._isDirectory)
entry._path += "\\";
entry._isValid = true;
@@ -86,23 +86,23 @@ void WindowsFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const c
list.push_back(new WindowsFilesystemNode(entry));
}
-char* WindowsFilesystemNode::toAscii(TCHAR *str) {
+const char* WindowsFilesystemNode::tcharToChar(const TCHAR *str) {
#ifndef UNICODE
- return (char *)str;
+ return str;
#else
- static char asciiString[MAX_PATH];
- WideCharToMultiByte(CP_ACP, 0, str, _tcslen(str) + 1, asciiString, sizeof(asciiString), NULL, NULL);
- return asciiString;
+ static char multiByteString[MAX_PATH];
+ WideCharToMultiByte(CP_UTF8, 0, str, _tcslen(str) + 1, multiByteString, MAX_PATH, NULL, NULL);
+ return multiByteString;
#endif
}
-const TCHAR* WindowsFilesystemNode::toUnicode(const char *str) {
+const TCHAR* WindowsFilesystemNode::charToTchar(const char *str) {
#ifndef UNICODE
- return (const TCHAR *)str;
+ return str;
#else
- static TCHAR unicodeString[MAX_PATH];
- MultiByteToWideChar(CP_ACP, 0, str, strlen(str) + 1, unicodeString, sizeof(unicodeString) / sizeof(TCHAR));
- return unicodeString;
+ static wchar_t wideCharString[MAX_PATH];
+ MultiByteToWideChar(CP_UTF8, 0, str, strlen(str) + 1, wideCharString, MAX_PATH);
+ return wideCharString;
#endif
}
@@ -116,9 +116,9 @@ WindowsFilesystemNode::WindowsFilesystemNode() {
WindowsFilesystemNode::WindowsFilesystemNode(const Common::String &p, const bool currentDir) {
if (currentDir) {
- char path[MAX_PATH];
+ TCHAR path[MAX_PATH];
GetCurrentDirectory(MAX_PATH, path);
- _path = path;
+ _path = tcharToChar(path);
} else {
assert(p.size() > 0);
_path = p;
@@ -133,7 +133,7 @@ WindowsFilesystemNode::WindowsFilesystemNode(const Common::String &p, const bool
void WindowsFilesystemNode::setFlags() {
// Check whether it is a directory, and whether the file actually exists
- DWORD fileAttribs = GetFileAttributes(toUnicode(_path.c_str()));
+ DWORD fileAttribs = GetFileAttributes(charToTchar(_path.c_str()));
if (fileAttribs == INVALID_FILE_ATTRIBUTES) {
_isDirectory = false;
@@ -175,13 +175,13 @@ bool WindowsFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, b
WindowsFilesystemNode entry;
char drive_name[2];
- drive_name[0] = toAscii(current_drive)[0];
+ drive_name[0] = tcharToChar(current_drive)[0];
drive_name[1] = '\0';
entry._displayName = drive_name;
entry._isDirectory = true;
entry._isValid = true;
entry._isPseudoRoot = false;
- entry._path = toAscii(current_drive);
+ entry._path = tcharToChar(current_drive);
myList.push_back(new WindowsFilesystemNode(entry));
}
} else {
@@ -192,7 +192,7 @@ bool WindowsFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, b
sprintf(searchPath, "%s*", _path.c_str());
- handle = FindFirstFile(toUnicode(searchPath), &desc);
+ handle = FindFirstFile(charToTchar(searchPath), &desc);
if (handle == INVALID_HANDLE_VALUE)
return false;
@@ -239,7 +239,7 @@ Common::WriteStream *WindowsFilesystemNode::createWriteStream() {
}
bool WindowsFilesystemNode::createDirectory() {
- if (CreateDirectory(toUnicode(_path.c_str()), NULL) != 0)
+ if (CreateDirectory(charToTchar(_path.c_str()), NULL) != 0)
setFlags();
return _isValid && _isDirectory;
diff --git a/backends/fs/windows/windows-fs.h b/backends/fs/windows/windows-fs.h
index 8a73dd73e4..aba5f75a89 100644
--- a/backends/fs/windows/windows-fs.h
+++ b/backends/fs/windows/windows-fs.h
@@ -96,20 +96,26 @@ private:
static void addFile(AbstractFSList &list, ListMode mode, const char *base, bool hidden, WIN32_FIND_DATA* find_data);
/**
- * Converts a Unicode string to Ascii format.
+ * Converts a string of TCHARs returned from a Windows API function to
+ * a character string. If UNICODE is defined then the incoming string
+ * is wide characters and is converted to UTF8, otherwise the incoming
+ * string is returned with no conversion.
*
- * @param str Common::String to convert from Unicode to Ascii.
- * @return str in Ascii format.
+ * @param str String to convert if UNICODE is defined
+ * @return str in UTF8 format if UNICODE is defined, otherwise just str
*/
- static char *toAscii(TCHAR *str);
+ static const char *tcharToChar(const TCHAR *str);
/**
- * Converts an Ascii string to Unicode format.
+ * Converts a character string to a string of TCHARs for passing
+ * to a Windows API function. If UNICODE is defined then the incoming
+ * string is converted from UTF8 to wide characters, otherwise the incoming
+ * string is returned with no conversion.
*
- * @param str Common::String to convert from Ascii to Unicode.
- * @return str in Unicode format.
+ * @param str String to convert if UNICODE is defined
+ * @return str in wide character format if UNICODE is defined, otherwise just str
*/
- static const TCHAR* toUnicode(const char *str);
+ static const TCHAR* charToTchar(const char *str);
/**
* Tests and sets the _isValid and _isDirectory flags, using the GetFileAttributes() function.
Commit: ee5162078e36a74b71e85b71ca1c97d3bab94904
https://github.com/scummvm/scummvm/commit/ee5162078e36a74b71e85b71ca1c97d3bab94904
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2021-06-29T12:38:01-05:00
Commit Message:
WIN32: Make OSystem_Win32 UNICODE compatible
Changed paths:
backends/platform/sdl/win32/win32.cpp
backends/platform/sdl/win32/win32_wrapper.cpp
backends/platform/sdl/win32/win32_wrapper.h
diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp
index da806681d4..667e58df1d 100644
--- a/backends/platform/sdl/win32/win32.cpp
+++ b/backends/platform/sdl/win32/win32.cpp
@@ -33,7 +33,7 @@
#define _WIN32_IE 0x500
#endif
#include <shlobj.h>
-#include <wchar.h>
+#include <tchar.h>
#include "common/scummsys.h"
#include "common/config-manager.h"
@@ -106,7 +106,7 @@ void OSystem_Win32::initBackend() {
freopen("CONOUT$","w",stdout);
freopen("CONOUT$","w",stderr);
}
- SetConsoleTitle("ScummVM Status Window");
+ SetConsoleTitle(TEXT("ScummVM Status Window"));
} else {
FreeConsole();
}
@@ -152,9 +152,12 @@ bool OSystem_Win32::displayLogFile() {
// Try opening the log file with the default text editor
// log files should be registered as "txtfile" by default and thus open in the default text editor
- HINSTANCE shellExec = ShellExecute(getHwnd(), NULL, _logFilePath.c_str(), NULL, NULL, SW_SHOWNORMAL);
- if ((intptr_t)shellExec > 32)
+ TCHAR *tLogFilePath = Win32::stringToTchar(_logFilePath);
+ HINSTANCE shellExec = ShellExecute(getHwnd(), NULL, tLogFilePath, NULL, NULL, SW_SHOWNORMAL);
+ if ((intptr_t)shellExec > 32) {
+ free(tLogFilePath);
return true;
+ }
// ShellExecute with the default verb failed, try the "Open with..." dialog
PROCESS_INFORMATION processInformation;
@@ -163,8 +166,8 @@ bool OSystem_Win32::displayLogFile() {
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
- char cmdLine[MAX_PATH * 2]; // CreateProcess may change the contents of cmdLine
- sprintf(cmdLine, "rundll32 shell32.dll,OpenAs_RunDLL %s", _logFilePath.c_str());
+ TCHAR cmdLine[MAX_PATH * 2]; // CreateProcess may change the contents of cmdLine
+ _stprintf(cmdLine, TEXT("rundll32 shell32.dll,OpenAs_RunDLL %s"), tLogFilePath);
BOOL result = CreateProcess(NULL,
cmdLine,
NULL,
@@ -175,6 +178,7 @@ bool OSystem_Win32::displayLogFile() {
NULL,
&startupInfo,
&processInformation);
+ free(tLogFilePath);
if (result) {
CloseHandle(processInformation.hProcess);
CloseHandle(processInformation.hThread);
@@ -185,7 +189,9 @@ bool OSystem_Win32::displayLogFile() {
}
bool OSystem_Win32::openUrl(const Common::String &url) {
- HINSTANCE result = ShellExecute(getHwnd(), NULL, /*(wchar_t*)nativeFilePath.utf16()*/url.c_str(), NULL, NULL, SW_SHOWNORMAL);
+ TCHAR *tUrl = Win32::stringToTchar(url);
+ HINSTANCE result = ShellExecute(getHwnd(), NULL, tUrl, NULL, NULL, SW_SHOWNORMAL);
+ free(tUrl);
// ShellExecute returns a value greater than 32 if successful
if ((intptr_t)result <= 32) {
warning("ShellExecute failed: error = %p", (void*)result);
@@ -207,14 +213,14 @@ Common::String OSystem_Win32::getSystemLanguage() const {
// We can not use "setlocale" (at least not for MSVC builds), since it
// will return locales like: "English_USA.1252", thus we need a special
// way to determine the locale string for Win32.
- char langName[9];
- char ctryName[9];
+ TCHAR langName[9];
+ TCHAR ctryName[9];
- if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME, langName, sizeof(langName)) != 0 &&
- GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, ctryName, sizeof(ctryName)) != 0) {
- Common::String localeName = langName;
+ if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME, langName, ARRAYSIZE(langName)) != 0 &&
+ GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, ctryName, ARRAYSIZE(ctryName)) != 0) {
+ Common::String localeName = Win32::tcharToString(langName);
localeName += "_";
- localeName += ctryName;
+ localeName += Win32::tcharToString(ctryName);
return localeName;
}
@@ -232,49 +238,49 @@ Common::String OSystem_Win32::getScreenshotsPath() {
}
// Use the My Pictures folder.
- char picturesPath[MAX_PATH];
+ TCHAR picturesPath[MAX_PATH];
if (SHGetFolderPathFunc(NULL, CSIDL_MYPICTURES, NULL, SHGFP_TYPE_CURRENT, picturesPath) != S_OK) {
warning("Unable to access My Pictures directory");
return Common::String();
}
- screenshotsPath = Common::String(picturesPath) + "\\ScummVM Screenshots\\";
+ _tcscat(picturesPath, TEXT("\\ScummVM Screenshots\\"));
// 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(screenshotsPath.c_str(), NULL)) {
+ if (!CreateDirectory(picturesPath, NULL)) {
if (GetLastError() != ERROR_ALREADY_EXISTS)
error("Cannot create ScummVM Screenshots folder");
}
- return screenshotsPath;
+ return Win32::tcharToString(picturesPath);
}
Common::String OSystem_Win32::getDefaultConfigFileName() {
- char configFile[MAX_PATH];
+ TCHAR configFile[MAX_PATH];
// Use the Application Data directory of the user profile.
if (SHGetFolderPathFunc(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, configFile) == S_OK) {
- strcat(configFile, "\\ScummVM");
+ _tcscat(configFile, TEXT("\\ScummVM"));
if (!CreateDirectory(configFile, NULL)) {
if (GetLastError() != ERROR_ALREADY_EXISTS)
error("Cannot create ScummVM application data folder");
}
- strcat(configFile, "\\" DEFAULT_CONFIG_FILE);
+ _tcscat(configFile, TEXT("\\" DEFAULT_CONFIG_FILE));
FILE *tmp = NULL;
- if ((tmp = fopen(configFile, "r")) == NULL) {
+ if ((tmp = _tfopen(configFile, TEXT("r"))) == NULL) {
// Check windows directory
- char oldConfigFile[MAX_PATH];
+ TCHAR oldConfigFile[MAX_PATH];
uint ret = GetWindowsDirectory(oldConfigFile, MAX_PATH);
if (ret == 0 || ret > MAX_PATH)
error("Cannot retrieve the path of the Windows directory");
- strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE);
- if ((tmp = fopen(oldConfigFile, "r"))) {
- strcpy(configFile, oldConfigFile);
+ _tcscat(oldConfigFile, TEXT("\\" DEFAULT_CONFIG_FILE));
+ if ((tmp = _tfopen(oldConfigFile, TEXT("r")))) {
+ _tcscpy(configFile, oldConfigFile);
fclose(tmp);
}
@@ -288,14 +294,14 @@ Common::String OSystem_Win32::getDefaultConfigFileName() {
if (ret == 0 || ret > MAX_PATH)
error("Cannot retrieve the path of the Windows directory");
- strcat(configFile, "\\" DEFAULT_CONFIG_FILE);
+ _tcscat(configFile, TEXT("\\" DEFAULT_CONFIG_FILE));
}
- return configFile;
+ return Win32::tcharToString(configFile);
}
Common::String OSystem_Win32::getDefaultLogFileName() {
- char logFile[MAX_PATH];
+ TCHAR logFile[MAX_PATH];
// Use the Application Data directory of the user profile.
if (SHGetFolderPathFunc(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, logFile) != S_OK) {
@@ -303,13 +309,13 @@ Common::String OSystem_Win32::getDefaultLogFileName() {
return Common::String();
}
- strcat(logFile, "\\ScummVM");
+ _tcscat(logFile, TEXT("\\ScummVM"));
CreateDirectory(logFile, NULL);
- strcat(logFile, "\\Logs");
+ _tcscat(logFile, TEXT("\\Logs"));
CreateDirectory(logFile, NULL);
- strcat(logFile, "\\scummvm.log");
+ _tcscat(logFile, TEXT("\\scummvm.log"));
- return logFile;
+ return Win32::tcharToString(logFile);
}
namespace {
diff --git a/backends/platform/sdl/win32/win32_wrapper.cpp b/backends/platform/sdl/win32/win32_wrapper.cpp
index c188ad999e..4ed76754f9 100644
--- a/backends/platform/sdl/win32/win32_wrapper.cpp
+++ b/backends/platform/sdl/win32/win32_wrapper.cpp
@@ -53,10 +53,16 @@ BOOL VerifyVersionInfoFunc(LPOSVERSIONINFOEXA lpVersionInformation, DWORD dwType
return verifyVersionInfo(lpVersionInformation, dwTypeMask, dwlConditionMask);
}
-HRESULT SHGetFolderPathFunc(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPSTR pszPath) {
- typedef HRESULT (WINAPI *SHGetFolderPathFunc)(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPSTR pszPath);
-
- SHGetFolderPathFunc pSHGetFolderPath = (SHGetFolderPathFunc)(void *)GetProcAddress(GetModuleHandle(TEXT("shell32.dll")), "SHGetFolderPathA");
+HRESULT SHGetFolderPathFunc(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath) {
+ typedef HRESULT (WINAPI *SHGetFolderPathFunc)(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath);
+
+ SHGetFolderPathFunc pSHGetFolderPath = (SHGetFolderPathFunc)(void *)GetProcAddress(GetModuleHandle(TEXT("shell32.dll")),
+#ifndef UNICODE
+ "SHGetFolderPathA"
+#else
+ "SHGetFolderPathW"
+#endif
+ );
if (pSHGetFolderPath)
return pSHGetFolderPath(hwnd, csidl, hToken, dwFlags, pszPath);
@@ -80,7 +86,12 @@ bool confirmWindowsVersion(int majorVersion, int minorVersion) {
return VerifyVersionInfoFunc(&versionInfo, VER_MAJORVERSION | VER_MINORVERSION, conditionMask);
}
-wchar_t *ansiToUnicode(const char *s, uint codePage) {
+wchar_t *ansiToUnicode(const char *s) {
+#ifndef UNICODE
+ uint codePage = CP_ACP;
+#else
+ uint codePage = CP_UTF8;
+#endif
DWORD size = MultiByteToWideChar(codePage, 0, s, -1, NULL, 0);
if (size > 0) {
@@ -92,7 +103,12 @@ wchar_t *ansiToUnicode(const char *s, uint codePage) {
return NULL;
}
-char *unicodeToAnsi(const wchar_t *s, uint codePage) {
+char *unicodeToAnsi(const wchar_t *s) {
+#ifndef UNICODE
+ uint codePage = CP_ACP;
+#else
+ uint codePage = CP_UTF8;
+#endif
DWORD size = WideCharToMultiByte(codePage, 0, s, -1, NULL, 0, 0, 0);
if (size > 0) {
@@ -104,4 +120,25 @@ char *unicodeToAnsi(const wchar_t *s, uint codePage) {
return NULL;
}
+TCHAR *stringToTchar(const Common::String& s) {
+#ifndef UNICODE
+ char *t = (char *)malloc(s.size() + 1);
+ strcpy(t, s.c_str());
+ return t;
+#else
+ return ansiToUnicode(s.c_str());
+#endif
+}
+
+Common::String tcharToString(const TCHAR *t) {
+#ifndef UNICODE
+ return t;
+#else
+ char *utf8 = unicodeToAnsi(t);
+ Common::String s = utf8;
+ free(utf8);
+ return s;
+#endif
+}
+
}
diff --git a/backends/platform/sdl/win32/win32_wrapper.h b/backends/platform/sdl/win32/win32_wrapper.h
index ee3b77bed6..f16ecaad67 100644
--- a/backends/platform/sdl/win32/win32_wrapper.h
+++ b/backends/platform/sdl/win32/win32_wrapper.h
@@ -24,8 +24,9 @@
#define PLATFORM_SDL_WIN32_WRAPPER_H
#include "common/scummsys.h"
+#include "common/str.h"
-HRESULT SHGetFolderPathFunc(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPSTR pszPath);
+HRESULT SHGetFolderPathFunc(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath);
// Helper functions
namespace Win32 {
@@ -41,25 +42,50 @@ bool confirmWindowsVersion(int majorVersion, int minorVersion);
/**
* Converts a C string into a Windows wide-character string.
* Used to interact with Win32 Unicode APIs with no ANSI fallback.
+ * If UNICODE is defined then the conversion will use code page CP_UTF8,
+ * otherwise CP_ACP will be used.
*
* @param s Source string
- * @param c Code Page, by default is CP_ACP (default Windows ANSI code page)
* @return Converted string
*
* @note Return value must be freed by the caller.
*/
-wchar_t *ansiToUnicode(const char *s, uint codePage = CP_ACP);
+wchar_t *ansiToUnicode(const char *s);
/**
* Converts a Windows wide-character string into a C string.
* Used to interact with Win32 Unicode APIs with no ANSI fallback.
+ * If UNICODE is defined then the conversion will use code page CP_UTF8,
+ * otherwise CP_ACP will be used.
*
* @param s Source string
- * @param c Code Page, by default is CP_ACP (default Windows ANSI code page)
* @return Converted string
*
* @note Return value must be freed by the caller.
*/
-char *unicodeToAnsi(const wchar_t *s, uint codePage = CP_ACP);
+char *unicodeToAnsi(const wchar_t *s);
+
+/**
+ * Converts a Common::String to a TCHAR array for the purpose of passing to
+ * a Windows API or CRT call. If UNICODE is defined then the string will be
+ * converted from UTF8 to to wide characters, otherwise the character array
+ * will be copied with no conversion.
+ *
+ * @param s Source string
+ * @return Converted string
+ *
+ * @note Return value must be freed by the caller.
+ */
+TCHAR *stringToTchar(const Common::String& s);
+
+/**
+ * Converts a TCHAR array returned from a Windows API or CRT call to a Common::String.
+ * If UNICODE is defined then the wide character array will be converted to UTF8,
+ * otherwise the char array will be copied with no conversion.
+ *
+ * @param s Source string
+ * @return Converted string
+ */
+Common::String tcharToString(const TCHAR *s);
}
Commit: 7deb79efabb4ac10bd6a5bff22b8445598a84d8b
https://github.com/scummvm/scummvm/commit/7deb79efabb4ac10bd6a5bff22b8445598a84d8b
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2021-06-29T12:38:01-05:00
Commit Message:
WIN32: Make Win32Plugin UNICODE compatible
Changed paths:
backends/plugins/win32/win32-provider.cpp
diff --git a/backends/plugins/win32/win32-provider.cpp b/backends/plugins/win32/win32-provider.cpp
index 848a3f935c..87aecca8b9 100644
--- a/backends/plugins/win32/win32-provider.cpp
+++ b/backends/plugins/win32/win32-provider.cpp
@@ -24,6 +24,7 @@
#if defined(DYNAMIC_MODULES) && defined(_WIN32)
+#include "backends/platform/sdl/win32/win32_wrapper.h"
#include "backends/plugins/win32/win32-provider.h"
#include "backends/plugins/dynamic-plugin.h"
#include "common/debug.h"
@@ -34,23 +35,11 @@
class Win32Plugin final : public DynamicPlugin {
-private:
- static const TCHAR* toUnicode(const char *x) {
- #ifndef UNICODE
- return (const TCHAR *)x;
- #else
- static TCHAR unicodeString[MAX_PATH];
- MultiByteToWideChar(CP_ACP, 0, x, strlen(x) + 1, unicodeString, sizeof(unicodeString) / sizeof(TCHAR));
- return unicodeString;
- #endif
- }
-
-
protected:
void *_dlHandle;
virtual VoidFunc findSymbol(const char *symbol) override {
- FARPROC func = GetProcAddress((HMODULE)_dlHandle, toUnicode(symbol));
+ FARPROC func = GetProcAddress((HMODULE)_dlHandle, symbol);
if (!func)
debug("Failed loading symbol '%s' from plugin '%s'", symbol, _filename.c_str());
@@ -63,7 +52,9 @@ public:
virtual bool loadPlugin() override {
assert(!_dlHandle);
- _dlHandle = LoadLibrary(toUnicode(_filename.c_str()));
+ TCHAR *tFilename = Win32::stringToTchar(_filename);
+ _dlHandle = LoadLibrary(tFilename);
+ free(tFilename);
if (!_dlHandle) {
debug("Failed loading plugin '%s' (error code %d)", _filename.c_str(), (int32) GetLastError());
Commit: abc3c36c37cec740a31e0525b5b528b6e535cdc0
https://github.com/scummvm/scummvm/commit/abc3c36c37cec740a31e0525b5b528b6e535cdc0
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2021-06-29T12:38:01-05:00
Commit Message:
WIN32: Make WindowsSaveFileManager UNICODE compatible
Changed paths:
backends/saves/windows/windows-saves.cpp
diff --git a/backends/saves/windows/windows-saves.cpp b/backends/saves/windows/windows-saves.cpp
index 8528ed544e..4488f1db6f 100644
--- a/backends/saves/windows/windows-saves.cpp
+++ b/backends/saves/windows/windows-saves.cpp
@@ -24,6 +24,7 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
+#include <tchar.h>
#if defined(__GNUC__) && defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
// required for SHGFP_TYPE_CURRENT in shlobj.h
#define _WIN32_IE 0x500
@@ -36,24 +37,23 @@
#include "backends/platform/sdl/win32/win32_wrapper.h"
WindowsSaveFileManager::WindowsSaveFileManager() {
- char defaultSavepath[MAX_PATH];
-
+ TCHAR defaultSavepath[MAX_PATH];
// Use the Application Data directory of the user profile.
if (SHGetFolderPathFunc(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, defaultSavepath) == S_OK) {
- strcat(defaultSavepath, "\\ScummVM");
+ _tcscat(defaultSavepath, TEXT("\\ScummVM"));
if (!CreateDirectory(defaultSavepath, NULL)) {
if (GetLastError() != ERROR_ALREADY_EXISTS)
error("Cannot create ScummVM application data folder");
}
- strcat(defaultSavepath, "\\Saved games");
+ _tcscat(defaultSavepath, TEXT("\\Saved games"));
if (!CreateDirectory(defaultSavepath, NULL)) {
if (GetLastError() != ERROR_ALREADY_EXISTS)
error("Cannot create ScummVM Saved games folder");
}
- ConfMan.registerDefault("savepath", defaultSavepath);
+ ConfMan.registerDefault("savepath", Win32::tcharToString(defaultSavepath));
} else {
warning("Unable to access application data directory");
}
Commit: e592afe160c80e4f7e93cabdc7be19c712da4964
https://github.com/scummvm/scummvm/commit/e592afe160c80e4f7e93cabdc7be19c712da4964
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2021-06-29T12:38:01-05:00
Commit Message:
WIN32: Make StdioStream UNICODE compatible
Changed paths:
backends/fs/stdiostream.cpp
diff --git a/backends/fs/stdiostream.cpp b/backends/fs/stdiostream.cpp
index 5f3b5cd267..5eebc6d0f9 100644
--- a/backends/fs/stdiostream.cpp
+++ b/backends/fs/stdiostream.cpp
@@ -27,6 +27,13 @@
#include "backends/fs/stdiostream.h"
+// for Windows unicode fopen(): _wfopen()
+#if defined(WIN32) && defined(UNICODE)
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include "backends/platform/sdl/win32/win32_wrapper.h"
+#endif
+
StdioStream::StdioStream(void *handle) : _handle(handle) {
assert(handle);
}
@@ -85,7 +92,13 @@ bool StdioStream::flush() {
}
StdioStream *StdioStream::makeFromPath(const Common::String &path, bool writeMode) {
+#if defined(WIN32) && defined(UNICODE)
+ wchar_t *wPath = Win32::stringToTchar(path);
+ FILE *handle = _wfopen(wPath, writeMode ? L"wb" : L"rb");
+ free(wPath);
+#else
FILE *handle = fopen(path.c_str(), writeMode ? "wb" : "rb");
+#endif
if (handle)
return new StdioStream(handle);
Commit: 544ab5a25be558f609ef1fb9ae493421ff9d672b
https://github.com/scummvm/scummvm/commit/544ab5a25be558f609ef1fb9ae493421ff9d672b
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2021-06-29T12:38:01-05:00
Commit Message:
WIN32: Make MidiDriver_WIN UNICODE compatible
Changed paths:
backends/midi/windows.cpp
diff --git a/backends/midi/windows.cpp b/backends/midi/windows.cpp
index 41450ae32a..03793f7e3d 100644
--- a/backends/midi/windows.cpp
+++ b/backends/midi/windows.cpp
@@ -32,6 +32,7 @@
#include "audio/musicplugin.h"
#include "audio/mpu401.h"
+#include "backends/platform/sdl/win32/win32_wrapper.h"
#include "common/config-manager.h"
#include "common/translation.h"
#include "common/textconsole.h"
@@ -151,10 +152,11 @@ void MidiDriver_WIN::sysEx(const byte *msg, uint16 length) {
}
void MidiDriver_WIN::check_error(MMRESULT result) {
- char buf[200];
+ TCHAR buf[MAXERRORLENGTH];
if (result != MMSYSERR_NOERROR) {
- midiOutGetErrorText(result, buf, 200);
- warning("MM System Error '%s'", buf);
+ midiOutGetErrorText(result, buf, MAXERRORLENGTH);
+ Common::String errorMessage = Win32::tcharToString(buf);
+ warning("MM System Error '%s'", errorMessage.c_str());
}
}
@@ -184,7 +186,8 @@ MusicDevices WindowsMusicPlugin::getDevices() const {
for (int i = 0; i < numDevs; i++) {
if (midiOutGetDevCaps(i, &tmp, sizeof(MIDIOUTCAPS)) != MMSYSERR_NOERROR)
break;
- deviceNames.push_back(tmp.szPname);
+ Common::String deviceName = Win32::tcharToString(tmp.szPname);
+ deviceNames.push_back(deviceName);
}
// Limit us to the number of actually retrieved devices.
Commit: c5604b20e46c2eb9dca17dfe3a961f984a0ad460
https://github.com/scummvm/scummvm/commit/c5604b20e46c2eb9dca17dfe3a961f984a0ad460
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2021-06-29T12:38:01-05:00
Commit Message:
WIN32: Make WindowsTextToSpeechManager UNICODE compatible
Changed paths:
backends/text-to-speech/windows/windows-text-to-speech.cpp
diff --git a/backends/text-to-speech/windows/windows-text-to-speech.cpp b/backends/text-to-speech/windows/windows-text-to-speech.cpp
index b5a1963bb0..599d8aab45 100644
--- a/backends/text-to-speech/windows/windows-text-to-speech.cpp
+++ b/backends/text-to-speech/windows/windows-text-to-speech.cpp
@@ -416,10 +416,10 @@ void WindowsTextToSpeechManager::createVoice(void *cpVoiceToken) {
}
Common::String WindowsTextToSpeechManager::lcidToLocale(LCID locale) {
- int nchars = GetLocaleInfoA(locale, LOCALE_SISO639LANGNAME, NULL, 0);
- char *languageCode = new char[nchars];
- GetLocaleInfoA(locale, LOCALE_SISO639LANGNAME, languageCode, nchars);
- Common::String result = languageCode;
+ int nchars = GetLocaleInfo(locale, LOCALE_SISO639LANGNAME, NULL, 0);
+ TCHAR *languageCode = new TCHAR[nchars];
+ GetLocaleInfo(locale, LOCALE_SISO639LANGNAME, languageCode, nchars);
+ Common::String result = Win32::tcharToString(languageCode);
delete[] languageCode;
return result;
}
Commit: eda2cc6b71a33df42cad5578621a0e803fdd40f3
https://github.com/scummvm/scummvm/commit/eda2cc6b71a33df42cad5578621a0e803fdd40f3
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2021-06-29T12:38:01-05:00
Commit Message:
WIN32: Make Win32ResourceArchive UNICODE compatible
Changed paths:
backends/platform/sdl/win32/win32.cpp
diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp
index 667e58df1d..026dadb2d2 100644
--- a/backends/platform/sdl/win32/win32.cpp
+++ b/backends/platform/sdl/win32/win32.cpp
@@ -340,7 +340,8 @@ BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName
return TRUE;
Win32ResourceArchive *arch = (Win32ResourceArchive *)lParam;
- arch->_files.push_back(lpszName);
+ Common::String filename = Win32::tcharToString(lpszName);
+ arch->_files.push_back(filename);
return TRUE;
}
@@ -371,7 +372,9 @@ const Common::ArchiveMemberPtr Win32ResourceArchive::getMember(const Common::Str
}
Common::SeekableReadStream *Win32ResourceArchive::createReadStreamForMember(const Common::String &name) const {
- HRSRC resource = FindResource(NULL, name.c_str(), MAKEINTRESOURCE(256));
+ TCHAR *tName = Win32::stringToTchar(name);
+ HRSRC resource = FindResource(NULL, tName, MAKEINTRESOURCE(256));
+ free(tName);
if (resource == NULL)
return 0;
Commit: d9df1919d5e51353fddad7c8e2dd3f9b99a6e7e0
https://github.com/scummvm/scummvm/commit/d9df1919d5e51353fddad7c8e2dd3f9b99a6e7e0
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2021-06-29T12:38:01-05:00
Commit Message:
WIN32: Make Win32AudioCDManager UNICODE compatible
Changed paths:
backends/audiocd/win32/win32-audiocd.cpp
backends/platform/sdl/win32/win32_wrapper.cpp
backends/platform/sdl/win32/win32_wrapper.h
engines/engine.cpp
diff --git a/backends/audiocd/win32/win32-audiocd.cpp b/backends/audiocd/win32/win32-audiocd.cpp
index 5d72daf6d2..a90e3a7a43 100644
--- a/backends/audiocd/win32/win32-audiocd.cpp
+++ b/backends/audiocd/win32/win32-audiocd.cpp
@@ -52,6 +52,7 @@
#include "audio/audiostream.h"
#include "backends/audiocd/audiocd-stream.h"
#include "backends/audiocd/default/default-audiocd.h"
+#include "backends/platform/sdl/win32/win32_wrapper.h"
#include "common/array.h"
#include "common/config-manager.h"
#include "common/debug.h"
@@ -197,7 +198,9 @@ bool Win32AudioCDManager::openCD(int drive) {
// Construct the drive path and try to open it
Common::String drivePath = Common::String::format("\\\\.\\%c:", drives[drive]);
- _driveHandle = CreateFileA(drivePath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
+ TCHAR *tDrivePath = Win32::stringToTchar(drivePath);
+ _driveHandle = CreateFile(tDrivePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
+ free(tDrivePath);
if (_driveHandle == INVALID_HANDLE_VALUE) {
warning("Failed to open drive %c:\\, error %d", drives[drive], (int)GetLastError());
return false;
@@ -228,7 +231,9 @@ bool Win32AudioCDManager::openCD(const Common::String &drive) {
// Construct the drive path and try to open it
Common::String drivePath = Common::String::format("\\\\.\\%c:", drives[0]);
- _driveHandle = CreateFileA(drivePath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
+ TCHAR *tDrivePath = Win32::stringToTchar(drivePath);
+ _driveHandle = CreateFile(tDrivePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
+ free(tDrivePath);
if (_driveHandle == INVALID_HANDLE_VALUE) {
warning("Failed to open drive %c:\\, error %d", drives[0], (int)GetLastError());
return false;
@@ -355,8 +360,10 @@ Win32AudioCDManager::DriveList Win32AudioCDManager::detectDrives() {
char gameDrive = 0;
if (ConfMan.hasKey("path")) {
Common::String gamePath = ConfMan.get("path");
- char fullPath[MAX_PATH];
- DWORD result = GetFullPathNameA(gamePath.c_str(), sizeof(fullPath), fullPath, 0);
+ TCHAR *tGamePath = Win32::stringToTchar(gamePath);
+ TCHAR fullPath[MAX_PATH];
+ DWORD result = GetFullPathName(tGamePath, MAX_PATH, fullPath, 0);
+ free(tGamePath);
if (result > 0 && result < sizeof(fullPath) && Common::isAlpha(fullPath[0]) && fullPath[1] == ':' && tryAddDrive(toupper(fullPath[0]), drives))
gameDrive = drives[0];
@@ -371,11 +378,9 @@ Win32AudioCDManager::DriveList Win32AudioCDManager::detectDrives() {
}
bool Win32AudioCDManager::tryAddDrive(char drive, DriveList &drives) {
- Common::String drivePath = Common::String::format("%c:\\", drive);
-
- // Ensure it's an actual CD drive
- if (GetDriveTypeA(drivePath.c_str()) != DRIVE_CDROM)
+ if (!Win32::isDriveCD(drive)) {
return false;
+ }
debug(2, "Detected drive %c:\\ as a CD drive", drive);
drives.push_back(drive);
diff --git a/backends/platform/sdl/win32/win32_wrapper.cpp b/backends/platform/sdl/win32/win32_wrapper.cpp
index 4ed76754f9..94db0372b7 100644
--- a/backends/platform/sdl/win32/win32_wrapper.cpp
+++ b/backends/platform/sdl/win32/win32_wrapper.cpp
@@ -86,6 +86,13 @@ bool confirmWindowsVersion(int majorVersion, int minorVersion) {
return VerifyVersionInfoFunc(&versionInfo, VER_MAJORVERSION | VER_MINORVERSION, conditionMask);
}
+bool isDriveCD(char driveLetter) {
+ TCHAR drivePath[] = TEXT("x:\\");
+ drivePath[0] = (TCHAR)driveLetter;
+
+ return (GetDriveType(drivePath) == DRIVE_CDROM);
+}
+
wchar_t *ansiToUnicode(const char *s) {
#ifndef UNICODE
uint codePage = CP_ACP;
diff --git a/backends/platform/sdl/win32/win32_wrapper.h b/backends/platform/sdl/win32/win32_wrapper.h
index f16ecaad67..fc6bf21122 100644
--- a/backends/platform/sdl/win32/win32_wrapper.h
+++ b/backends/platform/sdl/win32/win32_wrapper.h
@@ -39,6 +39,14 @@ namespace Win32 {
* @param minorVersion The minor version number (0.x)
*/
bool confirmWindowsVersion(int majorVersion, int minorVersion);
+
+/**
+ * Returns true if the drive letter is a CDROM
+ *
+ * @param driveLetter The drive letter to test
+ */
+bool isDriveCD(char driveLetter);
+
/**
* Converts a C string into a Windows wide-character string.
* Used to interact with Win32 Unicode APIs with no ANSI fallback.
diff --git a/engines/engine.cpp b/engines/engine.cpp
index 19c6ca1d74..06991c1c25 100644
--- a/engines/engine.cpp
+++ b/engines/engine.cpp
@@ -20,12 +20,10 @@
*
*/
-#define FORBIDDEN_SYMBOL_EXCEPTION_getcwd
-
#if defined(WIN32) && !defined(__SYMBIAN32__)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-#include <direct.h>
+#include "backends/platform/sdl/win32/win32_wrapper.h"
#endif
#include "engines/engine.h"
@@ -483,26 +481,21 @@ void Engine::checkCD() {
// If we can find a compressed audio track, then it should be ok even
// if it's running from CD.
- char buffer[MAX_PATH];
- int i;
-
+ char driveLetter;
const Common::FSNode gameDataDir(ConfMan.get("path"));
-
- if (gameDataDir.getPath().empty()) {
+ if (!gameDataDir.getPath().empty()) {
+ driveLetter = gameDataDir.getPath()[0];
+ } else {
// That's it! I give up!
- if (getcwd(buffer, MAX_PATH) == NULL)
+ Common::FSNode currentDir(".");
+ if (!currentDir.getPath().empty()) {
+ driveLetter = currentDir.getPath()[0];
+ } else {
return;
- } else
- Common::strlcpy(buffer, gameDataDir.getPath().c_str(), sizeof(buffer));
-
- for (i = 0; i < MAX_PATH - 1; i++) {
- if (buffer[i] == '\\')
- break;
+ }
}
- buffer[i + 1] = 0;
-
- if (GetDriveType(buffer) == DRIVE_CDROM) {
+ if (Win32::isDriveCD(driveLetter)) {
GUI::MessageDialog dialog(
_("You appear to be playing this game directly\n"
"from the CD. This is known to cause problems,\n"
Commit: 8b9bc17334bf31d8c4ccf992bbd06a38ca0abbe1
https://github.com/scummvm/scummvm/commit/8b9bc17334bf31d8c4ccf992bbd06a38ca0abbe1
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2021-06-29T12:38:01-05:00
Commit Message:
WIN32: Make Win32TaskbarManager UNICODE compatible
Changed paths:
backends/taskbar/win32/win32-taskbar.cpp
diff --git a/backends/taskbar/win32/win32-taskbar.cpp b/backends/taskbar/win32/win32-taskbar.cpp
index f738e277a6..c8d2f04106 100644
--- a/backends/taskbar/win32/win32-taskbar.cpp
+++ b/backends/taskbar/win32/win32-taskbar.cpp
@@ -58,6 +58,7 @@
#endif
#include <shlobj.h>
+#include <tchar.h>
#include "common/scummsys.h"
@@ -118,11 +119,13 @@ void Win32TaskbarManager::setOverlayIcon(const Common::String &name, const Commo
}
// Compute full icon path
- Common::String path = getIconPath(name, ".ico");
- if (path.empty())
+ Common::String iconPath = getIconPath(name, ".ico");
+ if (iconPath.empty())
return;
- HICON pIcon = (HICON)::LoadImage(NULL, path.c_str(), IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
+ TCHAR *tIconPath = Win32::stringToTchar(iconPath);
+ HICON pIcon = (HICON)::LoadImage(NULL, tIconPath, IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
+ free(tIconPath);
if (!pIcon) {
warning("[Win32TaskbarManager::setOverlayIcon] Cannot load icon!");
return;
@@ -216,7 +219,7 @@ void Win32TaskbarManager::setCount(int count) {
lFont.lfHeight = 10;
lFont.lfWeight = FW_BOLD;
lFont.lfItalic = 1;
- strcpy(lFont.lfFaceName, "Arial");
+ _tcscpy(lFont.lfFaceName, TEXT("Arial"));
HFONT hFont = CreateFontIndirect(&lFont);
SelectObject(hMemDC, hFont);
@@ -225,7 +228,9 @@ void Win32TaskbarManager::setCount(int count) {
SetRect(&rect, 4, 4, 12, 12);
SetTextColor(hMemDC, RGB(48, 48, 48));
SetBkMode(hMemDC, TRANSPARENT);
- DrawText(hMemDC, countString.c_str(), -1, &rect, DT_NOCLIP|DT_CENTER);
+ TCHAR *tCountString = Win32::stringToTchar(countString);
+ DrawText(hMemDC, tCountString, -1, &rect, DT_NOCLIP|DT_CENTER);
+ free(tCountString);
// Set the text alpha to fully opaque (we consider the data inside the text rect)
DWORD *lpdwPixel = (DWORD *)lpBits;
Commit: 1071f48be31a7b5d3ff0b254520c4499c1a004a0
https://github.com/scummvm/scummvm/commit/1071f48be31a7b5d3ff0b254520c4499c1a004a0
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2021-06-29T12:38:01-05:00
Commit Message:
WIN32: Make main() arguments UNICODE compatible
Changed paths:
backends/platform/sdl/win32/win32-main.cpp
backends/platform/sdl/win32/win32_wrapper.cpp
backends/platform/sdl/win32/win32_wrapper.h
diff --git a/backends/platform/sdl/win32/win32-main.cpp b/backends/platform/sdl/win32/win32-main.cpp
index afbab212c0..1464955345 100644
--- a/backends/platform/sdl/win32/win32-main.cpp
+++ b/backends/platform/sdl/win32/win32-main.cpp
@@ -35,6 +35,7 @@
#include <windows.h>
#include "backends/platform/sdl/win32/win32.h"
+#include "backends/platform/sdl/win32/win32_wrapper.h"
#include "backends/plugins/sdl/sdl-provider.h"
#include "base/main.h"
@@ -56,6 +57,10 @@ int __stdcall WinMain(HINSTANCE /*hInst*/, HINSTANCE /*hPrevInst*/, LPSTR /*lpC
}
int main(int argc, char *argv[]) {
+#ifdef UNICODE
+ argv = Win32::getArgvUtf8(&argc);
+#endif
+
// Create our OSystem instance
g_system = new OSystem_Win32();
assert(g_system);
@@ -73,6 +78,10 @@ int main(int argc, char *argv[]) {
// Free OSystem
g_system->destroy();
+#ifdef UNICODE
+ Win32::freeArgvUtf8(argc, argv);
+#endif
+
return res;
}
diff --git a/backends/platform/sdl/win32/win32_wrapper.cpp b/backends/platform/sdl/win32/win32_wrapper.cpp
index 94db0372b7..00ce8fe75c 100644
--- a/backends/platform/sdl/win32/win32_wrapper.cpp
+++ b/backends/platform/sdl/win32/win32_wrapper.cpp
@@ -22,6 +22,7 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
+#include <shellapi.h> // for CommandLineToArgvW()
#if defined(__GNUC__) && defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
// required for SHGetSpecialFolderPath in shlobj.h
#define _WIN32_IE 0x400
@@ -148,4 +149,28 @@ Common::String tcharToString(const TCHAR *t) {
#endif
}
+#ifdef UNICODE
+char **getArgvUtf8(int *argc) {
+ // get command line arguments in wide-character
+ LPWSTR *wargv = CommandLineToArgvW(GetCommandLineW(), argc);
+
+ // convert each argument to utf8
+ char **argv = (char **)malloc((*argc + 1) * sizeof(char *));
+ for (int i = 0; i < *argc; ++i) {
+ argv[i] = Win32::unicodeToAnsi(wargv[i]);
+ }
+ argv[*argc] = NULL; // null terminated array
+
+ LocalFree(wargv);
+ return argv;
+}
+
+void freeArgvUtf8(int argc, char **argv) {
+ for (int i = 0; i < argc; ++i) {
+ free(argv[i]);
+ }
+ free(argv);
+}
+#endif
+
}
diff --git a/backends/platform/sdl/win32/win32_wrapper.h b/backends/platform/sdl/win32/win32_wrapper.h
index fc6bf21122..8b6411b155 100644
--- a/backends/platform/sdl/win32/win32_wrapper.h
+++ b/backends/platform/sdl/win32/win32_wrapper.h
@@ -95,6 +95,26 @@ TCHAR *stringToTchar(const Common::String& s);
*/
Common::String tcharToString(const TCHAR *s);
+#ifdef UNICODE
+/**
+ * Returns command line arguments in argc / argv format in UTF8.
+ *
+ * @param argc argument count
+ * @return argument array
+ *
+ * @note Return value must be freed by the caller with freeArgvUtf8()
+ */
+char **getArgvUtf8(int *argc);
+
+/**
+ * Frees an argument array created by getArgvUtf8()
+ *
+ * @param argc argument count in argv
+ * @param argv argument array created by getArgvUtf8()
+ */
+void freeArgvUtf8(int argc, char **argv);
+#endif
+
}
#endif
More information about the Scummvm-git-logs
mailing list