summaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
authorNiels Martin Hansen <nielsm@indvikleren.dk>2021-02-21 20:48:21 +0100
committerNiels Martin Hansen <nielsm@indvikleren.dk>2021-02-23 11:25:39 +0100
commitb427ddce887617f17aefdbe1f22ca1e00d013c3d (patch)
tree06fd938bd05dd716ba2d573978789f2c8e068505 /src/os
parentbeeb9e0a1b1c6ceb61499edeb8cd6cf7999d12ea (diff)
downloadopenttd-b427ddce887617f17aefdbe1f22ca1e00d013c3d.tar.xz
Codechange: Switch to explicit wide strings
Diffstat (limited to 'src/os')
-rw-r--r--src/os/windows/crashlog_win.cpp92
-rw-r--r--src/os/windows/font_win32.cpp52
-rw-r--r--src/os/windows/font_win32.h2
-rw-r--r--src/os/windows/win32.cpp56
-rw-r--r--src/os/windows/win32.h9
5 files changed, 101 insertions, 110 deletions
diff --git a/src/os/windows/crashlog_win.cpp b/src/os/windows/crashlog_win.cpp
index 4529491bd..b0667ad8f 100644
--- a/src/os/windows/crashlog_win.cpp
+++ b/src/os/windows/crashlog_win.cpp
@@ -150,7 +150,7 @@ static uint32 CalcCRC(byte *data, uint size, uint32 crc)
return crc;
}
-static void GetFileInfo(DebugFileInfo *dfi, const TCHAR *filename)
+static void GetFileInfo(DebugFileInfo *dfi, const wchar_t *filename)
{
HANDLE file;
memset(dfi, 0, sizeof(*dfi));
@@ -183,7 +183,7 @@ static void GetFileInfo(DebugFileInfo *dfi, const TCHAR *filename)
static char *PrintModuleInfo(char *output, const char *last, HMODULE mod)
{
- TCHAR buffer[MAX_PATH];
+ wchar_t buffer[MAX_PATH];
DebugFileInfo dfi;
GetModuleFileName(mod, buffer, MAX_PATH);
@@ -491,7 +491,7 @@ char *CrashLogWindows::AppendDecodedStacktrace(char *buffer, const char *last) c
/* virtual */ int CrashLogWindows::WriteCrashDump(char *filename, const char *filename_last) const
{
int ret = 0;
- HMODULE dbghelp = LoadLibrary(_T("dbghelp.dll"));
+ HMODULE dbghelp = LoadLibrary(L"dbghelp.dll");
if (dbghelp != nullptr) {
typedef BOOL (WINAPI *MiniDumpWriteDump_t)(HANDLE, DWORD, HANDLE,
MINIDUMP_TYPE,
@@ -553,19 +553,19 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
}
if (GamelogTestEmergency()) {
- static const TCHAR _emergency_crash[] =
- _T("A serious fault condition occurred in the game. The game will shut down.\n")
- _T("As you loaded an emergency savegame no crash information will be generated.\n");
- MessageBox(nullptr, _emergency_crash, _T("Fatal Application Failure"), MB_ICONERROR);
+ static const wchar_t _emergency_crash[] =
+ L"A serious fault condition occurred in the game. The game will shut down.\n"
+ L"As you loaded an emergency savegame no crash information will be generated.\n";
+ MessageBox(nullptr, _emergency_crash, L"Fatal Application Failure", MB_ICONERROR);
ExitProcess(3);
}
if (SaveloadCrashWithMissingNewGRFs()) {
- static const TCHAR _saveload_crash[] =
- _T("A serious fault condition occurred in the game. The game will shut down.\n")
- _T("As you loaded an savegame for which you do not have the required NewGRFs\n")
- _T("no crash information will be generated.\n");
- MessageBox(nullptr, _saveload_crash, _T("Fatal Application Failure"), MB_ICONERROR);
+ static const wchar_t _saveload_crash[] =
+ L"A serious fault condition occurred in the game. The game will shut down.\n"
+ L"As you loaded an savegame for which you do not have the required NewGRFs\n"
+ L"no crash information will be generated.\n";
+ MessageBox(nullptr, _saveload_crash, L"Fatal Application Failure", MB_ICONERROR);
ExitProcess(3);
}
@@ -641,20 +641,20 @@ static void CDECL CustomAbort(int signal)
static bool _expanded;
-static const TCHAR _crash_desc[] =
- _T("A serious fault condition occurred in the game. The game will shut down.\n")
- _T("Please send the crash information and the crash.dmp file (if any) to the developers.\n")
- _T("This will greatly help debugging. The correct place to do this is https://github.com/OpenTTD/OpenTTD/issues. ")
- _T("The information contained in the report is displayed below.\n")
- _T("Press \"Emergency save\" to attempt saving the game. Generated file(s):\n")
- _T("%s");
+static const wchar_t _crash_desc[] =
+ L"A serious fault condition occurred in the game. The game will shut down.\n"
+ L"Please send the crash information and the crash.dmp file (if any) to the developers.\n"
+ L"This will greatly help debugging. The correct place to do this is https://github.com/OpenTTD/OpenTTD/issues. "
+ L"The information contained in the report is displayed below.\n"
+ L"Press \"Emergency save\" to attempt saving the game. Generated file(s):\n"
+ L"%s";
-static const TCHAR _save_succeeded[] =
- _T("Emergency save succeeded.\nIts location is '%s'.\n")
- _T("Be aware that critical parts of the internal game state may have become ")
- _T("corrupted. The saved game is not guaranteed to work.");
+static const wchar_t _save_succeeded[] =
+ L"Emergency save succeeded.\nIts location is '%s'.\n"
+ L"Be aware that critical parts of the internal game state may have become "
+ L"corrupted. The saved game is not guaranteed to work.";
-static const TCHAR * const _expand_texts[] = {_T("S&how report >>"), _T("&Hide report <<") };
+static const wchar_t * const _expand_texts[] = {L"S&how report >>", L"&Hide report <<" };
static void SetWndSize(HWND wnd, int mode)
{
@@ -677,17 +677,13 @@ static void SetWndSize(HWND wnd, int mode)
}
}
-/* When TCHAR is char, then _sntprintf becomes snprintf. When TCHAR is wchar it doesn't. Likewise for strcat. */
-#undef snprintf
-#undef strcat
-
static INT_PTR CALLBACK CrashDialogFunc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG: {
/* We need to put the crash-log in a separate buffer because the default
- * buffer in MB_TO_WIDE is not large enough (512 chars) */
- TCHAR crash_msgW[lengthof(CrashLogWindows::current->crashlog)];
+ * buffer in OTTD2FS is not large enough (512 chars) */
+ wchar_t crash_msgW[lengthof(CrashLogWindows::current->crashlog)];
/* Convert unix -> dos newlines because the edit box only supports that properly :( */
const char *unix_nl = CrashLogWindows::current->crashlog;
char dos_nl[lengthof(CrashLogWindows::current->crashlog)];
@@ -700,20 +696,20 @@ static INT_PTR CALLBACK CrashDialogFunc(HWND wnd, UINT msg, WPARAM wParam, LPARA
*p = '\0';
/* Add path to crash.log and crash.dmp (if any) to the crash window text */
- size_t len = _tcslen(_crash_desc) + 2;
- len += _tcslen(OTTD2FS(CrashLogWindows::current->crashlog_filename)) + 2;
- len += _tcslen(OTTD2FS(CrashLogWindows::current->crashdump_filename)) + 2;
- len += _tcslen(OTTD2FS(CrashLogWindows::current->screenshot_filename)) + 1;
-
- TCHAR *text = AllocaM(TCHAR, len);
- _sntprintf(text, len, _crash_desc, OTTD2FS(CrashLogWindows::current->crashlog_filename));
- if (OTTD2FS(CrashLogWindows::current->crashdump_filename)[0] != _T('\0')) {
- _tcscat(text, _T("\n"));
- _tcscat(text, OTTD2FS(CrashLogWindows::current->crashdump_filename));
+ size_t len = wcslen(_crash_desc) + 2;
+ len += wcslen(OTTD2FS(CrashLogWindows::current->crashlog_filename)) + 2;
+ len += wcslen(OTTD2FS(CrashLogWindows::current->crashdump_filename)) + 2;
+ len += wcslen(OTTD2FS(CrashLogWindows::current->screenshot_filename)) + 1;
+
+ wchar_t *text = AllocaM(wchar_t, len);
+ _snwprintf(text, len, _crash_desc, OTTD2FS(CrashLogWindows::current->crashlog_filename));
+ if (OTTD2FS(CrashLogWindows::current->crashdump_filename)[0] != L'\0') {
+ wcscat(text, L"\n");
+ wcscat(text, OTTD2FS(CrashLogWindows::current->crashdump_filename));
}
- if (OTTD2FS(CrashLogWindows::current->screenshot_filename)[0] != _T('\0')) {
- _tcscat(text, _T("\n"));
- _tcscat(text, OTTD2FS(CrashLogWindows::current->screenshot_filename));
+ if (OTTD2FS(CrashLogWindows::current->screenshot_filename)[0] != L'\0') {
+ wcscat(text, L"\n");
+ wcscat(text, OTTD2FS(CrashLogWindows::current->screenshot_filename));
}
SetDlgItemText(wnd, 10, text);
@@ -729,12 +725,12 @@ static INT_PTR CALLBACK CrashDialogFunc(HWND wnd, UINT msg, WPARAM wParam, LPARA
case 13: // Emergency save
char filename[MAX_PATH];
if (CrashLogWindows::current->WriteSavegame(filename, lastof(filename))) {
- size_t len = _tcslen(_save_succeeded) + _tcslen(OTTD2FS(filename)) + 1;
- TCHAR *text = AllocaM(TCHAR, len);
- _sntprintf(text, len, _save_succeeded, OTTD2FS(filename));
- MessageBox(wnd, text, _T("Save successful"), MB_ICONINFORMATION);
+ size_t len = wcslen(_save_succeeded) + wcslen(OTTD2FS(filename)) + 1;
+ wchar_t *text = AllocaM(wchar_t, len);
+ _snwprintf(text, len, _save_succeeded, OTTD2FS(filename));
+ MessageBox(wnd, text, L"Save successful", MB_ICONINFORMATION);
} else {
- MessageBox(wnd, _T("Save failed"), _T("Save failed"), MB_ICONINFORMATION);
+ MessageBox(wnd, L"Save failed", L"Save failed", MB_ICONINFORMATION);
}
break;
case 15: // Expand window to show crash-message
diff --git a/src/os/windows/font_win32.cpp b/src/os/windows/font_win32.cpp
index a4e60a780..9a9dba2f2 100644
--- a/src/os/windows/font_win32.cpp
+++ b/src/os/windows/font_win32.cpp
@@ -46,10 +46,10 @@ extern FT_Library _library;
* @param long_path the path in system encoding.
* @return the short path in ANSI (ASCII).
*/
-static const char *GetShortPath(const TCHAR *long_path)
+static const char *GetShortPath(const wchar_t *long_path)
{
static char short_path[MAX_PATH];
- WCHAR short_path_w[MAX_PATH];
+ wchar_t short_path_w[MAX_PATH];
GetShortPathName(long_path, short_path_w, lengthof(short_path_w));
WideCharToMultiByte(CP_ACP, 0, short_path_w, -1, short_path, lengthof(short_path), nullptr, nullptr);
return short_path;
@@ -69,8 +69,8 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
FT_Error err = FT_Err_Cannot_Open_Resource;
HKEY hKey;
LONG ret;
- TCHAR vbuffer[MAX_PATH], dbuffer[256];
- TCHAR *pathbuf;
+ wchar_t vbuffer[MAX_PATH], dbuffer[256];
+ wchar_t *pathbuf;
const char *font_path;
uint index;
size_t path_len;
@@ -83,10 +83,10 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
}
/* Convert font name to file system encoding. */
- TCHAR *font_namep = _tcsdup(OTTD2FS(font_name));
+ wchar_t *font_namep = wcsdup(OTTD2FS(font_name));
for (index = 0;; index++) {
- TCHAR *s;
+ wchar_t *s;
DWORD vbuflen = lengthof(vbuffer);
DWORD dbuflen = lengthof(dbuffer);
@@ -102,13 +102,13 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
* TTC files, font files which contain more than one font are separated
* by '&'. Our best bet will be to do substr match for the fontname
* and then let FreeType figure out which index to load */
- s = _tcschr(vbuffer, _T('('));
+ s = wcschr(vbuffer, L'(');
if (s != nullptr) s[-1] = '\0';
- if (_tcschr(vbuffer, _T('&')) == nullptr) {
- if (_tcsicmp(vbuffer, font_namep) == 0) break;
+ if (wcschr(vbuffer, L'&') == nullptr) {
+ if (wcsicmp(vbuffer, font_namep) == 0) break;
} else {
- if (_tcsstr(vbuffer, font_namep) != nullptr) break;
+ if (wcsstr(vbuffer, font_namep) != nullptr) break;
}
}
@@ -121,9 +121,9 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
* contain multiple fonts inside this single file. GetFontData however
* returns the whole file, so we need to check each font inside to get the
* proper font. */
- path_len = _tcslen(vbuffer) + _tcslen(dbuffer) + 2; // '\' and terminating nul.
- pathbuf = AllocaM(TCHAR, path_len);
- _sntprintf(pathbuf, path_len, _T("%s\\%s"), vbuffer, dbuffer);
+ path_len = wcslen(vbuffer) + wcslen(dbuffer) + 2; // '\' and terminating nul.
+ pathbuf = AllocaM(wchar_t, path_len);
+ _snwprintf(pathbuf, path_len, L"%s\\%s", vbuffer, dbuffer);
/* Convert the path into something that FreeType understands. */
font_path = GetShortPath(pathbuf);
@@ -228,13 +228,13 @@ err2:
ReleaseDC(nullptr, dc);
DeleteObject(font);
err1:
- return ret_font_name == nullptr ? WIDE_TO_MB((const TCHAR *)logfont->elfFullName) : ret_font_name;
+ return ret_font_name == nullptr ? FS2OTTD((const wchar_t *)logfont->elfFullName) : ret_font_name;
}
#endif /* WITH_FREETYPE */
class FontList {
protected:
- TCHAR **fonts;
+ wchar_t **fonts;
uint items;
uint capacity;
@@ -251,9 +251,9 @@ public:
free(this->fonts);
}
- bool Add(const TCHAR *font) {
+ bool Add(const wchar_t *font) {
for (uint i = 0; i < this->items; i++) {
- if (_tcscmp(this->fonts[i], font) == 0) return false;
+ if (wcscmp(this->fonts[i], font) == 0) return false;
}
if (this->items == this->capacity) {
@@ -261,7 +261,7 @@ public:
this->fonts = ReallocT(this->fonts, this->capacity);
}
- this->fonts[this->items++] = _tcsdup(font);
+ this->fonts[this->items++] = wcsdup(font);
return true;
}
@@ -279,7 +279,7 @@ static int CALLBACK EnumFontCallback(const ENUMLOGFONTEX *logfont, const NEWTEXT
EFCParam *info = (EFCParam *)lParam;
/* Skip duplicates */
- if (!info->fonts.Add((const TCHAR *)logfont->elfFullName)) return 1;
+ if (!info->fonts.Add((const wchar_t *)logfont->elfFullName)) return 1;
/* Only use TrueType fonts */
if (!(type & TRUETYPE_FONTTYPE)) return 1;
/* Don't use SYMBOL fonts */
@@ -305,7 +305,7 @@ static int CALLBACK EnumFontCallback(const ENUMLOGFONTEX *logfont, const NEWTEXT
}
char font_name[MAX_PATH];
- convert_from_fs((const TCHAR *)logfont->elfFullName, font_name, lengthof(font_name));
+ convert_from_fs((const wchar_t *)logfont->elfFullName, font_name, lengthof(font_name));
#ifdef WITH_FREETYPE
/* Add english name after font name */
@@ -342,7 +342,7 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
{
DEBUG(freetype, 1, "Trying fallback fonts");
EFCParam langInfo;
- if (GetLocaleInfo(MAKELCID(winlangid, SORT_DEFAULT), LOCALE_FONTSIGNATURE, (LPTSTR)&langInfo.locale, sizeof(langInfo.locale) / sizeof(TCHAR)) == 0) {
+ if (GetLocaleInfo(MAKELCID(winlangid, SORT_DEFAULT), LOCALE_FONTSIGNATURE, (LPTSTR)&langInfo.locale, sizeof(langInfo.locale) / sizeof(wchar_t)) == 0) {
/* Invalid langid or some other mysterious error, can't determine fallback font. */
DEBUG(freetype, 1, "Can't get locale info for fallback font (langid=0x%x)", winlangid);
return false;
@@ -601,7 +601,7 @@ void LoadWin32Font(FontSize fs)
} else if (strchr(settings->font, '.') != nullptr) {
/* Might be a font file name, try load it. */
- TCHAR fontPath[MAX_PATH] = {};
+ wchar_t fontPath[MAX_PATH] = {};
/* See if this is an absolute path. */
if (FileExists(settings->font)) {
@@ -619,7 +619,7 @@ void LoadWin32Font(FontSize fs)
/* Try a nice little undocumented function first for getting the internal font name.
* Some documentation is found at: http://www.undocprint.org/winspool/getfontresourceinfo */
typedef BOOL(WINAPI *PFNGETFONTRESOURCEINFO)(LPCTSTR, LPDWORD, LPVOID, DWORD);
- static PFNGETFONTRESOURCEINFO GetFontResourceInfo = (PFNGETFONTRESOURCEINFO)GetProcAddress(GetModuleHandle(_T("Gdi32")), "GetFontResourceInfoW");
+ static PFNGETFONTRESOURCEINFO GetFontResourceInfo = (PFNGETFONTRESOURCEINFO)GetProcAddress(GetModuleHandle(L"Gdi32"), "GetFontResourceInfoW");
if (GetFontResourceInfo != nullptr) {
/* Try to query an array of LOGFONTs that describe the file. */
@@ -634,10 +634,10 @@ void LoadWin32Font(FontSize fs)
/* No dice yet. Use the file name as the font face name, hoping it matches. */
if (logfont.lfFaceName[0] == 0) {
- TCHAR fname[_MAX_FNAME];
- _tsplitpath(fontPath, nullptr, nullptr, fname, nullptr);
+ wchar_t fname[_MAX_FNAME];
+ _wsplitpath(fontPath, nullptr, nullptr, fname, nullptr);
- _tcsncpy_s(logfont.lfFaceName, lengthof(logfont.lfFaceName), fname, _TRUNCATE);
+ wcsncpy_s(logfont.lfFaceName, lengthof(logfont.lfFaceName), fname, _TRUNCATE);
logfont.lfWeight = strcasestr(settings->font, " bold") != nullptr || strcasestr(settings->font, "-bold") != nullptr ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts.
}
} else {
diff --git a/src/os/windows/font_win32.h b/src/os/windows/font_win32.h
index 9a552125f..ba413fae5 100644
--- a/src/os/windows/font_win32.h
+++ b/src/os/windows/font_win32.h
@@ -33,7 +33,7 @@ public:
~Win32FontCache();
void ClearFontCache() override;
GlyphID MapCharToGlyph(WChar key) override;
- const char *GetFontName() override { return WIDE_TO_MB(this->logfont.lfFaceName); }
+ const char *GetFontName() override { return FS2OTTD(this->logfont.lfFaceName); }
const void *GetOSHandle() override { return &this->logfont; }
};
diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp
index dc6f5ef7b..27fec1ac0 100644
--- a/src/os/windows/win32.cpp
+++ b/src/os/windows/win32.cpp
@@ -57,7 +57,7 @@ bool LoadLibraryList(Function proc[], const char *dll)
{
while (*dll != '\0') {
HMODULE lib;
- lib = LoadLibrary(MB_TO_WIDE(dll));
+ lib = LoadLibrary(OTTD2FS(dll));
if (lib == nullptr) return false;
for (;;) {
@@ -77,12 +77,12 @@ bool LoadLibraryList(Function proc[], const char *dll)
void ShowOSErrorBox(const char *buf, bool system)
{
MyShowCursor(true);
- MessageBox(GetActiveWindow(), OTTD2FS(buf), _T("Error!"), MB_ICONSTOP | MB_TASKMODAL);
+ MessageBox(GetActiveWindow(), OTTD2FS(buf), L"Error!", MB_ICONSTOP | MB_TASKMODAL);
}
void OSOpenBrowser(const char *url)
{
- ShellExecute(GetActiveWindow(), _T("open"), OTTD2FS(url), nullptr, nullptr, SW_SHOWNORMAL);
+ ShellExecute(GetActiveWindow(), L"open", OTTD2FS(url), nullptr, nullptr, SW_SHOWNORMAL);
}
/* Code below for windows version of opendir/readdir/closedir copied and
@@ -132,7 +132,7 @@ static inline void dir_free(DIR *d)
}
}
-DIR *opendir(const TCHAR *path)
+DIR *opendir(const wchar_t *path)
{
DIR *d;
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box
@@ -141,12 +141,12 @@ DIR *opendir(const TCHAR *path)
if ((fa != INVALID_FILE_ATTRIBUTES) && (fa & FILE_ATTRIBUTE_DIRECTORY)) {
d = dir_calloc();
if (d != nullptr) {
- TCHAR search_path[MAX_PATH];
- bool slash = path[_tcslen(path) - 1] == '\\';
+ wchar_t search_path[MAX_PATH];
+ bool slash = path[wcslen(path) - 1] == '\\';
/* build search path for FindFirstFile, try not to append additional slashes
* as it throws Win9x off its groove for root directories */
- _sntprintf(search_path, lengthof(search_path), _T("%s%s*"), path, slash ? _T("") : _T("\\"));
+ _snwprintf(search_path, lengthof(search_path), L"%s%s*", path, slash ? L"" : L"\\");
*lastof(search_path) = '\0';
d->hFind = FindFirstFile(search_path, &d->fd);
@@ -204,8 +204,8 @@ bool FiosIsRoot(const char *file)
void FiosGetDrives(FileList &file_list)
{
- TCHAR drives[256];
- const TCHAR *s;
+ wchar_t drives[256];
+ const wchar_t *s;
GetLogicalDriveStrings(lengthof(drives), drives);
for (s = drives; *s != '\0';) {
@@ -245,10 +245,10 @@ bool FiosGetDiskFreeSpace(const char *path, uint64 *tot)
{
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box
bool retval = false;
- TCHAR root[4];
+ wchar_t root[4];
DWORD spc, bps, nfc, tnc;
- _sntprintf(root, lengthof(root), _T("%c:") _T(PATHSEP), path[0]);
+ _snwprintf(root, lengthof(root), L"%c:" PATHSEP, path[0]);
if (tot != nullptr && GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) {
*tot = ((spc * bps) * (uint64)nfc);
retval = true;
@@ -366,7 +366,7 @@ static INT_PTR CALLBACK HelpDialogFunc(HWND wnd, UINT msg, WPARAM wParam, LPARAM
*q = '\0';
/* We need to put the text in a separate buffer because the default
* buffer in OTTD2FS might not be large enough (512 chars). */
- TCHAR help_msg_buf[8192];
+ wchar_t help_msg_buf[8192];
SetDlgItemText(wnd, 11, convert_to_fs(help_msg, help_msg_buf, lengthof(help_msg_buf)));
SendDlgItemMessage(wnd, 11, WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), FALSE);
} return TRUE;
@@ -400,8 +400,8 @@ void ShowInfo(const char *str)
} else {
/* We need to put the text in a separate buffer because the default
* buffer in OTTD2FS might not be large enough (512 chars). */
- TCHAR help_msg_buf[8192];
- MessageBox(GetActiveWindow(), convert_to_fs(str, help_msg_buf, lengthof(help_msg_buf)), _T("OpenTTD"), MB_ICONINFORMATION | MB_OK);
+ wchar_t help_msg_buf[8192];
+ MessageBox(GetActiveWindow(), convert_to_fs(str, help_msg_buf, lengthof(help_msg_buf)), L"OpenTTD", MB_ICONINFORMATION | MB_OK);
}
MyShowCursor(old);
}
@@ -447,7 +447,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
char *getcwd(char *buf, size_t size)
{
- TCHAR path[MAX_PATH];
+ wchar_t path[MAX_PATH];
GetCurrentDirectory(MAX_PATH - 1, path);
convert_from_fs(path, buf, size);
return buf;
@@ -459,7 +459,7 @@ void DetermineBasePaths(const char *exe)
{
extern std::array<std::string, NUM_SEARCHPATHS> _searchpaths;
- TCHAR path[MAX_PATH];
+ wchar_t path[MAX_PATH];
#ifdef WITH_PERSONAL_DIR
if (SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_PERSONAL, nullptr, SHGFP_TYPE_CURRENT, path))) {
std::string tmp(FS2OTTD(path));
@@ -497,8 +497,8 @@ void DetermineBasePaths(const char *exe)
_searchpaths[SP_WORKING_DIR] = cwd_s;
} else {
/* Use the folder of the config file as working directory. */
- TCHAR config_dir[MAX_PATH];
- _tcsncpy(path, convert_to_fs(_config_file.c_str(), path, lengthof(path)), lengthof(path));
+ wchar_t config_dir[MAX_PATH];
+ wcsncpy(path, convert_to_fs(_config_file.c_str(), path, lengthof(path)), lengthof(path));
if (!GetFullPathName(path, lengthof(config_dir), config_dir, nullptr)) {
DEBUG(misc, 0, "GetFullPathName failed (%lu)\n", GetLastError());
_searchpaths[SP_WORKING_DIR].clear();
@@ -515,8 +515,8 @@ void DetermineBasePaths(const char *exe)
DEBUG(misc, 0, "GetModuleFileName failed (%lu)\n", GetLastError());
_searchpaths[SP_BINARY_DIR].clear();
} else {
- TCHAR exec_dir[MAX_PATH];
- _tcsncpy(path, convert_to_fs(exe, path, lengthof(path)), lengthof(path));
+ wchar_t exec_dir[MAX_PATH];
+ wcsncpy(path, convert_to_fs(exe, path, lengthof(path)), lengthof(path));
if (!GetFullPathName(path, lengthof(exec_dir), exec_dir, nullptr)) {
DEBUG(misc, 0, "GetFullPathName failed (%lu)\n", GetLastError());
_searchpaths[SP_BINARY_DIR].clear();
@@ -567,7 +567,7 @@ bool GetClipboardContents(char *buffer, const char *last)
* @see the current code-page comes from video\win32_v.cpp, event-notification
* WM_INPUTLANGCHANGE
*/
-const char *FS2OTTD(const TCHAR *name)
+const char *FS2OTTD(const wchar_t *name)
{
static char utf8_buf[512];
return convert_from_fs(name, utf8_buf, lengthof(utf8_buf));
@@ -582,9 +582,9 @@ const char *FS2OTTD(const TCHAR *name)
* @param console_cp convert to the console encoding instead of the normal system encoding.
* @return pointer to the converted string; if failed string is of zero-length
*/
-const TCHAR *OTTD2FS(const char *name, bool console_cp)
+const wchar_t *OTTD2FS(const char *name, bool console_cp)
{
- static TCHAR system_buf[512];
+ static wchar_t system_buf[512];
return convert_to_fs(name, system_buf, lengthof(system_buf), console_cp);
}
@@ -597,9 +597,9 @@ const TCHAR *OTTD2FS(const char *name, bool console_cp)
* @param buflen length in characters of the receiving buffer
* @return pointer to utf8_buf. If conversion fails the string is of zero-length
*/
-char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen)
+char *convert_from_fs(const wchar_t *name, char *utf8_buf, size_t buflen)
{
- const WCHAR *wide_buf = name;
+ const wchar_t *wide_buf = name;
/* Convert UTF-16 string to UTF-8. */
int len = WideCharToMultiByte(CP_UTF8, 0, wide_buf, -1, utf8_buf, (int)buflen, nullptr, nullptr);
@@ -619,7 +619,7 @@ char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen)
* @param console_cp convert to the console encoding instead of the normal system encoding.
* @return pointer to system_buf. If conversion fails the string is of zero-length
*/
-TCHAR *convert_to_fs(const char *name, TCHAR *system_buf, size_t buflen, bool console_cp)
+wchar_t *convert_to_fs(const char *name, wchar_t *system_buf, size_t buflen, bool console_cp)
{
int len = MultiByteToWideChar(CP_UTF8, 0, name, -1, system_buf, (int)buflen);
if (len == 0) system_buf[0] = '\0';
@@ -677,7 +677,7 @@ int OTTDStringCompare(const char *s1, const char *s2)
#endif
if (first_time) {
- _CompareStringEx = (PFNCOMPARESTRINGEX)GetProcAddress(GetModuleHandle(_T("Kernel32")), "CompareStringEx");
+ _CompareStringEx = (PFNCOMPARESTRINGEX)GetProcAddress(GetModuleHandle(L"Kernel32"), "CompareStringEx");
first_time = false;
}
@@ -698,7 +698,7 @@ int OTTDStringCompare(const char *s1, const char *s2)
}
}
- TCHAR s1_buf[512], s2_buf[512];
+ wchar_t s1_buf[512], s2_buf[512];
convert_to_fs(s1, s1_buf, lengthof(s1_buf));
convert_to_fs(s2, s2_buf, lengthof(s2_buf));
diff --git a/src/os/windows/win32.h b/src/os/windows/win32.h
index 6d980f099..60cbed6e9 100644
--- a/src/os/windows/win32.h
+++ b/src/os/windows/win32.h
@@ -16,13 +16,8 @@ bool MyShowCursor(bool show, bool toggle = false);
typedef void (*Function)(int);
bool LoadLibraryList(Function proc[], const char *dll);
-char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen);
-TCHAR *convert_to_fs(const char *name, TCHAR *utf16_buf, size_t buflen, bool console_cp = false);
-
-/* Function shortcuts for UTF-8 <> UNICODE conversion. These functions use an
- * internal buffer of max 512 characters. */
-# define MB_TO_WIDE(str) OTTD2FS(str)
-# define WIDE_TO_MB(str) FS2OTTD(str)
+char *convert_from_fs(const wchar_t *name, char *utf8_buf, size_t buflen);
+wchar_t *convert_to_fs(const char *name, wchar_t *utf16_buf, size_t buflen, bool console_cp = false);
#if defined(__MINGW32__) && !defined(__MINGW64__)
#define SHGFP_TYPE_CURRENT 0