-
-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
125 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
src/main/java/net/ccbluex/liquidbounce/ui/font/FontDetails.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/net/ccbluex/liquidbounce/utils/io/GsonExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package net.ccbluex.liquidbounce.utils.io | ||
|
||
import com.google.gson.Gson | ||
import com.google.gson.JsonArray | ||
import com.google.gson.JsonElement | ||
import com.google.gson.JsonParser | ||
import net.ccbluex.liquidbounce.file.FileManager.PRETTY_GSON | ||
import java.io.File | ||
|
||
private val parser = JsonParser() | ||
|
||
private val EMPTY_JSON_ARRAY = JsonArray() | ||
|
||
fun jsonArrayOf(): JsonArray = EMPTY_JSON_ARRAY | ||
|
||
fun jsonArrayOf(vararg elements: JsonElement): JsonArray = JsonArray(elements.size).apply { elements.forEach { add(it) } } | ||
|
||
fun File.writeJson(content: JsonElement, gson: Gson = PRETTY_GSON) = gson.toJson(content, bufferedWriter()) | ||
|
||
fun File.readJson(): JsonElement = parser.parse(bufferedReader()) | ||
|
||
|
32 changes: 32 additions & 0 deletions
32
src/main/java/net/ccbluex/liquidbounce/utils/io/ZipExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package net.ccbluex.liquidbounce.utils.io | ||
|
||
import java.io.File | ||
import java.util.zip.ZipInputStream | ||
|
||
private fun ZipInputStream.entrySequence() = generateSequence { nextEntry } | ||
|
||
fun File.extractZipTo(outputFolder: File) { | ||
require(this.isFile) { "You can only extract from a file." } | ||
require(outputFolder.isDirectory) { "You can only extract zip to a directory." } | ||
|
||
outputFolder.apply { | ||
if (!exists()) mkdirs() | ||
} | ||
|
||
ZipInputStream(inputStream()).use { zis -> | ||
zis.entrySequence().forEach { entry -> | ||
val newFile = File(outputFolder, entry.name) | ||
|
||
if (!newFile.canonicalPath.startsWith(outputFolder.canonicalPath)) { | ||
throw SecurityException("Illegal Zip Entry:${entry.name}") | ||
} | ||
|
||
if (entry.isDirectory) { | ||
newFile.mkdirs() | ||
} else { | ||
newFile.parentFile.mkdirs() | ||
zis.copyTo(newFile.outputStream()) | ||
} | ||
} | ||
} | ||
} |