Create Natives dir in XDG_CACHE_HOME, not the working dir. (fixes #129)

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-08-30 14:31:01 -05:00
parent 9fc00fc3c3
commit 31d0c237df
3 changed files with 21 additions and 7 deletions

View File

@ -33,16 +33,24 @@ import java.util.jar.JarFile;
* @author http://ninjacave.com * @author http://ninjacave.com
*/ */
public class NativeLoader { public class NativeLoader {
/** Directory where natives are unpacked. */ /** The directory to unpack natives to. */
public static final File NATIVE_DIR = new File("Natives/"); private final File nativeDir;
/**
* Constructor.
* @param dir the directory to unpack natives to
*/
public NativeLoader(File dir) {
nativeDir = dir;
}
/** /**
* Unpacks natives for the current operating system to the natives directory. * Unpacks natives for the current operating system to the natives directory.
* @throws IOException * @throws IOException
*/ */
public void loadNatives() throws IOException { public void loadNatives() throws IOException {
if (!NATIVE_DIR.exists()) if (!nativeDir.exists())
NATIVE_DIR.mkdir(); nativeDir.mkdir();
JarFile jarFile = Utils.getJarFile(); JarFile jarFile = Utils.getJarFile();
if (jarFile == null) if (jarFile == null)
@ -54,7 +62,7 @@ public class NativeLoader {
if (e == null) if (e == null)
break; break;
File f = new File(NATIVE_DIR, e.getName()); File f = new File(nativeDir, e.getName());
if (isNativeFile(e.getName()) && !e.isDirectory() && e.getName().indexOf('/') == -1 && !f.exists()) { if (isNativeFile(e.getName()) && !e.isDirectory() && e.getName().indexOf('/') == -1 && !f.exists()) {
InputStream in = jarFile.getInputStream(jarFile.getEntry(e.getName())); InputStream in = jarFile.getInputStream(jarFile.getEntry(e.getName()));
OutputStream out = new FileOutputStream(f); OutputStream out = new FileOutputStream(f);

View File

@ -139,9 +139,9 @@ public class Opsu extends StateBasedGame {
(nativeDir = new File("./build/natives/")).isDirectory())) (nativeDir = new File("./build/natives/")).isDirectory()))
; ;
else { else {
nativeDir = NativeLoader.NATIVE_DIR; nativeDir = Options.NATIVE_DIR;
try { try {
new NativeLoader().loadNatives(); new NativeLoader(nativeDir).loadNatives();
} catch (IOException e) { } catch (IOException e) {
Log.error("Error loading natives.", e); Log.error("Error loading natives.", e);
} }

View File

@ -64,6 +64,9 @@ public class Options {
/** The data directory. */ /** The data directory. */
private static final File DATA_DIR = getXDGBaseDir("XDG_DATA_HOME", ".local/share"); private static final File DATA_DIR = getXDGBaseDir("XDG_DATA_HOME", ".local/share");
/** The cache directory. */
private static final File CACHE_DIR = getXDGBaseDir("XDG_CACHE_HOME", ".cache");
/** File for logging errors. */ /** File for logging errors. */
public static final File LOG_FILE = new File(CONFIG_DIR, ".opsu.log"); public static final File LOG_FILE = new File(CONFIG_DIR, ".opsu.log");
@ -90,6 +93,9 @@ public class Options {
/** Score database name. */ /** Score database name. */
public static final File SCORE_DB = new File(DATA_DIR, ".opsu_scores.db"); public static final File SCORE_DB = new File(DATA_DIR, ".opsu_scores.db");
/** Directory where natives are unpacked. */
public static final File NATIVE_DIR = new File(CACHE_DIR, "Natives/");
/** Font file name. */ /** Font file name. */
public static final String FONT_NAME = "DroidSansFallback.ttf"; public static final String FONT_NAME = "DroidSansFallback.ttf";