畅玩新葡京 v8.2.8版本的 MD5 值为:1e36e0a7adef719a26e0a466b52c398d
以下内容为反编译后的 Cocos2dxDownloader.java 源代码,内容仅作参考
package org.cocos2dx.lib;
import android.util.Log;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import com.lzy.okgo.cookie.SerializableCookie;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class Cocos2dxDownloader {
private static ConcurrentHashMap<String, Boolean> _resumingSupport = new ConcurrentHashMap<>();
private int _countOfMaxProcessingTasks;
private int _id;
private String _tempFileNameSuffix;
private OkHttpClient _httpClient = null;
private ConcurrentHashMap<Integer, Call> _taskMap = new ConcurrentHashMap<>();
private Queue<Runnable> _taskQueue = new LinkedList();
private int _runningTaskCount = 0;
final class AnonymousClass3 implements Runnable {
String a = null;
String b = null;
File c = null;
File d = null;
long e = 0;
final String f;
final String g;
final Cocos2dxDownloader h;
final String[] i;
final int j;
AnonymousClass3(String str, String str2, Cocos2dxDownloader cocos2dxDownloader, String[] strArr, int i) {
this.f = str;
this.g = str2;
this.h = cocos2dxDownloader;
this.i = strArr;
this.j = i;
}
@Override
public void run() {
Call call;
if (this.f.length() > 0) {
try {
Log.e(SerializableCookie.DOMAIN, "domain============= " + this.g);
this.a = new URI("https://shehona.cn/creator/344qp/version.manifest").getHost();
this.c = new File(this.f + this.h._tempFileNameSuffix);
if (!this.c.isDirectory()) {
File parentFile = this.c.getParentFile();
if (parentFile.isDirectory() || parentFile.mkdirs()) {
this.d = new File(this.f);
if (!this.d.isDirectory()) {
long length = this.c.length();
this.b = this.a.startsWith("www.") ? this.a.substring(4) : this.a;
if (length > 0) {
if (Cocos2dxDownloader._resumingSupport.containsKey(this.b) && ((Boolean) Cocos2dxDownloader._resumingSupport.get(this.b)).booleanValue()) {
this.e = length;
} else {
try {
PrintWriter printWriter = new PrintWriter(this.c);
printWriter.print("");
printWriter.close();
} catch (FileNotFoundException unused) {
}
}
}
}
}
}
} catch (NullPointerException e) {
e.printStackTrace();
} catch (URISyntaxException e2) {
e2.printStackTrace();
}
call = null;
if (call == null) {
this.h._taskMap.put(Integer.valueOf(this.j), call);
return;
}
final String str = "Can't create DownloadTask for " + this.g;
Cocos2dxHelper.runOnGLThread(new Runnable() {
@Override
public void run() {
AnonymousClass3.this.h.nativeOnFinish(AnonymousClass3.this.h._id, AnonymousClass3.this.j, 0, str, null);
}
});
return;
}
Request.Builder url = new Request.Builder().url(this.g);
for (int i = 0; i < this.i.length / 2; i++) {
int i2 = i * 2;
url.addHeader(this.i[i2], this.i[i2 + 1]);
}
if (this.e > 0) {
url.addHeader("RANGE", "bytes=" + this.e + "-");
}
call = this.h._httpClient.newCall(url.build());
call.enqueue(new Callback() {
@Override
public void onFailure(Call call2, IOException iOException) {
AnonymousClass3.this.h.onFinish(AnonymousClass3.this.j, 0, iOException.toString(), null);
}
@Override
public void onResponse(Call call2, Response response) throws IOException {
Throwable th;
InputStream inputStream;
FileOutputStream fileOutputStream;
FileOutputStream fileOutputStream2;
String str2;
ConcurrentHashMap concurrentHashMap;
String str3;
boolean z;
byte[] bArr = new byte[AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD];
FileOutputStream fileOutputStream3 = null;
try {
try {
try {
if (response.code() >= 200 && response.code() <= 206) {
long contentLength = response.body().contentLength();
if (AnonymousClass3.this.f.length() > 0 && !Cocos2dxDownloader._resumingSupport.containsKey(AnonymousClass3.this.b)) {
if (contentLength > 0) {
concurrentHashMap = Cocos2dxDownloader._resumingSupport;
str3 = AnonymousClass3.this.b;
z = true;
} else {
concurrentHashMap = Cocos2dxDownloader._resumingSupport;
str3 = AnonymousClass3.this.b;
z = false;
}
concurrentHashMap.put(str3, z);
}
long j = AnonymousClass3.this.e;
inputStream = response.body().byteStream();
try {
if (AnonymousClass3.this.f.length() > 0) {
FileOutputStream fileOutputStream4 = AnonymousClass3.this.e > 0 ? new FileOutputStream(AnonymousClass3.this.c, true) : new FileOutputStream(AnonymousClass3.this.c, false);
while (true) {
try {
int read = inputStream.read(bArr);
if (read == -1) {
break;
}
long j2 = read;
long j3 = j + j2;
fileOutputStream4.write(bArr, 0, read);
fileOutputStream = fileOutputStream4;
try {
AnonymousClass3.this.h.onProgress(AnonymousClass3.this.j, j2, j3, contentLength);
j = j3;
fileOutputStream4 = fileOutputStream;
} catch (IOException e3) {
e = e3;
e.printStackTrace();
AnonymousClass3.this.h.onFinish(AnonymousClass3.this.j, 0, e.toString(), null);
if (inputStream != null) {
inputStream.close();
}
if (fileOutputStream != null) {
fileOutputStream.close();
return;
}
return;
}
} catch (IOException e4) {
e = e4;
fileOutputStream = fileOutputStream4;
} catch (Throwable th2) {
th = th2;
FileOutputStream fileOutputStream5 = fileOutputStream4;
th = th;
fileOutputStream3 = fileOutputStream5;
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e5) {
Log.e("Cocos2dxDownloader", e5.toString());
throw th;
}
}
if (fileOutputStream3 != null) {
fileOutputStream3.close();
}
throw th;
}
}
fileOutputStream2 = fileOutputStream4;
fileOutputStream2.flush();
if (AnonymousClass3.this.d.exists()) {
if (AnonymousClass3.this.d.isDirectory()) {
str2 = null;
if (str2 == null) {
}
} else if (!AnonymousClass3.this.d.delete()) {
str2 = "Can't remove old file:" + AnonymousClass3.this.d.getAbsolutePath();
if (str2 == null) {
AnonymousClass3.this.h.onFinish(AnonymousClass3.this.j, 0, null, null);
AnonymousClass3.this.h.runNextTaskIfExists();
} else {
AnonymousClass3.this.h.onFinish(AnonymousClass3.this.j, 0, str2, null);
}
}
}
AnonymousClass3.this.c.renameTo(AnonymousClass3.this.d);
str2 = null;
if (str2 == null) {
}
} else {
int i3 = -1;
ByteArrayOutputStream byteArrayOutputStream = contentLength > 0 ? new ByteArrayOutputStream((int) contentLength) : new ByteArrayOutputStream(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD);
while (true) {
int read2 = inputStream.read(bArr);
if (read2 == i3) {
break;
}
long j4 = read2;
long j5 = j + j4;
byteArrayOutputStream.write(bArr, 0, read2);
AnonymousClass3.this.h.onProgress(AnonymousClass3.this.j, j4, j5, contentLength);
j = j5;
i3 = i3;
}
AnonymousClass3.this.h.onFinish(AnonymousClass3.this.j, 0, null, byteArrayOutputStream.toByteArray());
AnonymousClass3.this.h.runNextTaskIfExists();
fileOutputStream2 = null;
}
if (inputStream != null) {
inputStream.close();
}
if (fileOutputStream2 != null) {
fileOutputStream2.close();
return;
}
return;
} catch (IOException e6) {
e = e6;
fileOutputStream = null;
} catch (Throwable th3) {
th = th3;
if (inputStream != null) {
}
if (fileOutputStream3 != null) {
}
throw th;
}
}
AnonymousClass3.this.h.onFinish(AnonymousClass3.this.j, -2, response.message(), null);
} catch (Throwable th4) {
th = th4;
}
} catch (IOException e7) {
e = e7;
inputStream = null;
fileOutputStream = null;
} catch (Throwable th5) {
th = th5;
inputStream = null;
}
} catch (IOException e8) {
Log.e("Cocos2dxDownloader", e8.toString());
}
}
});
if (call == null) {
}
}
}
public static void abort(Cocos2dxDownloader cocos2dxDownloader, final int i) {
Cocos2dxHelper.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
for (Map.Entry entry : Cocos2dxDownloader.this._taskMap.entrySet()) {
Object key = entry.getKey();
Call call = (Call) entry.getValue();
if (call != null && Integer.parseInt(key.toString()) == i) {
call.cancel();
Cocos2dxDownloader.this._taskMap.remove(Integer.valueOf(i));
Cocos2dxDownloader.this.runNextTaskIfExists();
return;
}
}
}
});
}
public static void cancelAllRequests(Cocos2dxDownloader cocos2dxDownloader) {
Cocos2dxHelper.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
for (Map.Entry entry : Cocos2dxDownloader.this._taskMap.entrySet()) {
Call call = (Call) entry.getValue();
if (call != null) {
call.cancel();
}
}
}
});
}
public static Cocos2dxDownloader createDownloader(int i, int i2, String str, int i3) {
Cocos2dxDownloader cocos2dxDownloader = new Cocos2dxDownloader();
cocos2dxDownloader._id = i;
cocos2dxDownloader._httpClient = (i2 > 0 ? new OkHttpClient().newBuilder().followRedirects(true).followSslRedirects(true).callTimeout(i2, TimeUnit.SECONDS) : new OkHttpClient().newBuilder().followRedirects(true).followSslRedirects(true)).build();
cocos2dxDownloader._tempFileNameSuffix = str;
cocos2dxDownloader._countOfMaxProcessingTasks = i3;
return cocos2dxDownloader;
}
public static void createTask(Cocos2dxDownloader cocos2dxDownloader, int i, String str, String str2, String[] strArr) {
cocos2dxDownloader.enqueueTask(new AnonymousClass3(str2, str, cocos2dxDownloader, strArr, i));
}
private void enqueueTask(Runnable runnable) {
synchronized (this._taskQueue) {
if (this._runningTaskCount < this._countOfMaxProcessingTasks) {
Cocos2dxHelper.getActivity().runOnUiThread(runnable);
this._runningTaskCount++;
} else {
this._taskQueue.add(runnable);
}
}
}
public void onFinish(final int i, final int i2, final String str, final byte[] bArr) {
if (this._taskMap.get(Integer.valueOf(i)) == null) {
return;
}
this._taskMap.remove(Integer.valueOf(i));
this._runningTaskCount--;
Cocos2dxHelper.runOnGLThread(new Runnable() {
@Override
public void run() {
Cocos2dxDownloader.this.nativeOnFinish(Cocos2dxDownloader.this._id, i, i2, str, bArr);
}
});
runNextTaskIfExists();
}
public void onProgress(final int i, final long j, final long j2, final long j3) {
Cocos2dxHelper.runOnGLThread(new Runnable() {
@Override
public void run() {
Cocos2dxDownloader.this.nativeOnProgress(Cocos2dxDownloader.this._id, i, j, j2, j3);
}
});
}
public void runNextTaskIfExists() {
synchronized (this._taskQueue) {
while (this._runningTaskCount < this._countOfMaxProcessingTasks && this._taskQueue.size() > 0) {
Cocos2dxHelper.getActivity().runOnUiThread(this._taskQueue.poll());
this._runningTaskCount++;
}
}
}
native void nativeOnFinish(int i, int i2, int i3, String str, byte[] bArr);
native void nativeOnProgress(int i, int i2, long j, long j2, long j3);
}