Search in sources :

Example 1 with IniFile

use of org.fagu.fmv.utils.IniFile in project fmv by f-agu.

the class Bootstrap method recurse.

/**
 * @param rootPath
 * @param currentFile
 * @param currentDepth
 * @param maxDepth
 */
private void recurse(Path rootPath, File currentFile, int currentDepth, int maxDepth) {
    if (currentFile.isFile()) {
        doFile(rootPath, currentFile);
        return;
    }
    System.out.println(currentFile);
    IniFile iniFile = loadIniFile(currentFile);
    File[] files = currentFile.listFiles(createFileFilter(iniFile));
    if (files != null) {
        Arrays.sort(files);
        for (File f : files) {
            recurse(rootPath, f, currentDepth + 1, maxDepth);
        }
    }
}
Also used : IniFile(org.fagu.fmv.utils.IniFile) IniFile(org.fagu.fmv.utils.IniFile) File(java.io.File)

Example 2 with IniFile

use of org.fagu.fmv.utils.IniFile in project fmv by f-agu.

the class Sync method sync.

// --------------------------------------------
/**
 * @param srcItem
 * @param destItemsList
 * @throws IOException
 */
private void sync(Item srcItem, List<Item> destItemsList) throws IOException {
    System.out.println(srcItem.toString());
    synchronizer.doNothingOnFolder(srcItem);
    Map<String, Item> listChildren = srcItem.listChildren();
    List<Dest> dests = new ArrayList<>();
    for (Item destItem : destItemsList) {
        Map<String, Item> map = destItem.listChildren();
        dests.add(new Dest(destItem, map, loadInitFile(map)));
    }
    IniFile srcInitFile = loadInitFile(listChildren);
    for (Entry<String, Item> entry : listChildren.entrySet()) {
        String name = entry.getKey();
        Item curSrcItem = entry.getValue();
        List<Item> curDestItems = new ArrayList<>();
        for (Dest dest : dests) {
            Item destItem = dest.item;
            Map<String, Item> destItems = dest.childMap;
            IniFile destInitFile = dest.iniFile;
            Item curDestItem = destItems.remove(name);
            if (curDestItem != null) {
                curDestItems.add(curDestItem);
            }
            if (!accept(curSrcItem, srcInitFile)) {
                synchronizer.ignore(curSrcItem.toString());
                continue;
            }
            if (curDestItem != null && !accept(curDestItem, destInitFile)) {
                synchronizer.ignore(curDestItem.toString());
                continue;
            }
            if (curDestItem == null) {
                if (curSrcItem.isDirectory()) {
                    Item ditem = synchronizer.mkdir(destItem, curSrcItem.getName());
                    if (ditem != null) {
                        sync(curSrcItem, Collections.singletonList(ditem));
                    }
                } else if (curSrcItem.isFile()) {
                    curDestItem = synchronizer.createFile(destItem, curSrcItem.getName());
                    if (curDestItem != null) {
                        final Item finalCurDestItem = curDestItem;
                        progressBar(progress -> synchronizer.copyForNew(curSrcItem, finalCurDestItem, progress), curSrcItem);
                    }
                } else {
                    synchronizer.unknown(srcItem.toString());
                }
            } else if (curDestItem.isFile() != curSrcItem.isFile() || curDestItem.isDirectory() != curSrcItem.isDirectory()) {
                synchronizer.conflict(curDestItem.toString());
            // conflict type
            } else if (curDestItem.isDirectory()) {
            // sync(curSrcItem, Collections.singletonList(curDestItem));
            } else if (curDestItem.size() != curSrcItem.size()) {
                // to update
                final Item finalCurDestItem = curDestItem;
                progressBar(progress -> synchronizer.copyForUpdate(curSrcItem, finalCurDestItem, progress), curSrcItem);
            }
            if (curSrcItem.isFile()) {
                synchronizer.doNothingOnFile(curDestItem);
            }
        }
        if (curSrcItem.isDirectory()) {
            sync(curSrcItem, curDestItems);
        }
    }
    for (Dest dest : dests) {
        for (Entry<String, Item> entry : dest.childMap.entrySet()) {
            Item value = entry.getValue();
            // to delete ?
            if (!accept(value, dest.iniFile)) {
                synchronizer.ignore(value.toString());
                continue;
            }
            synchronizer.delete(value);
        }
    }
}
Also used : ProgressPart(org.fagu.fmv.textprogressbar.part.ProgressPart) IniFile(org.fagu.fmv.utils.IniFile) IOException(java.io.IOException) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Objects(java.util.Objects) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ByteSize(org.fagu.fmv.utils.ByteSize) Map(java.util.Map) Entry(java.util.Map.Entry) TextProgressBar(org.fagu.fmv.textprogressbar.TextProgressBar) Collections(java.util.Collections) InputStream(java.io.InputStream) IniFile(org.fagu.fmv.utils.IniFile) ArrayList(java.util.ArrayList)

Aggregations

IniFile (org.fagu.fmv.utils.IniFile)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 StringUtils (org.apache.commons.lang3.StringUtils)1 TextProgressBar (org.fagu.fmv.textprogressbar.TextProgressBar)1 ProgressPart (org.fagu.fmv.textprogressbar.part.ProgressPart)1 ByteSize (org.fagu.fmv.utils.ByteSize)1