def gamelist(self): cur.execute( "select game.id, game.name, game.path, game.emu_id, game.gamesystem_id from game order by game.name" ) gl = [] for r in cur: i, n, p, e, s = r gl.append(GameInfo(i, n, p, e, s)) return gl
def load_playlists(): global playlist_list dblayer.connect() cur.execute("select id, name from playlist order by name") pl = [AllGames_Playlist()] playlist_table[-1] = pl[0] for r in cur: id, name = r p = Playlist(id, name) pl.append(p) playlist_table[id] = p playlist_list = pl
def get_game(idnum): cur.execute( "select game.id, game.name, game.path, game.emu_id, game.gamesystem_id from game where game.id = ? order by game.name", [idnum]) rs = cur.fetchall() if len(rs) > 1: raise ValueError, "Non unique id for game, multiple games matched" elif len(rs) == 0: raise ValueError, "Game not found" i, n, p, e, s = rs[0] gi = GameInfo(i, n, p, e, s) return gi
def lookup(self): if self.name != None: cur.execute("select id from playlist where name = ?", [self.name]) else: cur.execute("select name from playlist where id = ?", [self.id]) rs = cur.fetchall() if len(rs) > 1: raise ValueError, "Non unique name for playlist" else: raise ValueError, "Playlist not found" if self.name == None: self.name = rs[0][0] else: self.id = rs[0][0]
def gamelist(self): if self.gamelist_cache != None: return self.gamelist_cache cur.execute( "select game.id, game.name, game.path, game.emu_id, game.gamesystem_id from game, playlist_game where playlist_game.game_id = game.id and playlist_game.playlist_id = ? order by game.name", [self.id]) gl = [] for r in cur: i, n, p, e, s = r gl.append(GameInfo(i, n, p, e, s)) # enabling this could cause huge memory usage, but make things faster #self.gamelist_cache = gl return gl
def autoload_data(path, playlist, system=None, emulator=None): fileext_map = {} if system == None: for gsi in gamesystem_table.values(): for fe in gsi.fileexts: fileext_map[fe.upper()] = gsi print fileext_map for base, dirs, files in os.walk(path): for file in files: fn, fe = os.path.splitext(file) feu = fe.upper() if feu == '.ZIP': feu = scan_zip(os.path.join(path, base, file)) if not feu: continue autosystem = None if feu in fileext_map: autosystem = fileext_map[feu] if system != None: autosystem = system if autosystem != None: "We have a valid game, we know what system it's for, and we will use that system's default emulator" emuid = None if emulator != None: emuid = emulator.id sysid = None if autosystem != None: sysid = autosystem.id cur.execute( "insert into game (name, path, emu_id, gamesystem_id) values (?, ?, ?, ?)", [fn, os.path.join(path, base, file), emuid, sysid]) gameid = cur.lastrowid cur.execute( "insert into playlist_game (game_id, playlist_id) values (?, ?)", [gameid, playlist.id])
def initialize_emulator_row(emulator, gamesystem): cur.execute("insert into emulator (name, path, options) values (?, ?, ?)", [emulator.name, emulator.path, emulator.options]) emulator.id = cur.lastrowid cur.execute("insert into gamesystem (name, fileext) values (?, ?)", [gamesystem.name, ';'.join(gamesystem.fileexts)]) gamesystem.id = cur.lastrowid cur.execute( "insert into gamesystem_emulator (gamesystem_id, emulator_id) values (?, ?)", [gamesystem.id, emulator.id])
def load_emulators(): dblayer.connect() cur.execute("select id, name, path, options from emulator") for r in cur: id, name, path, options = r ei = EmulatorInfo(id, name, path, options) emulator_table[id] = ei cur.execute("select id, name, fileext from gamesystem") for r in cur: id, name, fileext = r gsi = GamesystemInfo(id, name, fileext) gamesystem_table[id] = gsi cur.execute("select gamesystem_id, emulator_id from gamesystem_emulator") for r in cur: gsid, eid = r gamesystem_table[gsid].emu_id = eid emulator_table[eid].system_id = gsid