修正热更无法正常运行的bug

This commit is contained in:
zhl 2020-12-23 20:07:21 +08:00
parent b1726e94ce
commit 098cc65123
2 changed files with 7 additions and 3 deletions

View File

@ -128,7 +128,7 @@ public class LaunchActivity extends Activity {
*/ */
private void getLocalVersionInfo() { private void getLocalVersionInfo() {
String fileName = gameUrl.replace("index.html", "version.json"); String fileName = gameUrl.replace("index.html", "version.json");
String realPath = getFileDirByUrl(fileName); String realPath = preloadPath + "/" + getFileDirByUrl(fileName) + "version.json" ;
File versionFile = new File(realPath); File versionFile = new File(realPath);
if (versionFile.exists()) { if (versionFile.exists()) {
JSONObject data = AssetsUtil.readJsonFromFile(this, realPath); JSONObject data = AssetsUtil.readJsonFromFile(this, realPath);
@ -198,7 +198,7 @@ public class LaunchActivity extends Activity {
}); });
} }
private void preloadGame() { private void preloadGame() {
String dir = preloadPath + getFileDirByUrl(gameUrl); String dir = preloadPath + "/" + getFileDirByUrl(gameUrl);
File dirFile = new File(dir); File dirFile = new File(dir);
if (!dirFile.exists()) { if (!dirFile.exists()) {
dirFile.mkdirs(); dirFile.mkdirs();

View File

@ -12,6 +12,7 @@ import org.json.JSONObject;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -187,12 +188,15 @@ public class AssetsUtil {
*/ */
public static String readFromFile(Context context, String path) { public static String readFromFile(Context context, String path) {
try { try {
InputStreamReader inputReader = new InputStreamReader(context.openFileInput(path)); FileInputStream fileInputStream = new FileInputStream(new File(path));
InputStreamReader inputReader = new InputStreamReader(fileInputStream);
BufferedReader bufReader = new BufferedReader(inputReader); BufferedReader bufReader = new BufferedReader(inputReader);
String line=""; String line="";
StringBuilder result= new StringBuilder(); StringBuilder result= new StringBuilder();
while((line = bufReader.readLine()) != null) while((line = bufReader.readLine()) != null)
result.append(line); result.append(line);
fileInputStream.close();
inputReader.close(); inputReader.close();
bufReader.close(); bufReader.close();
return result.toString(); return result.toString();