diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/context/AppPaths.java')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/context/AppPaths.java | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/context/AppPaths.java b/app/src/main/java/org/pacien/tincapp/context/AppPaths.java new file mode 100644 index 0000000..d854d4e --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/context/AppPaths.java | |||
@@ -0,0 +1,75 @@ | |||
1 | package org.pacien.tincapp.context; | ||
2 | |||
3 | import android.content.Context; | ||
4 | |||
5 | import java.io.File; | ||
6 | |||
7 | /** | ||
8 | * @author pacien | ||
9 | * @implNote Logs and PID files are stored in the cache directory for easy clean up. | ||
10 | */ | ||
11 | final public class AppPaths { | ||
12 | |||
13 | private AppPaths() { | ||
14 | // static class | ||
15 | } | ||
16 | |||
17 | static final private String CONFDIR = "conf"; | ||
18 | static final private String LOGDIR = "log"; | ||
19 | static final private String PIDDIR = "pid"; | ||
20 | |||
21 | static final private String TINCD_BIN = "libtincd.so"; | ||
22 | static final private String TINC_BIN = "libtinc.so"; | ||
23 | |||
24 | static final private String LOGFILE_FORMAT = "tinc.%s.log"; | ||
25 | static final private String PIDFILE_FORMAT = "tinc.%s.pid"; | ||
26 | |||
27 | static final private String NET_CONF_FILE = "network.conf"; | ||
28 | |||
29 | static private File createDirIfNotExists(File basePath, String newDir) { | ||
30 | File f = new File(basePath, newDir); | ||
31 | f.mkdirs(); | ||
32 | return f; | ||
33 | } | ||
34 | |||
35 | static public File confDir(Context ctx) { | ||
36 | return ctx.getDir(CONFDIR, Context.MODE_PRIVATE); | ||
37 | } | ||
38 | |||
39 | static public File confDir(Context ctx, String netName) { | ||
40 | return new File(confDir(ctx), netName); | ||
41 | } | ||
42 | |||
43 | static public File logDir(Context ctx) { | ||
44 | return createDirIfNotExists(ctx.getCacheDir(), LOGDIR); | ||
45 | } | ||
46 | |||
47 | static public File pidDir(Context ctx) { | ||
48 | return createDirIfNotExists(ctx.getCacheDir(), PIDDIR); | ||
49 | } | ||
50 | |||
51 | static public File logFile(Context ctx, String netName) { | ||
52 | return new File(logDir(ctx), String.format(LOGFILE_FORMAT, netName)); | ||
53 | } | ||
54 | |||
55 | static public File pidFile(Context ctx, String netName) { | ||
56 | return new File(pidDir(ctx), String.format(PIDFILE_FORMAT, netName)); | ||
57 | } | ||
58 | |||
59 | static public File netConfFile(Context ctx, String netName) { | ||
60 | return new File(confDir(ctx, netName), NET_CONF_FILE); | ||
61 | } | ||
62 | |||
63 | static public File binDir(Context ctx) { | ||
64 | return new File(ctx.getApplicationInfo().nativeLibraryDir); | ||
65 | } | ||
66 | |||
67 | static public File tincd(Context ctx) { | ||
68 | return new File(binDir(ctx), TINCD_BIN); | ||
69 | } | ||
70 | |||
71 | static public File tinc(Context ctx) { | ||
72 | return new File(binDir(ctx), TINC_BIN); | ||
73 | } | ||
74 | |||
75 | } | ||