aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt
blob: 078a81dd9dfb68cda1fdb523fac09cb58c519121 (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
package org.pacien.tincapp.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 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"

    fun cacheDir() = App.getContext().externalCacheDir!!
    fun confDir() = App.getContext().getExternalFilesDir(null)!!
    fun binDir() = File(App.getContext().applicationInfo.nativeLibraryDir)

    fun confDir(netName: String) = File(confDir(), netName)
    fun netConfFile(netName: String) = File(confDir(netName), NET_CONF_FILE)
    fun logFile(netName: String) = File(cacheDir(), String.format(LOGFILE_FORMAT, netName))
    fun pidFile(netName: String) = File(App.getContext().cacheDir, String.format(PIDFILE_FORMAT, netName))

    fun tincd() = File(binDir(), TINCD_BIN)
    fun tinc() = File(binDir(), TINC_BIN)

}