aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/android/scummvm-android-themeengine.patch
blob: 1eafe7fb625425a98f955be0719d60bac409af3f (plain)
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
diff -r 884e66fd1b9c gui/ThemeEngine.cpp
--- a/gui/ThemeEngine.cpp	Tue Apr 13 09:30:52 2010 +1000
+++ b/gui/ThemeEngine.cpp	Fri May 28 23:24:43 2010 +1000
@@ -390,21 +390,19 @@
 
 	// Try to create a Common::Archive with the files of the theme.
 	if (!_themeArchive && !_themeFile.empty()) {
-		Common::FSNode node(_themeFile);
-		if (node.getName().hasSuffix(".zip") && !node.isDirectory()) {
+		Common::ArchiveMemberPtr member = SearchMan.getMember(_themeFile);
+		if (member && member->getName().hasSuffix(".zip")) {
 #ifdef USE_ZLIB
-			Common::Archive *zipArchive = Common::makeZipArchive(node);
+			Common::Archive *zipArchive = Common::makeZipArchive(member->createReadStream());
 
 			if (!zipArchive) {
-				warning("Failed to open Zip archive '%s'.", node.getPath().c_str());
+				warning("Failed to open Zip archive '%s'.", member->getDisplayName().c_str());
 			}
 			_themeArchive = zipArchive;
 #else
 			warning("Trying to load theme '%s' in a Zip archive without zLib support", _themeFile.c_str());
 			return false;
 #endif
-		} else if (node.isDirectory()) {
-			_themeArchive = new Common::FSDirectory(node);
 		}
 	}
 
@@ -1436,6 +1434,30 @@
 	return tok.empty();
 }
 
+bool ThemeEngine::themeConfigUsable(const Common::ArchiveMember &member, Common::String &themeName) {
+	Common::File stream;
+	bool foundHeader = false;
+
+	if (member.getName().hasSuffix(".zip")) {
+#ifdef USE_ZLIB
+		Common::Archive *zipArchive = Common::makeZipArchive(member.createReadStream());
+
+		if (zipArchive && zipArchive->hasFile("THEMERC")) {
+			stream.open("THEMERC", *zipArchive);
+		}
+
+		delete zipArchive;
+#endif
+	}
+
+	if (stream.isOpen()) {
+		Common::String stxHeader = stream.readLine();
+		foundHeader = themeConfigParseHeader(stxHeader, themeName);
+	}
+
+	return foundHeader;
+}
+
 bool ThemeEngine::themeConfigUsable(const Common::FSNode &node, Common::String &themeName) {
 	Common::File stream;
 	bool foundHeader = false;
@@ -1493,10 +1515,6 @@
 	if (ConfMan.hasKey("themepath"))
 		listUsableThemes(Common::FSNode(ConfMan.get("themepath")), list);
 
-#ifdef DATA_PATH
-	listUsableThemes(Common::FSNode(DATA_PATH), list);
-#endif
-
 #if defined(MACOSX) || defined(IPHONE)
 	CFURLRef resourceUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
 	if (resourceUrl) {
@@ -1509,10 +1527,7 @@
 	}
 #endif
 
-	if (ConfMan.hasKey("extrapath"))
-		listUsableThemes(Common::FSNode(ConfMan.get("extrapath")), list);
-
-	listUsableThemes(Common::FSNode("."), list, 1);
+	listUsableThemes(SearchMan, list);
 
 	// Now we need to strip all duplicates
 	// TODO: It might not be the best idea to strip duplicates. The user might
@@ -1531,6 +1546,34 @@
 	output.clear();
 }
 
+void ThemeEngine::listUsableThemes(Common::Archive &archive, Common::List<ThemeDescriptor> &list) {
+	ThemeDescriptor td;
+
+#ifdef USE_ZLIB
+	Common::ArchiveMemberList fileList;
+	archive.listMatchingMembers(fileList, "*.zip");
+	for (Common::ArchiveMemberList::iterator i = fileList.begin();
+	     i != fileList.end(); ++i) {
+		td.name.clear();
+		if (themeConfigUsable(**i, td.name)) {
+			td.filename = (*i)->getName();
+			td.id = (*i)->getDisplayName();
+
+			// If the name of the node object also contains
+			// the ".zip" suffix, we will strip it.
+			if (td.id.hasSuffix(".zip")) {
+				for (int j = 0; j < 4; ++j)
+					td.id.deleteLastChar();
+			}
+
+			list.push_back(td);
+		}
+	}
+
+	fileList.clear();
+#endif
+}
+
 void ThemeEngine::listUsableThemes(const Common::FSNode &node, Common::List<ThemeDescriptor> &list, int depth) {
 	if (!node.exists() || !node.isReadable() || !node.isDirectory())
 		return;
diff -r 884e66fd1b9c gui/ThemeEngine.h
--- a/gui/ThemeEngine.h	Tue Apr 13 09:30:52 2010 +1000
+++ b/gui/ThemeEngine.h	Fri May 28 23:24:43 2010 +1000
@@ -560,11 +560,13 @@
 	static void listUsableThemes(Common::List<ThemeDescriptor> &list);
 private:
 	static bool themeConfigUsable(const Common::FSNode &node, Common::String &themeName);
+	static bool themeConfigUsable(const Common::ArchiveMember &member, Common::String &themeName);
 	static bool themeConfigParseHeader(Common::String header, Common::String &themeName);
 
 	static Common::String getThemeFile(const Common::String &id);
 	static Common::String getThemeId(const Common::String &filename);
 	static void listUsableThemes(const Common::FSNode &node, Common::List<ThemeDescriptor> &list, int depth = -1);
+	static void listUsableThemes(Common::Archive &archive, Common::List<ThemeDescriptor> &list);
 
 protected:
 	OSystem *_system; /** Global system object. */