package e.r;

import com.cvte.vman.instance.InvokeCmd;
import com.seewo.vcommons.constants.SeewoIntent;
import e.r.e;
import e.r.e.b;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.RandomAccess;

/* JADX INFO: loaded from: classes.dex */
public class g {
    /* JADX WARN: Removed duplicated region for block: B:35:0x00b3  */
    /* JADX WARN: Removed duplicated region for block: B:56:0x00b4 A[SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static boolean a(java.io.File r18, java.io.File r19, boolean r20, e.s.b.p r21, int r22) throws java.io.IOException {
        /*
            Method dump skipped, instruction units count: 250
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: e.r.g.a(java.io.File, java.io.File, boolean, e.s.b.p, int):boolean");
    }

    public static File b(File file, File file2, boolean z, int i2, int i3) {
        if ((i3 & 2) != 0) {
            z = false;
        }
        if ((i3 & 4) != 0) {
            i2 = InvokeCmd.CMD_TOUCH_CTRL_START;
        }
        e.s.c.k.e(file, "$this$copyTo");
        e.s.c.k.e(file2, SeewoIntent.KEY_TARGET_TO_3288);
        if (!file.exists()) {
            throw new j(file, null, "The source file doesn't exist.", 2);
        }
        if (file2.exists()) {
            if (!z) {
                throw new b(file, file2, "The destination file already exists.");
            }
            if (!file2.delete()) {
                throw new b(file, file2, "Tried to overwrite the destination, but failed to delete it.");
            }
        }
        if (!file.isDirectory()) {
            File parentFile = file2.getParentFile();
            if (parentFile != null) {
                parentFile.mkdirs();
            }
            FileInputStream fileInputStream = new FileInputStream(file);
            try {
                FileOutputStream fileOutputStream = new FileOutputStream(file2);
                try {
                    e.s.c.k.e(fileInputStream, "$this$copyTo");
                    e.s.c.k.e(fileOutputStream, "out");
                    byte[] bArr = new byte[i2];
                    while (true) {
                        int i4 = fileInputStream.read(bArr);
                        if (i4 < 0) {
                            break;
                        }
                        fileOutputStream.write(bArr, 0, i4);
                    }
                    d.a.u.a.g(fileOutputStream, null);
                    d.a.u.a.g(fileInputStream, null);
                } finally {
                }
            } finally {
            }
        } else if (!file2.mkdirs()) {
            throw new d(file, file2, "Failed to create target directory.");
        }
        return file2;
    }

    public static final boolean c(File file) {
        e.s.c.k.e(file, "$this$deleteRecursively");
        e.s.c.k.e(file, "$this$walkBottomUp");
        f fVar = f.BOTTOM_UP;
        e.s.c.k.e(file, "$this$walk");
        e.s.c.k.e(fVar, "direction");
        e.b bVar = new e(file, fVar).new b();
        while (true) {
            boolean z = true;
            while (bVar.hasNext()) {
                File next = bVar.next();
                if (!next.delete() && next.exists()) {
                    z = false;
                } else {
                    if (z) {
                        break;
                    }
                    z = false;
                }
            }
            return z;
        }
    }

    public static final c d(c cVar) {
        File file = cVar.f5982a;
        List<File> list = cVar.f5983b;
        ArrayList arrayList = new ArrayList(list.size());
        for (File file2 : list) {
            String name = file2.getName();
            if (name != null) {
                int iHashCode = name.hashCode();
                if (iHashCode != 46) {
                    if (iHashCode == 1472 && name.equals("..") && !arrayList.isEmpty() && (!e.s.c.k.a(((File) e.o.c.c(arrayList)).getName(), ".."))) {
                        arrayList.remove(arrayList.size() - 1);
                    }
                } else if (name.equals(".")) {
                }
            }
            arrayList.add(file2);
        }
        return new c(file, arrayList);
    }

    public static final String e(File file, File file2) throws IOException {
        String string;
        Iterable iterable;
        Iterable iterableT;
        e.s.c.k.e(file, "$this$toRelativeString");
        e.s.c.k.e(file2, "base");
        c cVarD = d(d.a.u.a.B(file));
        c cVarD2 = d(d.a.u.a.B(file2));
        if (!e.s.c.k.a(cVarD.f5982a, cVarD2.f5982a)) {
            string = null;
        } else {
            int size = cVarD2.f5983b.size();
            int size2 = cVarD.f5983b.size();
            int iMin = Math.min(size2, size);
            int i2 = 0;
            while (i2 < iMin && e.s.c.k.a(cVarD.f5983b.get(i2), cVarD2.f5983b.get(i2))) {
                i2++;
            }
            StringBuilder sb = new StringBuilder();
            int i3 = size - 1;
            if (i3 >= i2) {
                while (!e.s.c.k.a(cVarD2.f5983b.get(i3).getName(), "..")) {
                    sb.append("..");
                    if (i3 != i2) {
                        sb.append(File.separatorChar);
                    }
                    if (i3 != i2) {
                        i3--;
                    }
                }
                string = null;
            }
            if (i2 < size2) {
                if (i2 < size) {
                    sb.append(File.separatorChar);
                }
                List<File> list = cVarD.f5983b;
                e.s.c.k.e(list, "$this$drop");
                if (!(i2 >= 0)) {
                    throw new IllegalArgumentException(("Requested element count " + i2 + " is less than zero.").toString());
                }
                if (i2 == 0) {
                    iterableT = e.o.c.j(list);
                } else {
                    int size3 = list.size() - i2;
                    if (size3 <= 0) {
                        iterableT = e.o.f.f5965b;
                    } else if (size3 == 1) {
                        e.s.c.k.e(list, "$this$last");
                        iterableT = d.a.u.a.t(e.o.c.c(list));
                    } else {
                        ArrayList arrayList = new ArrayList(size3);
                        if (list instanceof RandomAccess) {
                            int size4 = list.size();
                            while (i2 < size4) {
                                arrayList.add(list.get(i2));
                                i2++;
                            }
                        } else {
                            ListIterator<File> listIterator = list.listIterator(i2);
                            while (listIterator.hasNext()) {
                                arrayList.add(listIterator.next());
                            }
                        }
                        iterable = arrayList;
                        String str = File.separator;
                        e.s.c.k.d(str, "File.separator");
                        e.o.c.a(iterable, sb, str, "", "", -1, "...", null);
                    }
                }
                iterable = iterableT;
                String str2 = File.separator;
                e.s.c.k.d(str2, "File.separator");
                e.o.c.a(iterable, sb, str2, "", "", -1, "...", null);
            }
            string = sb.toString();
        }
        if (string != null) {
            return string;
        }
        throw new IllegalArgumentException("this and base files have different roots: " + file + " and " + file2 + '.');
    }
}
