package defpackage;

import android.os.Build;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;

/* JADX INFO: renamed from: ːʾˎʿ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C1949 implements InterfaceC1093 {

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final InterfaceC5435 f7747;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final InterfaceC0636 f7748;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final File f7750;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final C4603 f7751;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final AtomicBoolean f7749 = new AtomicBoolean(false);

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final C2415 f7752 = new C2415();

    public C1949(File file, InterfaceC5435 interfaceC5435, InterfaceC0636 interfaceC0636, C4603 c4603) {
        this.f7750 = file;
        this.f7747 = interfaceC5435;
        this.f7748 = interfaceC0636;
        this.f7751 = c4603;
    }

    @Override // defpackage.InterfaceC1093
    public final void close() {
        this.f7749.set(true);
        this.f7751.mo1021();
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00cc A[Catch: all -> 0x0107, IOException -> 0x0109, TRY_ENTER, TryCatch #0 {IOException -> 0x0109, blocks: (B:43:0x00cc, B:45:0x00d2, B:47:0x00da, B:51:0x00e6, B:52:0x0106, B:48:0x00df, B:59:0x0112, B:66:0x011f, B:65:0x011c), top: B:76:0x0023 }] */
    /* JADX WARN: Removed duplicated region for block: B:59:0x0112 A[Catch: all -> 0x0107, IOException -> 0x0109, TRY_ENTER, TRY_LEAVE, TryCatch #0 {IOException -> 0x0109, blocks: (B:43:0x00cc, B:45:0x00d2, B:47:0x00da, B:51:0x00e6, B:52:0x0106, B:48:0x00df, B:59:0x0112, B:66:0x011f, B:65:0x011c), top: B:76:0x0023 }] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0015  */
    /* JADX WARN: Type inference failed for: r10v12 */
    /* JADX WARN: Type inference failed for: r10v13 */
    /* JADX WARN: Type inference failed for: r10v2, types: [ʾᵰ] */
    /* JADX WARN: Type inference failed for: r2v0, types: [int, ʾˏᵽ] */
    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m5210(ᵼˎᵜ r10, AbstractC3500 abstractC3500) throws IOException {
        C2032 c2032;
        ᵼˎᵜ file;
        InterfaceC0260 interfaceC0260;
        ?? r102;
        C4317 c4317;
        Throwable th;
        C4317 c43172;
        C1949 c1949;
        ᵼˎᵜ r103;
        if (abstractC3500 instanceof C2032) {
            c2032 = (C2032) abstractC3500;
            int i = c2032.f8077;
            if ((i & Integer.MIN_VALUE) != 0) {
                c2032.f8077 = i - Integer.MIN_VALUE;
            } else {
                c2032 = new C2032(this, abstractC3500);
            }
        }
        Object obj = c2032.f8076;
        ?? r2 = c2032.f8077;
        EnumC0111 enumC0111 = EnumC0111.f1384;
        try {
            try {
            } catch (IOException e) {
                e = e;
                file = r10;
            }
            try {
                try {
                    if (r2 == 0) {
                        ᵟˌᵫ.ˊˌˊ(obj);
                        if (this.f7749.get()) {
                            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("StorageConnection has already been disposed.");
                            return null;
                        }
                        File file2 = this.f7750;
                        File parentFile = file2.getCanonicalFile().getParentFile();
                        if (parentFile != null) {
                            parentFile.mkdirs();
                            if (!parentFile.isDirectory()) {
                                C4935.m10236(file2, "Unable to create parent directories of ");
                                return null;
                            }
                        }
                        c2032.f8078 = this;
                        c2032.f8079 = r10;
                        C2415 c2415 = this.f7752;
                        c2032.f8080 = c2415;
                        c2032.f8077 = 1;
                        if (c2415.mo1478(c2032) != enumC0111) {
                            interfaceC0260 = c2415;
                            r102 = r10;
                        }
                        return enumC0111;
                    }
                    if (r2 != 1) {
                        if (r2 != 2) {
                            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("call to 'resume' before 'invoke' with coroutine");
                            return null;
                        }
                        c43172 = c2032.f8075;
                        ᵼˎᵜ r104 = (File) c2032.f8080;
                        interfaceC0260 = (InterfaceC0260) c2032.f8079;
                        c1949 = c2032.f8078;
                        try {
                            ᵟˌᵫ.ˊˌˊ(obj);
                            r103 = r104;
                            try {
                                c43172.close();
                                th = null;
                            } catch (Throwable th2) {
                                th = th2;
                            }
                            if (th == null) {
                                throw th;
                            }
                            if (r103.exists()) {
                                File file3 = c1949.f7750;
                                if (!(Build.VERSION.SDK_INT >= 26 ? ˁᵨᵦ.ᵱʡˏ(r103, file3) : r103.renameTo(file3))) {
                                    throw new IOException("Unable to rename " + r103 + " to " + c1949.f7750 + ". This likely means that there are multiple instances of DataStore for this file. Ensure that you are only creating a single instance of datastore for this file.");
                                }
                            }
                            interfaceC0260.mo1477(null);
                            return C5063.f19112;
                        } catch (Throwable th3) {
                            th = th3;
                            try {
                                c43172.close();
                            } catch (Throwable th4) {
                                ᵷˆᵣ.ʽˈˋ(th, th4);
                            }
                            throw th;
                        }
                    }
                    InterfaceC0260 interfaceC02602 = (InterfaceC0260) c2032.f8080;
                    InterfaceC0321 interfaceC0321 = (InterfaceC0321) c2032.f8079;
                    C1949 c19492 = c2032.f8078;
                    ᵟˌᵫ.ˊˌˊ(obj);
                    interfaceC0260 = interfaceC02602;
                    this = c19492;
                    r102 = interfaceC0321;
                    c2032.f8078 = this;
                    c2032.f8079 = interfaceC0260;
                    c2032.f8080 = file;
                    c2032.f8075 = c4317;
                    c2032.f8077 = 2;
                    if (r102.mo1564(c4317, c2032) != enumC0111) {
                        c1949 = this;
                        r103 = file;
                        c43172 = c4317;
                        c43172.close();
                        th = null;
                        if (th == null) {
                        }
                    }
                    return enumC0111;
                } catch (Throwable th5) {
                    th = th5;
                    c43172 = c4317;
                    c43172.close();
                    throw th;
                }
                c4317 = new C4317(file, this.f7747);
            } catch (IOException e2) {
                e = e2;
                if (file.exists()) {
                    file.delete();
                }
                throw e;
            }
            file = new File(this.f7750.getAbsolutePath() + ".tmp");
        } catch (Throwable th6) {
            r2.mo1477(null);
            throw th6;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:31:0x0073  */
    /* JADX WARN: Removed duplicated region for block: B:58:0x007b A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m5211(C0931 c0931, AbstractC3500 abstractC3500) throws Throwable {
        C0827 c0827;
        boolean zM6132;
        Throwable th;
        C1268 c1268;
        C1949 c1949;
        boolean z;
        if (abstractC3500 instanceof C0827) {
            c0827 = (C0827) abstractC3500;
            int i = c0827.f3707;
            if ((i & Integer.MIN_VALUE) != 0) {
                c0827.f3707 = i - Integer.MIN_VALUE;
            } else {
                c0827 = new C0827(this, abstractC3500);
            }
        }
        Object obj = c0827.f3702;
        int i2 = c0827.f3707;
        if (i2 == 0) {
            ᵟˌᵫ.ˊˌˊ(obj);
            if (this.f7749.get()) {
                ᵕᵩʽᵲ.ᵪᵹᵥᵻ("StorageConnection has already been disposed.");
                return null;
            }
            zM6132 = this.f7752.m6132();
            try {
                C1268 c12682 = new C1268(this.f7750, this.f7747);
                try {
                    Object objValueOf = Boolean.valueOf(zM6132);
                    c0827.f3704 = this;
                    c0827.f3705 = c12682;
                    c0827.f3706 = zM6132;
                    c0827.f3707 = 1;
                    Object objMo1175 = c0931.mo1175(c12682, objValueOf, c0827);
                    Object obj2 = EnumC0111.f1384;
                    if (objMo1175 == obj2) {
                        return obj2;
                    }
                    c1949 = this;
                    z = zM6132;
                    obj = objMo1175;
                    c1268 = c12682;
                    c1268.close();
                    th = null;
                    if (th != null) {
                    }
                } catch (Throwable th2) {
                    th = th2;
                    c1268 = c12682;
                    c1268.close();
                    throw th;
                }
            } catch (Throwable th3) {
                th = th3;
            }
        } else {
            if (i2 != 1) {
                ᵕᵩʽᵲ.ᵪᵹᵥᵻ("call to 'resume' before 'invoke' with coroutine");
                return null;
            }
            z = c0827.f3706;
            c1268 = c0827.f3705;
            c1949 = c0827.f3704;
            try {
                ᵟˌᵫ.ˊˌˊ(obj);
                try {
                    c1268.close();
                    th = null;
                } catch (Throwable th4) {
                    th = th4;
                }
                if (th != null) {
                    if (z) {
                        c1949.f7752.mo1477(null);
                    }
                    return obj;
                }
                try {
                    throw th;
                } catch (Throwable th5) {
                    th = th5;
                    zM6132 = z;
                    this = c1949;
                }
            } catch (Throwable th6) {
                zM6132 = z;
                this = c1949;
                th = th6;
                try {
                    c1268.close();
                    throw th;
                } catch (Throwable th7) {
                    ᵷˆᵣ.ʽˈˋ(th, th7);
                    throw th;
                }
            }
        }
        if (zM6132) {
            this.f7752.mo1477(null);
        }
        throw th;
    }
}
