if(value.startsWith("(LONG)\"") || value.startsWith("(STRING)\"") || value.startsWith("(BOOLEAN)\"")) {   if((format == 3) || (format == 4) || (format == 0)) format = 3; else { format = 0; break; } } else {   if((format == 2) || (format == 4) || (format == 0)) format = 2; else { format = 0; break; } }
if(value.startsWith("(LONG)") || value.startsWith("(STRING)") || value.startsWith("(BOOLEAN)")) {   if((format == 3) || (format == 4) || (format == 0)) format = 3; else { format = 0; break; } } else {   if((format == 2) || (format == 4) || (format == 0)) format = 2; else { format = 0; break; } }
    private static int autoDetect(File dir)    {        // returns -1 if a file was not readable        // returns 0  if no file format was found        // returns 1  if YaCE 1 file format        // returns 2  if YaCE 2 file format        // returns 3  if YaCE 2 Remake file format        // ("reg_xxx" items are changed to "reginfo_xxx"        //  and Object format is given in YaCE 2 Remake)        // format = 4 is used if it cannot be divided between YaCE 2 and YaCE 2 Remake file format        // get directory list        String reglist[] = dir.list();        // only check the first 3 files (or all files if there are less than 3 files in the directory)        int to_check = (reglist.length < 3) ? reglist.length : 3;        // this is the format that is returned        int format = 0;        for(int i = 0; i < to_check; ++i)        {            String file = reglist[i];            // check if file is readable            if(!(new File(dir.getAbsolutePath() + "/" + file)).canRead())            {                format = -1;                break;            }            // check if YaCE 1 file            if(file.endsWith(".yri"))            {                // check if the other file formats are also YaCE 1                // if not, set format to 0 and break                if((format == 1) || (format == 0))                    format = 1;                else                {                    format = 0;                    break;                }                // check next file                continue;            }            // check if YaCE 2/YaCE 2 Remake file            if(file.endsWith(".yrf"))            {                // open file to check if YaCE 2 or YaCE 2 Remake file                FileInputStream fileinputstream = null;                try                {                    fileinputstream = new FileInputStream(dir.getAbsolutePath() + "/" + file);                }                catch(java.io.FileNotFoundException e)                {                    format = -1;                    break;                }                BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(fileinputstream));                try                {                    // read three lines and throw them away (1.: name, 2.: password, 3.: empty line)                    // there are some "equals()" to make a NullPointerException                    bufferedreader.readLine().equals("");                    bufferedreader.readLine().equals("");                    bufferedreader.readLine().equals("");                    // check if 4. line is "---REGITEMS---"                    if(!bufferedreader.readLine().equals("---REGITEMS---"))                    {                        format = 0;                        break;                    }                }                catch(java.io.IOException e)                {                    format = 0;                    break;                }                catch(NullPointerException e)                {                    format = -1;                    break;                }                String line;                // opening a new try-catch block because file end could now be arrived                // and then the converter would identify the files as undetected                try                {                    // read the next line                    line = bufferedreader.readLine();                }                catch(java.io.IOException e)                {                    // if it cannot be devided between YaCE 2 and YaCE 2 Remake file format                    format = 4;                    continue;                }                // check for a "="                if(line.indexOf("=") == -1)                {                    format = -1;                    break;                }                // cut the value out of line                String value = line.substring(line.indexOf("=") + 1);                // check if YaCE 2 Remake file ("(<object type>)" at value beginning)                if(value.startsWith("(LONG)\"") || value.startsWith("(STRING)\"") || value.startsWith("(BOOLEAN)\""))                {                    // check if the other file formats are also YaCE 2 Remake                    // if not, set format to 0 and break                    if((format == 3) || (format == 4) || (format == 0))                        format = 3;                    else                    {                        format = 0;                        break;                    }                }                else                {                    // check if the other file formats are also YaCE 2                    // if not, set format to 0 and break                    if((format == 2) || (format == 4) || (format == 0))                        format = 2;                    else                    {                        format = 0;                        break;                    }                }                // check next file                continue;            }            // if neither YaCE 1 nor YaCE 2/YaCE 2 Remake file, set format to 0 and break            format = 0;            break;        }        // check if format is 4        if(format == 4)            return 0;        return format;    }