米游社.apk(点击下载) / o.java


package gp;

import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import at.c;
import av.k1;
import av.l0;
import av.n0;
import com.google.android.gms.common.internal.ServiceSpecificExtraArgs;
import com.huawei.hms.push.e;
import com.xiaomi.mipush.sdk.Constants;
import du.d0;
import du.f0;
import du.k2;
import f00.t;
import f00.u;
import g00.h;
import io.rong.common.LibStorageUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.util.concurrent.TimeUnit;
import kotlin.Metadata;
import n0.l;
import okhttp3.OkHttpClient;
import uz.d;
import vs.b0;

@Metadata(bv = {}, d1 = {"\u0000`\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\u0003\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0018\u0002\n\u0002\b\t\bÆ\u0002\u0018\u00002\u00020\u0001B\t\b\u0002¢\u0006\u0004\b2\u00103J\u000e\u0010\u0004\u001a\u00020\u00002\u0006\u0010\u0003\u001a\u00020\u0002J,\u0010\r\u001a\u00020\f2\u0006\u0010\u0006\u001a\u00020\u00052\u0006\u0010\u0007\u001a\u00020\u00052\b\b\u0002\u0010\t\u001a\u00020\b2\b\b\u0002\u0010\u000b\u001a\u00020\nH\u0007J\u0006\u0010\u000e\u001a\u00020\fJ1\u0010\u0015\u001a\u00020\f2\u0006\u0010\u000f\u001a\u00020\u00052!\u0010\u0014\u001a\u001d\u0012\u0013\u0012\u00110\n¢\u0006\f\b\u0011\u0012\b\b\u0012\u0012\u0004\b\b(\u0013\u0012\u0004\u0012\u00020\f0\u0010J\u0010\u0010\u0018\u001a\u00020\f2\u0006\u0010\u0017\u001a\u00020\u0016H\u0003J\u0010\u0010\u001a\u001a\u00020\f2\u0006\u0010\u0019\u001a\u00020\u0005H\u0002J\u0012\u0010\u001d\u001a\u00020\b2\b\u0010\u001c\u001a\u0004\u0018\u00010\u001bH\u0002J\u0012\u0010\u001e\u001a\u00020\b2\b\u0010\u001c\u001a\u0004\u0018\u00010\u001bH\u0002J(\u0010!\u001a\u00020\f2\u0006\u0010 \u001a\u00020\u001f2\u0006\u0010\u0019\u001a\u00020\u00052\u0006\u0010\u000b\u001a\u00020\n2\u0006\u0010\u000f\u001a\u00020\u0005H\u0003J\u0018\u0010$\u001a\u00020\f2\u0006\u0010#\u001a\u00020\"2\u0006\u0010\u0007\u001a\u00020\u0005H\u0002R\"\u0010%\u001a\u00020\b8\u0006@\u0006X†\u000e¢\u0006\u0012\n\u0004\b%\u0010&\u001a\u0004\b'\u0010(\"\u0004\b)\u0010*R#\u00101\u001a\n ,*\u0004\u0018\u00010+0+8BX‚„\u0002¢\u0006\f\n\u0004\b-\u0010.\u001a\u0004\b/\u00100¨\u00064"}, d2 = {"Lgp/o;", "", "Lgp/c;", ServiceSpecificExtraArgs.CastExtraArgs.LISTENER, "x", "", "downloadUrl", "filePath", "", "startFromBreakpoint", "", "range", "Ldu/k2;", l.f93210b, "D", "url", "Lkotlin/Function1;", "Ldu/u0;", "name", "length", "onNext", "t", "", e.f31073a, "z", "path", "B", "Ljava/io/File;", LibStorageUtils.FILE, "k", "l", "Lsy/f0;", "responseBody", "F", "Ljava/io/InputStream;", "inputString", w1.a.U4, "isDownloading", "Z", "y", "()Z", "C", "(Z)V", "Landroid/content/SharedPreferences$Editor;", "kotlin.jvm.PlatformType", "mPreferenceEditor$delegate", "Ldu/d0;", "w", "()Landroid/content/SharedPreferences$Editor;", "mPreferenceEditor", "<init>", "()V", "sora_upgrade_release"}, k = 1, mv = {1, 5, 1})
/* compiled from: DownloadUtils.kt */
public final class o {
    @d

    /* renamed from: a  reason: collision with root package name */
    public static final o f66771a = new o();
    @d

    /* renamed from: b  reason: collision with root package name */
    public static final c f66772b;
    @d

    /* renamed from: c  reason: collision with root package name */
    public static final e f66773c;

    /* renamed from: d  reason: collision with root package name */
    public static final long f66774d = 10;
    @d

    /* renamed from: e  reason: collision with root package name */
    public static final String f66775e = "https://api-community.mihoyo.com/";
    @d

    /* renamed from: f  reason: collision with root package name */
    public static final b f66776f;
    @uz.e

    /* renamed from: g  reason: collision with root package name */
    public static c f66777g;

    /* renamed from: h  reason: collision with root package name */
    public static boolean f66778h;
    @uz.e

    /* renamed from: i  reason: collision with root package name */
    public static c f66779i;
    @d

    /* renamed from: j  reason: collision with root package name */
    public static String f66780j = "";
    @d

    /* renamed from: k  reason: collision with root package name */
    public static final d0 f66781k = f0.c(b.f66782a);

    @Metadata(bv = {}, d1 = {"\u0000\u001f\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0002\b\u0006*\u0001\u0000\b\n\u0018\u00002\u00020\u0001J\b\u0010\u0003\u001a\u00020\u0002H\u0016J\u0010\u0010\u0006\u001a\u00020\u00022\u0006\u0010\u0005\u001a\u00020\u0004H\u0016J\u0018\u0010\n\u001a\u00020\u00022\u0006\u0010\b\u001a\u00020\u00072\u0006\u0010\t\u001a\u00020\u0007H\u0016J\u0018\u0010\f\u001a\u00020\u00022\u0006\u0010\b\u001a\u00020\u00072\u0006\u0010\u000b\u001a\u00020\u0007H\u0016¨\u0006\r"}, d2 = {"gp/o$a", "Lgp/c;", "Ldu/k2;", "b", "", "progress", "onProgress", "", "url", "path", "a", "errorInfo", "c", "sora_upgrade_release"}, k = 1, mv = {1, 5, 1})
    /* compiled from: DownloadUtils.kt */
    public static final class a implements c {
        @Override // gp.c
        public void a(@d String str, @d String str2) {
            l0.p(str, "url");
            l0.p(str2, "path");
            c cVar = o.f66779i;
            if (cVar != null) {
                cVar.a(str, str2);
            }
        }

        @Override // gp.c
        public void b() {
            c cVar = o.f66779i;
            if (cVar != null) {
                cVar.b();
            }
        }

        @Override // gp.c
        public void c(@d String str, @d String str2) {
            l0.p(str, "url");
            l0.p(str2, "errorInfo");
            c cVar = o.f66779i;
            if (cVar != null) {
                cVar.c(str, str2);
            }
        }

        @Override // gp.c
        public void onProgress(int i10) {
            c cVar = o.f66779i;
            if (cVar != null) {
                cVar.onProgress(i10);
            }
        }
    }

    @Metadata(bv = {}, d1 = {"\u0000\b\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0002\u001a\n \u0001*\u0004\u0018\u00010\u00000\u0000H\n"}, d2 = {"Landroid/content/SharedPreferences$Editor;", "kotlin.jvm.PlatformType", "<anonymous>"}, k = 3, mv = {1, 5, 1})
    /* compiled from: DownloadUtils.kt */
    public static final class b extends n0 implements zu.a<SharedPreferences.Editor> {

        /* renamed from: a  reason: collision with root package name */
        public static final b f66782a = new b();

        public b() {
            super(0);
        }

        /* renamed from: a */
        public final SharedPreferences.Editor invoke() {
            return hp.d.f70359a.h().edit();
        }
    }

    static {
        a aVar = new a();
        f66772b = aVar;
        b bVar = new b(aVar);
        f66776f = bVar;
        OkHttpClient.a l02 = new OkHttpClient.a().c(bVar).l0(true);
        TimeUnit timeUnit = TimeUnit.SECONDS;
        Object g10 = new u.b().c("https://api-community.mihoyo.com/").j(l02.k(10, timeUnit).j0(10, timeUnit).R0(10, timeUnit).f()).a(h.d()).f().g(e.class);
        l0.o(g10, "Builder()\n            .baseUrl(url)\n            .client(httpClient)\n            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())\n            .build().create(DownloadService::class.java)");
        f66773c = (e) g10;
    }

    public static final void A(Throwable th2) {
        c cVar = f66772b;
        String str = f66780j;
        String message = th2.getMessage();
        if (message == null) {
            message = "download error";
        }
        cVar.c(str, message);
    }

    public static final void G(k1.f fVar, Integer num) {
        l0.p(fVar, "$progress");
        f66772b.onProgress(fVar.f8374a);
    }

    public static /* synthetic */ void n(o oVar, String str, String str2, boolean z10, long j10, int i10, Object obj) {
        if ((i10 & 4) != 0) {
            z10 = false;
        }
        if ((i10 & 8) != 0) {
            j10 = 0;
        }
        oVar.m(str, str2, z10, j10);
    }

    public static final void o(String str, long j10, String str2, sy.f0 f0Var) {
        l0.p(str, "$filePath");
        l0.p(str2, "$downloadUrl");
        o oVar = f66771a;
        l0.o(f0Var, "it");
        oVar.F(f0Var, str, j10, str2);
    }

    public static final void p(Throwable th2) {
        o oVar = f66771a;
        l0.o(th2, "it");
        oVar.z(th2);
    }

    public static final InputStream q(sy.f0 f0Var) {
        l0.p(f0Var, "t");
        return f0Var.byteStream();
    }

    public static final void r(String str, InputStream inputStream) {
        l0.p(str, "$filePath");
        o oVar = f66771a;
        l0.o(inputStream, "it");
        oVar.E(inputStream, str);
    }

    public static final void s(Throwable th2) {
        o oVar = f66771a;
        l0.o(th2, "it");
        oVar.z(th2);
    }

    public static final void u(zu.l lVar, t tVar) {
        l0.p(lVar, "$onNext");
        String e10 = tVar.f().e("Content-Length");
        lVar.invoke(Long.valueOf(e10 == null ? 0 : Long.parseLong(e10)));
    }

    public static final void v(Throwable th2) {
        ro.c.f114210d.d(l0.C("mihoyoTinker download err : ", th2.getMessage()));
    }

    public final void B(String str) {
        w().apply();
        f66780j = "";
        f66778h = false;
        f66772b.a(f66775e, str);
        ro.c.f114210d.d("mihoyo download finish");
        a.f66744a.a();
    }

    public final void C(boolean z10) {
        f66778h = z10;
    }

    public final void D() {
        c cVar = f66777g;
        if (cVar != null) {
            cVar.dispose();
        }
        f66777g = null;
        f66778h = false;
        f66780j = "";
    }

    public final void E(InputStream inputStream, String str) {
        File file = new File(str);
        if (file.exists()) {
            file.delete();
        }
        k(file);
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            byte[] bArr = new byte[1024];
            int read = inputStream.read(bArr);
            while (read != -1) {
                fileOutputStream.write(bArr, 0, read);
                read = inputStream.read(bArr);
            }
            inputStream.close();
            fileOutputStream.close();
            B(str);
        } catch (FileNotFoundException e10) {
            z(e10);
        } catch (IOException e11) {
            z(e11);
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:37:0x00a8  */
    /* JADX WARNING: Removed duplicated region for block: B:39:0x00ae  */
    /* JADX WARNING: Removed duplicated region for block: B:42:0x00b6 A[SYNTHETIC, Splitter:B:42:0x00b6] */
    /* JADX WARNING: Removed duplicated region for block: B:45:0x00bb A[Catch:{ Exception -> 0x00c0 }] */
    /* JADX WARNING: Removed duplicated region for block: B:46:0x00bc A[Catch:{ Exception -> 0x00c0 }] */
    /* JADX WARNING: Removed duplicated region for block: B:57:? A[RETURN, SYNTHETIC] */
    @SuppressLint({"CheckResult"})
    public final void F(sy.f0 f0Var, String str, long j10, String str2) {
        Throwable th2;
        InputStream inputStream;
        Exception e10;
        RandomAccessFile randomAccessFile = null;
        try {
            byte[] bArr = new byte[10240];
            long contentLength = f0Var.contentLength();
            inputStream = f0Var.byteStream();
            try {
                File file = new File(str);
                if (!file.exists()) {
                    file.getParentFile().mkdirs();
                    file.createNewFile();
                }
                RandomAccessFile randomAccessFile2 = new RandomAccessFile(file, "rwd");
                if (j10 == 0) {
                    try {
                        randomAccessFile2.setLength(contentLength);
                    } catch (Exception e11) {
                        e10 = e11;
                        randomAccessFile = randomAccessFile2;
                        try {
                            z(e10);
                            if (randomAccessFile != null) {
                            }
                            if (inputStream != null) {
                            }
                        } catch (Throwable th3) {
                            th2 = th3;
                            if (randomAccessFile != null) {
                                try {
                                    randomAccessFile.close();
                                } catch (Exception e12) {
                                    e12.printStackTrace();
                                    throw th2;
                                }
                            }
                            if (inputStream != null) {
                                inputStream.close();
                            }
                            throw th2;
                        }
                    } catch (Throwable th4) {
                        th2 = th4;
                        randomAccessFile = randomAccessFile2;
                        if (randomAccessFile != null) {
                        }
                        if (inputStream != null) {
                        }
                        throw th2;
                    }
                }
                randomAccessFile2.seek(j10);
                k1.f fVar = new k1.f();
                for (int read = inputStream.read(bArr); read != -1; read = inputStream.read(bArr)) {
                    randomAccessFile2.write(bArr, 0, read);
                    j10 += (long) read;
                    w().putLong(str2, j10);
                    int i10 = fVar.f8374a;
                    int length = (int) ((((long) 100) * j10) / randomAccessFile2.length());
                    fVar.f8374a = length;
                    if (length > 0 && length != i10) {
                        w().apply();
                        b0.l3(Integer.valueOf(fVar.f8374a)).I5(ys.a.c()).D5(new f(fVar));
                    }
                }
                B(str);
                try {
                    randomAccessFile2.close();
                    inputStream.close();
                } catch (Exception e13) {
                    e13.printStackTrace();
                }
            } catch (Exception e14) {
                e10 = e14;
                z(e10);
                if (randomAccessFile != null) {
                    randomAccessFile.close();
                }
                if (inputStream != null) {
                    inputStream.close();
                }
            }
        } catch (Exception e15) {
            e10 = e15;
            inputStream = null;
            z(e10);
            if (randomAccessFile != null) {
            }
            if (inputStream != null) {
            }
        } catch (Throwable th5) {
            th2 = th5;
            inputStream = null;
            if (randomAccessFile != null) {
            }
            if (inputStream != null) {
            }
            throw th2;
        }
    }

    public final boolean k(File file) {
        if (file == null) {
            return false;
        }
        if ((file.exists() && !file.delete()) || !l(file.getParentFile())) {
            return false;
        }
        try {
            return file.createNewFile();
        } catch (IOException e10) {
            e10.printStackTrace();
            return false;
        }
    }

    public final boolean l(File file) {
        if (file != null) {
            if (file.exists() ? file.isDirectory() : file.mkdirs()) {
                return true;
            }
        }
        return false;
    }

    @SuppressLint({"CheckResult"})
    public final void m(@d String str, @d String str2, boolean z10, long j10) {
        l0.p(str, "downloadUrl");
        l0.p(str2, "filePath");
        f66780j = str;
        ro.c cVar = ro.c.f114210d;
        cVar.d("mihoyoTinker download ");
        f66776f.b(z10);
        f66772b.b();
        f66778h = true;
        if (z10) {
            File file = new File(str2);
            String str3 = Constants.ACCEPT_TIME_SEPARATOR_SERVER;
            if (file.exists()) {
                str3 = l0.C(str3, Long.valueOf(file.length()));
            }
            cVar.a("download bytes=" + j10 + str3);
            c cVar2 = f66777g;
            if (cVar2 != null) {
                cVar2.dispose();
            }
            e eVar = f66773c;
            f66777g = eVar.c("bytes=" + j10 + '-', str).I5(yt.b.d()).a4(yt.b.d()).E5(new h(str2, j10, str), k.f66767a);
            return;
        }
        c cVar3 = f66777g;
        if (cVar3 != null) {
            cVar3.dispose();
        }
        f66777g = f66773c.a(str).z3(n.f66770a).I5(yt.b.d()).m7(yt.b.d()).a4(yt.b.d()).E5(new g(str2), m.f66769a);
    }

    public final void t(@d String str, @d zu.l<? super Long, k2> lVar) {
        l0.p(str, "url");
        l0.p(lVar, "onNext");
        c cVar = f66777g;
        if (cVar != null) {
            cVar.dispose();
        }
        f66777g = f66773c.b(str).I5(yt.b.d()).m7(yt.b.d()).a4(ys.a.c()).E5(new i(lVar), l.f66768a);
    }

    public final SharedPreferences.Editor w() {
        return (SharedPreferences.Editor) f66781k.getValue();
    }

    @d
    public final o x(@d c cVar) {
        l0.p(cVar, ServiceSpecificExtraArgs.CastExtraArgs.LISTENER);
        f66779i = cVar;
        return this;
    }

    public final boolean y() {
        return f66778h;
    }

    @SuppressLint({"CheckResult"})
    public final void z(Throwable th2) {
        th2.printStackTrace();
        w().apply();
        f66778h = false;
        f66780j = "";
        ro.c.f114210d.d(l0.C("mihoyo download err : ", th2.getMessage()));
        b0.l3(th2).I5(ys.a.c()).D5(j.f66766a);
    }
}