~ubuntu-branches/ubuntu/feisty/flac/feisty-security

« back to all changes in this revision

Viewing changes to src/plugin_winamp2/infobox.c

  • Committer: Bazaar Package Importer
  • Author(s): Tollef Fog Heen
  • Date: 2005-11-10 12:55:33 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20051110125533-2fmlml8wnb06r5vg
Tags: 1.1.2-3ubuntu1
* Merge with Debian
  - We did the C++ transition earlier than Debian, so add c2 suffix to
    liboggflac++ and libflac++

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* in_flac - Winamp2 FLAC input plugin
2
 
 * Copyright (C) 2002,2003,2004  Josh Coalson
 
2
 * Copyright (C) 2002,2003,2004,2005  Josh Coalson
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or
5
5
 * modify it under the terms of the GNU General Public License
28
28
typedef struct
29
29
{
30
30
        char filename[MAX_PATH];
31
 
        FLAC_Plugin__CanonicalTag tag;
 
31
        FLAC__StreamMetadata *tags;
32
32
} LOCALDATA;
33
33
 
34
 
static char buffer[1024];
 
34
static char buffer[8192];
35
35
static char *genres = NULL;
36
36
static DWORD genresSize = 0, genresCount = 0;
37
37
static BOOL genresChanged = FALSE, isNT;
174
174
        }
175
175
}
176
176
 
 
177
static wchar_t *AnsiToWide(const char *src)
 
178
{
 
179
        int len;
 
180
        wchar_t *dest;
 
181
 
 
182
        FLAC__ASSERT(0 != src);
 
183
 
 
184
        len = strlen(src) + 1;
 
185
        /* copy */
 
186
        dest = (wchar_t*)malloc(len*sizeof(wchar_t));
 
187
        if (dest) mbstowcs(dest, src, len);
 
188
        return dest;
 
189
}
 
190
 
177
191
/*
178
192
 *  Infobox helpers
179
193
 */
180
194
 
181
 
#define SetText(x,y)            WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, FLAC_plugin__canonical_get(&data->tag, y), -1, buffer, sizeof(buffer), NULL, NULL); \
 
195
#define SetText(x,y)            ucs2 = FLAC_plugin__tags_get_tag_ucs2(data->tags, y); \
 
196
                                WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, ucs2, -1, buffer, sizeof(buffer), NULL, NULL); \
 
197
                                if(ucs2) free(ucs2); \
182
198
                                SetDlgItemText(hwnd, x, buffer)
183
199
 
184
200
#define GetText(x,y)            GetDlgItemText(hwnd, x, buffer, sizeof(buffer));                        \
185
 
                                if (*buffer) FLAC_plugin__canonical_set_ansi(&data->tag, y, buffer);    \
186
 
                                else FLAC_plugin__canonical_remove_all(&data->tag, y)
 
201
                                if (*buffer) { ucs2 = AnsiToWide(buffer); FLAC_plugin__tags_set_tag_ucs2(data->tags, y, ucs2, /*replace_all=*/false); free(ucs2); } \
 
202
                                else FLAC_plugin__tags_delete_tag(data->tags, y)
187
203
 
188
 
#define SetTextW(x,y)           SetDlgItemTextW(hwnd, x, FLAC_plugin__canonical_get(&data->tag, y))
 
204
#define SetTextW(x,y)           ucs2 = FLAC_plugin__tags_get_tag_ucs2(data->tags, y); \
 
205
                                SetDlgItemTextW(hwnd, x, ucs2); \
 
206
                                free(ucs2)
189
207
 
190
208
#define GetTextW(x,y)           GetDlgItemTextW(hwnd, x, (WCHAR*)buffer, sizeof(buffer)/2);                     \
191
 
                                if (*(WCHAR*)buffer) FLAC_plugin__canonical_set(&data->tag, y, (WCHAR*)buffer); \
192
 
                                else FLAC_plugin__canonical_remove_all(&data->tag, y)
 
