diff options
author | Pacien TRAN-GIRARD | 2017-06-30 10:21:51 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2017-06-30 10:21:51 +0200 |
commit | c89016e7427defd1f8a095d7aeb30292a42fad92 (patch) | |
tree | aec80e6f501824f966ea727d2f6e102a75e9655f /app/src/main/java/org/pacien/tincapp/context/AppPaths.kt | |
parent | 94d77ce43152a4e144417d8d5cfff363f65c904e (diff) | |
download | tincapp-c89016e7427defd1f8a095d7aeb30292a42fad92.tar.gz |
Conversion to Kotlin
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.kt | 43 |
1 files changed, 43 insertions, 0 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 new file mode 100644 index 0000000..21db0a4 --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt | |||
@@ -0,0 +1,43 @@ | |||
1 | package org.pacien.tincapp.context | ||
2 | |||
3 | import android.content.Context | ||
4 | |||
5 | import java.io.File | ||
6 | |||
7 | /** | ||
8 | * @author pacien | ||
9 | * * | ||
10 | * @implNote Logs and PID files are stored in the cache directory for easy clean up. | ||
11 | */ | ||
12 | object AppPaths { | ||
13 | |||
14 | private val CONFDIR = "conf" | ||
15 | private val LOGDIR = "log" | ||
16 | private val PIDDIR = "pid" | ||
17 | |||
18 | private val TINCD_BIN = "libtincd.so" | ||
19 | private val TINC_BIN = "libtinc.so" | ||
20 | |||
21 | private val LOGFILE_FORMAT = "tinc.%s.log" | ||
22 | private val PIDFILE_FORMAT = "tinc.%s.pid" | ||
23 | |||
24 | private val NET_CONF_FILE = "network.conf" | ||
25 | |||
26 | private fun createDirIfNotExists(basePath: File, newDir: String): File { | ||
27 | val f = File(basePath, newDir) | ||
28 | f.mkdirs() | ||
29 | return f | ||
30 | } | ||
31 | |||
32 | fun confDir(ctx: Context): File = ctx.getDir(CONFDIR, Context.MODE_PRIVATE) | ||
33 | fun confDir(ctx: Context, netName: String): File = File(confDir(ctx), netName) | ||
34 | fun logDir(ctx: Context): File = createDirIfNotExists(ctx.cacheDir, LOGDIR) | ||
35 | fun pidDir(ctx: Context): File = createDirIfNotExists(ctx.cacheDir, PIDDIR) | ||
36 | fun logFile(ctx: Context, netName: String): File = File(logDir(ctx), String.format(LOGFILE_FORMAT, netName)) | ||
37 | fun pidFile(ctx: Context, netName: String): File = File(pidDir(ctx), String.format(PIDFILE_FORMAT, netName)) | ||
38 | fun netConfFile(ctx: Context, netName: String): File = File(confDir(ctx, netName), NET_CONF_FILE) | ||
39 | fun binDir(ctx: Context): File = File(ctx.applicationInfo.nativeLibraryDir) | ||
40 | fun tincd(ctx: Context): File = File(binDir(ctx), TINCD_BIN) | ||
41 | fun tinc(ctx: Context): File = File(binDir(ctx), TINC_BIN) | ||
42 | |||
43 | } | ||