Add support for checking for assets when opening android app

This commit is contained in:
drdev
2014-05-03 01:40:06 +00:00
parent 1729ce8a02
commit 4fd2df0093
2 changed files with 46 additions and 1 deletions

View File

@@ -80,6 +80,16 @@ public final class FileUtil {
FileUtil.writeFile(new File(filename), data); FileUtil.writeFile(new File(filename), data);
} }
public static void writeFile(File file, String text) {
try {
PrintWriter p = new PrintWriter(file);
p.print(text);
p.close();
} catch (final Exception ex) {
throw new RuntimeException("FileUtil : writeFile() error, problem writing file - " + file + " : " + ex);
}
}
// writes each element of ArrayList on a separate line // writes each element of ArrayList on a separate line
// this is used to write a file of Strings // this is used to write a file of Strings
// this will create a new file if needed // this will create a new file if needed
@@ -109,7 +119,7 @@ public final class FileUtil {
public static String readFileToString(String filename) { public static String readFileToString(String filename) {
return TextUtil.join(readFile(filename), "\n"); return TextUtil.join(readFile(filename), "\n");
} }
public static List<String> readFile(final String filename) { public static List<String> readFile(final String filename) {
return FileUtil.readFile(new File(filename)); return FileUtil.readFile(new File(filename));
} }

View File

@@ -1,5 +1,10 @@
package forge.screens; package forge.screens;
import java.io.File;
import java.io.IOException;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment; import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
@@ -7,10 +12,14 @@ import forge.Forge.Graphics;
import forge.assets.FSkin; import forge.assets.FSkin;
import forge.assets.FSkinFont; import forge.assets.FSkinFont;
import forge.assets.FSkinTexture; import forge.assets.FSkinTexture;
import forge.properties.ForgeConstants;
import forge.properties.ForgePreferences; import forge.properties.ForgePreferences;
import forge.properties.ForgePreferences.FPref; import forge.properties.ForgePreferences.FPref;
import forge.toolbox.FContainer; import forge.toolbox.FContainer;
import forge.toolbox.FProgressBar; import forge.toolbox.FProgressBar;
import forge.util.BuildInfo;
import forge.util.FileUtil;
import forge.util.TextUtil;
public class SplashScreen extends FContainer { public class SplashScreen extends FContainer {
private TextureRegion background; private TextureRegion background;
@@ -21,6 +30,8 @@ public class SplashScreen extends FContainer {
progressBar = new FProgressBar(); progressBar = new FProgressBar();
progressBar.setDescription("Welcome to Forge"); progressBar.setDescription("Welcome to Forge");
checkForAssets();
final ForgePreferences prefs = new ForgePreferences(); final ForgePreferences prefs = new ForgePreferences();
FSkin.loadLight(prefs.getPref(FPref.UI_SKIN), this); FSkin.loadLight(prefs.getPref(FPref.UI_SKIN), this);
} }
@@ -75,4 +86,28 @@ public class SplashScreen extends FContainer {
progressBar.setBounds(x + padding, y, w - 2 * padding, pbHeight); progressBar.setBounds(x + padding, y, w - 2 * padding, pbHeight);
g.draw(progressBar); g.draw(progressBar);
} }
//if not forge-gui-mobile-dev, check whether assets are up to date
private void checkForAssets() {
if (Gdx.app.getType() == ApplicationType.Desktop) { return; }
String versionStr = BuildInfo.getVersionString();
File versionFile = new File(ForgeConstants.ASSETS_DIR + "version.txt");
if (!versionFile.exists()) {
try {
versionFile.createNewFile();
}
catch (IOException e) {
e.printStackTrace();
Gdx.app.exit(); //can't continue if this fails
}
}
else if (versionStr.equals(TextUtil.join(FileUtil.readFile(versionFile), "\n"))) {
return; //if version matches what had been previously saved, no need to download assets
}
//save version string to file once assets finish downloading
//so they don't need to be re-downloaded until you upgrade again
FileUtil.writeFile(versionFile, versionStr);
}
} }