Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
package com.liulishuo.filedownloader.util;
/* loaded from: classes.dex */
public class DownloadServiceNotConnectedHelper {
public static boolean a(String str, String str2, boolean z) {
a("request start the task([%s], [%s], [%B]) in the download service", str, str2, Boolean.valueOf(z));
return false;
}
public static boolean b(int i) {
a("request pause the task[%d] in the download service", Integer.valueOf(i));
return false;
}
public static byte a(int i) {
a("request get the status for the task[%d] in the download service", Integer.valueOf(i));
return (byte) 0;
}
private static void a(String str, Object... objArr) {
FileDownloadLog.e(DownloadServiceNotConnectedHelper.class, str + ", but the download service isn't connected yet.\nYou can use FileDownloader#isServiceConnected() to check whether the service has been connected, \nbesides you can use following functions easier to control your code invoke after the service has been connected: \n1. FileDownloader#bindService(Runnable)\n2. FileDownloader#insureServiceBind()\n3. FileDownloader#insureServiceBindAsync()", objArr);
}
}

View File

@@ -0,0 +1,52 @@
package com.liulishuo.filedownloader.util;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/* loaded from: classes.dex */
public class FileDownloadExecutors {
static class FileDownloadThreadFactory implements ThreadFactory {
private final String a;
private final AtomicInteger c = new AtomicInteger(1);
private final ThreadGroup b = Thread.currentThread().getThreadGroup();
static {
new AtomicInteger(1);
}
FileDownloadThreadFactory(String str) {
this.a = FileDownloadUtils.k(str);
}
@Override // java.util.concurrent.ThreadFactory
public Thread newThread(Runnable runnable) {
Thread thread = new Thread(this.b, runnable, this.a + this.c.getAndIncrement(), 0L);
if (thread.isDaemon()) {
thread.setDaemon(false);
}
if (thread.getPriority() != 5) {
thread.setPriority(5);
}
return thread;
}
}
public static ThreadPoolExecutor a(String str) {
return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 15L, TimeUnit.SECONDS, new SynchronousQueue(), new FileDownloadThreadFactory(str));
}
public static ThreadPoolExecutor a(int i, String str) {
return a(i, new LinkedBlockingQueue(), str);
}
public static ThreadPoolExecutor a(int i, LinkedBlockingQueue<Runnable> linkedBlockingQueue, String str) {
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(i, i, 15L, TimeUnit.SECONDS, linkedBlockingQueue, new FileDownloadThreadFactory(str));
threadPoolExecutor.allowCoreThreadTimeOut(true);
return threadPoolExecutor;
}
}

View File

@@ -0,0 +1,81 @@
package com.liulishuo.filedownloader.util;
import android.annotation.SuppressLint;
import android.content.Context;
import com.liulishuo.filedownloader.IThreadPoolMonitor;
import com.liulishuo.filedownloader.connection.FileDownloadConnection;
import com.liulishuo.filedownloader.database.FileDownloadDatabase;
import com.liulishuo.filedownloader.exception.PathConflictException;
import com.liulishuo.filedownloader.message.MessageSnapshotFlow;
import com.liulishuo.filedownloader.message.MessageSnapshotTaker;
import com.liulishuo.filedownloader.model.FileDownloadModel;
import com.liulishuo.filedownloader.stream.FileDownloadOutputStream;
import java.io.File;
import java.io.IOException;
/* loaded from: classes.dex */
public class FileDownloadHelper {
@SuppressLint({"StaticFieldLeak"})
private static Context a;
public interface ConnectionCountAdapter {
int a(int i, String str, String str2, long j);
}
public interface ConnectionCreator {
FileDownloadConnection a(String str) throws IOException;
}
public interface DatabaseCustomMaker {
FileDownloadDatabase a();
}
public interface IdGenerator {
int a(int i, String str, String str2, boolean z);
int a(String str, String str2, boolean z);
}
public interface OutputStreamCreator {
FileDownloadOutputStream a(File file) throws IOException;
boolean a();
}
public static void a(Context context) {
a = context;
}
public static Context a() {
return a;
}
public static boolean a(int i, String str, boolean z, boolean z2) {
if (!z && str != null) {
File file = new File(str);
if (file.exists()) {
MessageSnapshotFlow.a().a(MessageSnapshotTaker.a(i, file, z2));
return true;
}
}
return false;
}
public static boolean a(int i, FileDownloadModel fileDownloadModel, IThreadPoolMonitor iThreadPoolMonitor, boolean z) {
if (!iThreadPoolMonitor.a(fileDownloadModel)) {
return false;
}
MessageSnapshotFlow.a().a(MessageSnapshotTaker.a(i, fileDownloadModel.getSoFar(), fileDownloadModel.getTotal(), z));
return true;
}
public static boolean a(int i, long j, String str, String str2, IThreadPoolMonitor iThreadPoolMonitor) {
int a2;
if (str2 == null || str == null || (a2 = iThreadPoolMonitor.a(str, i)) == 0) {
return false;
}
MessageSnapshotFlow.a().a(MessageSnapshotTaker.a(i, j, new PathConflictException(a2, str, str2)));
return true;
}
}

View File

@@ -0,0 +1,52 @@
package com.liulishuo.filedownloader.util;
import android.util.Log;
/* loaded from: classes.dex */
public class FileDownloadLog {
public static boolean a = false;
public static void a(Object obj, Throwable th, String str, Object... objArr) {
a(6, obj, th, str, objArr);
}
public static void b(Object obj, String str, Object... objArr) {
a(6, obj, str, objArr);
}
public static void c(Object obj, String str, Object... objArr) {
a(4, obj, str, objArr);
}
public static void d(Object obj, String str, Object... objArr) {
a(2, obj, str, objArr);
}
public static void e(Object obj, String str, Object... objArr) {
a(5, obj, str, objArr);
}
public static void a(Object obj, String str, Object... objArr) {
a(3, obj, str, objArr);
}
private static void a(int i, Object obj, String str, Object... objArr) {
a(i, obj, null, str, objArr);
}
private static void a(int i, Object obj, Throwable th, String str, Object... objArr) {
if ((i >= 5) || a) {
Log.println(i, a(obj), FileDownloadUtils.a(str, objArr));
if (th != null) {
th.printStackTrace();
}
}
}
private static String a(Object obj) {
StringBuilder sb = new StringBuilder();
sb.append("FileDownloader.");
sb.append((obj instanceof Class ? (Class) obj : obj.getClass()).getSimpleName());
return sb.toString();
}
}

View File

@@ -0,0 +1,74 @@
package com.liulishuo.filedownloader.util;
/* loaded from: classes.dex */
public class FileDownloadProperties {
public final int a;
public final long b;
public final boolean c;
public final boolean d;
public final int e;
public final boolean f;
public final boolean g;
public final boolean h;
public static class HolderClass {
private static final FileDownloadProperties a = new FileDownloadProperties();
}
public static FileDownloadProperties a() {
return HolderClass.a;
}
/* JADX WARN: Removed duplicated region for block: B:106:0x00c7 A[Catch: all -> 0x02a7, TryCatch #1 {all -> 0x02a7, blocks: (B:104:0x00c3, B:106:0x00c7, B:108:0x00cb, B:117:0x00d9), top: B:103:0x00c3 }] */
/* JADX WARN: Removed duplicated region for block: B:111:0x00e0 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:117:0x00d9 A[Catch: all -> 0x02a7, TRY_LEAVE, TryCatch #1 {all -> 0x02a7, blocks: (B:104:0x00c3, B:106:0x00c7, B:108:0x00cb, B:117:0x00d9), top: B:103:0x00c3 }] */
/* JADX WARN: Removed duplicated region for block: B:121:0x02ac A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:128:? A[SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:12:0x00fe */
/* JADX WARN: Removed duplicated region for block: B:21:0x0130 */
/* JADX WARN: Removed duplicated region for block: B:29:0x015b */
/* JADX WARN: Removed duplicated region for block: B:31:0x0170 */
/* JADX WARN: Removed duplicated region for block: B:33:0x018b */
/* JADX WARN: Removed duplicated region for block: B:35:0x01a0 */
/* JADX WARN: Removed duplicated region for block: B:43:0x01cd */
/* JADX WARN: Removed duplicated region for block: B:51:0x01f8 */
/* JADX WARN: Removed duplicated region for block: B:60:0x0225 */
/* JADX WARN: Removed duplicated region for block: B:62:? A[RETURN, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:63:0x021f */
/* JADX WARN: Removed duplicated region for block: B:64:0x01f4 */
/* JADX WARN: Removed duplicated region for block: B:65:0x01c8 */
/* JADX WARN: Removed duplicated region for block: B:66:0x019b */
/* JADX WARN: Removed duplicated region for block: B:67:0x0183 */
/* JADX WARN: Removed duplicated region for block: B:68:0x016a */
/* JADX WARN: Removed duplicated region for block: B:69:0x0157 */
/* JADX WARN: Removed duplicated region for block: B:70:0x0129 */
/* JADX WARN: Type inference failed for: r7v4 */
/* JADX WARN: Type inference failed for: r7v5, types: [boolean] */
/* JADX WARN: Type inference failed for: r7v7 */
/* JADX WARN: Type inference failed for: r8v1 */
/* JADX WARN: Type inference failed for: r8v2, types: [boolean, int] */
/* JADX WARN: Type inference failed for: r8v7 */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
private FileDownloadProperties() {
/*
Method dump skipped, instructions count: 702
To view this dump change 'Code comments level' option to 'DEBUG'
*/
throw new UnsupportedOperationException("Method not decompiled: com.liulishuo.filedownloader.util.FileDownloadProperties.<init>():void");
}
public static int a(int i) {
if (i > 12) {
FileDownloadLog.e(FileDownloadProperties.class, "require the count of network thread is %d, what is more than the max valid count(%d), so adjust to %d auto", Integer.valueOf(i), 12, 12);
return 12;
}
if (i >= 1) {
return i;
}
FileDownloadLog.e(FileDownloadProperties.class, "require the count of network thread is %d, what is less than the min valid count(%d), so adjust to %d auto", Integer.valueOf(i), 1, 1);
return 1;
}
}

