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:
parent
9fc00fc3c3
commit
31d0c237df
|
@ -33,16 +33,24 @@ import java.util.jar.JarFile;
|
|||
* @author http://ninjacave.com
|
||||
*/
|
||||
public class NativeLoader {
|
||||
/** Directory where natives are unpacked. */
|
||||
public static final File NATIVE_DIR = new File("Natives/");
|
||||
/** The directory to unpack natives to. */
|
||||
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.
|
||||
* @throws IOException
|
||||
*/
|
||||
public void loadNatives() throws IOException {
|
||||
if (!NATIVE_DIR.exists())
|
||||
NATIVE_DIR.mkdir();
|
||||
if (!nativeDir.exists())
|
||||
nativeDir.mkdir();
|
||||
|
||||
JarFile jarFile = Utils.getJarFile();
|
||||
if (jarFile == null)
|
||||
|
@ -54,7 +62,7 @@ public class NativeLoader {
|
|||
if (e == null)
|
||||
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()) {
|
||||
InputStream in = jarFile.getInputStream(jarFile.getEntry(e.getName()));
|
||||
OutputStream out = new FileOutputStream(f);
|
||||
|
|
|
@ -139,9 +139,9 @@ public class Opsu extends StateBasedGame {
|
|||
(nativeDir = new File("./build/natives/")).isDirectory()))
|
||||
;
|
||||
else {
|
||||
nativeDir = NativeLoader.NATIVE_DIR;
|
||||
nativeDir = Options.NATIVE_DIR;
|
||||
try {
|
||||
new NativeLoader().loadNatives();
|
||||
new NativeLoader(nativeDir).loadNatives();
|
||||
} catch (IOException e) {
|
||||
Log.error("Error loading natives.", e);
|
||||
}
|
||||
|
|
|
@ -64,6 +64,9 @@ public class Options {
|
|||
/** The data directory. */
|
||||
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. */
|
||||
public static final File LOG_FILE = new File(CONFIG_DIR, ".opsu.log");
|
||||
|
||||
|
@ -90,6 +93,9 @@ public class Options {
|
|||
/** Score database name. */
|
||||
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. */
|
||||
public static final String FONT_NAME = "DroidSansFallback.ttf";
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user