<commit_before>package org.hs5tb.groospin.base

import org.hs5tb.groospin.common.IniFile

/**
 * Created by Alberto on 17-Jun-17.
 */
class RetroArch {
    IniFile iniFile
    IniFile coreIniFile
    static EMPTY = "\"nul\""
    static DEVICE_PAD_WITH_ANALOG = "\"5\""
    static DEVICE_PAD = "\"1\""
    static DEVICE_NONE = "\"0\""

    static ANALOG_TO_DPAD_NONE = "\"0\""
    static ANALOG_TO_DPAD_RIGHT = "\"2\""
    static ANALOG_TO_DPAD_LEFT = "\"1\""

    RetroArch folder(String folder) {
        iniFile = new IniFile(equals: " = ").parse(new File(folder, "retroarch.cfg"))
        iniFile.put("system_directory", "\":\\system\"")
        iniFile.store()

        coreIniFile = new IniFile(equals: " = ").parse(new File(folder, "retroarch-core-options.cfg"))
        coreIniFile.put("beetle_psx_analog_toggle", "\"enabled\"")
        coreIniFile.store()

        File bettle = new File(folder, "config\\Beetle PSX\\Beetle PSX.cfg")
        if (!bettle.exists()) {
            bettle.parentFile.mkdirs()
            bettle.text = ""
        }
        this
    }

    RetroArch configureKeys(int player, Map<String, String> map) {
        map.each { String key, String val ->
            String used = used(val)
            key = "input_player${player}_${key.toLowerCase()}".toString()
            if (used && used != key) {
                throw new Exception("Key $val already used by ${used}")
            } else {
                iniFile.put(key, "\"${val.toLowerCase()}\"")
            }
        }
        this<commit_msg>allow override<commit_after>package org.hs5tb.groospin.base

import org.hs5tb.groospin.common.IniFile

/**
 * Created by Alberto on 17-Jun-17.
 */
class RetroArch {
    boolean override = false
    IniFile iniFile
    IniFile coreIniFile
    static EMPTY = "\"nul\""
    static DEVICE_PAD_WITH_ANALOG = "\"5\""
    static DEVICE_PAD = "\"1\""
    static DEVICE_NONE = "\"0\""

    static ANALOG_TO_DPAD_NONE = "\"0\""
    static ANALOG_TO_DPAD_RIGHT = "\"2\""
    static ANALOG_TO_DPAD_LEFT = "\"1\""

    RetroArch folder(String folder) {
        iniFile = new IniFile(equals: " = ").parse(new File(folder, "retroarch.cfg"))
        iniFile.put("system_directory", "\":\\system\"")
        iniFile.store()

        coreIniFile = new IniFile(equals: " = ").parse(new File(folder, "retroarch-core-options.cfg"))
        coreIniFile.put("beetle_psx_analog_toggle", "\"enabled\"")
        coreIniFile.store()

        File bettle = new File(folder, "config\\Beetle PSX\\Beetle PSX.cfg")
        if (!bettle.exists()) {
            bettle.parentFile.mkdirs()
            bettle.text = ""
        }
        this
    }

    RetroArch configureKeys(int player, Map<String, String> map) {
        map.each { String key, String val ->
            String used = used(val)
            key = "input_player${player}_${key.toLowerCase()}".toString()
            if (used && used != key) {
                if (override) {
                    println("    RetroArch warning: key $val already used by ${used}... removing")
                    iniFile.put(used, EMPTY)
                } else {
                    throw new Exception("Key $val already used by ${used}")
                }
            } else {
                iniFile.put(key, "\"${val.toLowerCase()}\"")
            }
        }
        this
{'fraction_non_alphanumeric': 0.1465543183869997, 'fraction_numerical': 0.0072223894071622025, 'mean_word_length': 2.1007462686567164, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '824472', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1095, 'n_words': 220}