]> granicus.if.org Git - taglib/commitdiff
Small change in Win9x support
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Sat, 18 May 2013 14:30:15 +0000 (23:30 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Sat, 18 May 2013 14:30:15 +0000 (23:30 +0900)
taglib/toolkit/tiostream.cpp

index 2d4f66d8e6c30d7d991ce23ce4007ff5f0f7d8c1..b77739752226de49c4163ae1df7b0da1a928a7fe 100644 (file)
@@ -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 <windows.h>
 
 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