Example usage for com.badlogic.gdx.files FileHandle isDirectory

List of usage examples for com.badlogic.gdx.files FileHandle isDirectory

Introduction

In this page you can find the example usage for com.badlogic.gdx.files FileHandle isDirectory.

Prototype

public boolean isDirectory() 

Source Link

Document

Returns true if this file is a directory.

Usage

From source file:br.com.questingsoftware.libgdx.g3db.G3DBConverter.java

License:Apache License

/** <p>
 * Convert all G3DJ files inside a folder to G3DB format (binary JSON).
 * </p>/* w  ww . j a v a 2  s . co  m*/
 * 
 * 
 * @param g3djFolder Folder containing files with the {@code g3dj} extension. Ths method will not recursively navigate folders.
 * 
 * @param overwrite If {@code true} and there's already a file with the same name and the {@code g3db} extension, the file will
 *           be overwritten. Otherwise a counter will be appended at the end of the file.
 * 
 * @throws IOException If there's an exception while reading the input file or writing the output file. */
public void convertFolder(FileHandle g3djFolder, boolean overwrite) throws IOException {
    ArrayList<FileHandle> g3djFiles = new ArrayList<FileHandle>();

    if (g3djFolder != null) {
        if (g3djFolder.isDirectory()) {
            for (FileHandle handle : g3djFolder.list()) {
                if (handle.name().toLowerCase().endsWith(".g3dj")) {
                    g3djFiles.add(handle);
                }
            }
        } else if (g3djFolder.name().toLowerCase().endsWith(".g3dj")) {
            FileHandle g3djFile = g3djFolder;
            g3djFolder = g3djFolder.parent();
            g3djFiles.add(g3djFile);
        }
    }

    for (FileHandle handle : g3djFiles) {
        convert(handle, overwrite);
    }
}

From source file:CB_UI.GL_UI.SoundCache.java

License:Open Source License

private static Music getMusikFromSetting(SettingsAudio set) {
    String path = set.getValue().Path;

    FileHandle handle = set.getValue().Class_Absolute ? Gdx.files.absolute(path)
            : GlobalCore.getInternalFileHandle(path);

    if (handle == null || !handle.exists() || handle.isDirectory() || path.length() == 0) {
        path = set.getDefaultValue().Path;
        handle = set.getValue().Class_Absolute ? Gdx.files.absolute(path)
                : GlobalCore.getInternalFileHandle(path);
        if (handle != null && handle.exists()) {
            set.loadDefault();//from ww w  .  j  av  a2s .  c o  m
            set.setDirty();
        }
    }

    if (handle == null || !handle.exists()) {
        Log.err(log, "LoadSound: " + set.getValue().Path);
        return null;
    }

    Music ret;
    try {
        ret = Gdx.audio.newMusic(handle);
    } catch (Exception e) {
        Log.err(log, "LoadSound: " + set.getValue().Path);
        return null;
    }
    return ret;
}

From source file:com.andgate.ikou.io.LevelDatabaseService.java

License:Open Source License

public static Level[] getLevels() {
    FileHandle[] levelFiles = Gdx.files.external(Constants.LEVELS_EXTERNAL_PATH).list();

    Array<Level> levels = new Array<>();

    for (FileHandle levelFile : levelFiles) {
        String extension = levelFile.extension();

        if (!levelFile.isDirectory() && extension.equals(Constants.LEVEL_EXTENSION_NO_DOT)) {
            try {
                levels.add(LevelService.read(levelFile));
            } catch (final IOException e) {
                final String errorMessage = "Failed to read level file.";
                Gdx.app.error(TAG, errorMessage, e);
            }/*ww  w  . ja v a  2s .c  o  m*/
        }
    }

    return levels.toArray(new Level[levels.size].getClass().getComponentType());
}

From source file:com.andgate.ikou.io.LevelDatabaseService.java

License:Open Source License

