Commit cc9f3921 authored by Janne Hyvärinen's avatar Janne Hyvärinen Committed by Erik de Castro Lopo
Browse files

Metaflac UTF-8 fixes (Windows)



Metaflac can now print all console supported characters from tags on the
screen. It also fixes metaflac to be able to import its own exports back
without non-ascii characters getting mutilated. And --no-utf8-convert
now works properly with import and export commands.
Signed-off-by: Erik de Castro Lopo's avatarErik de Castro Lopo <erikd@mega-nerd.com>
parent f6585b0b
......@@ -551,7 +551,7 @@ void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned
unsigned i, j;
/*@@@ yuck, should do this with a varargs function or something: */
#define PPR if(filename)flac_printf("%s:",filename);
#define PPR if(filename) { if(raw) printf("%s:",filename); else flac_printf("%s:",filename); }
PPR; printf("METADATA block #%u\n", block_number);
PPR; printf(" type: %u (%s)\n", (unsigned)block->type, block->type < FLAC__METADATA_TYPE_UNDEFINED? FLAC__MetadataTypeString[block->type] : "UNKNOWN");
PPR; printf(" is last: %s\n", block->is_last? "true":"false");
......
......@@ -96,7 +96,11 @@ FLAC__bool do_shorthand_operation__vorbis_comment(const char *filename, FLAC__bo
ok = remove_vc_firstfield(filename, block, operation->argument.vc_field_name.value, needs_write);
break;
case OP__SET_VC_FIELD:
#ifdef _WIN32 /* do not convert anything or things will break */
ok = set_vc_field(filename, block, &operation->argument.vc_field, needs_write, true);
#else
ok = set_vc_field(filename, block, &operation->argument.vc_field, needs_write, raw);
#endif
break;
case OP__IMPORT_VC_FROM:
ok = import_vc_from(filename, block, &operation->argument.filename, needs_write, raw);
......@@ -245,9 +249,7 @@ FLAC__bool set_vc_field(const char *filename, FLAC__StreamMetadata *block, const
}
else {
FLAC__bool needs_free = false;
#ifdef _WIN32 /* do not convert anything or things will break */
entry.entry = (FLAC__byte *)field->field;
#else
if(raw) {
entry.entry = (FLAC__byte *)field->field;
}
......@@ -259,7 +261,6 @@ FLAC__bool set_vc_field(const char *filename, FLAC__StreamMetadata *block, const
flac_fprintf(stderr, "%s: ERROR: converting comment '%s' to UTF-8\n", filename, field->field);
return false;
}
#endif
entry.length = strlen((const char *)entry.entry);
if(!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length)) {
if(needs_free)
......
......@@ -229,13 +229,18 @@ void write_vc_field(const char *filename, const FLAC__StreamMetadata_VorbisComme
{
if(0 != entry->entry) {
if(filename)
fprintf(f, "%s:", filename);
flac_fprintf(f, "%s:", filename);
if(!raw) {
/*
* WATCHOUT: comments that contain an embedded null will
* be truncated by utf_decode().
*/
#ifdef _WIN32 /* if we are outputting to console, we need to use proper print functions to show unicode characters */
if (f == stdout || f == stderr) {
flac_fprintf(f, "%s", entry->entry);
} else {
#endif
char *converted;
if(utf8_decode((const char *)entry->entry, &converted) >= 0) {
......@@ -245,6 +250,9 @@ void write_vc_field(const char *filename, const FLAC__StreamMetadata_VorbisComme
else {
(void) local_fwrite(entry->entry, 1, entry->length, f);
}
#ifdef _WIN32
}
#endif
}
else {
(void) local_fwrite(entry->entry, 1, entry->length, f);
......
......@@ -203,7 +203,7 @@ int utf8_decode(const char *from, char **to)
return -1;
}
chars = WideCharToMultiByte(GetConsoleCP(), WC_COMPOSITECHECK, unicode,
chars = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, unicode,
-1, NULL, 0, NULL, NULL);
if(chars < 0) /* underflow check */
......@@ -224,7 +224,7 @@ int utf8_decode(const char *from, char **to)
return -1;
}
err = WideCharToMultiByte(GetConsoleCP(), WC_COMPOSITECHECK, unicode,
err = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, unicode,
-1, *to, chars, NULL, NULL);
if(err != chars)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment