def onClick(self, controlID): if (controlID == 5101): # Close window button self.close() elif (controlID == 5110): # Import games self.close() self.gui.updateDB() elif (controlID == 5121): # Rescrape single games self.close() if(self.selectedGame == None or self.gameRow == None): xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(35013), util.localize(35014)) return romCollectionId = self.gameRow[util.GAME_romCollectionId] romCollection = self.gui.config.romCollections[str(romCollectionId)] files = File(self.gui.gdb).getRomsByGameId(self.gameRow[util.ROW_ID]) filename = files[0][0] romCollection.romPaths = (filename,) romCollections = {} romCollections[romCollection.id] = romCollection self.gui.rescrapeGames(romCollections) elif (controlID == 5122): # Rescrape selection self.close() romCollections = {} listSize = self.gui.getListSize() for i in range(0, listSize): selectedGame, gameRow = self.gui.getGameByPosition(self.gui.gdb, i) romCollectionId = gameRow[util.GAME_romCollectionId] try: romCollection = romCollections[str(romCollectionId)] except: romCollection = self.gui.config.romCollections[str(romCollectionId)] romCollection.romPaths = [] files = File(self.gui.gdb).getRomsByGameId(gameRow[util.ROW_ID]) filename = files[0][0] romCollection.romPaths.append(filename) romCollections[romCollection.id] = romCollection self.gui.rescrapeGames(romCollections) #self.gui.updateDB() elif (controlID == 5111): # add Rom Collection self.close() statusOk, errorMsg = wizardconfigxml.ConfigXmlWizard().addRomCollection(self.gui.config) if(statusOk == False): xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(35001), errorMsg) Logutil.log('Error updating config.xml: ' +errorMsg, util.LOG_LEVEL_INFO) return #update self.config statusOk, errorMsg = self.gui.config.readXml() if(statusOk == False): xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(35002), errorMsg) Logutil.log('Error reading config.xml: ' +errorMsg, util.LOG_LEVEL_INFO) return #import Games self.gui.updateDB() elif (controlID == 5112): # edit Rom Collection self.close() constructorParam = "720p" editRCdialog = dialogeditromcollection.EditRomCollectionDialog("script-RCB-editromcollection.xml", util.getAddonInstallPath(), "Default", constructorParam, gui=self.gui) del editRCdialog self.gui.config = Config(None) self.gui.config.readXml() elif (controlID == 5117): # edit scraper self.close() constructorParam = "720p" editscraperdialog = dialogeditscraper.EditOfflineScraper("script-RCB-editscraper.xml", util.getAddonInstallPath(), "Default", constructorParam, gui=self.gui) del editscraperdialog self.gui.config = Config(None) self.gui.config.readXml() elif (controlID == 5113): #Edit Game Command self.close() if(self.selectedGame == None or self.gameRow == None): xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(35015), util.localize(35014)) return origCommand = self.gameRow[util.GAME_gameCmd] command = '' romCollectionId = self.gameRow[util.GAME_romCollectionId] romCollection = self.gui.config.romCollections[str(romCollectionId)] if(romCollection.useBuiltinEmulator): success, selectedcore = self.selectlibretrocore(romCollection.name) if success: command = selectedcore else: Logutil.log("No libretro core was chosen. Won't update game command.", util.LOG_LEVEL_INFO) return else: keyboard = xbmc.Keyboard() keyboard.setHeading(util.localize(40035)) if(origCommand != None): keyboard.setDefault(origCommand) keyboard.doModal() if (keyboard.isConfirmed()): command = keyboard.getText() if(command != origCommand): Logutil.log("Updating game '%s' with command '%s'" %(str(self.gameRow[util.ROW_NAME]), command), util.LOG_LEVEL_INFO) Game(self.gui.gdb).update(('gameCmd',), (command,), self.gameRow[util.ROW_ID], True) self.gui.gdb.commit() elif (controlID == 5118): #(Un)Mark as Favorite self.close() if(self.selectedGame == None or self.gameRow == None): xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(35016), util.localize(35014)) return isFavorite = 1 if(self.gameRow[util.GAME_isFavorite] == 1): isFavorite = 0 Logutil.log("Updating game '%s' set isFavorite = %s" %(str(self.gameRow[util.ROW_NAME]), str(isFavorite)), util.LOG_LEVEL_INFO) Game(self.gui.gdb).update(('isFavorite',), (isFavorite,), self.gameRow[util.ROW_ID], True) self.gui.gdb.commit() if(isFavorite == 0): isFavorite = '' self.selectedGame.setProperty('isfavorite', str(isFavorite)) elif (controlID == 5119): #(Un)Mark as Favorite self.close() if(self.selectedGame == None or self.gameRow == None): xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(35016), util.localize(35014)) return isFavorite = 1 if(self.gameRow[util.GAME_isFavorite] == 1): isFavorite = 0 listSize = self.gui.getListSize() for i in range(0, listSize): selectedGame, gameRow = self.gui.getGameByPosition(self.gui.gdb, i) Logutil.log("Updating game '%s' set isFavorite = %s" %(str(gameRow[util.ROW_NAME]), str(isFavorite)), util.LOG_LEVEL_INFO) Game(self.gui.gdb).update(('isFavorite',), (isFavorite,), gameRow[util.ROW_ID], True) selectedGame.setProperty('isfavorite', str(isFavorite)) self.gui.gdb.commit() elif (controlID == 5120): #Export nfo files self.close() nfowriter.NfoWriter().exportLibrary(self.gui) elif (controlID == 5114): #Delete Rom self.close() pos = self.gui.getCurrentListPosition() if(pos == -1): xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(35017), util.localize(35018)) return dialog = xbmcgui.Dialog() if dialog.yesno(util.localize(51010), util.localize(40036)): gameID = self.gui.getGameId(self.gui.gdb,pos) self.gui.deleteGame(gameID) self.gui.showGames() if(pos > 0): pos = pos - 1 self.gui.setFilterSelection(self.gui.CONTROL_GAMES_GROUP_START, pos) else: self.gui.setFilterSelection(self.gui.CONTROL_GAMES_GROUP_START, 0) elif (controlID == 5115): #Remove Rom Collection self.close() constructorParam = "720p" removeRCDialog = dialogdeleteromcollection.RemoveRCDialog("script-RCB-removeRC.xml", util.getAddonInstallPath(), "Default", constructorParam, gui=self.gui) rDelStat = removeRCDialog.getDeleteStatus() if(rDelStat): selectedRCId = removeRCDialog.getSelectedRCId() rcDelStat = removeRCDialog.getRCDeleteStatus() self.gui.deleteRCGames(selectedRCId, rcDelStat, rDelStat) del removeRCDialog elif (controlID == 5116): #Clean DB self.close() self.gui.cleanDB() elif (controlID == 5223): #Open Settings self.close() self.gui.Settings.openSettings()
def insertData(self, gamedescription, gamenameFromFile, romCollection, romFiles, foldername, isUpdate, gameId, gui, isLocalArtwork, dialogDict=''): Logutil.log("Insert data", util.LOG_LEVEL_INFO) publisher = self.resolveParseResult(gamedescription, 'Publisher') developer = self.resolveParseResult(gamedescription, 'Developer') year = self.resolveParseResult(gamedescription, 'ReleaseYear') yearId = self.insertForeignKeyItem(gamedescription, 'ReleaseYear', Year(self.gdb)) genreIds = self.insertForeignKeyItemList(gamedescription, 'Genre', Genre(self.gdb)) reviewerId = self.insertForeignKeyItem(gamedescription, 'Reviewer', Reviewer(self.gdb)) publisherId = -1 developerId = -1 #read current properties for local artwork scraper if(not isLocalArtwork): publisherId = self.insertForeignKeyItem(gamedescription, 'Publisher', Publisher(self.gdb)) developerId = self.insertForeignKeyItem(gamedescription, 'Developer', Developer(self.gdb)) else: gameRow = Game(self.gdb).getObjectById(gameId) if(gameRow != None): publisherId = gameRow[GAME_publisherId] publisherRow = Publisher(self.gdb).getObjectById(gameId) if(publisherRow != None): publisher = publisherRow[util.ROW_NAME] developerId = gameRow[GAME_developerId] developerRow = Developer(self.gdb).getObjectById(gameId) if(developerRow != None): developer = developerRow[util.ROW_NAME] region = self.resolveParseResult(gamedescription, 'Region') media = self.resolveParseResult(gamedescription, 'Media') controller = self.resolveParseResult(gamedescription, 'Controller') players = self.resolveParseResult(gamedescription, 'Players') rating = self.resolveParseResult(gamedescription, 'Rating') votes = self.resolveParseResult(gamedescription, 'Votes') url = self.resolveParseResult(gamedescription, 'URL') perspective = self.resolveParseResult(gamedescription, 'Perspective') originalTitle = self.resolveParseResult(gamedescription, 'OriginalTitle') alternateTitle = self.resolveParseResult(gamedescription, 'AlternateTitle') translatedBy = self.resolveParseResult(gamedescription, 'TranslatedBy') version = self.resolveParseResult(gamedescription, 'Version') plot = self.resolveParseResult(gamedescription, 'Description') isFavorite = self.resolveParseResult(gamedescription, 'IsFavorite') if(isFavorite == ''): isFavorite = '0' launchCount = self.resolveParseResult(gamedescription, 'LaunchCount') if(launchCount == ''): launchCount = '0' if(gamedescription != None): gamename = self.resolveParseResult(gamedescription, 'Game') if(gamename != gamenameFromFile): try: self.possibleMismatchFile.write('%s, %s\n' %(gamename, gamenameFromFile)) except: self.possibleMismatchFile.write('%s, %s\n' %(gamename.encode('utf-8'), gamenameFromFile.encode('utf-8'))) if(gamename == ""): gamename = gamenameFromFile else: gamename = gamenameFromFile artWorkFound, artworkfiles, artworkurls = self.getArtworkForGame(romCollection, gamename, gamenameFromFile, gamedescription, gui, dialogDict, foldername, publisher, developer, isLocalArtwork) if(not artWorkFound): ignoreGamesWithoutArtwork = self.Settings.getSetting(util.SETTING_RCB_IGNOREGAMEWITHOUTARTWORK).upper() == 'TRUE' if(ignoreGamesWithoutArtwork): Logutil.log('No artwork found for game "%s". Game will not be imported.' %gamenameFromFile, util.LOG_LEVEL_WARNING) try: self.missingArtworkFile.write('--> No artwork found for game "%s". Game will not be imported.\n' %gamename) except: self.missingArtworkFile.write('--> No artwork found for game "%s". Game will not be imported.\n' %gamename.encode('utf-8')) return None, True #create Nfo file with game properties createNfoFile = self.Settings.getSetting(util.SETTING_RCB_CREATENFOFILE).upper() == 'TRUE' if(createNfoFile and gamedescription != None): genreList = [] try: genreList = gamedescription['Genre'] except: pass nfowriter.NfoWriter().createNfoFromDesc(gamename, plot, romCollection.name, publisher, developer, year, players, rating, votes, url, region, media, perspective, controller, originalTitle, alternateTitle, version, genreList, isFavorite, launchCount, romFiles[0], gamenameFromFile, artworkfiles, artworkurls) if(not isLocalArtwork): gameId = self.insertGame(gamename, plot, romCollection.id, publisherId, developerId, reviewerId, yearId, players, rating, votes, url, region, media, perspective, controller, originalTitle, alternateTitle, translatedBy, version, isFavorite, launchCount, isUpdate, gameId, romCollection.allowUpdate, ) if(gameId == None): return None, True for genreId in genreIds: genreGame = GenreGame(self.gdb).getGenreGameByGenreIdAndGameId(genreId, gameId) if(genreGame == None): GenreGame(self.gdb).insert((genreId, gameId)) for romFile in romFiles: fileType = FileType() fileType.id = 0 fileType.name = "rcb_rom" fileType.parent = "game" self.insertFile(romFile, gameId, fileType, None, None, None) Logutil.log("Importing files: " +str(artworkfiles), util.LOG_LEVEL_INFO) for fileType in artworkfiles.keys(): for fileName in artworkfiles[fileType]: self.insertFile(fileName, gameId, fileType, romCollection.id, publisherId, developerId) self.gdb.commit() return gameId, True
def onClick(self, controlID): if controlID == 5101: # Close window button self.close() elif controlID == 5110: # Import games self.close() self.gui.updateDB() elif controlID == 5121: # Rescrape single games self.close() if self.selectedGame is None: xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(32013), util.localize(32014)) return romCollectionId = self.selectedGame.getProperty('romCollectionId') romCollection = self.gui.config.romCollections[str(romCollectionId)] files = File(self.gui.gdb).getRomsByGameId(self.selectedGame.getProperty('gameId')) filename = files[0][0] romCollection.romPaths = (filename,) romCollections = {} romCollections[romCollection.id] = romCollection self.gui.rescrapeGames(romCollections) elif controlID == 5122: # Rescrape selection self.close() romCollections = {} listSize = self.gui.getListSize() for i in range(0, listSize): listItem = self.gui.getListItem(i) romCollectionId = listItem.getProperty('romCollectionId') try: romCollection = romCollections[str(romCollectionId)] except: romCollection = self.gui.config.romCollections[str(romCollectionId)] romCollection.romPaths = [] files = File(self.gui.gdb).getRomsByGameId(listItem.getProperty('gameId')) try: filename = files[0][0] romCollection.romPaths.append(filename) romCollections[romCollection.id] = romCollection except: log.info("Error getting filename for romCollectionId: {0}".format(romCollectionId)) self.gui.rescrapeGames(romCollections) #self.gui.updateDB() elif controlID == 5111: # Add Rom Collection self.close() statusOk, errorMsg = wizardconfigxml.ConfigXmlWizard().addRomCollection(self.gui.config) if statusOk is False: xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(32001), errorMsg) log.info("Error updating config.xml: {0}".format(errorMsg)) return #update self.config statusOk, errorMsg = self.gui.config.readXml() if statusOk is False: xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(32002), errorMsg) log.info("Error reading config.xml: {0}".format(errorMsg)) return #import Games self.gui.updateDB() elif controlID == 5112: # Edit Rom Collection self.close() constructorParam = "720p" editRCdialog = dialogeditromcollection.EditRomCollectionDialog("script-RCB-editromcollection.xml", util.getAddonInstallPath(), util.getConfiguredSkin(), constructorParam, gui=self.gui) del editRCdialog self.gui.config = Config(None) self.gui.config.readXml() elif controlID == 5113: # Edit Game Command self.close() if(self.selectedGame == None): xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(32015), util.localize(32014)) return origCommand = self.selectedGame.getProperty('gameCmd') command = xbmcgui.Dialog().input(util.localize(32135), defaultt=origCommand, type=xbmcgui.INPUT_ALPHANUM) if command != origCommand: log.info("Updating game '{0}' with command '{1}'".format(self.selectedGame.getLabel(), command)) Game(self.gui.gdb).update(('gameCmd',), (command,), self.selectedGame.getProperty('gameId'), True) self.gui.gdb.commit() elif controlID == 5118: # (Un)Mark as Favorite self.close() if self.selectedGame is None: xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(32016), util.localize(32014)) return isFavorite = '1' if self.selectedGame.getProperty('isfavorite') == '1': isFavorite = '0' log.info("Updating game '{0}' set isFavorite = {1}".format(self.selectedGame.getLabel(), isFavorite)) Game(self.gui.gdb).update(('isfavorite',), (isFavorite,), self.selectedGame.getProperty('gameId'), True) self.gui.gdb.commit() if isFavorite == '0': isFavorite = '' self.selectedGame.setProperty('isfavorite', str(isFavorite)) elif controlID == 5119: # (Un)Mark as Favorite self.close() if self.selectedGame is None: xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(32016), util.localize(32014)) return isFavorite = '1' if self.selectedGame.getProperty('isfavorite') == '1': isFavorite = '0' listSize = self.gui.getListSize() for i in range(0, listSize): listItem = self.gui.getListItem(i) log.info("Updating game '{0}' set isfavorite = {1}".format(listItem.getLabel(), isFavorite)) Game(self.gui.gdb).update(('isfavorite',), (isFavorite,), listItem.getProperty('gameId'), True) listItem.setProperty('isfavorite', str(isFavorite)) self.gui.gdb.commit() #HACK: removing favorites does not update the UI. So do it manually. if isFavorite == 0: self.gui.loadViewState() elif controlID == 5120: # Export nfo files self.close() nfowriter.NfoWriter().exportLibrary(self.gui.gdb, self.gui.config.romCollections) elif controlID == 5114: # Delete Rom self.close() pos = self.gui.getCurrentListPosition() if pos == -1: xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(32017), util.localize(32018)) return dialog = xbmcgui.Dialog() if dialog.yesno(util.localize(32510), util.localize(32136)): gameID = self.selectedGame.getProperty('gameId') self.gui.deleteGame(gameID) self.gui.showGames() if pos > 0: pos = pos - 1 self.gui.setFilterSelection(self.gui.CONTROL_GAMES_GROUP_START, pos) else: self.gui.setFilterSelection(self.gui.CONTROL_GAMES_GROUP_START, 0) elif controlID == 5115: # Remove Rom Collection self.close() constructorParam = "720p" removeRCDialog = dialogdeleteromcollection.RemoveRCDialog("script-RCB-removeRC.xml", util.getAddonInstallPath(), util.getConfiguredSkin(), constructorParam, gui=self.gui) rDelStat = removeRCDialog.getDeleteStatus() if rDelStat: selectedRCId = removeRCDialog.getSelectedRCId() rcDelStat = removeRCDialog.getRCDeleteStatus() self.gui.deleteRCGames(selectedRCId, rcDelStat, rDelStat) del removeRCDialog elif controlID == 5116: # Clean DB self.close() self.gui.cleanDB() elif controlID == 5223: # Open Settings self.close() self.gui.Settings.openSettings() elif controlID == 5224: # Set gameclient self.close() if not helper.isRetroPlayerSupported(): log.info("This RetroPlayer branch does not support selecting gameclients.") return if self.selectedGame is None or self.gameRow is None: xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(32015), util.localize(32014)) return #HACK: use alternateGameCmd to store gameclient information origGameClient = self.selectedGame.getProperty('alternateGameCmd') gameclient = '' romCollectionId = self.selectedGame.getProperty('romCollectionId') romCollection = self.gui.config.romCollections[str(romCollectionId)] success, selectedcore = helper.selectlibretrocore(romCollection.name) if success: gameclient = selectedcore else: log.info("No libretro core was chosen. Won't update game command.") return if gameclient != origGameClient: log.info("Updating game '{0}' with gameclient '{1}'".format(self.selectedGame.getLabel(), gameclient)) Game(self.gui.gdb).update(('alternateGameCmd',), (gameclient,), self.selectedGame.getProperty('gameId'), True) self.gui.gdb.commit()