spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit ec699bd7287ff10f60037a095529c6078f48c024
parent 98e865465b38c5c9c94d133276f483c18e5b55bd
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Sat, 10 Jul 2010 15:16:37 +1000

Files with Unicode names couldn't open on Windows

Diffstat:
Msrc/spek-audio.c | 20+++++++++++++++++---
Msrc/spek-audio.h | 1+
2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/spek-audio.c b/src/spek-audio.c @@ -16,6 +16,7 @@ * along with Spek. If not, see <http://www.gnu.org/licenses/>. */ +#include <glib.h> #include <glib/gi18n.h> #include "spek-audio.h" @@ -26,16 +27,26 @@ void spek_audio_init () { av_register_all (); } -SpekAudioContext * spek_audio_open (const char *file_name) { +SpekAudioContext * spek_audio_open (const gchar *file_name) { SpekAudioContext *cx; int i; cx = g_new0 (SpekAudioContext, 1); 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) { - cx->error = _("Cannot open input file"); - return cx; + if (!cx->short_name || + 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) { /* 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) { g_free (cx->file_name); } + if (cx->short_name != NULL) { + g_free (cx->short_name); + } if (cx->codec_name != NULL) { g_free (cx->codec_name); } diff --git a/src/spek-audio.h b/src/spek-audio.h @@ -25,6 +25,7 @@ typedef struct { /* Internal data */ + gchar *short_name; AVFormatContext *format_context; gint audio_stream; AVCodecContext *codec_context;