aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt
blob: 06bb3189d1ad27ab8fa2774e6c7bc0f62f45d8d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package org.pacien.tincapp.context

import android.content.Context

import java.io.File

/**
 * @author pacien
 * *
 * @implNote Logs and PID files are stored in the cache directory for easy clean up.
 */
object AppPaths {

    private val CONFDIR = "conf"
    private val LOGDIR = "log"
    private val PIDDIR = "pid"

    private val TINCD_BIN = "libtincd.so"
    private val TINC_BIN = "libtinc.so"

    private val LOGFILE_FORMAT = "tinc.%s.log"
    private val PIDFILE_FORMAT = "tinc.%s.pid"

    private val NET_CONF_FILE = "network.conf"

    private fun createDirIfNotExists(basePath: File, newDir: String): File {
        val f = File(basePath, newDir)
        f.mkdirs()
        return f
    }

    fun confDir(): File = App.getContext().getDir(CONFDIR, Context.MODE_PRIVATE)
    fun confDir(netName: String): File = File(confDir(), netName)
    fun logDir(): File = createDirIfNotExists(App.getContext().cacheDir, LOGDIR)
    fun pidDir(): File = createDirIfNotExists(App.getContext().cacheDir, PIDDIR)
    fun logFile(netName: String): File = File(logDir(), String.format(LOGFILE_FORMAT, netName))
    fun pidFile(netName: String): File = File(pidDir(), String.format(PIDFILE_FORMAT, netName))
    fun netConfFile(netName: String): File = File(confDir(netName), NET_CONF_FILE)
    fun binDir(): File = File(App.getContext().applicationInfo.nativeLibraryDir)
    fun tincd(): File = File(binDir(), TINCD_BIN)
    fun tinc(): File = File(binDir(), TINC_BIN)

}