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

This commit is contained in:
zhl 2020-12-23 20:03:02 +08:00
parent 0645e6e5de
commit 54e887e8f1
2 changed files with 7 additions and 3 deletions

View File

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

View File

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