1. Wez Furlong
  2. atomicparsley

Commits

Oleg Oshmyan  committed fe9acaa

Fixed calls to non-Unicode CreateFile on Win32

  • Participants
  • Parent commits 55ec709
  • Branches default

Comments (0)

Files changed (4)

File src/CDtoc.cpp

View file
  • Ignore whitespace
 	memset(cd_device_path, 0, 16);
 	sprintf(cd_device_path, "\\\\.\\%s:", id3args_drive);
 	
-	HANDLE cdrom_device = CreateFileA(cd_device_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+	HANDLE cdrom_device = APar_OpenFileWin32(cd_device_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 	if (cdrom_device != INVALID_HANDLE_VALUE) {
 		Windows_ioctlReadCDTOC(cdrom_device);
 		if (cdTOC != NULL) {

File src/main.cpp

View file
  • Ignore whitespace
 			FILETIME createTime, accessTime, writeTime;
 			if (preserve_timestamps == true)
 			{
-				hFile = CreateFileA(ISObasemediafile, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
+				hFile = APar_OpenFileWin32(ISObasemediafile, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
 				if (hFile != INVALID_HANDLE_VALUE)
 					{
 					GetFileTime(hFile,&createTime,&accessTime,&writeTime);
 			if (preserve_timestamps == true)
 			{
 
-				hFileOut = CreateFileA(ISObasemediafile, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
+				hFileOut = APar_OpenFileWin32(ISObasemediafile, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
 
 				if (hFileOut != INVALID_HANDLE_VALUE)
 					{

File src/util.cpp

View file
  • Ignore whitespace
 	}
 	return -1;
 }
+
+/*----------------------
+APar_OpenFileWin32
+	utf8_filepath - a pointer to a string (possibly utf8) of the full path to the file
+	... - passed on to the CreateFile function
+
+	take an ascii/utf8 filepath (which if under a unicode enabled Win32 OS was already converted from utf16le to utf8 at program start) and test if
+		AP is running on a unicode enabled Win32 OS. If it is, convert the utf8 filepath to a utf16 (native-endian) filepath & pass that to a wide CreateFile
+		with the 8-bit file flags changed to 16-bit file flags, otherwise pass the utf8 filepath to an ANSI CreateFile
+----------------------*/
+HANDLE APar_OpenFileWin32(const char* utf8_filepath, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) {
+	if ( IsUnicodeWinOS() && UnicodeOutputStatus == WIN32_UTF16) {
+		HANDLE hFile = NULL;
+		wchar_t* utf16_filepath = Convert_multibyteUTF8_to_wchar(utf8_filepath);
+		hFile = CreateFileW(utf16_filepath, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
+		free(utf16_filepath);
+		return hFile;
+	} else {
+		return CreateFileA(utf8_filepath, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
+	}
+}
+
 #endif
 
 

File src/util.h

View file
  • Ignore whitespace
 
 #if defined (_WIN32)
 int fseeko(FILE *stream, uint64_t pos, int whence);
+HANDLE APar_OpenFileWin32(const char* utf8_filepath, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
 #endif
 bool IsUnicodeWinOS();