ExtendedInfo.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <bfc/platform/types.h>
  2. #include <windows.h>
  3. #include <strsafe.h>
  4. #include "api__in_mod.h"
  5. #include "resource.h"
  6. #include <libopenmpt/libopenmpt.h>
  7. #include "../nu/AutoChar.h"
  8. #include "../nu/ns_wc.h"
  9. #include <libopenmpt/libopenmpt_stream_callbacks_file.h>
  10. static wchar_t *open_filename = 0;
  11. static openmpt_module *info_mod = 0;
  12. openmpt_module *OpenMod(const wchar_t *filename);
  13. extern "C" __declspec(dllexport)
  14. int winampGetExtendedFileInfoW(const wchar_t *fn, const char *data, wchar_t *dest, size_t destlen)
  15. {
  16. if (!_stricmp(data, "type"))
  17. {
  18. dest[0]='0';
  19. dest[1]=0;
  20. return 1;
  21. }
  22. else if (!_stricmp(data, "family"))
  23. {
  24. size_t len;
  25. const wchar_t *p;
  26. if (!fn || !fn[0]) {
  27. return 0;
  28. }
  29. len = wcslen(fn);
  30. if (len < 4 || L'.' != fn[len - 4]) {
  31. return 0;
  32. }
  33. p = &fn[len - 3];
  34. const char *tracker = openmpt_get_tracker_name(AutoChar(p));
  35. if (tracker && *tracker) {
  36. *dest = 0;
  37. MultiByteToWideCharSZ(CP_UTF8, 0, tracker, -1, dest, (int)destlen);
  38. openmpt_free_string(tracker);
  39. return 1;
  40. }
  41. openmpt_free_string(tracker);
  42. return 0;
  43. } else {
  44. if (!open_filename || _wcsicmp(open_filename,fn)) {
  45. free(open_filename);
  46. open_filename = _wcsdup(fn);
  47. openmpt_module_destroy(info_mod);
  48. info_mod = 0;
  49. info_mod = OpenMod(fn);
  50. }
  51. int retval = 0;
  52. if (!_stricmp(data, "length")) {
  53. double seconds = openmpt_module_get_duration_seconds(info_mod);
  54. StringCchPrintf(dest, destlen, L"%.0f", seconds*1000.0);
  55. retval = 1;
  56. } else if (!_stricmp(data, "artist")) {
  57. const char *value = openmpt_module_get_metadata(info_mod, "artist");
  58. MultiByteToWideCharSZ(CP_UTF8, 0, value, -1, dest, (int)destlen);
  59. openmpt_free_string(value);
  60. retval = 1;
  61. } else if (!_stricmp(data, "tool")) {
  62. const char *value = openmpt_module_get_metadata(info_mod, "tracker");
  63. MultiByteToWideCharSZ(CP_UTF8, 0, value, -1, dest, (int)destlen);
  64. openmpt_free_string(value);
  65. retval = 1;
  66. } else if (!_stricmp(data, "title")) {
  67. const char *value = openmpt_module_get_metadata(info_mod, "title");
  68. MultiByteToWideCharSZ(CP_UTF8, 0, value, -1, dest, (int)destlen);
  69. openmpt_free_string(value);
  70. retval = 1;
  71. } else if (!_stricmp(data, "year")) {
  72. const char *value = openmpt_module_get_metadata(info_mod, "date");
  73. MultiByteToWideCharSZ(CP_UTF8, 0, value, -1, dest, (int)destlen);
  74. openmpt_free_string(value);
  75. retval = 1;
  76. } else if (!_stricmp(data, "comment")) {
  77. const char *value = openmpt_module_get_metadata(info_mod, "message");
  78. MultiByteToWideCharSZ(CP_UTF8, 0, value, -1, dest, (int)destlen);
  79. openmpt_free_string(value);
  80. retval = 1;
  81. }
  82. return retval;
  83. }
  84. return 0;
  85. }