Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    private final static String DATABASE_NAME = "RPG_RT.ldb", TREEMAP_NAME = "RPG_RT.lmt", INI_FILE = "RPG_RT.ini";

    /**
     * Tests if a folder is a RPG2k Game.
     * (contains DATABASE_NAME and TREEMAP_NAME)
     *
     * @param dir Directory to test
     * @return true if RPG2k game
     */
    public static boolean isRpg2kGame(File dir) {
        if (!dir.isDirectory() || !dir.canRead()) {
            return false;
        }

        boolean databaseFound = false;
        boolean treemapFound = false;

        for (File entry : dir.listFiles()) {
            if (entry.isFile() && entry.canRead()) {
                if (!databaseFound && entry.getName().equalsIgnoreCase(DATABASE_NAME)) {
                    databaseFound = true;
                } else if (!treemapFound && entry.getName().equalsIgnoreCase(TREEMAP_NAME)) {
                    treemapFound = true;
                }

                if (databaseFound && treemapFound) {
                    return true;
                }
            }
        }

        return false;
    }
}