1
0

Metadata.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "main.h"
  2. #include "Metadata.h"
  3. #include "api.h"
  4. #include <api/service/waservicefactory.h>
  5. /**
  6. ** Author: Ben Allison
  7. ** original date: April 10, 2006
  8. */
  9. Metadata::~Metadata()
  10. {
  11. for ( wchar_t *l_key : keys )
  12. free( l_key );
  13. keys.clear();
  14. }
  15. int Metadata::GetExtendedFileInfo(const wchar_t *filename, const wchar_t *tag, wchar_t *data, size_t dataLength)
  16. {
  17. // benski> old way CUT: return in_get_extended_fileinfoW(filename, tag, data, dataLength);
  18. /*
  19. int result = 0; // failure
  20. svc_metaTag *metaTag = GetMetaTagObject(filename, METATAG_ALL, 0, 0);
  21. if (metaTag)
  22. {
  23. if (metaTag->metaTag_open(filename) == METATAG_SUCCESS)
  24. metaTag->getMetaData(tag, reinterpret_cast<__int8 *>(data), dataLength*sizeof(wchar_t), METATYPE_STRING);
  25. metaTag->metaTag_close();
  26. }
  27. else // TODO: we could get rid of this as soon as we make extendedMetaTag (see TODO at end of file)
  28. */
  29. return in_get_extended_fileinfoW(filename, tag, data, dataLength);
  30. //return !!(result == METATAG_SUCCESS);
  31. }
  32. int Metadata::SetExtendedFileInfo(const wchar_t *filename, const wchar_t *tag, const wchar_t *data)
  33. {
  34. return in_set_extended_fileinfoW(filename, tag, const_cast<wchar_t *>(data));
  35. }
  36. int Metadata::WriteExtendedFileInfo(const wchar_t *filename)
  37. {
  38. return in_write_extended_fileinfo();
  39. }
  40. inline static bool InList(const GUID guid, GUID *exclude, int numExcludes)
  41. {
  42. if (!exclude)
  43. return false;
  44. while (numExcludes--)
  45. {
  46. if (guid == exclude[numExcludes])
  47. return true;
  48. }
  49. return false;
  50. }
  51. svc_metaTag *Metadata::GetMetaTagObject(const wchar_t *filename, int flags, GUID *exclude, int numExcludes)
  52. {
  53. int i = 0;
  54. waServiceFactory *sf = 0;
  55. do
  56. {
  57. sf = WASABI_API_SVC->service_enumService(WaSvc::METATAG, i++);
  58. if (sf)
  59. {
  60. svc_metaTag *metaTag = static_cast<svc_metaTag *>(sf->getInterface());
  61. if (metaTag
  62. && !InList(metaTag->getGUID(), exclude, numExcludes)
  63. && flags & metaTag->getFlags()
  64. && metaTag->isOurFile(filename))
  65. return metaTag;
  66. sf->releaseInterface(metaTag);
  67. }
  68. }
  69. while (sf);
  70. return 0;
  71. }
  72. svc_metaTag *Metadata::GetMetaTagObjectByGUID(const GUID metaTagGuid)
  73. {
  74. waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(metaTagGuid);
  75. if (sf && sf->getServiceType() == WaSvc::METATAG) // just to be safe
  76. return static_cast<svc_metaTag *>(sf->getInterface());
  77. return NULL;
  78. }
  79. uint32_t Metadata::GenerateKey(const wchar_t *field)
  80. {
  81. Nullsoft::Utility::AutoLock keyLock(keyGuard);
  82. // TODO this is hella slow but it'll get the ball rolling on implementing this
  83. for (size_t i=0;i!=keys.size();i++)
  84. {
  85. if (!_wcsicmp(field, keys[i]))
  86. return (uint32_t)i;
  87. }
  88. keys.push_back(_wcsdup(field));
  89. return (uint32_t)keys.size()-1;
  90. }
  91. // TODO: extendedMetaTag, derived from svc_metaTag, that uses getExtendedFileInfo
  92. #define CBCLASS Metadata
  93. START_DISPATCH;
  94. CB(API_METADATA_GETEXTENDEDFILEINFO, GetExtendedFileInfo)
  95. CB(API_METADATA_SETEXTENDEDFILEINFO, SetExtendedFileInfo)
  96. CB(API_METADATA_WRITEEXTENDEDFILEINFO, WriteExtendedFileInfo)
  97. CB(API_METADATA_GETMETATAGOBJECT, GetMetaTagObject)
  98. CB(API_METADATA_GETMETATAGOBJECTBYGUID, GetMetaTagObjectByGUID)
  99. CB(API_METADATA_GENERATEKEY, GenerateKey)
  100. END_DISPATCH;
  101. #undef CBCLASS