]> granicus.if.org Git - taglib/commitdiff
Assume that CreateFileW() is always available.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Sun, 30 Oct 2016 13:25:34 +0000 (22:25 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Sun, 30 Oct 2016 13:25:34 +0000 (22:25 +0900)
This drops support for Windows 9x.

taglib/toolkit/tfilestream.cpp
taglib/toolkit/tiostream.cpp

index 229b65c4043b9ea73b27abbab0cebb0739d26dc9..507e87849aeeee74149a08b56f23b104ad2b47ee 100644 (file)
@@ -52,14 +52,9 @@ namespace
     const DWORD access = readOnly ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE);
 
 #if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)
-    return CreateFile2(path.toString().toCWString(), access, FILE_SHARE_READ, OPEN_EXISTING, NULL);
+    return CreateFile2(path.wstr().c_str(), access, FILE_SHARE_READ, OPEN_EXISTING, NULL);
 #else
-    if(!path.wstr().empty())
-      return CreateFileW(path.wstr().c_str(), access, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
-    else if(!path.str().empty())
-      return CreateFileA(path.str().c_str(), access, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
-    else
-      return InvalidFileHandle;
+    return CreateFileW(path.wstr().c_str(), access, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
 #endif
   }
 
index 72fe32a6183e677b1d2f914d5862d59284a1b229..de0bd505347cfa6309bcc6472ab55bae03f520e7 100644 (file)
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
+#ifdef _WIN32
+# include <windows.h>
+# include <tstring.h>
+#endif
+
 #include "tiostream.h"
 
 using namespace TagLib;
 
 #ifdef _WIN32
 
-# include "tstring.h"
-# include "tdebug.h"
-# 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.
-
-  bool supportsUnicode()
-  {
-#ifdef UNICODE
-    return true;
-#else
-    const FARPROC p = GetProcAddress(GetModuleHandleA("kernel32"), "CreateFileW");
-    return (p != NULL);
-#endif
-  }
-
-  // Indicates whether the system supports Unicode file names.
-
-  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 wchar_t *wstr)
+  std::wstring ansiToUnicode(const char *str)
   {
-    if(SystemSupportsUnicode) {
-      debug("unicodeToAnsi() - Should not be used on WinNT systems.");
-    }
-
-    const int len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
+    const int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
     if(len == 0)
-      return std::string();
+      return std::wstring();
 
-    std::string str(len, '\0');
-    WideCharToMultiByte(CP_ACP, 0, wstr, -1, &str[0], len, NULL, NULL);
+    std::wstring wstr(len - 1, L'\0');
+    MultiByteToWideChar(CP_ACP, 0, str, -1, &wstr[0], len);
 
-    return str;
+    return wstr;
   }
 }
 
-// If WinNT, stores a Unicode string into m_wname directly.
-// If Win9x, converts and stores it into m_name to avoid calling Unicode version functions.
+// m_name is no longer used, but kept for backward compatibility.
 
-FileName::FileName(const wchar_t *name)
-  : m_name (SystemSupportsUnicode ? "" : unicodeToAnsi(name))
-  , m_wname(SystemSupportsUnicode ? name : L"")
+FileName::FileName(const wchar_t *name) :
+  m_name(),
+  m_wname(name)
 {
 }
 
-FileName::FileName(const char *name)
-  : m_name(name)
+FileName::FileName(const char *name) :
+  m_name(),
+  m_wname(ansiToUnicode(name))
 {
 }
 
-FileName::FileName(const FileName &name)
-  : m_name (name.m_name)
-  m_wname(name.m_wname)
+FileName::FileName(const FileName &name) :
+  m_name(),
+  m_wname(name.m_wname)
 {
 }
 
@@ -115,25 +91,9 @@ const std::string &FileName::str() const
 
 String FileName::toString() const
 {
-  if(!m_wname.empty()) {
-    return String(m_wname);
-  }
-  else if(!m_name.empty()) {
-    const int len = MultiByteToWideChar(CP_ACP, 0, m_name.c_str(), -1, NULL, 0);
-    if(len == 0)
-      return String();
-
-    std::vector<wchar_t> buf(len);
-    MultiByteToWideChar(CP_ACP, 0, m_name.c_str(), -1, &buf[0], len);
-
-    return String(&buf[0]);
-  }
-  else {
-    return String();
-  }
+  return String(m_wname.c_str());
 }
 
-
 #endif  // _WIN32
 
 ////////////////////////////////////////////////////////////////////////////////