Пример #1
0
def create_auto_conf_file(conf):
    """Create DOSBox configuration file based on environment.

    Different sections are either hard-coded or generated based on
    user environment (used midi port, current screen resolution, etc.).
    """

    name = 'steam_dos_auto.conf'

    mport = midi.detect_software_synthesiser(r'timidity|fluid')
    if mport:
        print_err('steam-dos: Detected', mport.name, 'on', mport.addr)

    with open(name, 'w') as auto:
        auto.write('# Generated by steam-dos\n')
        auto.write('# This file is re-created on every run\n')
        auto.write('\n')

        sdl_fullresolution = settings.get_dosbox_fullresolution()
        auto.write(SDL_SECTION_1.format(resolution=sdl_fullresolution))

        render_scaler = settings.get_dosbox_scaler()
        render_aspect = 'false'
        if conf and conf.has_section('render'):
            render_aspect = conf['render'].get('aspect', 'false')
        auto.write(
            RENDER_SECTION_1.format(scaler=render_scaler,
                                    aspect=render_aspect))

        base, irq, dma, hdma = 220, 7, 1, 5  # DOSBox defaults
        print_err('steam-dos: Setting up DOSBox audio:')
        print_err(SBLASTER_INFO.format(base=base, irq=irq, dma=dma))
        auto.write(SBLASTER_SECTION.format(base=base, irq=irq, dma=dma,
                                           hdma=hdma))  # yapf: disable
        if mport:
            print_err(MIDI_INFO)
            auto.write(MIDI_SECTION.format(port=mport.addr))
        else:
            print_err(MIDI_INFO_NA)

        if conf and conf.has_section('dos'):
            dos_xms = conf['dos'].get('xms', 'true')
            dos_ems = conf['dos'].get('ems', 'true')
            dos_umb = conf['dos'].get('umb', 'true')
            auto.write(DOS_SECTION.format(xms=dos_xms,
                                          ems=dos_ems,
                                          umb=dos_umb))  # yapf: disable

    return name