Skip to content

Commit 61da9c3

Browse files
committed
...
1 parent fea458e commit 61da9c3

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

src/main/kotlin/StringCare.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ open class StringCare : Plugin<Project> {
2323
absoluteProjectPath = project.absolutePath()
2424

2525
this.project.afterEvaluate {
26-
extension.modules?.forEach { module ->
26+
extension.modules.forEach { module ->
2727
when {
2828
module.stringFiles.isNotEmpty() && module.srcFolders.isNotEmpty() -> {
2929
moduleMap[module.name!!] = Configuration(module.name).apply {

src/main/kotlin/components/Extensions.kt

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package components
33
import StringCare.*
44
import groovy.json.StringEscapeUtils
55
import models.ResourceFile
6+
import org.apache.xerces.dom.DeferredElementImpl
67
import org.gradle.api.Project
78
import org.gradle.api.Task
89
import org.gradle.api.internal.plugins.DslObject
910
import org.w3c.dom.Document
11+
import org.w3c.dom.Node
1012
import org.xml.sax.InputSource
1113
import java.io.*
1214
import javax.xml.parsers.DocumentBuilderFactory
@@ -156,7 +158,6 @@ fun File.removeHiddenAttributes() {
156158
val content = this.getContent()
157159
.replace("hidden=\"true\"", "")
158160
.replace("hidden=\"false\"", "")
159-
.replace("hidden", "")
160161
FileWriter(this.absolutePath).use { it.write(content) }
161162
updateXML(this.getXML())
162163
}
@@ -191,4 +192,38 @@ fun Task.onMergeResourcesStartsVariant(): String = this.name.substring(merge.len
191192
fun Task.onMergeResourcesFinishVariant(): String = this.name.substring(merge.length)
192193
.substring(0, this.name.substring(merge.length).length - resources.length)
193194

195+
fun Node.extractHtml(): String {
196+
val stringBuilder = StringBuilder()
197+
for (i in 0 until this.childNodes.length) {
198+
val item = this.childNodes.item(i)
199+
val type = item.getType()
200+
when (type) {
201+
StringType.BR -> stringBuilder.append("<br>${item.textContent}</br>")
202+
StringType.I -> stringBuilder.append("<i>${item.textContent}</i>")
203+
StringType.STRONG -> stringBuilder.append("<strong>${item.textContent}</strong>")
204+
StringType.TEXT -> stringBuilder.append(item.textContent)
205+
}
206+
207+
}
208+
return stringBuilder.toString()
209+
}
210+
211+
enum class StringType {
212+
BR,
213+
TEXT,
214+
I,
215+
STRONG
216+
}
217+
218+
fun Node.getType(): StringType {
219+
return when {
220+
this.toString().contains("[br:") -> StringType.BR
221+
this.toString().contains("[i:") -> StringType.I
222+
this.toString().contains("[strong:") -> StringType.STRONG
223+
this.toString().contains("[#text") -> StringType.TEXT
224+
else -> StringType.TEXT
225+
}
226+
}
194227

228+
// [#text:
229+
// ]

src/main/kotlin/components/Stark.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@ open class Stark {
3737
when {
3838
dir.toString().endsWith(".jar") -> {
3939
val jar = File(dir)
40-
val zip = File(jar.absolutePath.replace(".jar", ".zip"))
40+
val zipFile = File(jar.absolutePath.replace(".jar", ".zip"))
4141

42-
jar.copyTo(zip, true)
42+
jar.copyTo(zipFile, true)
4343

44-
ZipFile(zip.absolutePath).use { zip ->
44+
ZipFile(zipFile.absolutePath).use { zip ->
4545
zip.entries().asSequence().forEach { entry ->
4646
zip.getInputStream(entry).use { input ->
4747
if (entry.name == fileName) {
48-
lib = File(entry.name).apply {
48+
49+
lib = File("$resourceBackup${File.separator}${entry.name}").apply {
4950
this.outputStream().use { output ->
5051
input.copyTo(output)
5152
}

src/main/kotlin/components/XParser.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ fun restoreFiles(projectPath: String, module: String): List<File> {
2727
}.map {
2828
it.restore(projectPath)
2929
}
30+
File("$projectPath${File.separator}$resourceBackup").deleteRecursively()
3031
return resourceFiles
3132
}
3233

@@ -41,6 +42,7 @@ fun parseXML(file: File): List<StringEntity> {
4142
val attributes = mutableListOf<SAttribute>()
4243
var obfuscate = false
4344
var androidTreatment = true
45+
var containsHtml = false
4446
for (a in 0 until node.attributes.length) {
4547
val attribute = node.attributes.item(a)
4648
for (n in 0 until attribute.childNodes.length) {
@@ -53,11 +55,17 @@ fun parseXML(file: File): List<StringEntity> {
5355
if (attribute.nodeName == "androidTreatment" && attr.nodeValue == "false") {
5456
androidTreatment = false
5557
}
58+
if (attribute.nodeName == "containsHtml" && attr.nodeValue != "false") {
59+
containsHtml = true
60+
}
5661
attributes.add(SAttribute(attribute.nodeName, attr.nodeValue))
5762
}
5863
}
5964
if (obfuscate) {
60-
entities.add(StringEntity(name, attributes, node.textContent, "string", i, androidTreatment))
65+
entities.add(StringEntity(name, attributes, when {
66+
containsHtml -> node.extractHtml()
67+
else -> node.textContent
68+
}, "string", i, androidTreatment))
6169
}
6270
}
6371
return entities

src/main/kotlin/models/StringEntity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class StringEntity(
66
var value: String,
77
val tag: String,
88
val index: Int,
9-
val androidTreatment: Boolean = false
9+
val androidTreatment: Boolean = true
1010
)
1111

1212
data class SAttribute(val name: String, val value: String)

0 commit comments

Comments
 (0)