From: Tsuda Kageyu Date: Sat, 18 May 2013 14:30:15 +0000 (+0900) Subject: Small change in Win9x support X-Git-Tag: v1.9~39^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=36d9fc1973e592b41af5e25848ae205861ac5f5a;p=taglib Small change in Win9x support --- diff --git a/taglib/toolkit/tiostream.cpp b/taglib/toolkit/tiostream.cpp index 2d4f66d8..b7773975 100644 --- a/taglib/toolkit/tiostream.cpp +++ b/taglib/toolkit/tiostream.cpp @@ -29,30 +29,26 @@ using namespace TagLib; #ifdef _WIN32 -// MSVC 2008 or later can't produce the binary for Win9x. -#if !defined(_MSC_VER) || (_MSC_VER < 1500) +# include namespace { + // Check if the running system has CreateFileW() function. + // Windows9x systems don't have CreateFileW() or can't accept Unicode file names. - // Determines whether or not the running system is WinNT. - // In other words, whether the system supports Unicode. - - bool isWinNT() + bool supportsUnicode() { - OSVERSIONINFOA ver = {}; - ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA); - if(GetVersionExA(&ver)) { - return (ver.dwPlatformId == VER_PLATFORM_WIN32_NT); - } - else { - return false; - } + const FARPROC p = GetProcAddress(GetModuleHandleA("kernel32"), "CreateFileW"); + return (p != NULL); } + + // Indicates whether the system supports Unicode file names. - const bool IsWinNT = isWinNT(); + const bool SystemSupportsUnicode = supportsUnicode(); // Converts a UTF-16 string into a local encoding. + // This function should only be used in Windows9x systems which don't support + // Unicode file names. std::string unicodeToAnsi(const std::wstring &wstr) { @@ -71,20 +67,11 @@ namespace // If Win9x, converts and stores it into m_name to avoid calling Unicode version functions. FileName::FileName(const wchar_t *name) - : m_wname(IsWinNT ? name : L"") - , m_name(IsWinNT ? "" : unicodeToAnsi(name)) -{ -} - -#else - -FileName::FileName(const wchar_t *name) - : m_wname(name) + : m_wname(SystemSupportsUnicode ? name : L"") + , m_name (SystemSupportsUnicode ? "" : unicodeToAnsi(name)) { } -#endif - FileName::FileName(const char *name) : m_name(name) { @@ -92,7 +79,7 @@ FileName::FileName(const char *name) FileName::FileName(const FileName &name) : m_wname(name.m_wname) - , m_name(name.m_name) + , m_name (name.m_name) { } @@ -116,7 +103,7 @@ const std::string &FileName::str() const return m_name; } -#endif +#endif // _WIN32 //////////////////////////////////////////////////////////////////////////////// // public members