Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import os
- import json
- from galaxy.api.plugin import Plugin, create_and_run_plugin
- from galaxy.api.types import Game, LicenseInfo
- from galaxy.api.errors import (
- AuthenticationRequired, UnknownBackendResponse, AccessDenied, InvalidCredentials, UnknownError, ApplicationError
- )
- from galaxy.api.consts import Platform, LicenseType
- from galaxy.api.jsonrpc import InvalidParams
- SETTINGS_FILE = "settings.json"
- ACCEPTED_FORMATS = ('.bin', '.md', '.68k', '.smd', '.sgd')
- class GenesisKEGAPlugin(Plugin):
- def __init__(self, reader, writer, token):
- super().__init__(Platform.Generic, "0.1", reader, writer, token)
- async def get_owned_games(self):
- # this function and get_local_games are near duplicates
- # as attempts to remedy the failed to start error
- games = []
- # put a try and except here
- with open(SETTINGS_FILE, 'r') as settings_data:
- json_data = json.load(settings_data)
- rom_dirs = json_data['romDirs']
- for dir in rom_dirs:
- for subdir, dirs, files in os.walk(dir):
- for file in files:
- if file.lower().endswith(ACCEPTED_FORMATS):
- genesis_ROM = Game()
- genesis_ROM.game_title = file
- genesis_ROM.game_id = os.path.join(subdir, file)
- genesis_ROM.dlcs = []
- genesis_ROM.license_info = "SinglePurchase"
- games.append(genesis_ROM)
- return games
- async def get_local_games(self):
- # this function and get_owned_games are near duplicates
- # as attempts to remedy the failed to start error
- local_games = []
- # put a try and except here
- with open(SETTINGS_FILE, 'r') as settings_data:
- json_data = json.load(settings_data)
- rom_dirs = json_data['romDirs']
- for dir in rom_dirs:
- for subdir, dirs, files in os.walk(dir):
- for file in files:
- if file.lower().endswith(ACCEPTED_FORMATS):
- genesis_ROM = LocalGame()
- genesis_ROM.game_id = os.path.join(subdir, file)
- genesis_ROM.local_game_state = 1
- local_games.append(genesis_ROM)
- return local_games
- async def check_for_new_games(self):
- games = await self.get_local_games()
- for game in games:
- if game not in self.owned_games_cache:
- self.owned_games_cache.append(game)
- self.add_game(game)
- async def launch_game(self, game_id):
- with open(SETTINGS_FILE, 'r') as settings_data:
- json_data = json.load(settings_data)
- kega_path = json_data['kegaDir']
- launch_parameters = kega_path + "fusion.exe \"" + game_id + "\" -gen"
- os.system(launch_parameters)
- def tick(self):
- async def _update_local_games():
- loop = asyncio.get_running_loop()
- new_list = await loop.run_in_executor(None, get_local_games())
- notify_list = get_state_changes(self._local_games_cache, new_list)
- self._local_games_cache = new_list
- for local_game_notify in notify_list:
- self.update_local_game_status(local_game_notify)
- def main():
- create_and_run_plugin(GenesisKEGAPlugin, sys.argv)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement