summaryrefslogtreecommitdiff
path: root/asdcplib/src/KM_fileio.cpp
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-11-26 03:58:54 +0000
committerCarl Hetherington <cth@carlh.net>2013-11-26 03:58:54 +0000
commit66ea991028e62daf8bae5b6f1ad348c3eabe1da8 (patch)
tree259411dd2336e2a7934e73ffe5af387b9f097b5e /asdcplib/src/KM_fileio.cpp
parent2ee05f7ecc1847f1840610090ef3c093cf4a6554 (diff)
Try to fix non-trivial filename character encoding on Windows.
Diffstat (limited to 'asdcplib/src/KM_fileio.cpp')
-rw-r--r--asdcplib/src/KM_fileio.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/asdcplib/src/KM_fileio.cpp b/asdcplib/src/KM_fileio.cpp
index d48e7554..df2eb974 100644
--- a/asdcplib/src/KM_fileio.cpp
+++ b/asdcplib/src/KM_fileio.cpp
@@ -679,6 +679,7 @@ Kumu::FileWriter::StopHashing()
//------------------------------------------------------------------------------------------
//
+/** @param filename File name (UTF-8 encoded) */
Kumu::Result_t
Kumu::FileReader::OpenRead(const char* filename) const
{
@@ -688,7 +689,12 @@ Kumu::FileReader::OpenRead(const char* filename) const
// suppress popup window on error
UINT prev = ::SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
- const_cast<FileReader*>(this)->m_Handle = ::CreateFileA(filename,
+ wchar_t buffer[1024];
+ if (MultiByteToWideChar (CP_UTF8, MB_PRECOMPOSED, filename, -1, buffer, 1024)) {
+ return Kumu::RESULT_FAIL;
+ }
+
+ const_cast<FileReader*>(this)->m_Handle = ::CreateFileW(buffer,
(GENERIC_READ), // open for reading
FILE_SHARE_READ, // share for reading
NULL, // no security
@@ -803,7 +809,7 @@ Kumu::FileReader::Read(byte_t* buf, ui32_t buf_len, ui32_t* read_count) const
//------------------------------------------------------------------------------------------
//
-//
+/** @param filename File name (UTF-8 encoded) */
Kumu::Result_t
Kumu::FileWriter::OpenWrite(const char* filename)
{
@@ -813,7 +819,12 @@ Kumu::FileWriter::OpenWrite(const char* filename)
// suppress popup window on error
UINT prev = ::SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
- m_Handle = ::CreateFileA(filename,
+ wchar_t buffer[1024];
+ if (MultiByteToWideChar (CP_UTF8, MB_PRECOMPOSED, filename, -1, buffer, 1024)) {
+ return Kumu::RESULT_FAIL;
+ }
+
+ m_Handle = ::CreateFileW(buffer,
(GENERIC_WRITE|GENERIC_READ), // open for reading
FILE_SHARE_READ, // share for reading
NULL, // no security
@@ -831,7 +842,7 @@ Kumu::FileWriter::OpenWrite(const char* filename)
return Kumu::RESULT_OK;
}
-//
+/** @param filename File name (UTF-8 encoded) */
Kumu::Result_t
Kumu::FileWriter::OpenModify(const char* filename)
{
@@ -841,7 +852,12 @@ Kumu::FileWriter::OpenModify(const char* filename)
// suppress popup window on error
UINT prev = ::SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
- m_Handle = ::CreateFileA(filename,
+ wchar_t buffer[1024];
+ if (MultiByteToWideChar (CP_UTF8, MB_PRECOMPOSED, filename, -1, buffer, 1024)) {
+ return Kumu::RESULT_FAIL;
+ }
+
+ m_Handle = ::CreateFileW(buffer,
(GENERIC_WRITE|GENERIC_READ), // open for reading
FILE_SHARE_READ, // share for reading
NULL, // no security