Files with Unicode names couldn't open on Windows

This commit is contained in:
Alexander Kojevnikov 2010-07-10 15:16:37 +10:00
parent 98e865465b
commit ec699bd728
2 changed files with 18 additions and 3 deletions

View File

@ -16,6 +16,7 @@
* along with Spek. If not, see <http://www.gnu.org/licenses/>. * along with Spek. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <glib.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include "spek-audio.h" #include "spek-audio.h"
@ -26,16 +27,26 @@ void spek_audio_init () {
av_register_all (); av_register_all ();
} }
SpekAudioContext * spek_audio_open (const char *file_name) { SpekAudioContext * spek_audio_open (const gchar *file_name) {
SpekAudioContext *cx; SpekAudioContext *cx;
int i; int i;
cx = g_new0 (SpekAudioContext, 1); cx = g_new0 (SpekAudioContext, 1);
cx->file_name = g_strdup (file_name); cx->file_name = g_strdup (file_name);
#ifdef G_OS_WIN32
/* av_open_input_file() cannot open files with Unicode chars in it
* when running under Windows. When this happens we will re-try
* using the corresponding short file name.
*/
cx->short_name = g_win32_locale_filename_from_utf8 (file_name);
#endif
if (av_open_input_file (&cx->format_context, file_name, NULL, 0, NULL) != 0) { if (av_open_input_file (&cx->format_context, file_name, NULL, 0, NULL) != 0) {
cx->error = _("Cannot open input file"); if (!cx->short_name ||
return cx; av_open_input_file (&cx->format_context, cx->short_name, NULL, 0, NULL) != 0 ) {
cx->error = _("Cannot open input file");
return cx;
}
} }
if (av_find_stream_info (cx->format_context) < 0) { if (av_find_stream_info (cx->format_context) < 0) {
/* 24-bit APE returns an error but parses the stream info just fine */ /* 24-bit APE returns an error but parses the stream info just fine */
@ -170,6 +181,9 @@ void spek_audio_close (SpekAudioContext *cx) {
if (cx->file_name != NULL) { if (cx->file_name != NULL) {
g_free (cx->file_name); g_free (cx->file_name);
} }
if (cx->short_name != NULL) {
g_free (cx->short_name);
}
if (cx->codec_name != NULL) { if (cx->codec_name != NULL) {
g_free (cx->codec_name); g_free (cx->codec_name);
} }

View File

@ -25,6 +25,7 @@
typedef struct { typedef struct {
/* Internal data */ /* Internal data */
gchar *short_name;
AVFormatContext *format_context; AVFormatContext *format_context;
gint audio_stream; gint audio_stream;
AVCodecContext *codec_context; AVCodecContext *codec_context;