def xmlwriter(data): #xmlwriter() is loaded automatically after scan is run
        tree = open('games.xml' ,'w')
        tree.write('''<?xml version="1.0"?>\n''')
        root = Element("Library")
        for key, value in sorted(data.items()): #removes extensions for filenames for key values
            game = ET.SubElement(root, 'game')
            system = ET.SubElement(game, 'system')
            title = ET.SubElement(game, 'title')
            path = ET.SubElement(game, 'path')
            core = ET.SubElement(game, 'core')
            image = ET.SubElement(game, 'image')

            game_extension = key[-4::].lower()
            if win32_check.check():
                core_ext = '.dll'
                win32_tags(system, core, game_extension)
            else:
                core_ext = '.so'
                linux_tags(system, core, game_extension)
                print(core.text)
            if '.gb' in game_extension:
                clean_key = key.strip(key[-3::])
            else:
                clean_key = key.strip(key[-4::])

            title.text = clean_key
            image.text = root_path.change() + '/missing_artwork.png'
            path.text = '"{:}"'.format(value)


        indent(root) #root doesn't have to be returned
        tree.write(ET.tostring(root).decode('utf-8'))
        tree.close()
        return 'Wrote .xml'
def cores_list(path='/usr/lib/libretro'):
    if win32_check.check():
        pass
    else:
        with open(root_path.path() + '/linux_cores.txt', 'r') as fid:
            cores = fid.readlines()
            clean_cores = get_jslist(cores, tag='available')
        return clean_cores
def launch(game_path, core, *args):
    '''game_path and core are defined in main.qml'''
    if win32_check.check():
        run = exe() + ' ' + '-c ' + root_dir + cfg() + ' ' + self._core + ' ' + game_path 
        return os.system(run)
    else:
        run = exe(exe_path='/usr/bin/retroarch') + ' {:}'.format("".join(args)) + '-c ' + cfg(cfg_path='~/.config/retroarch/custom.cfg') + ' -L ' + core + ' ' + game_path
        os.system(run)
        return run
def call():
    if win32_check.check() == False:
        subp.Popen(shlex.split('gnome-terminal -x bash -c "/usr/bin/retroarch-joyconfig"'))
        return '*nix terminal opened'
    else:
        root_dir = os.path.dirname(os.path.realpath(__file__))
        joy_path = root_dir + '\\retroarch_v1.0\\retroarch-joyconfig.exe'
        subprocess.call(joy_path)
        return 'Windows terminal opened'
import win32_check
import os


if win32_check.check():
    RETRO_PATH = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'retroarch_v1.0'))
    OUTPUT_CFG = RETRO_PATH + '\\custom.cfg'
else:
    RETRO_PATH = os.path.abspath(os.path.dirname( __file__ ))
    OUTPUT_CFG = os.path.expanduser('~') + '/.config/retroarch/custom.cfg'

def get_config_data(cfg_file=RETRO_PATH + '/linux_retroarch.cfg'):
    with open(cfg_file, 'r') as  infile:
        cfg_data = infile.readlines()
        return cfg_data

def write_config(fid=OUTPUT_CFG, new_data=get_config_data()):
    with open(fid, "w") as outfile:
        outfile.seek(0)
        for lines in new_data:
            outfile.write("".join(lines))