package com.dumpster.cleaner.utils

import android.os.Environment
import com.dumpster.cleaner.MyApplication
import com.dumpster.cleaner.R
import com.dumpster.cleaner.utils.KotlinExt.toFormatTime2
import java.io.File

object WriteLogEx {
    private val logoDir by lazy(LazyThreadSafetyMode.NONE) {
        val appName = MyApplication.appContext.resources.getString(R.string.app_name)
        val log = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "${appName}_logo")
        if (!log.exists()) log.mkdirs()
        log
    }

    fun writeLogFile(key: String, log: String) {
        val logName = key + "_" + System.currentTimeMillis().toFormatTime2() + ".txt"
        val logFile = File(logoDir, logName)
        logFile.createNewFile()
        logFile.writeText(log, Charsets.UTF_8)
    }
}