209
                                if (*(WCHAR*)buffer) FLAC_plugin__tags_set_tag_ucs2(data->tags, y, (WCHAR*)buffer, /*replace_all=*/false); \
 
210
                                else FLAC_plugin__tags_delete_tag(data->tags, y)
193
211
 
194
212
 
195
213
static BOOL InitInfoboxInfo(HWND hwnd, const char *file)
196
214
{
197
215
        LOCALDATA *data = LocalAlloc(LPTR, sizeof(LOCALDATA));
 
216
        wchar_t *ucs2;
198
217
        FLAC__StreamMetadata streaminfo;
199
218
        DWORD    length, bps, ratio, rg;
200
219
        LONGLONG filesize;
208
227
        if (!filesize) return FALSE;
209
228
        if (!FLAC__metadata_get_streaminfo(file, &streaminfo))
210
229
                return FALSE;
211
 
        ReadTags(file, &data->tag, false);
 
230
        ReadTags(file, &data->tags, false);
212
231
 
213
232
        length = (DWORD)(streaminfo.data.stream_info.total_samples / streaminfo.data.stream_info.sample_rate);
214
233
        bps = (DWORD)(filesize / (125*streaminfo.data.stream_info.total_samples/streaminfo.data.stream_info.sample_rate));
215
234
        ratio = bps*1000000 / (streaminfo.data.stream_info.sample_rate*streaminfo.data.stream_info.channels*streaminfo.data.stream_info.bits_per_sample);
216
 
        rg  = FLAC_plugin__canonical_get(&data->tag, L"REPLAYGAIN_TRACK_GAIN") ? 1 : 0;
217
 
        rg |= FLAC_plugin__canonical_get(&data->tag, L"REPLAYGAIN_ALBUM_GAIN") ? 2 : 0;
 
235
        rg  = FLAC_plugin__tags_get_tag_utf8(data->tags, "REPLAYGAIN_TRACK_GAIN") ? 1 : 0;
 
236
        rg |= FLAC_plugin__tags_get_tag_utf8(data->tags, "REPLAYGAIN_ALBUM_GAIN") ? 2 : 0;
218
237
 
219
238
        sprintf(buffer, "Sample rate: %d Hz\nChannels: %d\nBits per sample: %d\nMin block size: %d\nMax block size: %d\n"
220
239
                        "File size: %I64d bytes\nTotal samples: %I64d\nLength: %d:%02d\nAvg. bitrate: %d\nCompression ratio: %d.%d%%\n"
228
247
        /* tag */
229
248
        if (isNT)
230
249
        {
231
 
                SetTextW(IDC_TITLE,   L"TITLE");
232
 
                SetTextW(IDC_ARTIST,  L"ARTIST");
233
 
                SetTextW(IDC_ALBUM,   L"ALBUM");
234
 
                SetTextW(IDC_COMMENT, L"COMMENT");
235
 
                SetTextW(IDC_YEAR,    L"DATE");
236
 
                SetTextW(IDC_TRACK,   L"TRACKNUMBER");
237
 
                SetTextW(IDC_GENRE,   L"GENRE");
 
250
                SetTextW(IDC_TITLE,   "TITLE");
 
251
                SetTextW(IDC_ARTIST,  "ARTIST");
 
252
                SetTextW(IDC_ALBUM,   "ALBUM");
 
253
                SetTextW(IDC_COMMENT, "COMMENT");
 
254
                SetTextW(IDC_YEAR,    "DATE");
 
255
                SetTextW(IDC_TRACK,   "TRACKNUMBER");
 
256
                SetTextW(IDC_GENRE,   "GENRE");
238
257
        }
239
258
        else
240
259
        {
241
 
                SetText(IDC_TITLE,   L"TITLE");
242
 
                SetText(IDC_ARTIST,  L"ARTIST");
243
 
                SetText(IDC_ALBUM,   L"ALBUM");
244
 
                SetText(IDC_COMMENT, L"COMMENT");
245
 
                SetText(IDC_YEAR,    L"DATE");
246
 
                SetText(IDC_TRACK,   L"TRACKNUMBER");
247
 
                SetText(IDC_GENRE,   L"GENRE");
 
260
                SetText(IDC_TITLE,   "TITLE");
 
261
                SetText(IDC_ARTIST,  "ARTIST");
 
262
                SetText(IDC_ALBUM,   "ALBUM");
 
263
                SetText(IDC_COMMENT, "COMMENT");
 
264
                SetText(IDC_YEAR,    "DATE");
 
265
                SetText(IDC_TRACK,   "TRACKNUMBER");
 
266
                SetText(IDC_GENRE,   "GENRE");
248
267
        }
249
268
 
250
269
        return TRUE;
251
270
}
252
271
 
253
 
static void __inline SetTag(HWND hwnd, const char *filename, FLAC_Plugin__CanonicalTag *tag)
 
272
static void __inline SetTag(HWND hwnd, const char *filename, FLAC__StreamMetadata *tags)
254
273
{
255
274
        strcpy(buffer, infoTitle);
256
275
 
257
 
        if (FLAC_plugin__vorbiscomment_set(filename, tag))
 
276
        if (FLAC_plugin__tags_set(filename, tags))
258
277
                strcat(buffer, " [Updated]");
259
278
        else strcat(buffer, " [Failed]");
260
279
 
264
283
static void UpdateTag(HWND hwnd)
265
284
{
266
285
        LOCALDATA *data = (LOCALDATA*)GetWindowLong(hwnd, GWL_USERDATA);
 
286
        wchar_t *ucs2;
267
287
 
268
288
        /* get fields */
269
289
        if (isNT)
270
290
        {
271
 
                GetTextW(IDC_TITLE,   L"TITLE");
272
 
                GetTextW(IDC_ARTIST,  L"ARTIST");
273
 
                GetTextW(IDC_ALBUM,   L"ALBUM");
274
 
                GetTextW(IDC_COMMENT, L"COMMENT");
275
 
                GetTextW(IDC_YEAR,    L"DATE");
276
 
                GetTextW(IDC_TRACK,   L"TRACKNUMBER");
277
 
                GetTextW(IDC_GENRE,   L"GENRE");
 
291
                GetTextW(IDC_TITLE,   "TITLE");
 
292
                GetTextW(IDC_ARTIST,  "ARTIST");
 
293
                GetTextW(IDC_ALBUM,   "ALBUM");
 
294
                GetTextW(IDC_COMMENT, "COMMENT");
 
295
                GetTextW(IDC_YEAR,    "DATE");
 
296
                GetTextW(IDC_TRACK,   "TRACKNUMBER");
 
297
                GetTextW(IDC_GENRE,   "GENRE");
278
298
 
279
 
                WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, FLAC_plugin__canonical_get(&data->tag, L"GENRE"), -1, buffer, sizeof(buffer), NULL, NULL);
 
299
                ucs2 = FLAC_plugin__tags_get_tag_ucs2(data->tags, "GENRE");
 
300
                WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, ucs2, -1, buffer, sizeof(buffer), NULL, NULL);
 
301
                free(ucs2);
280
302
        }
281
303
        else
282
304
        {
283
 
                GetText(IDC_TITLE,   L"TITLE");
284
 
                GetText(IDC_ARTIST,  L"ARTIST");
285
 
                GetText(IDC_ALBUM,   L"ALBUM");
286
 
                GetText(IDC_COMMENT, L"COMMENT");
287
 
                GetText(IDC_YEAR,    L"DATE");
288
 
                GetText(IDC_TRACK,   L"TRACKNUMBER");
289
 
                GetText(IDC_GENRE,   L"GENRE");
 
305
                GetText(IDC_TITLE,   "TITLE");
 
306
                GetText(IDC_ARTIST,  "ARTIST");
 
307
                GetText(IDC_ALBUM,   "ALBUM");
 
308
                GetText(IDC_COMMENT, "COMMENT");
 
309
                GetText(IDC_YEAR,    "DATE");
 
310
                GetText(IDC_TRACK,   "TRACKNUMBER");
 
311
                GetText(IDC_GENRE,   "GENRE");
290
312
        }
291
313
 
292
314
        /* update genres list (buffer should contain genre) */
293
315
        if (buffer[0]) AddGenre(hwnd, buffer);
294
316
 
295
317
        /* write tag */
296
 
        SetTag(hwnd, data->filename, &data->tag);
 
318
        SetTag(hwnd, data->filename, data->tags);
297
319
}
298
320
 
