1
0

skininfo.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #include <precomp.h>
  2. #include "skininfo.h"
  3. #include "../xml/obj_xml.h"
  4. #include <api/xml/XMLAutoInclude.h>
  5. #include <api/xml/LoadXML.h>
  6. #include "../nu/AutoChar.h"
  7. #include "gen.h"
  8. #include "resource.h"
  9. #include "../Agave/Language/api_language.h"
  10. SkinInfosXmlReader::SkinInfosXmlReader(const wchar_t *skinname) : SkinInfoBlock(skinname)
  11. {
  12. waServiceFactory *parserFactory = WASABI_API_SVC->service_getServiceByGuid(obj_xmlGUID);
  13. if (parserFactory)
  14. {
  15. obj_xml *parser = (obj_xml *)parserFactory->getInterface();
  16. if (parser)
  17. {
  18. {
  19. StringPathCombine skinPath(WASABI_API_SKIN->getSkinsPath(), skinname);
  20. XMLAutoInclude include(parser, skinPath);
  21. parser->xmlreader_registerCallback(L"WinampAbstractionLayer",this);
  22. //parser->xmlreader_registerCallback(L"WinampAbstractionLayer\fSkinInfo", this);
  23. parser->xmlreader_registerCallback(L"WinampAbstractionLayer\fSkinInfo\f*", this);
  24. parser->xmlreader_registerCallback(L"WasabiXML",this);
  25. //parser->xmlreader_registerCallback(L"WasabiXML\fSkinInfo", this);
  26. parser->xmlreader_registerCallback(L"WasabiXML\fSkinInfo\f*", this);
  27. parser->xmlreader_open();
  28. skinPath.AppendPath(L"skin.xml");
  29. LoadXmlFile(parser, skinPath);
  30. parser->xmlreader_unregisterCallback(this);
  31. }
  32. parser->xmlreader_close();
  33. parserFactory->releaseInterface(parser);
  34. parser = 0;
  35. }
  36. }
  37. }
  38. void SkinInfosXmlReader::xmlReaderOnStartElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
  39. {
  40. if (!_wcsicmp(xmltag, L"WinampAbstractionLayer") || !_wcsicmp(xmltag, L"WasabiXML"))
  41. {
  42. const wchar_t *version = params->getItemValue(L"version");
  43. if (version)
  44. walversion = version;
  45. }
  46. }
  47. void SkinInfosXmlReader::xmlReaderOnCharacterDataCallback(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *s)
  48. {
  49. if (!wcscmp(xmltag, L"name")) { fullname = s;}
  50. else if (!wcscmp(xmltag, L"version")) { version = s;}
  51. else if (!wcscmp(xmltag, L"comment")) { comment = s;}
  52. else if (!wcscmp(xmltag, L"author")) { author = s;}
  53. else if (!wcscmp(xmltag, L"email")) { email = s;}
  54. else if (!wcscmp(xmltag, L"homepage")) { homepage = s;}
  55. else if (!wcscmp(xmltag, L"parentskin")) { parentskin = s;}
  56. else if (!wcscmp(xmltag, L"screenshot")) { screenshot = s;}
  57. }
  58. extern int m_are_we_loaded;
  59. static StringW skin;
  60. const wchar_t *getSkinInfoW()
  61. {
  62. static StringW skininfoW;
  63. // these checks is repeated in getSkinInfo, also
  64. if (!m_are_we_loaded) return NULL;
  65. if (skin.iscaseequal(WASABI_API_SKIN->getSkinName()) && !skininfoW.isempty()) return skininfoW;
  66. skininfoW = L"";
  67. SkinInfosXmlReader r(WASABI_API_SKIN->getSkinName());
  68. /* skin name */
  69. const wchar_t *name = r.getFullName();
  70. if (name && *name)
  71. skininfoW += name;
  72. else
  73. skininfoW += WASABI_API_SKIN->getSkinName();
  74. /* skin version */
  75. const wchar_t *ver = r.getVersion();
  76. if (ver && *ver)
  77. {
  78. skininfoW += L" v";
  79. skininfoW += ver;
  80. }
  81. skininfoW += L"\r\n";
  82. /* skin author & e-mail */
  83. const wchar_t *aut = r.getAuthor();
  84. if (aut && *aut)
  85. {
  86. skininfoW += WASABI_API_LNGSTRINGW(IDS_BY_SPACE);
  87. skininfoW += aut;
  88. const wchar_t *email = r.getEmail();
  89. if (email && *email)
  90. {
  91. skininfoW += L" (";
  92. skininfoW += email;
  93. skininfoW += L")";
  94. }
  95. skininfoW += L"\r\n";
  96. }
  97. /* skin homepage */
  98. const wchar_t *web = r.getHomepage();
  99. if (web && *web)
  100. {
  101. skininfoW += web;
  102. skininfoW += L"\r\n";
  103. }
  104. skininfoW += L"\r\n";
  105. const wchar_t *comment = r.getComment();
  106. if (comment && *comment)
  107. skininfoW += comment;
  108. skin = WASABI_API_SKIN->getSkinName();
  109. return skininfoW;
  110. }
  111. const char *getSkinInfo()
  112. {
  113. static String skininfo;
  114. // these checks is repeated in getSkinInfoW, also
  115. if (!m_are_we_loaded) return NULL;
  116. if (skin.iscaseequal(WASABI_API_SKIN->getSkinName()) && !skininfo.isempty()) return skininfo;
  117. // get the wide character version
  118. const wchar_t *wideSkinInfo = getSkinInfoW();
  119. // and convert
  120. skininfo = AutoChar(wideSkinInfo);
  121. return skininfo;
  122. }