龙城战记 v1.0.1版本的 MD5 值为:00000931b93a3ccf40631848e86a593d
以下内容为反编译后的 UpdateActivity.java 源代码,内容仅作参考
package qksdkproxy;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.TextView;
import com.sy.lzzj.gdt.R;
import com.unisound.client.SpeechConstants;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.TimeUnit;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONException;
import org.json.JSONObject;
import qksdkproxy.sdkproxy.sdksupport.QKUnityPlayerActivity;
public class UpdateActivity extends Activity {
private String cdnPath = "";
private int errorNums = 0;
private TextView labTip;
private Runnable runnable;
static int access$008(UpdateActivity updateActivity) {
int i = updateActivity.errorNums;
updateActivity.errorNums = i + 1;
return i;
}
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
if ((getIntent().getFlags() & 4194304) != 0) {
finish();
return;
}
setContentView(R.layout.update_layout);
hideBottomUIMenu();
this.labTip = (TextView) findViewById(R.id.labTip);
this.labTip.setText(R.string.update_init);
getCDN();
}
protected void hideBottomUIMenu() {
if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) {
getWindow().getDecorView().setSystemUiVisibility(8);
} else if (Build.VERSION.SDK_INT >= 19) {
getWindow().getDecorView().setSystemUiVisibility(SpeechConstants.VPR_EVENT_RECORDING_STOP);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.e("mmmm", "UpdateActivity..........onDestroy");
}
private void getCDN() {
try {
String packageName = getPackageName();
SendRequest(packageName, getPackageManager().getPackageInfo(packageName, 0).versionName);
} catch (Exception unused) {
}
}
private String GetCDNPath() {
try {
InputStream open = getAssets().open("PlatformSettings.txt");
byte[] bArr = new byte[open.available()];
open.read(bArr);
Object obj = new JSONObject(new String(bArr)).get("postGetUpdate");
return obj != null ? obj.toString() : "http://login.bxcq.handgame666.com/getUpdate.php";
} catch (JSONException | Exception unused) {
return "http://login.bxcq.handgame666.com/getUpdate.php";
}
}
public void SendRequest(final String str, final String str2) {
String str3 = GetCDNPath() + "?appid=" + str + "&appver=" + str2;
Log.e("mmmm", str3);
new OkHttpClient.Builder().connectTimeout(3L, TimeUnit.SECONDS).readTimeout(3L, TimeUnit.SECONDS).writeTimeout(3L, TimeUnit.SECONDS).build().newCall(new Request.Builder().get().url(str3).build()).enqueue(new Callback() {
@Override
public void onFailure(Call call, final IOException iOException) {
UpdateActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
UpdateActivity.access$008(UpdateActivity.this);
if (UpdateActivity.this.errorNums < 3) {
UpdateActivity.this.SendRequest(str, str2);
} else {
UpdateActivity.this.showCDNErrorMessage(iOException.getMessage());
}
}
});
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.code() == 404) {
Log.e("获取CDN地址", "404 not found!");
UpdateActivity.this.showCDNErrorMessage("404 not found!");
} else {
UpdateActivity.this.parseCDN(response.body().string());
}
}
});
}
public void parseCDN(String str) {
try {
Log.e("parseCDN", str);
JSONObject jSONObject = new JSONObject(str);
String string = jSONObject.getString("ErrorCode");
if (string.equals("0")) {
JSONObject jSONObject2 = new JSONObject(jSONObject.getString("Data"));
String string2 = jSONObject2.getString("appstoreurl");
if (string2 != null && string2.length() > 0) {
openURL(string2);
} else {
this.cdnPath = jSONObject2.getString("cdn");
save(this.cdnPath);
checkCodeUpdate();
Log.v("获取CDN地址", this.cdnPath);
}
} else {
showCDNErrorMessage("解析cdn地址出错,错误码是:" + string);
Log.e("获取CDN地址", "失败" + string);
}
} catch (JSONException e) {
showCDNErrorMessage("解析cdn地址异常:" + e.getMessage());
Log.e("获取CDN地址", "失败:" + str + " " + e.toString());
}
}
private void openURL(String str) {
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.setData(Uri.parse(str));
startActivity(intent);
}
private void checkCodeUpdate() {
new OkHttpClient().newCall(new Request.Builder().get().url(this.cdnPath + "/android/update.txt").build()).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException iOException) {
UpdateActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Log.e("获取配置文件", "失败");
UpdateActivity.this.enterGame();
}
});
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.code() == 404) {
UpdateActivity.this.enterGameNoUpdate();
} else {
UpdateActivity.this.parseSetting(response.body().string());
}
}
});
}
public void parseSetting(String str) {
try {
JSONObject jSONObject = new JSONObject(str);
int i = jSONObject.getInt("version");
int i2 = jSONObject.getInt("size");
String string = jSONObject.getString("filename");
String str2 = getApplication().getExternalFilesDir("").toString() + "/Bundles/Android/";
String str3 = this.cdnPath + "/android/" + string;
File file = new File(str2 + string);
if (file.exists()) {
byte[] bArr = new byte[4];
FileInputStream fileInputStream = new FileInputStream(file);
int i3 = 0;
if (fileInputStream.available() >= 4) {
fileInputStream.read(bArr, 0, 4);
i3 = bytesToInt(bArr, 0);
}
fileInputStream.close();
if (i3 < i) {
downloadDLL(str3, str2, string);
return;
}
if (i3 != i) {
enterGameNoUpdate();
return;
} else if (i2 == file.length()) {
enterGameNoUpdate();
return;
} else {
downloadDLL(str3, str2, string);
return;
}
}
downloadDLL(str3, str2, string);
} catch (Exception e) {
e.printStackTrace();
Log.e("获取配置文件", "配置文件解析错误,进入游戏 " + e.toString());
showParseErrorMessage();
}
}
private void downloadDLL(String str, final String str2, final String str3) {
runOnUiThread(new Runnable() {
@Override
public void run() {
UpdateActivity.this.labTip.setText(R.string.update_update);
}
});
File file = new File(str2);
if (file.exists()) {
file.delete();
}
file.mkdirs();
new OkHttpClient().newCall(new Request.Builder().url(str).build()).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException iOException) {
UpdateActivity.this.OnDllDownloadFailed(iOException.getMessage());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
InputStream inputStream;
FileOutputStream fileOutputStream;
if (response.code() == 404) {
UpdateActivity.this.OnDllDownloadFailed("404 Not Found!");
return;
}
byte[] bArr = new byte[2048];
long j = 0;
long contentLength = response.body().contentLength();
File file2 = new File(str2 + str3);
InputStream inputStream2 = null;
try {
inputStream = response.body().byteStream();
try {
fileOutputStream = new FileOutputStream(file2);
while (true) {
try {
int read = inputStream.read(bArr);
if (read == -1) {
break;
}
fileOutputStream.write(bArr, 0, read);
j += read;
UpdateActivity.this.OnDllDownloading((int) (((((float) j) * 1.0f) / ((float) contentLength)) * 100.0f));
} catch (Exception e) {
e = e;
inputStream2 = inputStream;
try {
UpdateActivity.this.OnDllDownloadFailed(e.getMessage());
if (inputStream2 != null) {
inputStream2.close();
}
if (fileOutputStream != null) {
fileOutputStream.close();
}
if (j >= contentLength || !file2.exists()) {
return;
}
file2.delete();
} catch (Throwable th) {
th = th;
inputStream = inputStream2;
if (inputStream != null) {
inputStream.close();
}
if (fileOutputStream != null) {
fileOutputStream.close();
}
if (j < contentLength && file2.exists()) {
file2.delete();
}
throw th;
}
} catch (Throwable th2) {
th = th2;
if (inputStream != null) {
}
if (fileOutputStream != null) {
}
if (j < contentLength) {
file2.delete();
}
throw th;
}
}
fileOutputStream.flush();
UpdateActivity.this.OnDllDownloadSucess();
if (inputStream != null) {
inputStream.close();
}
fileOutputStream.close();
if (j >= contentLength || !file2.exists()) {
return;
}
} catch (Exception e2) {
e = e2;
fileOutputStream = null;
} catch (Throwable th3) {
th = th3;
fileOutputStream = null;
}
} catch (Exception e3) {
e = e3;
fileOutputStream = null;
} catch (Throwable th4) {
th = th4;
inputStream = null;
fileOutputStream = null;
}
file2.delete();
}
});
}
public void OnDllDownloading(final int i) {
runOnUiThread(new Runnable() {
@Override
public void run() {
UpdateActivity.this.labTip.setText("游戏逻辑更新中" + String.valueOf(i) + "%");
}
});
}
public void OnDllDownloadSucess() {
Log.e("下载进度", "下载成功进入游戏");
enterGame();
}
public void OnDllDownloadFailed(String str) {
showDownloadDLLErrorMessage(str);
}
public static int bytesToInt(byte[] bArr, int i) {
return ((bArr[i + 3] & 255) << 24) | (bArr[i] & 255) | ((bArr[i + 1] & 255) << 8) | ((bArr[i + 2] & 255) << 16);
}
public void enterGameNoUpdate() {
runOnUiThread(new Runnable() {
@Override
public void run() {
final Handler handler = new Handler();
UpdateActivity.this.runnable = new Runnable() {
@Override
public void run() {
handler.removeCallbacks(UpdateActivity.this.runnable);
UpdateActivity.this.startActivity(new Intent(UpdateActivity.this, (Class<?>) QKUnityPlayerActivity.class));
UpdateActivity.this.overridePendingTransition(0, 0);
UpdateActivity.this.finish();
}
};
handler.postDelayed(UpdateActivity.this.runnable, 1500L);
}
});
}
public void enterGame() {
runOnUiThread(new Runnable() {
@Override
public void run() {
UpdateActivity.this.startActivity(new Intent(UpdateActivity.this, (Class<?>) QKUnityPlayerActivity.class));
UpdateActivity.this.overridePendingTransition(0, 0);
UpdateActivity.this.finish();
}
});
}
public void showCDNErrorMessage(final String str) {
runOnUiThread(new Runnable() {
@Override
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(UpdateActivity.this);
builder.setTitle(R.string.update_error_title);
builder.setMessage(str);
builder.setPositiveButton(UpdateActivity.this.getString(R.string.update_error_ok_text), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
System.exit(0);
}
});
builder.setCancelable(false);
builder.create().show();
}
});
}
private void showDownloadDLLErrorMessage(final String str) {
runOnUiThread(new Runnable() {
@Override
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(UpdateActivity.this);
builder.setTitle(R.string.update_error_title);
builder.setMessage("2131230812,错误信息:" + str);
builder.setPositiveButton(UpdateActivity.this.getString(R.string.update_error_ok_text), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
System.exit(0);
}
});
builder.setCancelable(false);
builder.create().show();
}
});
}
private void showParseErrorMessage() {
runOnUiThread(new Runnable() {
@Override
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(UpdateActivity.this);
builder.setTitle(R.string.update_error_title);
builder.setMessage(R.string.parseError);
builder.setPositiveButton(UpdateActivity.this.getString(R.string.update_error_ok_text), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
System.exit(0);
}
});
builder.setCancelable(false);
builder.create().show();
}
});
}
private void save(String str) {
try {
File file = new File(getApplication().getExternalFilesDir("").toString() + "/cdn.txt");
if (!file.exists()) {
new File(file.getParent()).mkdirs();
file.createNewFile();
}
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(str.getBytes());
fileOutputStream.flush();
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}