package com.mbridge.msdk.foundation.download.resource; import android.text.TextUtils; import com.mbridge.msdk.foundation.download.core.ExecutorManager; import com.mbridge.msdk.foundation.download.core.GlobalComponent; import com.mbridge.msdk.foundation.download.resource.stream.DownloadFileOutputStream; import com.mbridge.msdk.foundation.download.resource.stream.FileDownloadRandomAccessDownloadFile; import com.mbridge.msdk.foundation.download.utils.ILogger; import com.mbridge.msdk.foundation.download.utils.UnzipUtility; import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.math.BigInteger; import java.net.MalformedURLException; import java.net.URL; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Queue; public class MBResourceManager { private static volatile MBResourceManager MBResourceManager; private MBResourceManager() { } public static MBResourceManager getInstance() { if (MBResourceManager == null) { synchronized (MBResourceManager.class) { if (MBResourceManager == null) { MBResourceManager = new MBResourceManager(); } } } return MBResourceManager; } public void unZip(String str, String str2) throws IOException { if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) { throw new IOException("zipFilePath or destDirectory is null"); } new UnzipUtility().unzip(str, str2); } public void deleteFile(File file) { if (file != null && file.exists()) { if (file.isFile()) { file.delete(); return; } for (File file2 : file.listFiles()) { deleteFile(new File(file2.getAbsolutePath())); } file.delete(); } } /* JADX WARNING: Code restructure failed: missing block: B:8:0x0027, code lost: return ""; */ /* JADX WARNING: Removed duplicated region for block: B:9:? A[ExcHandler: UnsupportedEncodingException | NoSuchAlgorithmException (unused java.lang.Throwable), SYNTHETIC, Splitter:B:5:0x0009] */ public String getDownloadId(String str) { try { new URL(str); } catch (MalformedURLException unused) { str = null; } try { MessageDigest instance = MessageDigest.getInstance("MD5"); instance.update(str.getBytes("UTF-8")); return new BigInteger(1, instance.digest()).toString(16); } catch (UnsupportedEncodingException | NoSuchAlgorithmException unused2) { } } public void deleteFile(String str) { deleteFile(new File(str)); } public long getFileSize(File file) { long j = 0; if (file == null || !file.exists()) { return 0; } if (!file.isDirectory()) { return file.length(); } for (File file2 : file.listFiles()) { j += getFileSize(file2); } return j; } public DownloadFileOutputStream getDownloadFileOutputStream(File file) throws IOException { if (file != null) { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } file.createNewFile(); return new FileDownloadRandomAccessDownloadFile(file); } throw new IOException("file is null"); } /* JADX WARNING: Code restructure failed: missing block: B:5:0x0012, code lost: r0 = r5.getResourceStrategyQueue(); */ public void executeResourceStrategy(final ResourceConfig resourceConfig) { final Queue<ResourceStrategy> resourceStrategyQueue; if (resourceConfig != null && resourceConfig.getResourceStrategyQueue() != null && !resourceConfig.getResourceStrategyQueue().isEmpty() && resourceStrategyQueue != null && !resourceStrategyQueue.isEmpty()) { ILogger logger = GlobalComponent.getInstance().getLogger(); logger.log("ResourceStrategy", "配置的资源管理策略数量: " + resourceStrategyQueue.size()); ExecutorManager.getInstance().getExecutorSupplier().getLruCacheThreadTasks().execute(new Runnable() { /* class com.mbridge.msdk.foundation.download.resource.MBResourceManager.AnonymousClass1 */ public void run() { while (true) { ResourceStrategy resourceStrategy = (ResourceStrategy) resourceStrategyQueue.poll(); if (resourceStrategy != null) { ResourceStrategyExecutor resourceStrategyExecutor = new ResourceStrategyExecutor(resourceStrategy); ILogger logger = GlobalComponent.getInstance().getLogger(); logger.log("ResourceStrategy", "执行策略: " + resourceStrategyExecutor.getResourceStrategyName()); MBResourceManager unused = MBResourceManager.MBResourceManager; resourceStrategyExecutor.processResource(MBResourceManager.getInstance(), GlobalComponent.getInstance().getDatabaseHelper(), resourceConfig); } else { return; } } } }); } } }