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)); })), 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) { public static void loadLight(String skinName, final SplashScreen splashScreen,FileHandle prefDir) {
preferredDir = prefDir; preferredDir = prefDir;
loadLight(skinName,splashScreen); loadLight(skinName,splashScreen);
@@ -81,13 +96,15 @@ public class FSkin {
//ensure skins directory exists //ensure skins directory exists
final FileHandle dir = Gdx.files.absolute(ForgeConstants.CACHE_SKINS_DIR); final FileHandle dir = Gdx.files.absolute(ForgeConstants.CACHE_SKINS_DIR);
if(preferredDir==null) if(preferredDir == null)
{ {
if (!dir.exists() || !dir.isDirectory()) { if (!isValidDirectory(dir)) {
//if skins directory doesn't exist, point to internal assets/skin directory instead for the sake of the splash screen final FileHandle def = Gdx.files.absolute(ForgeConstants.DEFAULT_SKINS_DIR);
preferredDir = GuiBase.isAndroid() ? Gdx.files.internal("fallback_skin") : Gdx.files.classpath("fallback_skin"); if (def.exists() && def.isDirectory()) //if default skin exists
} preferredDir = def;
else { 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 (splashScreen != null) {
if (allSkins == null) { //initialize if (allSkins == null) { //initialize
allSkins = new Array<>(); 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 FSkinTexture.BG_TEXTURE.load(); //load background texture early for splash screen