Switch from Gdx.files.local to Gdx.files.absolute

Ensure directories created for data and cache
This commit is contained in:
drdev
2014-05-08 18:02:47 +00:00
parent 3926826bcb
commit 82f121a7ef
6 changed files with 25 additions and 14 deletions

View File

@@ -73,7 +73,7 @@ public class FSkin {
FSkinTexture.BG_TEXTURE.load(preferredDir, ForgeConstants.DEFAULT_SKINS_DIR); //load background texture early for splash screen FSkinTexture.BG_TEXTURE.load(preferredDir, ForgeConstants.DEFAULT_SKINS_DIR); //load background texture early for splash screen
if (splashScreen != null) { if (splashScreen != null) {
final FileHandle f = Gdx.files.local(preferredDir + "bg_splash.png"); final FileHandle f = Gdx.files.absolute(preferredDir + "bg_splash.png");
if (!f.exists()) { if (!f.exists()) {
if (!skinName.equals("default")) { if (!skinName.equals("default")) {
FSkin.loadLight("default", splashScreen); FSkin.loadLight("default", splashScreen);
@@ -135,12 +135,12 @@ public class FSkin {
// Grab and test various sprite files. // Grab and test various sprite files.
String defaultDir = ForgeConstants.DEFAULT_SKINS_DIR; String defaultDir = ForgeConstants.DEFAULT_SKINS_DIR;
final FileHandle f1 = Gdx.files.local(defaultDir + SourceFile.ICONS.getFilename()); final FileHandle f1 = Gdx.files.absolute(defaultDir + SourceFile.ICONS.getFilename());
final FileHandle f2 = Gdx.files.local(preferredDir + SourceFile.ICONS.getFilename()); final FileHandle f2 = Gdx.files.absolute(preferredDir + SourceFile.ICONS.getFilename());
final FileHandle f3 = Gdx.files.local(defaultDir + SourceFile.FOILS.getFilename()); final FileHandle f3 = Gdx.files.absolute(defaultDir + SourceFile.FOILS.getFilename());
final FileHandle f4 = Gdx.files.local(defaultDir + ForgeConstants.SPRITE_AVATARS_FILE); final FileHandle f4 = Gdx.files.absolute(defaultDir + ForgeConstants.SPRITE_AVATARS_FILE);
final FileHandle f5 = Gdx.files.local(preferredDir + ForgeConstants.SPRITE_AVATARS_FILE); final FileHandle f5 = Gdx.files.absolute(preferredDir + ForgeConstants.SPRITE_AVATARS_FILE);
final FileHandle f6 = Gdx.files.local(defaultDir + SourceFile.OLD_FOILS.getFilename()); final FileHandle f6 = Gdx.files.absolute(defaultDir + SourceFile.OLD_FOILS.getFilename());
try { try {
textures.put(f1.path(), new Texture(f1)); textures.put(f1.path(), new Texture(f1));
@@ -299,7 +299,7 @@ public class FSkin {
public static ArrayList<String> getSkinDirectoryNames() { public static ArrayList<String> getSkinDirectoryNames() {
final ArrayList<String> mySkins = new ArrayList<String>(); final ArrayList<String> mySkins = new ArrayList<String>();
final FileHandle dir = Gdx.files.local(ForgeConstants.SKINS_DIR); final FileHandle dir = Gdx.files.absolute(ForgeConstants.SKINS_DIR);
if (!dir.exists() || !dir.isDirectory()) { if (!dir.exists() || !dir.isDirectory()) {
System.err.println("FSkin > can't find skins directory!"); System.err.println("FSkin > can't find skins directory!");
} }

View File

@@ -48,7 +48,7 @@ public class FSkinFont {
String dir = FSkin.getDir(); String dir = FSkin.getDir();
//generate .fnt and .png files from .ttf if needed //generate .fnt and .png files from .ttf if needed
FileHandle ttfFile = Gdx.files.local(dir + TTF_FILE); FileHandle ttfFile = Gdx.files.absolute(dir + TTF_FILE);
if (ttfFile.exists()) { if (ttfFile.exists()) {
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(ttfFile); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(ttfFile);
font = generator.generateFont(size); font = generator.generateFont(size);

View File

@@ -256,7 +256,7 @@ public enum FSkinImage implements FImage {
String preferredFile = preferredDir + filename; String preferredFile = preferredDir + filename;
Texture texture = textures.get(preferredFile); Texture texture = textures.get(preferredFile);
if (texture == null) { if (texture == null) {
FileHandle file = Gdx.files.local(preferredFile); FileHandle file = Gdx.files.absolute(preferredFile);
if (file.exists()) { if (file.exists()) {
try { try {
texture = new Texture(file); texture = new Texture(file);
@@ -328,7 +328,7 @@ public enum FSkinImage implements FImage {
String defaultFile = defaultDir + filename; String defaultFile = defaultDir + filename;
texture = textures.get(defaultFile); texture = textures.get(defaultFile);
if (texture == null) { if (texture == null) {
FileHandle file = Gdx.files.local(defaultFile); FileHandle file = Gdx.files.absolute(defaultFile);
if (file.exists()) { if (file.exists()) {
try { try {
texture = new Texture(file); texture = new Texture(file);

View File

@@ -22,7 +22,7 @@ public enum FSkinTexture implements FImage {
public void load(String preferredDir, String defaultDir) { public void load(String preferredDir, String defaultDir) {
String preferredFile = preferredDir + filename; String preferredFile = preferredDir + filename;
FileHandle file = Gdx.files.local(preferredFile); FileHandle file = Gdx.files.absolute(preferredFile);
if (file.exists()) { if (file.exists()) {
try { try {
texture = new Texture(file); texture = new Texture(file);
@@ -35,7 +35,7 @@ public enum FSkinTexture implements FImage {
if (texture == null) { if (texture == null) {
//use default file if can't use preferred file //use default file if can't use preferred file
String defaultFile = defaultDir + filename; String defaultFile = defaultDir + filename;
file = Gdx.files.local(defaultFile); file = Gdx.files.absolute(defaultFile);
if (file.exists()) { if (file.exists()) {
try { try {
texture = new Texture(file); texture = new Texture(file);
@@ -43,6 +43,7 @@ public enum FSkinTexture implements FImage {
catch (final Exception e) { catch (final Exception e) {
System.err.println("Failed to load skin file: " + defaultFile); System.err.println("Failed to load skin file: " + defaultFile);
e.printStackTrace(); e.printStackTrace();
return;
} }
} }
} }

View File

@@ -61,7 +61,7 @@ public class ImageCache {
static { static {
Texture defImage = null; Texture defImage = null;
try { try {
defImage = new Texture(Gdx.files.local(ForgeConstants.NO_CARD_FILE)); defImage = new Texture(Gdx.files.absolute(ForgeConstants.NO_CARD_FILE));
} catch (Exception ex) { } catch (Exception ex) {
System.err.println("could not load default card image"); System.err.println("could not load default card image");
} finally { } finally {

View File

@@ -54,6 +54,16 @@ public class ForgeProfileProperties {
cardPicsDir = cacheDir + "pics/cards/"; cardPicsDir = cacheDir + "pics/cards/";
cardPicsSubDir = new HashMap<String, String>(); cardPicsSubDir = new HashMap<String, String>();
serverPort = 0; serverPort = 0;
//ensure directories exist
File dir = new File(userDir);
if (!dir.exists()) {
dir.mkdirs();
}
dir = new File(cacheDir);
if (!dir.exists()) {
dir.mkdirs();
}
} }
public ForgeProfileProperties(String filename) { public ForgeProfileProperties(String filename) {