Newer
Older
Endoscope / app / src / main / java / com / casic / endoscope / utils / FileManager.kt
package com.casic.endoscope.utils

import android.os.Environment
import android.util.Log
import com.pengxh.kt.lite.extensions.timestampToDate
import java.io.File

object FileManager {
    private const val kTag = "FileManager"
    private lateinit var directory: File

    fun getRootDirectory(): File {
        directory = File("${Environment.getExternalStorageDirectory()}/Endoscope")
        if (!directory.exists()) {
            Log.d(kTag, "createRootDirectory: 新建文件夹")
            directory.mkdirs()
        }
        Log.d(kTag, "createRootDirectory: $directory")
        return directory
    }

    fun getVideoFileDir(): File {
        val videoDir = File(getRootDirectory(), "Video")
        if (!videoDir.exists()) {
            videoDir.mkdir()
        }

        val childDir = File(videoDir, System.currentTimeMillis().timestampToDate())
        if (!childDir.exists()) {
            childDir.mkdir()
        }
        return childDir
    }

    fun getImageFileDir(): File {
        val imageDir = File(getRootDirectory(), "Picture")
        if (!imageDir.exists()) {
            imageDir.mkdir()
        }

        val childDir = File(imageDir, System.currentTimeMillis().timestampToDate())
        if (!childDir.exists()) {
            childDir.mkdir()
        }
        return childDir
    }
}