i.java 源代码


package com.ss.android.downloadlib.addownload.i;

import android.content.Context;
import com.baidu.mobads.sdk.internal.bj;
import com.ss.android.downloadlib.addownload.il;
import com.ss.android.downloadlib.e.nr;
import com.ss.android.socialbase.downloader.downloader.Downloader;
import com.ss.android.socialbase.downloader.model.DownloadInfo;
import com.ss.android.socialbase.downloader.setting.DownloadSetting;
import java.io.File;
import java.io.FileOutputStream;
import java.util.List;

public class i {
    public static void g() {
        List<DownloadInfo> g = com.ss.android.socialbase.appdownloader.ql.zy().g(il.getContext());
        if (g == null || g.size() <= 0) {
            return;
        }
        for (int i = 0; i < g.size(); i++) {
            DownloadInfo downloadInfo = g.get(i);
            File file = new File(downloadInfo.getTempPath(), downloadInfo.getTempName());
            long lastModified = file.lastModified();
            long optInt = DownloadSetting.obtain(downloadInfo.getId()).optInt("download_file_expire_hours", 0) * 3600000;
            if (optInt <= 0) {
                optInt = bj.d;
            }
            if (file.isFile() && file.exists() && System.currentTimeMillis() - lastModified >= optInt) {
                g(file);
                Downloader.getInstance(il.getContext()).clearDownloadData(downloadInfo.getId());
            }
        }
    }

    public static void zc() {
        List successedDownloadInfosWithMimeType = Downloader.getInstance(il.getContext()).getSuccessedDownloadInfosWithMimeType("application/vnd.android.package-archive");
        if (successedDownloadInfosWithMimeType == null || successedDownloadInfosWithMimeType.isEmpty()) {
            return;
        }
        for (int i = 0; i < successedDownloadInfosWithMimeType.size(); i++) {
            DownloadInfo downloadInfo = (DownloadInfo) successedDownloadInfosWithMimeType.get(i);
            if (downloadInfo != null) {
                String str = downloadInfo.getSavePath() + File.separator + downloadInfo.getName();
                File file = new File(str);
                if (file.exists()) {
                    long currentTimeMillis = System.currentTimeMillis() - file.lastModified();
                    long optInt = DownloadSetting.obtain(downloadInfo.getId()).optInt("download_complete_file_expire_hours", 0) * 3600000;
                    if (optInt <= 0) {
                        optInt = bj.d;
                    }
                    boolean z = true;
                    if (currentTimeMillis < optInt && !nr.fy(il.getContext(), str)) {
                        z = false;
                    }
                    if (z) {
                        g(file);
                    }
                }
            }
        }
    }

    public static void g(Context context) {
        File externalCacheDir;
        if (context == null || (externalCacheDir = context.getExternalCacheDir()) == null) {
            return;
        }
        try {
            g(externalCacheDir.getPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void g(File file) {
        FileOutputStream fileOutputStream;
        Exception e;
        FileOutputStream fileOutputStream2 = null;
        try {
            try {
                fileOutputStream = new FileOutputStream(file);
                try {
                    fileOutputStream.write("1".getBytes());
                    fileOutputStream.close();
                } catch (Exception e2) {
                    e = e2;
                    e.printStackTrace();
                    if (fileOutputStream != null) {
                        try {
                            fileOutputStream.close();
                        } catch (Exception e3) {
                            e3.printStackTrace();
                        }
                    }
                    file.delete();
                }
            } catch (Throwable th) {
                th = th;
                fileOutputStream2 = fileOutputStream;
                if (fileOutputStream2 != null) {
                    try {
                        fileOutputStream2.close();
                    } catch (Exception e4) {
                        e4.printStackTrace();
                    }
                }
                throw th;
            }
        } catch (Exception e5) {
            fileOutputStream = null;
            e = e5;
        } catch (Throwable th2) {
            th = th2;
            if (fileOutputStream2 != null) {
            }
            throw th;
        }
        file.delete();
    }

    private static void g(String str) {
        File file = new File(str);
        if (file.exists()) {
            if (file.isFile()) {
                file.delete();
                return;
            }
            String[] list = file.list();
            if (list == null) {
                return;
            }
            for (String str2 : list) {
                if (str2 != null) {
                    String str3 = str.endsWith(File.separator) ? str + str2 : str + File.separator + str2;
                    File file2 = new File(str3);
                    if (file2.isFile()) {
                        file2.delete();
                    }
                    if (file2.isDirectory()) {
                        g(str3);
                    }
                }
            }
            file.delete();
        }
    }
}