public static LevelData[] getOldLevelDatas() {
    ProgressDatabase progressDB = ProgressDatabaseService.read();
    FileHandle[] levelsDirFolders = Gdx.files.internal(Constants.LEVELS_INTERNAL_PATH + "old/").list();

    LevelData[] levels = new LevelData[levelsDirFolders.length];

    for (int i = 0; i < levelsDirFolders.length; i++) {
        FileHandle level = levelsDirFolders[i];

        if (level.isDirectory()) {
            String levelName = level.name();
            int totalFloors = level.list().length;
            int completedFloors = progressDB.getFloorsCompleted(levelName);

            levels[i] = new LevelData(levelName, totalFloors, completedFloors);
        }//ww  w. j  a  v  a 2 s .  c om
    }

    return levels;
}

From source file:com.badlogic.gdx.spriter.demo.SpriterDemoUtils.java

static void findFiles(Array<FileHandle> files, FileHandle fileHandle, String[] acceptedExtensions) {
    if (fileHandle.isDirectory()) {
        for (FileHandle child : fileHandle.list())
            findFiles(files, child, acceptedExtensions);
    } else {//from   w ww  .ja  v  a2 s.c  om
        String extension = fileHandle.extension();
        for (String acceptedExtension : acceptedExtensions) {
            if (acceptedExtension.equalsIgnoreCase(extension)) {
                files.add(fileHandle);
                break;
            }
        }
    }
}

From source file:com.badlogic.gdx.tests.utils.AssetsFileGenerator.java

License:Apache License

private static final void traverse(FileHandle directory, String base, StringBuffer list) {
    if (directory.name().equals(".svn"))
        return;/*from w w  w.  ja  v  a 2 s  .  co  m*/
    String dirName = directory.toString().replace("\\", "/").replace(base, "") + "/";
    System.out.println(dirName);
    for (FileHandle file : directory.list()) {
        if (file.isDirectory()) {
            traverse(file, base, list);
        } else {
            String fileName = file.toString().replace("\\", "/").replace(base, "");
            if (fileName.endsWith(".png") || fileName.endsWith(".jpg") || fileName.endsWith(".jpeg")) {
                list.append("i:" + fileName + "\n");
                System.out.println(fileName);
            } else if (fileName.endsWith(".glsl") || fileName.endsWith(".fnt") || fileName.endsWith(".pack")
                    || fileName.endsWith(".obj") || file.extension().equals("") || fileName.endsWith("txt")) {
                list.append("t:" + fileName + "\n");
                System.out.println(fileName);
            } else {
                if (fileName.endsWith(".mp3") || fileName.endsWith(".ogg") || fileName.endsWith(".wav"))
                    continue;
                list.append("b:" + fileName + "\n");
                System.out.println(fileName);
            }
        }
    }
}

From source file:com.blastedstudios.gdxworld.util.ui.TreeFileChooser.java

License:Apache License

/** passes an Accessor that creates labels representing the file name (with slash if it's a folder) using the given label style to {@link #fileNode(FileHandle, FileFilter, Accessor, Accessor)} (labelSupplier)
 *  @param labelStyle the {@link LabelStyle} to use for created labels
 *  @see #fileNode(FileHandle, FileFilter, Accessor, Accessor) */
public static Node fileNode(FileHandle file, FileFilter filter, final LabelStyle labelStyle,
        Accessor<Void, Node> nodeConsumer) {
    return fileNode(file, filter, new Accessor<Label, FileHandle>() {
        @Override/*from w  w w  .  j av  a 2s  .co m*/
        public Label access(FileHandle file) {
            String name = file.name();
            if (file.isDirectory())
                name += File.separator;
            return new Label(name, labelStyle);
        }
    }, nodeConsumer);
}

From source file:com.blastedstudios.gdxworld.util.ui.TreeFileChooser.java

License:Apache License

