package epson.maintain;


import android.support.annotation.VisibleForTesting;
import java.util.HashMap;

public class FirmInfFile {
    private static final String INF_KEY_URL_ROM_EFU = "URLROMEFU";
    private int mInfFileVersion = 0;
    int mRomNum;
    final HashMap<String, String> mUpdateInf = new HashMap<>();

    public synchronized String getRomUrl(int i) {
        String str;
        if (i <= mRomNum) {
            str = mUpdateInf.get(String.format("URLROM%d", new Object[]{Integer.valueOf(i)}));
        } else {
            str = null;
        }
        return str;
    }

    public synchronized String getMainVersion() {
        return mUpdateInf.get("VERMAIN");
    }

    public synchronized String getNetVersion() {
        return mUpdateInf.get("VERNET");
    }

    public synchronized int getRomNum() {
        return mRomNum;
    }

    @Nullable
    public synchronized String getfuUrl() {
        return mUpdateInf.get(INF_KEY_URL_ROM_EFU);
    }

    public synchronized int getInfFileVersion() {
        return mInfFileVersion;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:27:0x0042, code lost:
        return false;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public synchronized boolean checkInfFileVersion(byte[] r4) {
        /*
            r3 = this;
            monitor-enter(r3)
            r0 = 0
            r3.mInfFileVersion = r0     // Catch:{ all -> 0x0043 }
            boolean r4 = r3.parseInfFile(r4)     // Catch:{ all -> 0x0043 }
            if (r4 != 0) goto L_0x000c
            monitor-exit(r3)
            return r0
        L_0x000c:
            java.util.HashMap<java.lang.String, java.lang.String> r4 = r3.mUpdateInf     // Catch:{ all -> 0x0043 }
            java.lang.String r1 = "VERMAIN"
            boolean r4 = r4.containsKey(r1)     // Catch:{ all -> 0x0043 }
            if (r4 == 0) goto L_0x0041
            java.util.HashMap<java.lang.String, java.lang.String> r4 = r3.mUpdateInf     // Catch:{ all -> 0x0043 }
            java.lang.String r1 = "VERNET"
            boolean r4 = r4.containsKey(r1)     // Catch:{ all -> 0x0043 }
            if (r4 != 0) goto L_0x0021
            goto L_0x0041
        L_0x0021:
            java.util.HashMap<java.lang.String, java.lang.String> r4 = r3.mUpdateInf     // Catch:{ all -> 0x0043 }
            java.lang.String r1 = "URLROM1"
            boolean r4 = r4.containsKey(r1)     // Catch:{ all -> 0x0043 }
            r1 = 1
            if (r4 == 0) goto L_0x0030
            r3.mInfFileVersion = r1     // Catch:{ all -> 0x0043 }
            monitor-exit(r3)
            return r1
        L_0x0030:
            java.util.HashMap<java.lang.String, java.lang.String> r4 = r3.mUpdateInf     // Catch:{ all -> 0x0043 }
            java.lang.String r2 = "URLROMEFU"
            boolean r4 = r4.containsKey(r2)     // Catch:{ all -> 0x0043 }
            if (r4 == 0) goto L_0x003f
            r4 = 2
            r3.mInfFileVersion = r4     // Catch:{ all -> 0x0043 }
            monitor-exit(r3)
            return r1
        L_0x003f:
            monitor-exit(r3)
            return r0
        L_0x0041:
            monitor-exit(r3)
            return r0
        L_0x0043:
            r4 = move-exception
            monitor-exit(r3)
            throw r4
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.maintain.FirmInfFile.checkInfFileVersion(byte[]):boolean");
    }

    /* access modifiers changed from: package-private */
    /* JADX WARNING: Code restructure failed: missing block: B:29:0x0071, code lost:
        return false;
     */
    @android.support.annotation.VisibleForTesting
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public synchronized boolean parseInfFile(byte[] r10) {
        /*
            r9 = this;
            monitor-enter(r9)
            r0 = 0
            if (r10 == 0) goto L_0x0070
            int r1 = r10.length     // Catch:{ all -> 0x006d }
            r2 = 4
            if (r1 >= r2) goto L_0x0009
            goto L_0x0070
        L_0x0009:
            int r1 = r10.length     // Catch:{ all -> 0x006d }
            int r1 = r1 - r2
            byte[] r1 = new byte[r1]     // Catch:{ all -> 0x006d }
            int r3 = r1.length     // Catch:{ all -> 0x006d }
            java.lang.System.arraycopy(r10, r2, r1, r0, r3)     // Catch:{ all -> 0x006d }
            java.lang.String r10 = new java.lang.String     // Catch:{ all -> 0x006d }
            r10.<init>(r1)     // Catch:{ all -> 0x006d }
            java.lang.String r1 = ";\r\n"
            java.lang.String[] r10 = r10.split(r1)     // Catch:{ all -> 0x006d }
            java.util.HashMap<java.lang.String, java.lang.String> r1 = r9.mUpdateInf     // Catch:{ all -> 0x006d }
            r1.clear()     // Catch:{ all -> 0x006d }
            r9.mRomNum = r0     // Catch:{ all -> 0x006d }
            int r1 = r10.length     // Catch:{ all -> 0x006d }
            r2 = 0
        L_0x0025:
            r3 = 1
            if (r2 >= r1) goto L_0x006b
            r4 = r10[r2]     // Catch:{ all -> 0x006d }
            java.lang.String r5 = ":"
            int r5 = r4.indexOf(r5)     // Catch:{ all -> 0x006d }
            r6 = -1
            if (r5 != r6) goto L_0x0034
            goto L_0x0068
        L_0x0034:
            java.lang.String r7 = r4.substring(r0, r5)     // Catch:{ all -> 0x006d }
            int r5 = r5 + 1
            int r8 = r4.length()     // Catch:{ all -> 0x006d }
            java.lang.String r4 = r4.substring(r5, r8)     // Catch:{ all -> 0x006d }
            boolean r5 = epson.maintain.FirmwareManager.DEV_FWUPDATE     // Catch:{ all -> 0x006d }
            if (r5 == 0) goto L_0x0056
            java.lang.String r5 = "URLROM"
            int r5 = r7.indexOf(r5)     // Catch:{ all -> 0x006d }
            if (r5 == r6) goto L_0x0056
            java.lang.String r5 = "https://epsonpfu.ebz.epson.net"
            java.lang.String r8 = "https://epsonpfu-stg.ebz.epson.net"
            java.lang.String r4 = r4.replaceAll(r5, r8)     // Catch:{ all -> 0x006d }
        L_0x0056:
            java.lang.String r5 = "URLROM"
            int r5 = r7.indexOf(r5)     // Catch:{ all -> 0x006d }
            if (r5 == r6) goto L_0x0063
            int r5 = r9.mRomNum     // Catch:{ all -> 0x006d }
            int r5 = r5 + r3
            r9.mRomNum = r5     // Catch:{ all -> 0x006d }
        L_0x0063:
            java.util.HashMap<java.lang.String, java.lang.String> r3 = r9.mUpdateInf     // Catch:{ all -> 0x006d }
            r3.put(r7, r4)     // Catch:{ all -> 0x006d }
        L_0x0068:
            int r2 = r2 + 1
            goto L_0x0025
        L_0x006b:
            monitor-exit(r9)
            return r3
        L_0x006d:
            r10 = move-exception
            monitor-exit(r9)
            throw r10
        L_0x0070:
            monitor-exit(r9)
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.maintain.FirmInfFile.parseInfFile(byte[]):boolean");
    }

    @VisibleForTesting
    static String getComparableVersion(@Nullable String str) {
        if (str == null || str.length() < 6) {
            throw new IllegalArgumentException();
        }
        return str.substring(4, 6) + str.substring(2, 4);
    }

    public int compareVersion(String str) {
        return getComparableVersion(str).compareTo(getComparableVersion(getMainVersion()));
    }
}