299
321
static void RemoveTag(HWND hwnd)
300
322
{
301
323
        LOCALDATA *data = (LOCALDATA*)GetWindowLong(hwnd, GWL_USERDATA);
302
 
        FLAC_plugin__canonical_tag_clear(&data->tag);
 
324
        FLAC_plugin__tags_delete_all(data->tags);
303
325
 
304
326
        SetDlgItemText(hwnd, IDC_TITLE,   "");
305
327
        SetDlgItemText(hwnd, IDC_ARTIST,  "");
309
331
        SetDlgItemText(hwnd, IDC_TRACK,   "");
310
332
        SetDlgItemText(hwnd, IDC_GENRE,   "");
311
333
 
312
 
        SetTag(hwnd, data->filename, &data->tag);
 
334
        SetTag(hwnd, data->filename, data->tags);
313
335
}
314
336
 
315
337
 
329
351
        case WM_DESTROY:
330
352
                {
331
353
                        LOCALDATA *data = (LOCALDATA*)GetWindowLong(hwnd, GWL_USERDATA);
332
 
                        FLAC_plugin__canonical_tag_clear(&data->tag);
 
354
                        FLAC_plugin__tags_destroy(&data->tags);
333
355
                        LocalFree(data);
334
356
                        DeinitGenres(hwnd, FALSE);
335
357
                }
