aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/context/AppPaths.java
blob: d854d4e0c9d7b03d4d7e86054a3dda583867fda3 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package org.pacien.tincapp.context;

import android.content.Context;

import java.io.File;

/**
 * @author pacien
 * @implNote Logs and PID files are stored in the cache directory for easy clean up.
 */
final public class AppPaths {

	private AppPaths() {
		// static class
	}

	static final private String CONFDIR = "conf";
	static final private String LOGDIR = "log";
	static final private String PIDDIR = "pid";

	static final private String TINCD_BIN = "libtincd.so";
	static final private String TINC_BIN = "libtinc.so";

	static final private String LOGFILE_FORMAT = "tinc.%s.log";
	static final private String PIDFILE_FORMAT = "tinc.%s.pid";

	static final private String NET_CONF_FILE = "network.conf";

	static private File createDirIfNotExists(File basePath, String newDir) {
		File f = new File(basePath, newDir);
		f.mkdirs();
		return f;
	}

	static public File confDir(Context ctx) {
		return ctx.getDir(CONFDIR, Context.MODE_PRIVATE);
	}

	static public File confDir(Context ctx, String netName) {
		return new File(confDir(ctx), netName);
	}

	static public File logDir(Context ctx) {
		return createDirIfNotExists(ctx.getCacheDir(), LOGDIR);
	}

	static public File pidDir(Context ctx) {
		return createDirIfNotExists(ctx.getCacheDir(), PIDDIR);
	}

	static public File logFile(Context ctx, String netName) {
		return new File(logDir(ctx), String.format(LOGFILE_FORMAT, netName));
	}

	static public File pidFile(Context ctx, String netName) {
		return new File(pidDir(ctx), String.format(PIDFILE_FORMAT, netName));
	}

	static public File netConfFile(Context ctx, String netName) {
		return new File(confDir(ctx, netName), NET_CONF_FILE);
	}

	static public File binDir(Context ctx) {
		return new File(ctx.getApplicationInfo().nativeLibraryDir);
	}

	static public File tincd(Context ctx) {
		return new File(binDir(ctx), TINCD_BIN);
	}

	static public File tinc(Context ctx) {
		return new File(binDir(ctx), TINC_BIN);
	}

}