blob: 673faa7c33421216f405074994eee7909674ca90 (
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
|
package org.pacien.tincapp.context
import java.io.File
import java.io.FileNotFoundException
/**
* @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"
private val NET_HOSTS_DIR = "hosts"
private val NET_INVITATION_FILE = "invitation-data"
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 hostsDir(netName: String) = File(confDir(netName), NET_HOSTS_DIR)
fun netConfFile(netName: String) = File(confDir(netName), NET_CONF_FILE)
fun invitationFile(netName: String) = File(confDir(netName), NET_INVITATION_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 existing(f: File) = f.apply { if (!exists()) throw FileNotFoundException(f.absolutePath) }
fun tincd() = File(binDir(), TINCD_BIN)
fun tinc() = File(binDir(), TINC_BIN)
}
|