/** creates an anonymous subclass of {@link Node} that recursively adds the children of the given file to it when being {@link Node#setExpanded(boolean) expanded} for the first time
 *  @param file the file to put in {@link Node#setObject(Object)}
 *  @param filter Filters children from being added. May be null to accept all files.
 *  @param labelSupplier supplies labels to use
 *  @param nodeConsumer Does something with nodes after they were created. May be null.
 *  @return the created Node *//*  w ww .ja v  a2  s .co  m*/
public static Node fileNode(final FileHandle file, final FileFilter filter,
        final Accessor<Label, FileHandle> labelSupplier, final Accessor<Void, Node> nodeConsumer) {
    Label label = labelSupplier.access(file);

    Node node;
    if (file.isDirectory()) {
        final Node dummy = new Node(new Actor());

        node = new Node(label) {
            private boolean childrenAdded;

            @Override
            public void setExpanded(boolean expanded) {
                if (expanded == isExpanded())
                    return;

                if (expanded && !childrenAdded) {
                    if (filter != null)
                        for (File child : file.file().listFiles(filter))
                            add(fileNode(file.child(child.getName()), filter, labelSupplier, nodeConsumer));
                    else
                        for (FileHandle child : file.list())
                            add(fileNode(child, filter, labelSupplier, nodeConsumer));
                    childrenAdded = true;
                    remove(dummy);
                }

                super.setExpanded(expanded);
            }
        };
        node.add(dummy);

        if (nodeConsumer != null)
            nodeConsumer.access(dummy);
    } else
        node = new Node(label);
    node.setObject(file);

    if (nodeConsumer != null)
        nodeConsumer.access(node);

    return node;
}

From source file:com.dongbat.invasion.registry.EnemyRegistry.java

public static void load() {
    FileHandle internal = Gdx.files.internal("./enemy");
    for (FileHandle file : internal.list()) {
        if (file.isDirectory()) {
            continue;
        }/*from w w  w.  j a v a  2 s.  c o  m*/
        String content = file.readString();
        EnemyInfo enemyInfo = getEnemyInfo(content);
        if (enemyInfo != null) {
            enemyRegistry.put(file.nameWithoutExtension(), enemyInfo);
        }
    }
}

From source file:com.intrepid.studio.animation.GenerateAnimationPackInfo.java

private void createMapGroupTagResource() {
    rootContent.foreachFilesInContentDirectoriesExec(new FileExec() {
        @Override/*  w w w  . jav a  2  s .  c om*/
        public void runOver(FileHandle fHandle) {
            if (fHandle.name().equals(GROUP_TAG)) {
                String resDir = fHandle.path().replace(GROUP_TAG, "");
                String groupTagName = fHandle.readString().trim().toLowerCase();

                System.out.println("\n-- GROUP TAG FOUND -----------------------------");
                System.out.println("GROUP TAG: " + groupTagName);
                System.out.println("Resources Dir: " + resDir);

                for (FileHandle fRes : getFileHandle(resDir).list()) {
                    if (fRes.isDirectory()) { //ignore files
                        String path = fRes.path();
                        String[] split = path.split("/");
                        //                     String dir = split[ split.length - 2 ];
                        String name = split[split.length - 1];
                        String filename = path + "/" + name + ".";

                        FileHandle sai = new FileHandle(filename + SAI_EXTENSION);
                        FileHandle png = new FileHandle(filename + TEXTURE_EXTENSION);

                        System.out.println("  " + sai.name() + ": " + (sai.exists() ? "OK" : "ERROR") + ", "
                                + png.name() + ": " + (png.exists() ? "OK" : "ERROR"));

                        boolean hasData = sai.exists() && png.exists();
                        if (hasData) {
                            TagResource tagResource = new TagResource(sai, png);

                            if (!mapGroupTagResource.containsKey(groupTagName)) {
                                mapGroupTagResource.put(groupTagName, new GroupTag(groupTagName));
                            }
                            mapGroupTagResource.get(groupTagName).addTagResource(tagResource);
                        }
                    }
                }
            }
        }
    });
}