[go: up one dir, main page]

Menu

[r100]: / in_vgm / trunk / fileinfo.c  Maximize  Restore  History

Download this file

827 lines (733 with data), 27.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
#include <windows.h>
#include <stdio.h>
#include <zlib.h>
#include "fileinfo.h"
#include "vgm.h"
#include "gd3.h"
#include "common.h"
#include "Winamp SDK/Winamp/wa_ipc.h"
#include "Winamp SDK/Winamp/in2.h"
#include "resource.h"
extern In_Module mod;
// Ought to move these "globals" into a struct or something, just to make it less icky
extern char *TempHTMLFile;
extern char *CurrentURL;
extern char *CurrentURLFilename;
extern char *FilenameForInfoDlg;
extern int UseMB,MLJapanese, MLType, LoopForever, MLShowFM, NumLoops, PlaybackRate, FileInfoJapanese;
// forward declarations
int LoadInfo(const char *filename, struct TFileTagInfo *fileinfo);
//-----------------------------------------------------------------
// Returns a formatted string for the file's length
// Doesn't scale it using the playback rate
//-----------------------------------------------------------------
char *FormatLength( char *buffer, struct TFileTagInfo *fileinfo )
{
char temp[1024];
PrintTime(buffer, fileinfo->tracklength / 1000.0 ); // total length
if ( fileinfo->looplength > 0 )
{
// file has a loop
if ( fileinfo->tracklength - fileinfo->looplength > 500 )
{
// intro > 500ms
strcat( buffer, " (" );
strcat( buffer, PrintTime( temp, ( fileinfo->tracklength - fileinfo->looplength ) / 1000.0 ) );
strcat( buffer, " intro and " );
strcat( buffer, PrintTime( temp, fileinfo->looplength / 1000.0 ) );
strcat( buffer, " loop)" );
}
else
{
// small or no intro
strcat( buffer, " (looped)" );
}
}
else
{
strcat( buffer, " (no loop)" );
}
return buffer;
}
//-----------------------------------------------------------------
// Show GD3 info as HTML
//-----------------------------------------------------------------
void InfoInBrowser(const char *filename, int UseMB, int ForceOpen) {
FILE *f;
char *packname = NULL;
int i, j;
char *url;
char tempstr[1024]; // used for inline printf()s
const char What[10][32]={
"Track Title", "",
"Game Name", "",
"System Name", "",
"Track Author", "",
"Game Release Date", "VGM Creator"
};
struct TFileTagInfo fileinfo;
memset( &fileinfo, 0, sizeof(struct TFileTagInfo) );
if ( LoadInfo( filename, &fileinfo ) )
{
f = fopen(TempHTMLFile,"w"); // open temp HTML file for writing
if ( f )
{
// Put start text
fprintf(f,
#include "htmlbefore.txt"
);
// Add length row
fprintf( f, "<tr><td class=what>Length</td><td colspan=2 class=is>%s</td></tr>", FormatLength( tempstr, &fileinfo ) );
// Add file size row
fprintf( f, "<tr><td class=what>Size</td><td class=is colspan=2>%d bytes (%.2f bps)</td></tr>",
fileinfo.filesize,
fileinfo.bitrate
);
// first 8 strings are alternating English/Japanese
for ( i = GD3_TITLEEN; i <= GD3_AUTHORJP; ++i ) {
if ( i % 2 - 1 ) // odd number: add row title
fprintf( f, "<tr><td class=what>%s</td><td class=is>", What[i] );
if ( fileinfo.tags[i] && *(fileinfo.tags[i]) )
{
// string is not blank
for ( j = 0; *(fileinfo.tags[i] + j); j++ )
// write each character as a NCR
fprintf( f, "&#%d;", *(fileinfo.tags[i] + j) );
}
else
// put a NBSP for blanks to make the cell fill out properly
fprintf( f, "&nbsp;");
if ( i % 2 ) // even number: end row
fprintf( f, "</td></tr>" );
else // odd number: continue row
fprintf( f, "</td><td class=is>" );
}
// Strings 8 to 10 have rows to themselves
for ( i = GD3_DATE; i < GD3_NOTES; ++i ) {
fprintf( f, "<tr><td class=what>%s</td><td colspan=2 class=is>", What[i] );
if ( fileinfo.tags[i] && *(fileinfo.tags[i]) ) // string is not blank
for ( j = 0; *(fileinfo.tags[i] + j); j++ )
fprintf( f, "&#%d;", *(fileinfo.tags[i] + j) );
else
fprintf( f, "&nbsp;" );
fprintf(f, "</td></tr>" );
}
if ( fileinfo.tags[GD3_NOTES] && *(fileinfo.tags[GD3_NOTES]) )
{
// Notes (10th string) need some processing of line breaks
fprintf(f, "<tr><td class=what>Notes</td><td colspan=2 class=is>" );
for ( j = 0; *(fileinfo.tags[GD3_NOTES] + j); ++j ) {
if (*(fileinfo.tags[GD3_NOTES] + j) == '\n')
fprintf( f, "<br>" );
else
fprintf( f, "&#%d;", *(fileinfo.tags[GD3_NOTES] + j) );
}
// End of strings
fprintf( f, "</td></tr>" );
}
// Try for the pack readme
{
char *p;
FILE *freadme;
char *buffer;
char *readme;
BOOL success = FALSE;
readme = malloc( strlen( filename ) + 16 ); // plenty of space in all weird cases
if( readme )
{
p = strrchr( filename, '\\' ); // p points to the last \ in the filename
if ( p )
{
while( !success ) {
p = strstr( p, " - " ); // find first " - " after current position of p
if ( p ) {
strncpy( readme, filename, p - filename ); // copy filename up until the " - "
strcpy( readme + ( p - filename ), ".txt" ); // terminate it with a ".txt\0"
freadme = fopen( readme, "r" ); // try to open file
if ( freadme ) {
// save pack name for later use
packname = malloc( strlen( readme ) );
if ( packname ) {
strncpy( packname, readme, strlen( readme ) - 4 );
packname[ strlen( readme ) - 4 ] = '\0';
}
success = TRUE;
fprintf( f, "<tr><td class=what>Pack readme</td><td class=is colspan=2><textarea id=readme cols=50 rows=20 readonly>");
buffer = malloc( 1024 );
while ( fgets( buffer, 1024, freadme ) )
fputs( buffer, f );
free( buffer );
fprintf( f, "</textarea></td></tr>" );
fclose( freadme );
}
p++; // make it not find this " - " next iteration
} else break;
}
}
free(readme);
}
}
// Try for image
if ( packname ) {
FILE *fimage;
char *imagefile = malloc( strlen( packname ) + 10 );
BOOL foundit = FALSE;
sprintf( imagefile, "%s.png", packname );
if ( fimage = fopen( imagefile, "r" ) )
foundit = TRUE;
if ( !foundit )
{
sprintf( imagefile, "%s.gif", packname );
if ( fimage = fopen( imagefile, "r" ) )
foundit = TRUE;
}
if ( !foundit )
{
sprintf( imagefile, "%s.jpg", packname );
if ( fimage = fopen( imagefile, "r" ) )
foundit = TRUE;
}
if ( !foundit )
{
// try folder.jpg
char *p;
strcpy( imagefile, packname );
p = strrchr( imagefile, '\\' );
if ( p )
{
strcpy( p, "\\folder.jpg" );
if ( fimage = fopen( imagefile, "r" ) )
foundit = TRUE;
}
}
if ( foundit )
{
fclose( fimage );
fprintf(f,"<tr><td class=what>Pack image</td><td class=is colspan=2><img src=\"file:///%s\"></td></tr>", imagefile);
}
free( imagefile );
}
fputs("</table>",f);
fputs(
#include "htmlafter.txt"
,f
);
fclose(f);
if ( UseMB ) {
url = malloc( strlen( TempHTMLFile ) + 9 );
sprintf( url, "file:///%s", TempHTMLFile );
if ( ForceOpen ) SendMessage(mod.hMainWindow,WM_USER,(WPARAM)NULL,IPC_MBOPEN); // open minibrowser
SendMessage(mod.hMainWindow,WM_USER,(WPARAM)url,IPC_MBOPEN); // display file
free(url);
}
else ShellExecute(mod.hMainWindow,NULL,TempHTMLFile,NULL,NULL,SW_SHOWNORMAL);
}
}
}
//-----------------------------------------------------------------
// GD3 helper stuff
//-----------------------------------------------------------------
struct TFileTagInfo LastFileInfo = {NULL};
//-----------------------------------------------------------------
// Get the track number for a given filename
// by trying to find its M3U playlist
//-----------------------------------------------------------------
int GetTrackNumber(const char *filename) {
// assumes a filename "Streets of Rage II - Never Return Alive.vgz"
// will have a playlist "Streets of Rage II.m3u"
// returns track number, or 0 for not found
FILE *f;
char *playlist;
char *p;
char *fn;
char buff[1024]; // buffer for reading lines from file
int number=0;
int linenumber;
playlist=malloc(strlen(filename)+16); // plenty of space in all weird cases
if(playlist) {
p=strrchr(filename,'\\'); // p points to the last \ in the filename
if(p){
// isolate filename
fn=malloc(strlen(p));
if(fn) {
strcpy(fn,p+1);
while(number==0) {
p=strstr(p," - "); // find first " - " after current position of p
if(p) {
strncpy(playlist,filename,p-filename); // copy filename up until the " - "
strcpy(playlist+(p-filename),".m3u"); // terminate it with a ".m3u\0"
f=fopen(playlist,"r"); // try to open file
if(f) {
linenumber=1;
// read through file, a line at a time
while(fgets(buff,1024,f) && (number==0)) { // fgets will read in all characters up to and including the line break
if(strnicmp(buff,fn,strlen(fn))==0) {
// found it!
number=linenumber;
}
if((strlen(buff)>3)&&(buff[0]!='#')) linenumber++; // count lines that are (probably) valid but not #EXTINF lines
}
fclose(f);
}
p++; // make it not find this " - " next iteration
} else break;
}
free(fn);
}
}
free(playlist);
}
return number;
}
//-----------------------------------------------------------------
// Load the given file's GD3 info into the given TFileTagInfo struct
//-----------------------------------------------------------------
int LoadInfo(const char *filename, struct TFileTagInfo *fileinfo)
{
// load info from filename into fileinfo
gzFile *fh;
struct TVGMHeader VGMHeader;
int i;
// Blank info
// Free pointed data first
free( fileinfo->filename );
for (i=0;i<NUMGD3TAGS;++i) {
free( fileinfo->tags[i] );
}
// Zero the struct - assuming zero is a nice field to initialise things to
memset( fileinfo, 0, sizeof(struct TFileTagInfo) );
// copy filename
fileinfo->filename = malloc(strlen(filename)+1);
strcpy(fileinfo->filename, filename);
// get file size
fileinfo->filesize = FileSize(filename);
// Start to read things in
fh=gzopen(filename,"rb");
if (fh==0) { // file not opened
return 0;
}
i=gzread(fh,&VGMHeader,sizeof(VGMHeader));
if ( (i < sizeof(VGMHeader))
|| (VGMHeader.VGMIdent != VGMIDENT)
|| ((VGMHeader.Version<MINVERSION) || ((VGMHeader.Version & REQUIREDMAJORVER)!=REQUIREDMAJORVER))
) {
gzclose(fh);
return 0;
}
// VGM header OK
fileinfo->tracklength = (int) (
(VGMHeader.TotalLength)
/44.1
*((PlaybackRate&&VGMHeader.RecordingRate)?(double)VGMHeader.RecordingRate/PlaybackRate:1)
);
fileinfo->looplength = (int) (
(VGMHeader.LoopLength)
/44.1
*((PlaybackRate&&VGMHeader.RecordingRate)?(double)VGMHeader.RecordingRate/PlaybackRate:1)
);
if ( LoopForever )
fileinfo->length = -1000;
else
fileinfo->length = fileinfo->tracklength + NumLoops * fileinfo->looplength;
// bytes * 8 = bits
// ms / 1000 = seconds
// thus (bytes * 8 ) / (ms / 1000) = bytes * 8000 / ms
fileinfo->bitrate = (float)fileinfo->filesize * 8000 / fileinfo->tracklength;
fileinfo->chips_used[VGM_CHIP_SN76489] = VGMHeader.PSGClock > 0;
fileinfo->chips_used[VGM_CHIP_YM2413] = VGMHeader.YM2413Clock > 0;
if (VGMHeader.Version<0x0110)
{
// VGM <1.10 only has one clock setting for all FM chips
fileinfo->chips_used[VGM_CHIP_YM2612] = fileinfo->chips_used[VGM_CHIP_YM2151] = fileinfo->chips_used[VGM_CHIP_YM2413];
}
else
{
fileinfo->chips_used[VGM_CHIP_YM2612] = VGMHeader.YM2612Clock > 0;
fileinfo->chips_used[VGM_CHIP_YM2151] = VGMHeader.YM2151Clock > 0;
}
// vgmversion is a fixed-size buffer, big enough for all possible values
_snprintf( fileinfo->vgmversion, 7, "%x.%02x", VGMHeader.Version >> 8, VGMHeader.Version & 0xff );
if (VGMHeader.GD3Offset>0) {
// GD3 tag exists
struct TGD3Header GD3Header;
gzseek(fh,VGMHeader.GD3Offset+0x14,SEEK_SET);
i=gzread(fh,&GD3Header,sizeof(GD3Header));
if (
(i==sizeof(GD3Header)) &&
(GD3Header.GD3Ident == GD3IDENT) &&
(GD3Header.Version>=MINGD3VERSION) &&
((GD3Header.Version & REQUIREDGD3MAJORVER)==REQUIREDGD3MAJORVER)
) {
// GD3 is acceptable version
wchar *GD3data,*p;
GD3data=malloc(GD3Header.Length); // Allocate memory for string data
gzread(fh,GD3data,GD3Header.Length); // Read it in
// convert into struct
p = GD3data;
for (i=0; i<NUMGD3TAGS; ++i)
{
int len;
// skip leading whitespace
while (*p && *p < 256 && isspace(*p))
p++;
// copy tag, exclude trailing whitespace
len = wcslen(p);
while (len > 0 && p[len-1] < 256 && isspace(p[len-1]))
len--;
if (len > 0)
{
fileinfo->tags[i] = malloc( (len + 1) * sizeof(wchar) );
if ( fileinfo->tags[i] )
{
wcsncpy( fileinfo->tags[i], p, len );
fileinfo->tags[i][len]=0; // null terminate
}
// special cases?
switch(i) {
case GD3_GAMEEN:
case GD3_GAMEJP: // album: append " (FM)" for FM soundtracks if wanted
if ( MLShowFM
&& VGMHeader.YM2413Clock
&& (
// hack: not for 7MHzish clocks, for VGM < 1.10, because that's likely to be a YM2612 clock
(VGMHeader.Version >= 0x0110) || (VGMHeader.YM2413Clock < 7000000)
)
)
{
// re-allocate with a bit on the end and replace original
wchar *buffer = malloc( (len + 6)*sizeof(wchar) );
if ( buffer )
{
swprintf( buffer, L"%s (FM)", fileinfo->tags[i] );
free( fileinfo->tags[i] );
fileinfo->tags[i] = buffer;
}
}
break;
}
}
else
{
fileinfo->tags[i]=NULL; // not needed, but I'm being explicit
}
// move pointer on
p += wcslen(p)+1;
}
free(GD3data); // Free memory for string buffer
}
}
else
{
// blank GD3 entries
// note: the pointers were all zeroed above (memset()) but I'm doing this explicitly just in case
for (i=0; i<NUMGD3TAGS; ++i)
{
fileinfo->tags[i] = NULL;
}
}
gzclose(fh);
return 1;
// done!
}
//-----------------------------------------------------------------
// GetExtendedFileInfoW worker function
//-----------------------------------------------------------------
int GetExtendedFileInfo(const char *filename,const char *metadata,wchar *ret,int retlen) {
// return zero on failure
int tagindex=GD3X_UNKNOWN;
// can't do anything with no buffer
if(!ret || !retlen)
return 0;
// first, tags that don't need to look at the file itself
if(stricmp(metadata,"type")==0) { // type
_snwprintf(ret,retlen,L"%d",MLType);
return 1;
}
if(stricmp(metadata,"track")==0) { // track number
int i=GetTrackNumber(filename);
if(i>0) {
_snwprintf(ret,retlen,L"%d",i);
return 1;
} else return 0;
}
// next, check if we've already looked at this file
if (!LastFileInfo.filename || strcmp(LastFileInfo.filename,filename)!=0)
{
LoadInfo(filename, &LastFileInfo);
// do another check on that filename in case it failed
if (!LastFileInfo.filename || strcmp(LastFileInfo.filename,filename)!=0)
return 0;
}
// now start returning stuff
*ret=0;
if(stricmp(metadata,"artist")==0) tagindex=GD3_AUTHOREN; // author
else if(stricmp(metadata,"length")==0) tagindex=GD3X_LENGTH; // length /ms
else if(stricmp(metadata,"title")==0) tagindex=GD3_TITLEEN; // track title
else if(stricmp(metadata,"album")==0) tagindex=GD3_GAMEEN; // game name
else if(stricmp(metadata,"comment")==0) tagindex=GD3_NOTES; // comment
else if(stricmp(metadata,"year")==0) tagindex=GD3_DATE; // year
else if(stricmp(metadata,"genre")==0) tagindex=GD3_SYSTEMEN; // system
#ifdef _DEBUG
if(tagindex==GD3X_UNKNOWN)
{
// debug: get metadata types
OutputDebugString("in_vgm: Unknown metadata type: \"");
OutputDebugString(metadata);
OutputDebugString("\"\n");
}
#endif
if((MLJapanese)&&(tagindex>=GD3_TITLEEN)&&(tagindex<=GD3_AUTHOREN)) tagindex++; // Increment index for Japanese
switch (tagindex) {
case GD3X_LENGTH:
_snwprintf(ret,retlen,L"%d",LastFileInfo.length);
break;
case GD3_TITLEEN: case GD3_TITLEJP: case GD3_GAMEEN: case GD3_GAMEJP: case GD3_SYSTEMEN: case GD3_SYSTEMJP:
case GD3_AUTHOREN: case GD3_AUTHORJP: case GD3_DATE: case GD3_RIPPER: case GD3_NOTES:
// copy from LastFileInfo, but check for empty ones and use the alternative
if (
( (LastFileInfo.tags[tagindex] == NULL) || (wcslen(LastFileInfo.tags[tagindex]) == 0) )
&&( tagindex <= GD3_AUTHORJP)
) {
// tweak index to point to alternative
if(tagindex%2) tagindex--;
else tagindex++;
}
if ( LastFileInfo.tags[tagindex] )
{
// special cases
switch(tagindex)
{
case GD3_DATE: // year
{
// try to detect various date formats
// Not yyyy/mm/dd:
// nn/nn/yy n/n/yy nn/n/yy n/nn/yy
// nn/nn/yyyy n/n/yyyy nn/n/yyyy n/nn/yyyy
// Should be:
// yyyy
// yyyy/mm
// yyyy/mm/dd
wchar *lastslash = wcsrchr( LastFileInfo.tags[tagindex], L'/' );
if (lastslash != NULL)
{
long year = wcstol(lastslash+1,NULL,10);
if (year > 31) // looks like a year
{
if ( year < 100 ) // 2-digit, yuck
{
year += 1900;
if (year < 1950) // not many sound chips around then, due to lack of transistors
year += 100;
}
_snwprintf(ret,retlen,L"%d",year);
}
}
if (!*ret)
{
// else, try the first bit
wcsncpy( ret, LastFileInfo.tags[tagindex], 4 );
ret[4]=0;
}
}
break;
default:
// copy
wcsncpy( ret, LastFileInfo.tags[tagindex], retlen );
break;
}
}
break;
default:
// do nothing
break;
}
if ( *ret == 0 )
// empty buffer: we didn't have anything to add
return 0;
else
return 1;
}
//-----------------------------------------------------------------
// winampGetExtendedFileInfoW (Unicode) export for Winamp 5.25+
// Winamp will call this one when it expects a Unicode result
//-----------------------------------------------------------------
__declspec(dllexport) int winampGetExtendedFileInfoW(const wchar *wfilename,const char *metadata,wchar *ret,int retlen) {
char *filename;
int filename_length, result;
// hack: convert filename to ASCII
// problem: filenames are a bit more accurate than random-insert-?-o-matic will do for us, so international filenames might be screwed
filename_length = WideCharToMultiByte( CP_ACP, WC_COMPOSITECHECK, wfilename, -1, NULL, 0, NULL, NULL ) + 1;
filename = malloc(filename_length);
WideCharToMultiByte( CP_ACP, WC_COMPOSITECHECK, wfilename, -1, filename, filename_length, NULL, NULL );
// get tag info
result = GetExtendedFileInfo( filename, metadata, ret, retlen );
// free ASCII filename
free(filename);
return result;
}
//-----------------------------------------------------------------
// winampGetExtendedFileInfo (non-Unicode) export for old Winamps
// Winamp will call this one when it expects an ASCII result
// eg. from a non-Unicode API call
//-----------------------------------------------------------------
__declspec(dllexport) int winampGetExtendedFileInfo(const char *filename,const char *metadata,char *ret,int retlen) {
wchar *wret;
int result;
// allocate wchar result buffer
wret = malloc((retlen+1) * sizeof(wchar));
// get tag info
result = GetExtendedFileInfo( filename, metadata, wret, retlen );
// convert result to ASCII/MBCS
WideCharToMultiByte(CP_ACP,WC_COMPOSITECHECK,wret,-1,ret,retlen,NULL,NULL);
// free local buffer
free(wret);
return result;
}
//-----------------------------------------------------------------
// File info dialogue callback function
// Have to store file info outside because it's called multiple times
//-----------------------------------------------------------------
struct TFileTagInfo InfoDialogFileInfo;
BOOL CALLBACK FileInfoDialogProc(HWND DlgWin,UINT wMessage,WPARAM wParam,LPARAM lParam) {
const int DlgFields[NUMGD3TAGS] = {
ebTitle, ebTitle,
ebName, ebName,
ebSystem, ebSystem,
ebAuthor, ebAuthor,
ebDate,
ebCreator,
ebNotes
};
switch (wMessage) { // process messages
case WM_INITDIALOG: {
//----------------------------------------------------------------
// Initialise dialogue
//----------------------------------------------------------------
int i;
char tempstr[1024];
if ( IsURL( FilenameForInfoDlg ) ) {
// Filename is a URL
if (
CurrentURLFilename && CurrentURL && (
( strcmp( FilenameForInfoDlg, CurrentURLFilename ) == 0) ||
( strcmp( FilenameForInfoDlg, CurrentURL ) == 0)
)
)
{
// If it's the current file, look at the temp file
// but display the URL
SetDlgItemText( DlgWin, ebFilename, CurrentURL );
FilenameForInfoDlg = CurrentURLFilename;
}
else
{
// If it's not the current file, no info
SetDlgItemText( DlgWin, ebFilename, FilenameForInfoDlg );
SetDlgItemText( DlgWin, ebNotes, "Information unavailable for this URL" );
DISABLECONTROL( DlgWin, btnInfoInBrowser );
return TRUE;
}
} else {
// Filename is not a URL
SetDlgItemText( DlgWin, ebFilename, FilenameForInfoDlg );
}
// Load metadata
LoadInfo( FilenameForInfoDlg, &InfoDialogFileInfo );
// VGM version
SetDlgItemText( DlgWin, ebVersion, InfoDialogFileInfo.vgmversion );
// Chips used
SETCHECKBOX( DlgWin, rbSN76489, InfoDialogFileInfo.chips_used[VGM_CHIP_SN76489] );
SETCHECKBOX( DlgWin, rbYM2413, InfoDialogFileInfo.chips_used[VGM_CHIP_YM2413] );
SETCHECKBOX( DlgWin, rbYM2612, InfoDialogFileInfo.chips_used[VGM_CHIP_YM2612] );
SETCHECKBOX( DlgWin, rbYM2151, InfoDialogFileInfo.chips_used[VGM_CHIP_YM2151] );
if ( InfoDialogFileInfo.chips_used[VGM_CHIP_YM2413] == InfoDialogFileInfo.chips_used[VGM_CHIP_YM2612]
&& InfoDialogFileInfo.chips_used[VGM_CHIP_YM2413] == InfoDialogFileInfo.chips_used[VGM_CHIP_YM2151] )
{
// looks like an old VGM file, so hide those extra boxes and rename the other one
SetDlgItemText( DlgWin, rbYM2413, "FM chips" );
HIDECONTROL( DlgWin, rbYM2612 );
HIDECONTROL( DlgWin, rbYM2151 );
}
// Size and bitrate
sprintf(
tempstr,
"%d bytes (%.2f bps)",
InfoDialogFileInfo.filesize,
InfoDialogFileInfo.bitrate
);
SetDlgItemText(DlgWin,ebSize,tempstr);
// Length
SetDlgItemText( DlgWin, ebLength, FormatLength( tempstr, &InfoDialogFileInfo ) );
// Set non-language-changing fields here
for ( i = GD3_DATE; i < NUMGD3TAGS; ++i ) {
if ( !SetDlgItemTextW( DlgWin, DlgFields[i], InfoDialogFileInfo.tags[i] ) )
{
// Widechar text setting failed, try WC2MB
char MBCSstring[1024 * 2] = "";
WideCharToMultiByte( CP_ACP, WC_COMPOSITECHECK, InfoDialogFileInfo.tags[i], -1, MBCSstring, 1024 * 2, NULL, NULL );
SetDlgItemTextA( DlgWin, DlgFields[i], MBCSstring );
}
}
// trigger English or Japanese for other fields
SETCHECKBOX( DlgWin, rbEnglish + FileInfoJapanese, TRUE );
PostMessage( DlgWin, WM_COMMAND, rbEnglish + FileInfoJapanese, 0);
return TRUE;
}
case WM_COMMAND:
//----------------------------------------------------------------
// Control messages
//----------------------------------------------------------------
switch (LOWORD(wParam)) {
case IDOK:
//----------------------------------------------------------------
// OK button
//----------------------------------------------------------------
FileInfoJapanese=IsDlgButtonChecked(DlgWin,rbJapanese);
EndDialog(DlgWin,0); // return 0 = OK
return TRUE;
case IDCANCEL:
//----------------------------------------------------------------
// [X], Esc, Alt+F4
//----------------------------------------------------------------
EndDialog(DlgWin,1); // return 1 = Cancel, stops further dialogues being opened
return TRUE;
case btnConfigure:
//----------------------------------------------------------------
// Configure Plugin
//----------------------------------------------------------------
mod.Config(DlgWin);
break;
case rbEnglish:
case rbJapanese:
//----------------------------------------------------------------
// English/Japanese
//----------------------------------------------------------------
{
int i;
// offset by 1 for japanese
const int offset = (LOWORD(wParam) == rbJapanese ? 1 : 0);
// fill in fields
for ( i = GD3_TITLEEN; i <= GD3_AUTHOREN; i += 2 ) {
if ( !SetDlgItemTextW( DlgWin, DlgFields[i + offset], InfoDialogFileInfo.tags[i + offset] ) )
{
// ASCII conversion fallback
char MBCSstring[1024 * 2] = "";
WideCharToMultiByte( CP_ACP, WC_COMPOSITECHECK, InfoDialogFileInfo.tags[i + offset], -1, MBCSstring, 1024 * 2, NULL, NULL );
SetDlgItemText( DlgWin, DlgFields[i + offset], MBCSstring );
}
}
}
break;
case btnInfoInBrowser:
//----------------------------------------------------------------
// Info In Browser
//----------------------------------------------------------------
InfoInBrowser( FilenameForInfoDlg, UseMB, TRUE );
break;
default:
break;
}
break;
}
return FALSE ; // return FALSE to signify message not processed
}