aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/context/AppPaths.kt')
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/AppPaths.kt26
1 files changed, 6 insertions, 20 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt
index 58c6de2..078a81d 100644
--- a/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt
+++ b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt
@@ -1,7 +1,6 @@
1package org.pacien.tincapp.context 1package org.pacien.tincapp.context
2 2
3import java.io.File 3import java.io.File
4import java.io.Serializable
5 4
6/** 5/**
7 * @author pacien 6 * @author pacien
@@ -10,9 +9,6 @@ import java.io.Serializable
10 */ 9 */
11object AppPaths { 10object AppPaths {
12 11
13 enum class Storage { INTERNAL, EXTERNAL }
14 data class NetConf(val storage: Storage, val netName: String) : Serializable
15
16 private val TINCD_BIN = "libtincd.so" 12 private val TINCD_BIN = "libtincd.so"
17 private val TINC_BIN = "libtinc.so" 13 private val TINC_BIN = "libtinc.so"
18 14
@@ -21,24 +17,14 @@ object AppPaths {
21 17
22 private val NET_CONF_FILE = "network.conf" 18 private val NET_CONF_FILE = "network.conf"
23 19
24 fun filesDir(storage: Storage): File = when (storage) { 20 fun cacheDir() = App.getContext().externalCacheDir!!
25 Storage.INTERNAL -> App.getContext().filesDir 21 fun confDir() = App.getContext().getExternalFilesDir(null)!!
26 Storage.EXTERNAL -> App.getContext().getExternalFilesDir(null)
27 }
28
29 fun cacheDir(storage: Storage): File = when (storage) {
30 Storage.INTERNAL -> App.getContext().cacheDir
31 Storage.EXTERNAL -> App.getContext().externalCacheDir
32 }
33
34 fun binDir() = File(App.getContext().applicationInfo.nativeLibraryDir) 22 fun binDir() = File(App.getContext().applicationInfo.nativeLibraryDir)
35 23
36 fun confDir(storage: Storage) = filesDir(storage) 24 fun confDir(netName: String) = File(confDir(), netName)
37 fun confDir(netConf: NetConf) = File(confDir(netConf.storage), netConf.netName) 25 fun netConfFile(netName: String) = File(confDir(netName), NET_CONF_FILE)
38 26 fun logFile(netName: String) = File(cacheDir(), String.format(LOGFILE_FORMAT, netName))
39 fun netConfFile(netConf: NetConf) = File(confDir(netConf), NET_CONF_FILE) 27 fun pidFile(netName: String) = File(App.getContext().cacheDir, String.format(PIDFILE_FORMAT, netName))
40 fun logFile(netConf: NetConf) = File(cacheDir(netConf.storage), String.format(LOGFILE_FORMAT, netConf.netName))
41 fun pidFile(netConf: NetConf) = File(cacheDir(Storage.INTERNAL), String.format(PIDFILE_FORMAT, netConf.netName))
42 28
43 fun tincd() = File(binDir(), TINCD_BIN) 29 fun tincd() = File(binDir(), TINCD_BIN)
44 fun tinc() = File(binDir(), TINC_BIN) 30 fun tinc() = File(binDir(), TINC_BIN)