aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/General/gen_ff/skininfo.cpp
blob: 520bd767d92779dce479d79c040b54cf7e6c9626 (plain) (blame)
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
#include <precomp.h>
#include "skininfo.h"
#include "../xml/obj_xml.h"
#include <api/xml/XMLAutoInclude.h>
#include <api/xml/LoadXML.h>
#include "../nu/AutoChar.h"
#include "gen.h"
#include "resource.h"
#include "../Agave/Language/api_language.h"

SkinInfosXmlReader::SkinInfosXmlReader(const wchar_t *skinname) : SkinInfoBlock(skinname)
{
	waServiceFactory *parserFactory = WASABI_API_SVC->service_getServiceByGuid(obj_xmlGUID);
	if (parserFactory)
	{
		obj_xml *parser = (obj_xml *)parserFactory->getInterface();
		if (parser)
		{
			{
				StringPathCombine skinPath(WASABI_API_SKIN->getSkinsPath(), skinname);

				XMLAutoInclude include(parser, skinPath);
				parser->xmlreader_registerCallback(L"WinampAbstractionLayer",this);
				//parser->xmlreader_registerCallback(L"WinampAbstractionLayer\fSkinInfo", this);
				parser->xmlreader_registerCallback(L"WinampAbstractionLayer\fSkinInfo\f*", this);
				parser->xmlreader_registerCallback(L"WasabiXML",this);
				//parser->xmlreader_registerCallback(L"WasabiXML\fSkinInfo", this);
				parser->xmlreader_registerCallback(L"WasabiXML\fSkinInfo\f*", this);
				parser->xmlreader_open();

				skinPath.AppendPath(L"skin.xml");
				LoadXmlFile(parser, skinPath);
				parser->xmlreader_unregisterCallback(this);
			}
			parser->xmlreader_close();
			parserFactory->releaseInterface(parser);
			parser = 0;
		}
	}
}

void SkinInfosXmlReader::xmlReaderOnStartElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
{
	if (!_wcsicmp(xmltag, L"WinampAbstractionLayer") || !_wcsicmp(xmltag, L"WasabiXML"))
	{
		const wchar_t *version = params->getItemValue(L"version");
		if (version)
			walversion = version;
	}
}

void SkinInfosXmlReader::xmlReaderOnCharacterDataCallback(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *s)
{
	if (!wcscmp(xmltag, L"name")) { fullname = s;}
	else if (!wcscmp(xmltag, L"version")) { version = s;}
	else if (!wcscmp(xmltag, L"comment")) { comment = s;}
	else if (!wcscmp(xmltag, L"author")) { author = s;}
	else if (!wcscmp(xmltag, L"email")) { email = s;}
	else if (!wcscmp(xmltag, L"homepage")) { homepage = s;}
	else if (!wcscmp(xmltag, L"parentskin")) { parentskin = s;}
	else if (!wcscmp(xmltag, L"screenshot")) { screenshot = s;}
}

extern int m_are_we_loaded;
static StringW skin;

const wchar_t *getSkinInfoW()
{
	static StringW skininfoW;

	// these checks is repeated in getSkinInfo, also
	if (!m_are_we_loaded) return NULL;
	if (skin.iscaseequal(WASABI_API_SKIN->getSkinName()) && !skininfoW.isempty()) return skininfoW;

	skininfoW = L"";
	SkinInfosXmlReader r(WASABI_API_SKIN->getSkinName());

	/* skin name */
	const wchar_t *name = r.getFullName();
	if (name && *name)
		skininfoW += name;
	else
		skininfoW += WASABI_API_SKIN->getSkinName();

	/* skin version */
	const wchar_t *ver = r.getVersion();
	if (ver && *ver)
	{
		skininfoW += L" v";
		skininfoW += ver;
	}
	skininfoW += L"\r\n";

	/* skin author & e-mail */
	const wchar_t *aut = r.getAuthor();
	if (aut && *aut)
	{
		skininfoW += WASABI_API_LNGSTRINGW(IDS_BY_SPACE);
		skininfoW += aut;

		const wchar_t *email = r.getEmail();
		if (email && *email)
		{
			skininfoW += L" (";
			skininfoW += email;
			skininfoW += L")";
		}
		skininfoW += L"\r\n";
	}

	/* skin homepage */
	const wchar_t *web = r.getHomepage();
	if (web && *web)
	{
		skininfoW += web;
		skininfoW += L"\r\n";
	}
	skininfoW += L"\r\n";
	const wchar_t *comment = r.getComment();
	if (comment && *comment)
		skininfoW += comment;

	skin = WASABI_API_SKIN->getSkinName();
	return skininfoW;
}

const char *getSkinInfo()
{
	static String skininfo;

	// these checks is repeated in getSkinInfoW, also
	if (!m_are_we_loaded) return NULL;
	if (skin.iscaseequal(WASABI_API_SKIN->getSkinName()) && !skininfo.isempty()) return skininfo;

	// get the wide character version
	const wchar_t *wideSkinInfo = getSkinInfoW();

	// and convert
	skininfo = AutoChar(wideSkinInfo);
	return skininfo;
}