package com.github.mjdev.libaums.fs.fat32;

import java.nio.ByteBuffer;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
class FatLfnDirectoryEntry {
    private FatDirectoryEntry actualEntry;
    private String lfnName;

    private FatLfnDirectoryEntry() {
    }

    private FatLfnDirectoryEntry(FatDirectoryEntry fatDirectoryEntry, String str) {
        this.actualEntry = fatDirectoryEntry;
        this.lfnName = str;
    }

    static FatLfnDirectoryEntry createNew(String str, ShortName shortName) {
        FatLfnDirectoryEntry fatLfnDirectoryEntry = new FatLfnDirectoryEntry();
        fatLfnDirectoryEntry.lfnName = str;
        FatDirectoryEntry fatDirectoryEntryCreateNew = FatDirectoryEntry.createNew();
        fatLfnDirectoryEntry.actualEntry = fatDirectoryEntryCreateNew;
        fatDirectoryEntryCreateNew.setShortName(shortName);
        return fatLfnDirectoryEntry;
    }

    static FatLfnDirectoryEntry read(FatDirectoryEntry fatDirectoryEntry, List<FatDirectoryEntry> list) {
        StringBuilder sb = new StringBuilder(list.size() * 13);
        if (list.size() > 0) {
            for (int size = list.size() - 1; size >= 0; size--) {
                list.get(size).extractLfnPart(sb);
            }
            return new FatLfnDirectoryEntry(fatDirectoryEntry, sb.toString());
        }
        return new FatLfnDirectoryEntry(fatDirectoryEntry, null);
    }

    void serialize(ByteBuffer byteBuffer) {
        if (this.lfnName != null) {
            byte bCalculateCheckSum = this.actualEntry.getShortName().calculateCheckSum();
            int entryCount = getEntryCount();
            int i = entryCount - 2;
            FatDirectoryEntry.createLfnPart(this.lfnName, i * 13, bCalculateCheckSum, entryCount - 1, true).serialize(byteBuffer);
            while (true) {
                int i2 = i - 1;
                if (i <= 0) {
                    break;
                }
                FatDirectoryEntry.createLfnPart(this.lfnName, i2 * 13, bCalculateCheckSum, i, false).serialize(byteBuffer);
                i = i2;
            }
        }
        this.actualEntry.serialize(byteBuffer);
    }

    int getEntryCount() {
        String str = this.lfnName;
        if (str == null) {
            return 1;
        }
        int length = str.length();
        int i = length / 13;
        return length % 13 != 0 ? i + 2 : i + 1;
    }

    String getName() {
        String lowerCase;
        String str = this.lfnName;
        if (str != null) {
            return str;
        }
        String string = this.actualEntry.getShortName().getString();
        String[] strArrSplit = string.split(".");
        if (strArrSplit.length != 2) {
            lowerCase = "";
        } else {
            string = strArrSplit[0];
            lowerCase = string;
        }
        if (this.actualEntry.isShortNameLowerCase()) {
            string = string.toLowerCase();
        }
        if (this.actualEntry.isShortNameExtLowerCase()) {
            lowerCase = lowerCase.toLowerCase();
        }
        return !lowerCase.isEmpty() ? string + "." + lowerCase : string;
    }

    void setName(String str, ShortName shortName) {
        this.lfnName = str;
        this.actualEntry.setShortName(shortName);
    }

    long getFileSize() {
        return this.actualEntry.getFileSize();
    }

    void setFileSize(long j) {
        this.actualEntry.setFileSize(j);
    }

    long getStartCluster() {
        return this.actualEntry.getStartCluster();
    }

    void setStartCluster(long j) {
        this.actualEntry.setStartCluster(j);
    }

    void setLastAccessedTimeToNow() {
        this.actualEntry.setLastAccessedDateTime(System.currentTimeMillis());
    }

    void setLastModifiedTimeToNow() {
        this.actualEntry.setLastModifiedDateTime(System.currentTimeMillis());
    }

    boolean isDirectory() {
        return this.actualEntry.isDirectory();
    }

    void setDirectory() {
        this.actualEntry.setDirectory();
    }

    FatDirectoryEntry getActualEntry() {
        return this.actualEntry;
    }

    static void copyDateTime(FatLfnDirectoryEntry fatLfnDirectoryEntry, FatLfnDirectoryEntry fatLfnDirectoryEntry2) {
        FatDirectoryEntry actualEntry = fatLfnDirectoryEntry.getActualEntry();
        FatDirectoryEntry actualEntry2 = fatLfnDirectoryEntry.getActualEntry();
        actualEntry2.setCreatedDateTime(actualEntry.getCreatedDateTime());
        actualEntry2.setLastAccessedDateTime(actualEntry.getLastAccessedDateTime());
        actualEntry2.setLastModifiedDateTime(actualEntry.getLastModifiedDateTime());
    }

    public String toString() {
        return "[FatLfnDirectoryEntry getName()=" + getName() + "]";
    }
}
