Advertisement
Guest User

Segag Galaxy plugin

a guest
Jul 24th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.45 KB | None | 0 0
  1. import sys
  2. import os
  3. import json
  4. from galaxy.api.plugin import Plugin, create_and_run_plugin
  5. from galaxy.api.types import Game, LicenseInfo
  6. from galaxy.api.errors import (
  7.     AuthenticationRequired, UnknownBackendResponse, AccessDenied, InvalidCredentials, UnknownError, ApplicationError
  8. )
  9. from galaxy.api.consts import Platform, LicenseType
  10. from galaxy.api.jsonrpc import InvalidParams
  11.  
  12. SETTINGS_FILE = "settings.json"
  13. ACCEPTED_FORMATS = ('.bin', '.md', '.68k', '.smd', '.sgd')
  14.  
  15. class GenesisKEGAPlugin(Plugin):
  16.     def __init__(self, reader, writer, token):
  17.         super().__init__(Platform.Generic, "0.1", reader, writer, token)
  18.  
  19.     async def get_owned_games(self):
  20.         # this function and get_local_games are near duplicates
  21.         # as attempts to remedy the failed to start error
  22.         games = []
  23.         # put a try and except here
  24.         with open(SETTINGS_FILE, 'r') as settings_data:
  25.             json_data = json.load(settings_data)
  26.             rom_dirs = json_data['romDirs']
  27.         for dir in rom_dirs:
  28.             for subdir, dirs, files in os.walk(dir):
  29.                 for file in files:
  30.                     if file.lower().endswith(ACCEPTED_FORMATS):
  31.                         genesis_ROM = Game()
  32.                         genesis_ROM.game_title = file
  33.                         genesis_ROM.game_id = os.path.join(subdir, file)
  34.                         genesis_ROM.dlcs = []
  35.                         genesis_ROM.license_info = "SinglePurchase"
  36.                         games.append(genesis_ROM)
  37.         return games
  38.  
  39.     async def get_local_games(self):
  40.         # this function and get_owned_games are near duplicates
  41.         # as attempts to remedy the failed to start error
  42.         local_games = []
  43.         # put a try and except here
  44.         with open(SETTINGS_FILE, 'r') as settings_data:
  45.             json_data = json.load(settings_data)
  46.             rom_dirs = json_data['romDirs']
  47.         for dir in rom_dirs:
  48.             for subdir, dirs, files in os.walk(dir):
  49.                 for file in files:
  50.                     if file.lower().endswith(ACCEPTED_FORMATS):
  51.                         genesis_ROM = LocalGame()
  52.                         genesis_ROM.game_id = os.path.join(subdir, file)
  53.                         genesis_ROM.local_game_state = 1
  54.                         local_games.append(genesis_ROM)
  55.         return local_games
  56.  
  57.     async def check_for_new_games(self):
  58.         games = await self.get_local_games()
  59.         for game in games:
  60.             if game not in self.owned_games_cache:
  61.                 self.owned_games_cache.append(game)
  62.                 self.add_game(game)
  63.  
  64.     async def launch_game(self, game_id):
  65.         with open(SETTINGS_FILE, 'r') as settings_data:
  66.             json_data = json.load(settings_data)
  67.             kega_path = json_data['kegaDir']
  68.             launch_parameters = kega_path + "fusion.exe \"" + game_id + "\" -gen"
  69.             os.system(launch_parameters)
  70.  
  71.     def tick(self):
  72.         async def _update_local_games():
  73.             loop = asyncio.get_running_loop()
  74.             new_list = await loop.run_in_executor(None, get_local_games())
  75.             notify_list = get_state_changes(self._local_games_cache, new_list)
  76.             self._local_games_cache = new_list
  77.             for local_game_notify in notify_list:
  78.                 self.update_local_game_status(local_game_notify)
  79.  
  80. def main():
  81.     create_and_run_plugin(GenesisKEGAPlugin, sys.argv)
  82.  
  83. if __name__ == "__main__":
  84.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement