r37937 - in trunk/stream: stream.c stream.h stream_dvd.c stream_file.c
Author: reimar Date: Sat Apr 29 14:09:32 2017 New Revision: 37937 Log: stream_dvd.c: Partially support non-ascii file paths. MPlayer arguments are in UTF-8 but libdvdread does not support that. Instead convert to local code page, which should work at least for names that are possible to represent in that. Cleanup and refactor similar code in stream_file.c. Patch by Tadashi Ando [ando at je-pu-pu jp]. with small modifications by me. Modified: trunk/stream/stream.c trunk/stream/stream.h trunk/stream/stream_dvd.c trunk/stream/stream_file.c Modified: trunk/stream/stream.c ============================================================================== --- trunk/stream/stream.c Sat Apr 29 14:09:30 2017 (r37936) +++ trunk/stream/stream.c Sat Apr 29 14:09:32 2017 (r37937) @@ -746,3 +746,70 @@ int parse_chapter_range(const m_option_t } return 0; } + +#if defined(__MINGW32__) || defined(__CYGWIN__) +wchar_t *utf8_to_wide_char(const char *utf8) +{ + int conv_size; + wchar_t *wide_char = NULL; + + int wide_char_size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, utf8, -1, wide_char, 0); + if (wide_char_size < 0) goto err_out; + + wide_char = calloc(wide_char_size, sizeof(*wide_char)); + if (!wide_char) goto err_out; + + conv_size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, utf8, -1, wide_char, wide_char_size); + if (conv_size <= 0) goto err_out; + + return wide_char; + +err_out: + free(wide_char); + + return 0; +} + +static char *wide_char_to_local_windows_code_page(const wchar_t *wide_char) +{ + int conv_size; + + char *ansi = NULL; + + int ansi_size = WideCharToMultiByte(CP_ACP, 0, wide_char, -1, NULL, 0, NULL, NULL); + if (ansi_size < 0) goto err_out; + + ansi = calloc(ansi_size, sizeof(*ansi)); + if (!ansi) goto err_out; + + conv_size = WideCharToMultiByte(CP_ACP, 0, wide_char, -1, ansi, ansi_size, NULL, NULL); + if (conv_size < 0) goto err_out; + + return ansi; + +err_out: + free(ansi); + + return 0; +} + +char *utf8_to_local_windows_code_page(const char *utf8) +{ + char *windows_local_code_page = NULL; + + wchar_t *wide_char = utf8_to_wide_char(utf8); + if (!wide_char) goto err_out; + + windows_local_code_page = wide_char_to_local_windows_code_page(wide_char); + if (!windows_local_code_page) goto err_out; + + free(wide_char); + + return windows_local_code_page; + +err_out: + free(wide_char); + free(windows_local_code_page); + return NULL; +} +#endif Modified: trunk/stream/stream.h ============================================================================== --- trunk/stream/stream.h Sat Apr 29 14:09:30 2017 (r37936) +++ trunk/stream/stream.h Sat Apr 29 14:09:32 2017 (r37937) @@ -404,4 +404,9 @@ int bluray_id_from_lang(stream_t *s, enu int parse_chapter_range(const m_option_t *conf, const char *range); +#if defined(__MINGW32__) || defined(__CYGWIN__) +wchar_t *utf8_to_wide_char(const char *utf8); +char *utf8_to_local_windows_code_page(const char *utf8); +#endif + #endif /* MPLAYER_STREAM_H */ Modified: trunk/stream/stream_dvd.c ============================================================================== --- trunk/stream/stream_dvd.c Sat Apr 29 14:09:30 2017 (r37936) +++ trunk/stream/stream_dvd.c Sat Apr 29 14:09:32 2017 (r37937) @@ -790,7 +790,14 @@ static int open_s(stream_t *stream,int m } else #endif /* defined(__APPLE__) || defined(__DARWIN__) */ { +#if defined(__MINGW32__) || defined(__CYGWIN__) + char *ansi_dvd_device_current = utf8_to_local_windows_code_page(dvd_device_current); + + dvd = DVDOpen(ansi_dvd_device_current ? ansi_dvd_device_current : dvd_device_current); + free(ansi_dvd_device_current); +#else dvd = DVDOpen(dvd_device_current); +#endif if(!dvd) { mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CantOpenDVD,dvd_device_current, strerror(errno)); goto fail; Modified: trunk/stream/stream_file.c ============================================================================== --- trunk/stream/stream_file.c Sat Apr 29 14:09:30 2017 (r37936) +++ trunk/stream/stream_file.c Sat Apr 29 14:09:32 2017 (r37937) @@ -123,17 +123,13 @@ static int control(stream_t *s, int cmd, #ifdef __MINGW32__ static int win32_open(const char *fname, int m, int omode) { - int cnt; int fd = -1; - wchar_t fname_w[MAX_PATH]; - int WINAPI (*mb2wc)(UINT, DWORD, LPCSTR, int, LPWSTR, int) = NULL; - HMODULE kernel32 = GetModuleHandle("Kernel32.dll"); - if (!kernel32) goto fallback; - mb2wc = GetProcAddress(kernel32, "MultiByteToWideChar"); - if (!mb2wc) goto fallback; - cnt = mb2wc(CP_UTF8, MB_ERR_INVALID_CHARS, fname, -1, fname_w, sizeof(fname_w) / sizeof(*fname_w)); - if (cnt <= 0) goto fallback; + wchar_t *fname_w = utf8_to_wide_char(fname); + if (!fname_w) goto fallback; + fd = _wsopen(fname_w, m, SH_DENYNO, omode); + free(fname_w); + if (fd != -1 || (m & O_CREAT)) return fd;
participants (1)
-
reimar