NativeLibraryLoader: use the OS's cache folder instead of home folder for storing natives
This commit is contained in:
parent
51c8894e03
commit
b300915092
@ -226,7 +226,7 @@ public final class NativeLibraryLoader {
|
|||||||
if (extractionFolder == null) {
|
if (extractionFolder == null) {
|
||||||
File workingFolder = new File("").getAbsoluteFile();
|
File workingFolder = new File("").getAbsoluteFile();
|
||||||
if (!workingFolder.canWrite()) {
|
if (!workingFolder.canWrite()) {
|
||||||
setExtractionDirToStorageDir();
|
setExtractionFolderToUserCache();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
File file = new File(workingFolder + File.separator + ".jmetestwrite");
|
File file = new File(workingFolder + File.separator + ".jmetestwrite");
|
||||||
@ -234,20 +234,74 @@ public final class NativeLibraryLoader {
|
|||||||
file.delete();
|
file.delete();
|
||||||
extractionFolder = workingFolder;
|
extractionFolder = workingFolder;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
setExtractionDirToStorageDir();
|
setExtractionFolderToUserCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return extractionFolder;
|
return extractionFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine jME3's cache folder for the user account based on the OS.
|
||||||
|
*
|
||||||
|
* If the OS cache folder is missing, the assumption is that this
|
||||||
|
* particular version of the OS does not have a dedicated cache folder,
|
||||||
|
* hence, we use the user's home folder instead as the root.
|
||||||
|
*
|
||||||
|
* The folder returned is as follows:<br>
|
||||||
|
* <ul>
|
||||||
|
* <li>Windows: ~\AppData\Local\jme3</li>
|
||||||
|
* <li>Mac OS X: ~/Library/Caches/jme3</li>
|
||||||
|
* <li>Linux: ~/.cache/jme3</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @return the user cache folder.
|
||||||
|
*/
|
||||||
|
private static File getJmeUserCacheFolder() {
|
||||||
|
File userHomeFolder = new File(System.getProperty("user.home"));
|
||||||
|
File userCacheFolder = null;
|
||||||
|
|
||||||
|
switch (JmeSystem.getPlatform()) {
|
||||||
|
case Linux32:
|
||||||
|
case Linux64:
|
||||||
|
userCacheFolder = new File(userHomeFolder, ".cache");
|
||||||
|
break;
|
||||||
|
case MacOSX32:
|
||||||
|
case MacOSX64:
|
||||||
|
case MacOSX_PPC32:
|
||||||
|
case MacOSX_PPC64:
|
||||||
|
userCacheFolder = new File(new File(userHomeFolder, "Library"), "Caches");
|
||||||
|
break;
|
||||||
|
case Windows32:
|
||||||
|
case Windows64:
|
||||||
|
userCacheFolder = new File(new File(userHomeFolder, "AppData"), "Local");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userCacheFolder == null || !userCacheFolder.exists()) {
|
||||||
|
// Fallback to home directory if cache folder is missing
|
||||||
|
return new File(userHomeFolder, ".jme3");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new File(userCacheFolder, "jme3");
|
||||||
|
}
|
||||||
|
|
||||||
private static void setExtractionDirToStorageDir() {
|
private static void setExtractionFolderToUserCache() {
|
||||||
logger.log(Level.WARNING, "Working directory is not writable. Using home directory instead.");
|
File extractFolderInHome = getJmeUserCacheFolder();
|
||||||
extractionFolder = new File(JmeSystem.getStorageFolder(),
|
|
||||||
"natives_" + Integer.toHexString(computeNativesHash()));
|
if (!extractFolderInHome.exists()) {
|
||||||
|
extractFolderInHome.mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
|
extractionFolder = new File(extractFolderInHome, "natives_" + Integer.toHexString(computeNativesHash()));
|
||||||
|
|
||||||
if (!extractionFolder.exists()) {
|
if (!extractionFolder.exists()) {
|
||||||
extractionFolder.mkdir();
|
extractionFolder.mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.log(Level.WARNING, "Working directory is not writable. "
|
||||||
|
+ "Natives will be extracted to:\n{0}",
|
||||||
|
extractionFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int computeNativesHash() {
|
private static int computeNativesHash() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user