View File

@@ -0,0 +1,500 @@
package com.liulishuo.filedownloader.util;
import android.app.ActivityManager;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Environment;
import android.os.PowerManager;
import android.os.Process;
import android.os.StatFs;
import android.text.TextUtils;
import com.liulishuo.filedownloader.connection.FileDownloadConnection;
import com.liulishuo.filedownloader.download.CustomComponentHolder;
import com.liulishuo.filedownloader.exception.FileDownloadGiveUpRetryException;
import com.liulishuo.filedownloader.exception.FileDownloadSecurityException;
import com.liulishuo.filedownloader.model.FileDownloadModel;
import com.liulishuo.filedownloader.stream.FileDownloadOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/* loaded from: classes.dex */
public class FileDownloadUtils {
private static int a = 65536;
private static long b = 2000;
private static String c;
private static Boolean d;
private static final Pattern e = Pattern.compile("attachment;\\s*filename\\*\\s*=\\s*\"*([^\"]*)'\\S*'([^\"]*)\"*");
private static final Pattern f = Pattern.compile("attachment;\\s*filename\\s*=\\s*\"*([^\"\\n]*)\"*");
public static void a(int i) throws IllegalAccessException {
if (!c(FileDownloadHelper.a())) {
throw new IllegalAccessException("This value is used in the :filedownloader process, so set this value in your process is without effect. You can add 'process.non-separate=true' in 'filedownloader.properties' to share the main process to FileDownloadService. Or you can configure this value in 'filedownloader.properties' by 'download.min-progress-step'.");
}
a = i;
}
public static String b() {
return !TextUtils.isEmpty(c) ? c : FileDownloadHelper.a().getExternalCacheDir() == null ? Environment.getDownloadCacheDirectory().getAbsolutePath() : FileDownloadHelper.a().getExternalCacheDir().getAbsolutePath();
}
public static int c() {
return a;
}
public static long d() {
return b;
}
public static boolean e() {
ConnectivityManager connectivityManager = (ConnectivityManager) FileDownloadHelper.a().getSystemService("connectivity");
if (connectivityManager == null) {
FileDownloadLog.e(FileDownloadUtils.class, "failed to get connectivity manager!", new Object[0]);
return true;
}
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo == null || activeNetworkInfo.getType() != 1;
}
public static String f(String str) {
return m(str);
}
public static String g(String str) {
return b(b(), f(str));
}
public static long h(String str) {
return Build.VERSION.SDK_INT >= 18 ? new StatFs(str).getAvailableBytes() : r0.getAvailableBlocks() * r0.getBlockSize();
}
public static String i(String str) {
int length = str.length();
int i = (File.separatorChar == '\\' && length > 2 && str.charAt(1) == ':') ? 2 : 0;
int lastIndexOf = str.lastIndexOf(File.separatorChar);
int i2 = (lastIndexOf != -1 || i <= 0) ? lastIndexOf : 2;
if (i2 == -1) {
return null;
}
char charAt = str.charAt(length - 1);
char c2 = File.separatorChar;
if (charAt == c2) {
return null;
}
return (str.indexOf(c2) == i2 && str.charAt(i) == File.separatorChar) ? str.substring(0, i2 + 1) : str.substring(0, i2);
}
public static String j(String str) {
return a("%s.temp", str);
}
public static String k(String str) {
return "FileDownloader-" + str;
}
public static boolean l(String str) {
return true;
}
public static String m(String str) {
try {
byte[] digest = MessageDigest.getInstance("MD5").digest(str.getBytes("UTF-8"));
StringBuilder sb = new StringBuilder(digest.length * 2);
for (byte b2 : digest) {
int i = b2 & 255;
if (i < 16) {
sb.append("0");
}
sb.append(Integer.toHexString(i));
}
return sb.toString();
} catch (UnsupportedEncodingException e2) {
throw new RuntimeException("Huh, UTF-8 should be supported?", e2);
} catch (NoSuchAlgorithmException e3) {
throw new RuntimeException("Huh, MD5 should be supported?", e3);
}
}
public static String n(String str) {
Matcher matcher;
if (str == null) {
return null;
}
try {
matcher = e.matcher(str);
} catch (UnsupportedEncodingException | IllegalStateException unused) {
}
if (matcher.find()) {
return URLDecoder.decode(matcher.group(2), matcher.group(1));
}
Matcher matcher2 = f.matcher(str);
if (matcher2.find()) {
return matcher2.group(1);
}
return null;
}
public static long o(String str) {
if (str != null && str.length() != 0) {
try {
Matcher matcher = Pattern.compile("bytes (\\d+)-(\\d+)/\\d+").matcher(str);
if (matcher.find()) {
return (Long.parseLong(matcher.group(2)) - Long.parseLong(matcher.group(1))) + 1;
}
} catch (Exception e2) {
FileDownloadLog.a(FileDownloadUtils.class, e2, "parse content length from content range error", new Object[0]);
}
}
return -1L;
}
public static long p(String str) {
if (str == null) {
return -1L;
}
String[] split = str.split("/");
if (split.length >= 2) {
try {
return Long.parseLong(split[1]);
} catch (NumberFormatException unused) {
FileDownloadLog.e(FileDownloadUtils.class, "parse instance length failed with %s", str);
}
}
return -1L;
}
public static int c(String str, String str2) {
return CustomComponentHolder.i().c().a(str, str2, false);
}
public static void d(Context context) {
File a2 = a(context);
try {
a2.getParentFile().mkdirs();
a2.createNewFile();
} catch (IOException e2) {
e2.printStackTrace();
}
}
public static void a(long j) throws IllegalAccessException {
if (c(FileDownloadHelper.a())) {
b = j;
return;
}
throw new IllegalAccessException("This value is used in the :filedownloader process, so set this value in your process is without effect. You can add 'process.non-separate=true' in 'filedownloader.properties' to share the main process to FileDownloadService. Or you can configure this value in 'filedownloader.properties' by 'download.min-progress-time'.");
}
public static boolean c(Context context) {
Boolean bool = d;
if (bool != null) {
return bool.booleanValue();
}
boolean z = false;
if (!FileDownloadProperties.a().d) {
int myPid = Process.myPid();
ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
if (activityManager == null) {
FileDownloadLog.e(FileDownloadUtils.class, "fail to get the activity manager!", new Object[0]);
return false;
}
List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = activityManager.getRunningAppProcesses();
if (runningAppProcesses != null && !runningAppProcesses.isEmpty()) {
Iterator<ActivityManager.RunningAppProcessInfo> it = runningAppProcesses.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
ActivityManager.RunningAppProcessInfo next = it.next();
if (next.pid == myPid) {
z = next.processName.endsWith(":filedownloader");
break;
}
}
} else {
FileDownloadLog.e(FileDownloadUtils.class, "The running app process info list from ActivityManager is null or empty, maybe current App is not running.", new Object[0]);
return false;
}
} else {
z = true;
}
d = Boolean.valueOf(z);
return d.booleanValue();
}
public static String b(String str, String str2) {
if (str2 == null) {
throw new IllegalStateException("can't generate real path, the file name is null");
}
if (str != null) {
return a("%s%s%s", str, File.separator, str2);
}
throw new IllegalStateException("can't generate real path, the directory is null");
}
private static String d(FileDownloadConnection fileDownloadConnection) {
return fileDownloadConnection.a("Content-Range");
}
public static void e(String str) {
if (str != null) {
File file = new File(str);
if (file.exists()) {
file.delete();
}
}
}
public static int a(String str, String str2, boolean z) {
return CustomComponentHolder.i().c().a(str, str2, z);
}
public static void d(String str) {
if (str != null) {
File file = new File(str);
if (file.exists()) {
file.delete();
}
}
}
public static String a(String str, Object... objArr) {
return String.format(Locale.ENGLISH, str, objArr);
}
public static long b(String str) {
if (str == null) {
return -1L;
}
try {
return Long.parseLong(str);
} catch (NumberFormatException unused) {
return -1L;
}
}
public static boolean e(Context context) {
return Build.VERSION.SDK_INT >= 26 && !b(context);
}
public static File a(Context context) {
return new File(context.getFilesDir().getAbsolutePath() + File.separator + "filedownloader", ".old_file_converted");
}
public static String b(int i, FileDownloadConnection fileDownloadConnection) {
if (fileDownloadConnection != null) {
String a2 = fileDownloadConnection.a("Etag");
if (FileDownloadLog.a) {
FileDownloadLog.a(FileDownloadUtils.class, "etag find %s for task(%d)", a2, Integer.valueOf(i));
}
return a2;
}
throw new RuntimeException("connection is null when findEtag");
}
public static String a(String str, boolean z, String str2) {
if (str == null) {
return null;
}
if (!z) {
return str;
}
if (str2 == null) {
return null;
}
return b(str, str2);
}
public static boolean a(String str) {
return FileDownloadHelper.a().checkCallingOrSelfPermission(str) == 0;
}
public static long a(int i, FileDownloadConnection fileDownloadConnection) {
long b2 = b(fileDownloadConnection.a("Content-Length"));
String a2 = fileDownloadConnection.a("Transfer-Encoding");
if (b2 >= 0) {
return b2;
}
if (a2 != null && a2.equals("chunked")) {
return -1L;
}
if (FileDownloadProperties.a().c) {
if (!FileDownloadLog.a) {
return -1L;
}
FileDownloadLog.a(FileDownloadUtils.class, "%d response header is not legal but HTTP lenient is true, so handle as the case of transfer encoding chunk", Integer.valueOf(i));
return -1L;
}
throw new FileDownloadGiveUpRetryException("can't know the size of the download file, and its Transfer-Encoding is not Chunked either.\nyou can ignore such exception by add http.lenient=true to the filedownloader.properties");
}
public static long b(FileDownloadConnection fileDownloadConnection) {
long c2 = c(fileDownloadConnection);
if (c2 < 0) {
FileDownloadLog.e(FileDownloadUtils.class, "don't get instance length fromContent-Range header", new Object[0]);
c2 = -1;
}
if (c2 == 0 && FileDownloadProperties.a().h) {
return -1L;
}
return c2;
}
private static boolean b(Context context) {
List<ActivityManager.RunningAppProcessInfo> runningAppProcesses;
PowerManager powerManager;
ActivityManager activityManager = (ActivityManager) context.getApplicationContext().getSystemService("activity");
if (activityManager == null || (runningAppProcesses = activityManager.getRunningAppProcesses()) == null || (powerManager = (PowerManager) context.getSystemService("power")) == null) {
return false;
}
if (Build.VERSION.SDK_INT > 19) {
if (!powerManager.isInteractive()) {
return false;
}
} else if (!powerManager.isScreenOn()) {
return false;
}
String packageName = context.getApplicationContext().getPackageName();
for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) {
if (runningAppProcessInfo.processName.equals(packageName) && runningAppProcessInfo.importance == 100) {
return true;
}
}
return false;
}
public static boolean c(int i, FileDownloadConnection fileDownloadConnection) {
if (i == 206 || i == 1) {
return true;
}
return "bytes".equals(fileDownloadConnection.a("Accept-Ranges"));
}
public static long c(FileDownloadConnection fileDownloadConnection) {
return p(d(fileDownloadConnection));
}
public static FileDownloadOutputStream c(String str) throws IOException {
if (!TextUtils.isEmpty(str)) {
if (l(str)) {
File file = new File(str);
if (file.exists() && file.isDirectory()) {
throw new RuntimeException(a("found invalid internal destination path[%s], & path is directory[%B]", str, Boolean.valueOf(file.isDirectory())));
}
if (!file.exists() && !file.createNewFile()) {
throw new IOException(a("create new file error %s", file.getAbsolutePath()));
}
return CustomComponentHolder.i().a(file);
}
throw new RuntimeException(a("found invalid internal destination filename %s", str));
}
throw new RuntimeException("found invalid internal destination path, empty");
}
public static long a(FileDownloadConnection fileDownloadConnection) {
long o = o(d(fileDownloadConnection));
if (o < 0) {
return -1L;
}
return o;
}
public static String a(FileDownloadConnection fileDownloadConnection, String str) throws FileDownloadSecurityException {
String n = n(fileDownloadConnection.a("Content-Disposition"));
if (TextUtils.isEmpty(n)) {
return f(str);
}
if (n.contains("../")) {
throw new FileDownloadSecurityException(a("The filename [%s] from the response is not allowable, because it contains '../', which can raise the directory traversal vulnerability", n));
}
return n;
}
public static boolean a(int i, FileDownloadModel fileDownloadModel) {
return a(i, fileDownloadModel, (Boolean) null);
}
public static boolean a(int i, FileDownloadModel fileDownloadModel, Boolean bool) {
if (fileDownloadModel == null) {
if (FileDownloadLog.a) {
FileDownloadLog.a(FileDownloadUtils.class, "can't continue %d model == null", Integer.valueOf(i));
}
return false;
}
if (fileDownloadModel.getTempFilePath() == null) {
if (FileDownloadLog.a) {
FileDownloadLog.a(FileDownloadUtils.class, "can't continue %d temp path == null", Integer.valueOf(i));
}
return false;
}
return a(i, fileDownloadModel, fileDownloadModel.getTempFilePath(), bool);
}
public static boolean a(int i, FileDownloadModel fileDownloadModel, String str, Boolean bool) {
if (str == null) {
if (!FileDownloadLog.a) {
return false;
}
FileDownloadLog.a(FileDownloadUtils.class, "can't continue %d path = null", Integer.valueOf(i));
return false;
}
File file = new File(str);
boolean exists = file.exists();
boolean isDirectory = file.isDirectory();
if (exists && !isDirectory) {
long length = file.length();
long soFar = fileDownloadModel.getSoFar();
if (fileDownloadModel.getConnectionCount() <= 1 && soFar == 0) {
if (!FileDownloadLog.a) {
return false;
}
FileDownloadLog.a(FileDownloadUtils.class, "can't continue %d the downloaded-record is zero.", Integer.valueOf(i));
return false;
}
long total = fileDownloadModel.getTotal();
if (length >= soFar && (total == -1 || (length <= total && soFar < total))) {
if (bool == null || bool.booleanValue() || total != length) {
return true;
}
if (!FileDownloadLog.a) {
return false;
}
FileDownloadLog.a(FileDownloadUtils.class, "can't continue %d, because of the output stream doesn't support seek, but the task has already pre-allocated, so we only can download it from the very beginning.", Integer.valueOf(i));
return false;
}
if (!FileDownloadLog.a) {
return false;
}
FileDownloadLog.a(FileDownloadUtils.class, "can't continue %d dirty data fileLength[%d] sofar[%d] total[%d]", Integer.valueOf(i), Long.valueOf(length), Long.valueOf(soFar), Long.valueOf(total));
return false;
}
if (!FileDownloadLog.a) {
return false;
}
FileDownloadLog.a(FileDownloadUtils.class, "can't continue %d file not suit, exists[%B], directory[%B]", Integer.valueOf(i), Boolean.valueOf(exists), Boolean.valueOf(isDirectory));
return false;
}
public static void a(String str, String str2) {
e(str2);
d(str);
}
public static boolean a(long j, long j2) {
return j > ((long) c()) && j2 > d();
}
public static String a() {
return a("FileDownloader/%s", "1.7.5");
}
}