Merge pull request #3845 from kevlahnota/newmaster2

update theme check
This commit is contained in:
kevlahnota
2023-10-02 23:43:03 +08:00
committed by GitHub

View File

@@ -60,6 +60,21 @@ public class FSkin {
});
})), null, false, true));
}
private static boolean isValidDirectory(FileHandle fileHandle) {
if (fileHandle == null)
return false;
if (!fileHandle.exists())
return false;
if (!fileHandle.isDirectory())
return false;
String[] lists = fileHandle.file().list();
if (lists == null)
return false;
return lists.length > 0;
}
private static void useFallbackDir() {
preferredDir = GuiBase.isAndroid() ? Gdx.files.internal("fallback_skin") : Gdx.files.classpath("fallback_skin");
}
public static void loadLight(String skinName, final SplashScreen splashScreen,FileHandle prefDir) {
preferredDir = prefDir;
loadLight(skinName,splashScreen);
@@ -83,11 +98,13 @@ public class FSkin {
final FileHandle dir = Gdx.files.absolute(ForgeConstants.CACHE_SKINS_DIR);
if(preferredDir == null)
{
if (!dir.exists() || !dir.isDirectory()) {
//if skins directory doesn't exist, point to internal assets/skin directory instead for the sake of the splash screen
preferredDir = GuiBase.isAndroid() ? Gdx.files.internal("fallback_skin") : Gdx.files.classpath("fallback_skin");
}
else {
if (!isValidDirectory(dir)) {
final FileHandle def = Gdx.files.absolute(ForgeConstants.DEFAULT_SKINS_DIR);
if (def.exists() && def.isDirectory()) //if default skin exists
preferredDir = def;
else //if skins directory doesn't exist, point to internal assets/skin directory instead for the sake of the splash screen
useFallbackDir();
} else {
if (splashScreen != null) {
if (allSkins == null) { //initialize
allSkins = new Array<>();
@@ -107,6 +124,10 @@ public class FSkin {
}
}
}
//check preferredDir
if (!isValidDirectory(preferredDir)) {
useFallbackDir();
}
FSkinTexture.BG_TEXTURE.load(); //load background texture early for splash screen