Beispiel #1
0
 def __parse_game_entry__(self, launcher, ini_dir, i):
     num = i + 1
     name = launcher['game%dname' % num]
     prog = launcher['game%dprog' % num]
     path = launcher['game%dpath' % num]
     exe = launcher['game%dexe' % num]
     cmd = launcher['game%dcmd' % num]
     self.games[i] = {'name': name}
     game = self.games[i]
     orig_cwd = os.getcwd()
     os.chdir(ini_dir)
     real_path = to_posix_path(path)
     if real_path:
         game['path'] = os.path.join(ini_dir, real_path)
     else:
         print_err("steam-dos: error: can't find path", path)
         game['path'] = orig_cwd
     if prog.lower() == 'dosbox':  # used only in Legacy launcher
         game['args'] = ['-c', 'mount C .',
                         '-c', 'C:',
                         '-c', exe,
                         '-c', 'exit']  # yapf: disable
     else:  # usually 'other', most common option
         game['args'] = argsplit_windows(cmd)
     os.chdir(orig_cwd)
Beispiel #2
0
 def __assure_sf2_exists__(self):
     sf2 = self.__get_str__('midi', 'soundfont', DEFAULT_MIDI_SOUNDFONT)
     sf2_search = [
         ['/usr/share/sounds/sf2'],
         ['/usr/share/soundfonts'],
         ['/usr/local/share/sounds/sf2'],
         ['/usr/local/share/soundfonts'],
         [DATA_HOME, 'sounds/sf2'],
         [DATA_HOME, 'soundfonts'],
     ]
     selected = ''
     default = ''
     os_default = ''
     for path in sf2_search:
         selected_path = os.path.join(*path, sf2)
         default1_path = os.path.join(*path, DEFAULT_MIDI_SOUNDFONT)
         default2_path = os.path.join(*path, 'default.sf2')
         if os.path.isfile(selected_path):
             selected = selected_path
         if os.path.isfile(default1_path):
             default = default1_path
         if os.path.isfile(default2_path):
             os_default = default2_path
     use_sf2 = selected or default or os_default
     if not use_sf2:
         print_err('steam-dos: warning: No suitable soundfont found.',
                   'Disabling MIDI support.')
         self.store.set('midi', 'enable', 'False')
         return
     _, found_file = os.path.split(use_sf2)
     if found_file != sf2:
         print_err(('steam-dos: warning: {0} soundfont not found. '
                    'Using {1} instead.').format(sf2, found_file))
     self.store.set('midi', 'soundfont', use_sf2)
Beispiel #3
0
def start_fluidsynth(sfont):
    """Start FluidSynth process."""
    cmd = ['fluidsynth', '-a', 'pulseaudio', sfont]
    proc = subprocess.Popen(cmd, shell=False, stdout=subprocess.DEVNULL)
    print_err('steam-dos: Starting MIDI client (pid: {0})'.format(proc.pid))
    print_err('steam-dos: Using soundfont: {}'.format(sfont))
    time.sleep(1.0)  # TODO properly wait until sequencer is online
    atexit.register(stop_software_midi_synth, proc.pid)
Beispiel #4
0
def start_timidity(sfont):
    """Start TiMidity++ process."""
    cmd = ['timidity', '-iA', '-x', 'soundfont {0}'.format(sfont)]
    proc = subprocess.Popen(cmd, shell=False, stdout=subprocess.DEVNULL)
    print_err('steam-dos: Starting MIDI client (pid: {0})'.format(proc.pid))
    print_err('steam-dos: Using soundfont: {0}'.format(sfont))
    time.sleep(1.0)  # TODO properly wait until sequencer is online
    atexit.register(stop_software_midi_synth, proc.pid)
