diff options
author | Niels Martin Hansen <nielsm@indvikleren.dk> | 2021-02-21 20:04:24 +0100 |
---|---|---|
committer | Niels Martin Hansen <nielsm@indvikleren.dk> | 2021-02-23 11:25:39 +0100 |
commit | beeb9e0a1b1c6ceb61499edeb8cd6cf7999d12ea (patch) | |
tree | 49a38ab01da7773138ac04d50bf4211cf9157941 /src/os | |
parent | 4bc69fec622f2f5f628b2344566994e2da005515 (diff) | |
download | openttd-beeb9e0a1b1c6ceb61499edeb8cd6cf7999d12ea.tar.xz |
Remove: [Win32] Last pretenses of being able to build for Windows 95
Diffstat (limited to 'src/os')
-rw-r--r-- | src/os/windows/font_win32.cpp | 22 | ||||
-rw-r--r-- | src/os/windows/win32.cpp | 127 | ||||
-rw-r--r-- | src/os/windows/win32.h | 11 |
3 files changed, 11 insertions, 149 deletions
diff --git a/src/os/windows/font_win32.cpp b/src/os/windows/font_win32.cpp index 1b4a41ccf..a4e60a780 100644 --- a/src/os/windows/font_win32.cpp +++ b/src/os/windows/font_win32.cpp @@ -49,14 +49,9 @@ extern FT_Library _library; static const char *GetShortPath(const TCHAR *long_path) { static char short_path[MAX_PATH]; -#ifdef UNICODE WCHAR 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); -#else - /* Technically not needed, but do it for consistency. */ - GetShortPathName(long_path, short_path, lengthof(short_path)); -#endif return short_path; } @@ -68,8 +63,7 @@ static const char *GetShortPath(const TCHAR *long_path) * kept in memory then until the font is no longer needed. This could mean * an additional memory usage of 30MB (just for fonts!) when using an eastern * font for all font sizes */ -#define FONT_DIR_NT "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts" -#define FONT_DIR_9X "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Fonts" +static const wchar_t *FONT_DIR_NT = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"; FT_Error GetFontByFaceName(const char *font_name, FT_Face *face) { FT_Error err = FT_Err_Cannot_Open_Resource; @@ -81,14 +75,10 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face) uint index; size_t path_len; - /* On windows NT (2000, NT3.5, XP, etc.) the fonts are stored in the - * "Windows NT" key, on Windows 9x in the Windows key. To save us having - * to retrieve the windows version, we'll just query both */ - ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T(FONT_DIR_NT), 0, KEY_READ, &hKey); - if (ret != ERROR_SUCCESS) ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T(FONT_DIR_9X), 0, KEY_READ, &hKey); + ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, FONT_DIR_NT, 0, KEY_READ, &hKey); if (ret != ERROR_SUCCESS) { - DEBUG(freetype, 0, "Cannot open registry key HKLM\\SOFTWARE\\Microsoft\\Windows (NT)\\CurrentVersion\\Fonts"); + DEBUG(freetype, 0, "Cannot open registry key HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"); return err; } @@ -122,7 +112,7 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face) } } - if (!SUCCEEDED(OTTDSHGetFolderPath(nullptr, CSIDL_FONTS, nullptr, SHGFP_TYPE_CURRENT, vbuffer))) { + if (!SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_FONTS, nullptr, SHGFP_TYPE_CURRENT, vbuffer))) { DEBUG(freetype, 0, "SHGetFolderPath cannot return fonts directory"); goto folder_error; } @@ -629,11 +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); -#ifdef UNICODE static PFNGETFONTRESOURCEINFO GetFontResourceInfo = (PFNGETFONTRESOURCEINFO)GetProcAddress(GetModuleHandle(_T("Gdi32")), "GetFontResourceInfoW"); -#else - static PFNGETFONTRESOURCEINFO GetFontResourceInfo = (PFNGETFONTRESOURCEINFO)GetProcAddress(GetModuleHandle(_T("Gdi32")), "GetFontResourceInfoA"); -#endif if (GetFontResourceInfo != nullptr) { /* Try to query an array of LOGFONTs that describe the file. */ diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index ffc4f8c1a..dc6f5ef7b 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -52,8 +52,6 @@ bool MyShowCursor(bool show, bool toggle) /** * Helper function needed by dynamically loading libraries - * XXX: Hurray for MS only having an ANSI GetProcAddress function - * on normal windows and no Wide version except for in Windows Mobile/CE */ bool LoadLibraryList(Function proc[], const char *dll) { @@ -419,11 +417,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi CrashLog::InitialiseCrashLog(); -#if defined(UNICODE) - /* Check if a win9x user started the win32 version */ - if (HasBit(GetVersion(), 31)) usererror("This version of OpenTTD doesn't run on windows 95/98/ME.\nPlease download the win9x binary and try again."); -#endif - /* Convert the command line to UTF-8. We need a dedicated buffer * for this because argv[] points into this buffer and this needs to * be available between subsequent calls to FS2OTTD(). */ @@ -468,7 +461,7 @@ void DetermineBasePaths(const char *exe) TCHAR path[MAX_PATH]; #ifdef WITH_PERSONAL_DIR - if (SUCCEEDED(OTTDSHGetFolderPath(nullptr, CSIDL_PERSONAL, nullptr, SHGFP_TYPE_CURRENT, path))) { + if (SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_PERSONAL, nullptr, SHGFP_TYPE_CURRENT, path))) { std::string tmp(FS2OTTD(path)); AppendPathSeparator(tmp); tmp += PERSONAL_DIR; @@ -482,7 +475,7 @@ void DetermineBasePaths(const char *exe) _searchpaths[SP_PERSONAL_DIR].clear(); } - if (SUCCEEDED(OTTDSHGetFolderPath(nullptr, CSIDL_COMMON_DOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, path))) { + if (SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_COMMON_DOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, path))) { std::string tmp(FS2OTTD(path)); AppendPathSeparator(tmp); tmp += PERSONAL_DIR; @@ -556,17 +549,6 @@ bool GetClipboardContents(char *buffer, const char *last) CloseClipboard(); if (out_len == 0) return false; -#if !defined(UNICODE) - } else if (IsClipboardFormatAvailable(CF_TEXT)) { - OpenClipboard(nullptr); - cbuf = GetClipboardData(CF_TEXT); - - ptr = (const char*)GlobalLock(cbuf); - strecpy(buffer, FS2OTTD(ptr), last); - - GlobalUnlock(cbuf); - CloseClipboard(); -#endif /* UNICODE */ } else { return false; } @@ -576,10 +558,7 @@ bool GetClipboardContents(char *buffer, const char *last) /** - * Convert to OpenTTD's encoding from that of the local environment. - * When the project is built in UNICODE, the system codepage is irrelevant and - * the input string is wide. In ANSI mode, the string is in the - * local codepage which we'll convert to wide-char, and then to UTF-8. + * Convert to OpenTTD's encoding from wide characters. * OpenTTD internal encoding is UTF8. * The returned value's contents can only be guaranteed until the next call to * this function. So if the value is needed for anything else, use convert_from_fs @@ -595,10 +574,7 @@ const char *FS2OTTD(const TCHAR *name) } /** - * Convert from OpenTTD's encoding to that of the local environment. - * When the project is built in UNICODE the system codepage is irrelevant and - * the converted string is wide. In ANSI mode, the UTF8 string is converted - * to multi-byte. + * Convert from OpenTTD's encoding to wide characters. * OpenTTD internal encoding is UTF8. * The returned value's contents can only be guaranteed until the next call to * this function. So if the value is needed for anything else, use convert_from_fs @@ -615,7 +591,7 @@ const TCHAR *OTTD2FS(const char *name, bool console_cp) /** * Convert to OpenTTD's encoding from that of the environment in - * UNICODE. OpenTTD encoding is UTF8, local is wide + * UNICODE. OpenTTD encoding is UTF8, local is wide. * @param name pointer to a valid string that will be converted * @param utf8_buf pointer to a valid buffer that will receive the converted string * @param buflen length in characters of the receiving buffer @@ -623,19 +599,7 @@ const TCHAR *OTTD2FS(const char *name, bool console_cp) */ char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen) { -#if defined(UNICODE) const WCHAR *wide_buf = name; -#else - /* Convert string from the local codepage to UTF-16. */ - int wide_len = MultiByteToWideChar(CP_ACP, 0, name, -1, nullptr, 0); - if (wide_len == 0) { - utf8_buf[0] = '\0'; - return utf8_buf; - } - - WCHAR *wide_buf = AllocaM(WCHAR, wide_len); - MultiByteToWideChar(CP_ACP, 0, name, -1, wide_buf, wide_len); -#endif /* Convert UTF-16 string to UTF-8. */ int len = WideCharToMultiByte(CP_UTF8, 0, wide_buf, -1, utf8_buf, (int)buflen, nullptr, nullptr); @@ -647,7 +611,7 @@ char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen) /** * Convert from OpenTTD's encoding to that of the environment in - * UNICODE. OpenTTD encoding is UTF8, local is wide + * UNICODE. OpenTTD encoding is UTF8, local is wide. * @param name pointer to a valid string that will be converted * @param system_buf pointer to a valid wide-char buffer that will receive the * converted string @@ -657,91 +621,12 @@ char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen) */ TCHAR *convert_to_fs(const char *name, TCHAR *system_buf, size_t buflen, bool console_cp) { -#if defined(UNICODE) int len = MultiByteToWideChar(CP_UTF8, 0, name, -1, system_buf, (int)buflen); if (len == 0) system_buf[0] = '\0'; -#else - int len = MultiByteToWideChar(CP_UTF8, 0, name, -1, nullptr, 0); - if (len == 0) { - system_buf[0] = '\0'; - return system_buf; - } - - WCHAR *wide_buf = AllocaM(WCHAR, len); - MultiByteToWideChar(CP_UTF8, 0, name, -1, wide_buf, len); - - len = WideCharToMultiByte(console_cp ? CP_OEMCP : CP_ACP, 0, wide_buf, len, system_buf, (int)buflen, nullptr, nullptr); - if (len == 0) system_buf[0] = '\0'; -#endif return system_buf; } -/** - * Our very own SHGetFolderPath function for support of windows operating - * systems that don't have this function (eg Win9x, etc.). We try using the - * native function, and if that doesn't exist we will try a more crude approach - * of environment variables and hope for the best - */ -HRESULT OTTDSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath) -{ - static HRESULT (WINAPI *SHGetFolderPath)(HWND, int, HANDLE, DWORD, LPTSTR) = nullptr; - static bool first_time = true; - - /* We only try to load the library one time; if it fails, it fails */ - if (first_time) { -#if defined(UNICODE) -# define W(x) x "W" -#else -# define W(x) x "A" -#endif - /* The function lives in shell32.dll for all current Windows versions, but it first started to appear in SHFolder.dll. */ - if (!LoadLibraryList((Function*)&SHGetFolderPath, "shell32.dll\0" W("SHGetFolderPath") "\0\0")) { - if (!LoadLibraryList((Function*)&SHGetFolderPath, "SHFolder.dll\0" W("SHGetFolderPath") "\0\0")) { - DEBUG(misc, 0, "Unable to load " W("SHGetFolderPath") "from either shell32.dll or SHFolder.dll"); - } - } -#undef W - first_time = false; - } - - if (SHGetFolderPath != nullptr) return SHGetFolderPath(hwnd, csidl, hToken, dwFlags, pszPath); - - /* SHGetFolderPath doesn't exist, try a more conservative approach, - * eg environment variables. This is only included for legacy modes - * MSDN says: that 'pszPath' is a "Pointer to a null-terminated string of - * length MAX_PATH which will receive the path" so let's assume that - * Windows 95 with Internet Explorer 5.0, Windows 98 with Internet Explorer 5.0, - * Windows 98 Second Edition (SE), Windows NT 4.0 with Internet Explorer 5.0, - * Windows NT 4.0 with Service Pack 4 (SP4) */ - { - DWORD ret; - switch (csidl) { - case CSIDL_FONTS: // Get the system font path, eg %WINDIR%\Fonts - ret = GetEnvironmentVariable(_T("WINDIR"), pszPath, MAX_PATH); - if (ret == 0) break; - _tcsncat(pszPath, _T("\\Fonts"), MAX_PATH); - - return (HRESULT)0; - - case CSIDL_PERSONAL: - case CSIDL_COMMON_DOCUMENTS: { - HKEY key; - if (RegOpenKeyEx(csidl == CSIDL_PERSONAL ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, REGSTR_PATH_SPECIAL_FOLDERS, 0, KEY_READ, &key) != ERROR_SUCCESS) break; - DWORD len = MAX_PATH; - ret = RegQueryValueEx(key, csidl == CSIDL_PERSONAL ? _T("Personal") : _T("Common Documents"), nullptr, nullptr, (LPBYTE)pszPath, &len); - RegCloseKey(key); - if (ret == ERROR_SUCCESS) return (HRESULT)0; - break; - } - - /* XXX - other types to go here when needed... */ - } - } - - return E_INVALIDARG; -} - /** Determine the current user's locale. */ const char *GetCurrentLocale(const char *) { diff --git a/src/os/windows/win32.h b/src/os/windows/win32.h index 8cc85865f..6d980f099 100644 --- a/src/os/windows/win32.h +++ b/src/os/windows/win32.h @@ -19,19 +19,10 @@ 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. When unicode is not - * defined these macros return the string passed to them, with UNICODE - * they return a pointer to the converted string. These functions use an +/* Function shortcuts for UTF-8 <> UNICODE conversion. These functions use an * internal buffer of max 512 characters. */ -#if defined(UNICODE) # define MB_TO_WIDE(str) OTTD2FS(str) # define WIDE_TO_MB(str) FS2OTTD(str) -#else -# define MB_TO_WIDE(str) (str) -# define WIDE_TO_MB(str) (str) -#endif - -HRESULT OTTDSHGetFolderPath(HWND, int, HANDLE, DWORD, LPTSTR); #if defined(__MINGW32__) && !defined(__MINGW64__) #define SHGFP_TYPE_CURRENT 0 |