Skip to content

Commit

Permalink
Update HydraLabVpnLoggerTemp.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
hydraxman authored Jan 7, 2025
1 parent 2043c5a commit ede52fb
Showing 1 changed file with 2 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,6 @@ class HydraLabVpnLoggerTemp(private var filePath: String?) {
private var lines = mutableListOf<String>()
private var linesStaging = listOf<String>()

init {
if (filePath != null) {
filePath = Environment.getExternalStorageDirectory().toString() + filePath

val publicFolder = Path(Environment.getExternalStorageDirectory().toString()).toString()
val fileUrl = Path(filePath.toString()).toString()
if (!fileUrl.startsWith(publicFolder + File.separator)) {
throw IllegalArgumentException("Invalid file path")
}

val file = File(fileUrl ?: "")
if (file.exists()) {
file.writeText("")
} else {
file.createNewFile()
}
}
}

fun stringify(packet: Packet): String {
return packet.toString()
Expand All @@ -42,29 +24,10 @@ class HydraLabVpnLoggerTemp(private var filePath: String?) {
}

private fun log(line: String) {
lines.add(line)
if (lines.size >= 100) {
flush()
}

}

fun flush() {
linesStaging = lines.toList()
lines.clear()
if (filePath == null) {
return
}
GlobalScope.launch(Dispatchers.IO) {
try {
FileWriter(filePath, true).use { writer ->
for (line in linesStaging) {
writer.write(line)
writer.write("\n")
}
}
} catch (e: IOException) {
e.printStackTrace()
}
}

}
}

0 comments on commit ede52fb

Please sign in to comment.