Beispiel #5
0
 def __get_screen_number__(self):
     tokens = self.get_dosbox_fullscreenmode().split()
     screen = '0'
     if tokens == [] or tokens[0] != 'screen':
         print_err('steam-dos: error: unknown option value:', tokens[0])
     if len(tokens) >= 2 and tokens[0] == 'screen':
         screen = tokens[1]
     screen = os.environ.get('SDL_VIDEO_FULLSCREEN_HEAD', screen)
     screen = os.environ.get('SDL_VIDEO_FULLSCREEN_DISPLAY', screen)
     screen = os.environ.get('SDOS_SCREEN', screen)
     return screen
Beispiel #6
0
 def get_dosbox_cmd(self):
     # dosbox.cmd is new name for dosbox.bin
     dosbox_cmd = self.__get_str__('dosbox', 'cmd', None)
     dosbox_bin = self.__get_str__('dosbox', 'bin', DEFAULT_DOSBOX_BINARY)
     if not dosbox_cmd:
         dosbox_cmd = dosbox_bin
     cmd = os.environ.get('SDOS_DOSBOX_CMD', dosbox_cmd)
     try:
         split = shlex.split(cmd, comments=True)
         return [os.path.expanduser(s) for s in split]
     except ValueError as err:
         print_err('steam-dos: error: invalid dosbox.bin value:', err)
         return [DEFAULT_DOSBOX_BINARY]
Beispiel #7
0
def tweak_command(app_id, cmd_line):
    """Convert command line based on TWEAKS_DB."""
    assert len(cmd_line) >= 1
    orig_cmd = ' '.join(cmd_line)
    exec_replacements = TWEAKS_DB[app_id]['commands']
    for expr, replacement in exec_replacements.items():
        exe_pattern = re.compile(expr)
        if exe_pattern.match(orig_cmd):
            if 'args' in replacement:
                return replacement['args']
            raise KeyError
    print_err('steam-dos: error: no suitable tweak found for:', cmd_line)
    return cmd_line[1:]
Beispiel #8
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
Beispiel #9
0
 def select_game(self):
     """Select game in collection."""
     index = 0
     try:
         index = int(SIERRA_GAME) - 1
     except ValueError:
         print_err('steam-dos: warning: SDOS_SIERRA_GAME must be',
                   'a numerical value')
     self.selected_game = min(max(0, index), self.games_num - 1)
     if self.selected_game != index:
         print_err('steam-dos: warning: game', SIERRA_GAME, 'not found.')
         print_err('steam-dos: warning: This collection defines games',
                   '1..' + str(self.games_num))
         self.selected_game = 0
Beispiel #10
0
    def __setup_fullscreen__(self):
        user_choice = self.get_dosbox_fullscreenmode()
        env_override = 'SDOS_SCREEN' in os.environ or \
                       'SDL_VIDEO_FULLSCREEN_DISPLAY' in os.environ or \
                       'SDL_VIDEO_FULLSCREEN_HEAD' in os.environ

        if user_choice == 'desktop' and not env_override:
            return

        screen = self.__get_screen_number__()
        all_screens = xlib.query_screens()

        if all_screens == {}:
            print_err('steam-dos: error: no screens detected')
        for number, info in all_screens.items():
            print_err("steam-dos: screen '{}': {}x{}".format(
                number, info.width, info.height))

        if screen not in all_screens:
            print_err("steam-dos: screen '{}' not found".format(screen))
            if '0' in all_screens:
                screen = '0'
                print_err("steam-dos: using '" + screen + "' instead")
            else:
                print_err("steam-dos: using desktop as screen instead")
                return

        print_err("steam-dos: selected screen '{}'".format(screen))
        os.putenv('SDL_VIDEO_FULLSCREEN_DISPLAY', screen)  # SDL >= 1.2.14
        os.putenv('SDL_VIDEO_FULLSCREEN_HEAD', screen)  # SDL >= 1.2.10
        info = all_screens[screen]
        self.fullresolution = '{}x{}'.format(info.width, info.height)
Beispiel #11
0
def stop_software_midi_synth(pid):
    """Stop software synthesiser process."""
    print_err('steam-dos: Stopping MIDI client {0}'.format(pid))
    os.kill(pid, signal.SIGTERM)  # TODO ProcessLookupError: