package j3;

import V4.C;
import V4.E;
import V4.N;
import Y4.H;
import Y4.c0;
import com.debridstream.tv.updater.UpdateViewModel;
import java.io.File;
import java.util.regex.Pattern;
import k3.C2381a;
import m3.AbstractC2467b;
import w4.C3137A;

/* JADX INFO: renamed from: j3.o, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C2363o extends C4.j implements J4.e {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public int f19597a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final /* synthetic */ UpdateViewModel f19598b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ C2381a f19599c;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C2363o(UpdateViewModel updateViewModel, C2381a c2381a, A4.d dVar) {
        super(2, dVar);
        this.f19598b = updateViewModel;
        this.f19599c = c2381a;
    }

    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        return new C2363o(this.f19598b, this.f19599c, dVar);
    }

    @Override // J4.e
    public final Object invoke(Object obj, Object obj2) {
        return ((C2363o) create((C) obj, (A4.d) obj2)).invokeSuspend(C3137A.f25453a);
    }

    @Override // C4.a
    public final Object invokeSuspend(Object obj) {
        c0 c0Var;
        Object value;
        Object objH;
        c0 c0Var2;
        Object value2;
        C2359k c2359k;
        String message;
        c0 c0Var3;
        Object value3;
        B4.a aVar = B4.a.f492a;
        int i6 = this.f19597a;
        UpdateViewModel updateViewModel = this.f19598b;
        if (i6 == 0) {
            AbstractC2467b.l(obj);
            H h5 = updateViewModel._uiState;
            do {
                c0Var = (c0) h5;
                value = c0Var.getValue();
            } while (!c0Var.i(value, C2359k.a((C2359k) value, false, null, false, true, new Float(0.0f), null, false, false, false, null, 487)));
            C2381a c2381a = this.f19599c;
            String str = c2381a.f19784e;
            Pattern patternCompile = Pattern.compile("[^a-zA-Z0-9._-]");
            kotlin.jvm.internal.o.g(patternCompile, "compile(...)");
            String strReplaceAll = patternCompile.matcher(str).replaceAll("_");
            kotlin.jvm.internal.o.g(strReplaceAll, "replaceAll(...)");
            File file = new File(new File(updateViewModel.getApplication().getCacheDir(), "updates"), strReplaceAll);
            c5.e eVar = N.f8259a;
            c5.d dVar = c5.d.f13466b;
            C2362n c2362n = new C2362n(updateViewModel, c2381a, file, null);
            this.f19597a = 1;
            objH = E.H(dVar, c2362n, this);
            if (objH == aVar) {
                return aVar;
            }
        } else {
            if (i6 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            AbstractC2467b.l(obj);
            objH = obj;
        }
        Object obj2 = ((w4.n) objH).f25472a;
        if (!(obj2 instanceof w4.m)) {
            File file2 = (File) obj2;
            H h6 = updateViewModel._uiState;
            do {
                c0Var3 = (c0) h6;
                value3 = c0Var3.getValue();
            } while (!c0Var3.i(value3, C2359k.a((C2359k) value3, false, null, false, false, new Float(1.0f), file2.getAbsolutePath(), false, false, false, null, 455)));
            updateViewModel.installUpdateOrRequestPermission();
        }
        Throwable thA = w4.n.a(obj2);
        if (thA != null) {
            H h7 = updateViewModel._uiState;
            do {
                c0Var2 = (c0) h7;
                value2 = c0Var2.getValue();
                c2359k = (C2359k) value2;
                message = thA.getMessage();
                if (message == null) {
                    message = "Download failed";
                }
            } while (!c0Var2.i(value2, C2359k.a(c2359k, false, null, false, false, null, null, false, false, false, message, 455)));
        }
        return C3137A.f25453a;
    }
}
