mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
Add support for checking for assets when opening android app
This commit is contained in:
@@ -80,6 +80,16 @@ public final class FileUtil {
|
||||
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
|
||||
// this is used to write a file of Strings
|
||||
// this will create a new file if needed
|
||||
@@ -109,7 +119,7 @@ public final class FileUtil {
|
||||
public static String readFileToString(String filename) {
|
||||
return TextUtil.join(readFile(filename), "\n");
|
||||
}
|
||||
|
||||
|
||||
public static List<String> readFile(final String filename) {
|
||||
return FileUtil.readFile(new File(filename));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
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.BitmapFont.HAlignment;
|
||||
|
||||
@@ -7,10 +12,14 @@ import forge.Forge.Graphics;
|
||||
import forge.assets.FSkin;
|
||||
import forge.assets.FSkinFont;
|
||||
import forge.assets.FSkinTexture;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.toolbox.FContainer;
|
||||
import forge.toolbox.FProgressBar;
|
||||
import forge.util.BuildInfo;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.TextUtil;
|
||||
|
||||
public class SplashScreen extends FContainer {
|
||||
private TextureRegion background;
|
||||
@@ -21,6 +30,8 @@ public class SplashScreen extends FContainer {
|
||||
progressBar = new FProgressBar();
|
||||
progressBar.setDescription("Welcome to Forge");
|
||||
|
||||
checkForAssets();
|
||||
|
||||
final ForgePreferences prefs = new ForgePreferences();
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user