lang updater

This commit is contained in:
minjaesong
2019-02-24 00:27:50 +09:00
parent 8cc9b98a12
commit 8432ad1377
34 changed files with 266 additions and 198 deletions

View File

@@ -1,5 +1,8 @@
package net.torvald.terrarum.utils
import com.google.gson.GsonBuilder
import net.torvald.terrarum.AppLoader
/**
* Created by minjaesong on 2016-03-04.
*/
@@ -7,6 +10,25 @@ object JsonWriter {
private val formattingRegex = Regex("""(?<=[\{,\[])|(?=[\]}])""")
fun getJsonBuilder() = if (AppLoader.IS_DEVELOPMENT_BUILD) {
getPrettyBuilder()
}
else {
GsonBuilder()
.serializeNulls()
.disableHtmlEscaping()
.enableComplexMapKeySerialization()
.create()
}
fun getPrettyBuilder() = GsonBuilder()
.setPrettyPrinting()
.serializeNulls()
.disableHtmlEscaping()
.enableComplexMapKeySerialization()
.create()
/**
* serialise a class to the file as JSON, using Google GSON.
*
@@ -15,9 +37,9 @@ object JsonWriter {
*/
@Throws(java.io.IOException::class)
fun writeToFile(c: Any, path: String) {
val classElem = com.google.gson.Gson().toJsonTree(c)
val jsonString = classElem.toString()
val writer = java.io.FileWriter(path)
val jsonString = getJsonBuilder().toJson(c)
val writer = java.io.FileWriter(path, false)
writer.write(jsonString.replace(formattingRegex, "\n"))
writer.close()
}
@@ -30,8 +52,10 @@ object JsonWriter {
*/
@Throws(java.io.IOException::class)
fun writeToFile(jsonObject: com.google.gson.JsonObject, path: String) {
val writer = java.io.FileWriter(path)
writer.write(jsonObject.toString().replace(formattingRegex, "\n"))
val writer = java.io.FileWriter(path, false)
writer.write(getPrettyBuilder().toJson(jsonObject))
//writer.write(jsonObject.toString().replace(formattingRegex, "\n"))
writer.close()
}