390
412
        return (char*)c;
391
413
}
392
414
 
393
 
void ReadTags(const char *fileName, FLAC_Plugin__CanonicalTag *tag, BOOL forDisplay)
 
415
void ReadTags(const char *fileName, FLAC__StreamMetadata **tags, BOOL forDisplay)
394
416
{
395
 
        FLAC_plugin__canonical_tag_init(tag);
396
 
        FLAC_plugin__vorbiscomment_get(fileName, tag, forDisplay ? flac_cfg.title.sep : NULL);
397
 
 
398
 
        /* add file name */
399
 
        if (forDisplay)
400
 
        {
401
 
                char *c;
402
 
                FLAC_plugin__canonical_set_ansi(tag, L"filepath", fileName);
403
 
 
404
 
                strcpy(buffer, GetFileName(fileName));
405
 
                if (c = strrchr(buffer, '.')) *c = 0;
406
 
                FLAC_plugin__canonical_set_ansi(tag, L"filename", buffer);
 
417
        if(FLAC_plugin__tags_get(fileName, tags)) {
 
418
 
 
419
                /* add file name */
 
420
                if (forDisplay)
 
421
                {
 
422
                        char *c;
 
423
                        wchar_t *ucs2;
 
424
                        ucs2 = AnsiToWide(fileName);
 
425
                        FLAC_plugin__tags_set_tag_ucs2(*tags, "filepath", ucs2, /*replace_all=*/true);
 
426
                        free(ucs2);
 
427
 
 
428
                        strcpy(buffer, GetFileName(fileName));
 
429
                        if (c = strrchr(buffer, '.')) *c = 0;
 
430
                        ucs2 = AnsiToWide(buffer);
 
431
                        FLAC_plugin__tags_set_tag_ucs2(*tags, "filename", ucs2, /*replace_all=*/true);
 
432
                        free(ucs2);
 
433
                }
407
434
        }
408
435
}
409
436