java: Check for pak0.pk3 and download it if not found

This commit is contained in:
rafal1137 2020-05-16 15:54:05 +02:00
parent 10dce0a220
commit 648a5e2fd4

View file

@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import com.google.common.io.Files;
import com.loopj.android.http.AsyncHttpClient;
@ -20,7 +21,9 @@ public class ETLMain extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
File etl_pak = new File(getExternalFilesDir(null), "pak2.pk3");
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
File etl_pak = new File(getExternalFilesDir(null), "/etlegacy/etmain/pak0.pk3");
final Intent intent = new Intent(ETLMain.this, ETLActivity.class);
if (etl_pak.exists()) {
@ -28,8 +31,8 @@ public class ETLMain extends Activity {
finish();
}
else {
AsyncHttpClient client = new AsyncHttpClient();
client.get("http://mirror.etlegacy.com/etmain/pak2.pk3", new FileAsyncHttpResponseHandler(this) {
final AsyncHttpClient client = new AsyncHttpClient();
client.get("http://mirror.etlegacy.com/etmain/pak0.pk3", new FileAsyncHttpResponseHandler(this) {
@Override
public void onSuccess(int statusCode, Header[] headers, File file) {
@ -40,9 +43,10 @@ public class ETLMain extends Activity {
super.onFinish();
if (file.getAbsoluteFile().exists()) {
try {
Files.move(file.getAbsoluteFile(), new File(getExternalFilesDir(null), "pak2.pk3"));
finish();
Files.move(file.getAbsoluteFile(), new File(getExternalFilesDir(null), "/etlegacy/etmain/pak0.pk3"));
client.cancelAllRequests(true);
startActivity(intent);
finish();
} catch (IOException e) {
e.printStackTrace();
}