def __copyLauncherScriptsToUserdata(self): log.info('__copyLauncherScriptsToUserdata') oldBasePath = os.path.join(util.getAddonInstallPath(), 'resources', 'scriptfiles') newBasePath = os.path.join(util.getAddonDataPath(), 'scriptfiles') files = [] # Copy applaunch shell script/batch file if self.env == 'win32': files.append('applaunch.bat') else: files.append('applaunch.sh') # Copy VBS files if self.env == 'win32' and __addon__.getSetting( util.SETTING_RCB_USEVBINSOLOMODE).lower() == 'true': files += ['applaunch-vbs.bat', 'LaunchKodi.vbs', 'Sleep.vbs'] for f in files: if not xbmcvfs.exists(os.path.join(newBasePath, f)): log.debug("Copying file {0} from {1} to {2}".format( f, oldBasePath, newBasePath)) if not xbmcvfs.copy(os.path.join(oldBasePath, f), os.path.join(newBasePath, f)): log.warn("Error copying file")
def createXboxCutFile(emuCommandLine, filenameRows, romCollection): Logutil.log("Begin launcher.createXboxCutFile", util.LOG_LEVEL_INFO) cutFile = os.path.join(util.getAddonDataPath(), 'temp.cut') # Write new temp.cut try: fh = open(cutFile,'w') # truncate to 0 fh.write("<shortcut>\n") fh.write("<path>%s</path>\n" %emuCommandLine) if (romCollection.xboxCreateShortcutAddRomfile): filename = getRomfilenameForXboxCutfile(filenameRows, romCollection) if(filename == ""): return "" fh.write("<custom>\n") fh.write("<game>%s</game>\n" %filename) fh.write("</custom>\n") fh.write("</shortcut>\n") fh.write("\n") fh.close() except Exception, (exc): Logutil.log("Cannot write to temp.cut: " +str(exc), util.LOG_LEVEL_ERROR) return ""
def copyLauncherScriptsToUserdata(settings): Logutil.log('copyLauncherScriptsToUserdata', util.LOG_LEVEL_INFO) oldBasePath = os.path.join(util.getAddonInstallPath(), 'resources', 'scriptfiles') newBasePath = os.path.join(util.getAddonDataPath(), 'scriptfiles') if (util.getEnvironment() == 'win32'): oldPath = os.path.join(oldBasePath, 'applaunch.bat') newPath = os.path.join(newBasePath, 'applaunch.bat') else: oldPath = os.path.join(oldBasePath, 'applaunch.sh') newPath = os.path.join(newBasePath, 'applaunch.sh') util.copyFile(oldPath, newPath) #copy VBS files if (util.getEnvironment() == 'win32' and settings.getSetting( util.SETTING_RCB_USEVBINSOLOMODE).lower() == 'true'): oldPath = os.path.join(oldBasePath, 'applaunch-vbs.bat') newPath = os.path.join(newBasePath, 'applaunch-vbs.bat') util.copyFile(oldPath, newPath) oldPath = os.path.join(oldBasePath, 'LaunchXBMC.vbs') newPath = os.path.join(newBasePath, 'LaunchXBMC.vbs') util.copyFile(oldPath, newPath) oldPath = os.path.join(oldBasePath, 'Sleep.vbs') newPath = os.path.join(newBasePath, 'Sleep.vbs') util.copyFile(oldPath, newPath)
def copyLauncherScriptsToUserdata(settings): Logutil.log('copyLauncherScriptsToUserdata', util.LOG_LEVEL_INFO) oldBasePath = os.path.join(util.getAddonInstallPath(), 'resources', 'scriptfiles') newBasePath = os.path.join(util.getAddonDataPath(), 'scriptfiles') if(util.getEnvironment() == 'win32'): oldPath = os.path.join(oldBasePath, 'applaunch.bat') newPath = os.path.join(newBasePath, 'applaunch.bat') else: oldPath = os.path.join(oldBasePath, 'applaunch.sh') newPath = os.path.join(newBasePath, 'applaunch.sh') util.copyFile(oldPath, newPath) #copy VBS files if(util.getEnvironment() == 'win32' and settings.getSetting(util.SETTING_RCB_USEVBINSOLOMODE).lower() == 'true'): oldPath = os.path.join(oldBasePath, 'applaunch-vbs.bat') newPath = os.path.join(newBasePath, 'applaunch-vbs.bat') util.copyFile(oldPath, newPath) oldPath = os.path.join(oldBasePath, 'LaunchXBMC.vbs') newPath = os.path.join(newBasePath, 'LaunchXBMC.vbs') util.copyFile(oldPath, newPath) oldPath = os.path.join(oldBasePath, 'Sleep.vbs') newPath = os.path.join(newBasePath, 'Sleep.vbs') util.copyFile(oldPath, newPath)
def runUpdate(): xbmc.log('RCB: runUpdate') gdb = GameDataBase(util.getAddonDataPath()) gdb.connect() #create db if not existent and maybe update to new version gdb.checkDBStructure() configFile = config.Config(None) configFile.readXml() selectedRomCollection = '' selectedScraper = '' xbmc.log('RCB: parameters = %s' % sys.argv) for arg in sys.argv: param = str(arg) xbmc.log('RCB: param = %s' % param) if 'selectedRomCollection' in param: selectedRomCollection = param.replace('selectedRomCollection=', '') if 'selectedScraper' in param: selectedScraper = param.replace('selectedScraper=', '') romCollections = configFile.romCollections if selectedRomCollection and selectedScraper: romCollections = prepareRomCollections(configFile, selectedRomCollection, selectedScraper) progress = ProgressDialogBk() progress.create('Rom Collection Browser', 'Update DB') with HandleAbort(): dbupdate.DBUpdate().updateDB(gdb, progress, romCollections, False) progress.close()
def backupAutoexec(gdb, fName): Logutil.log("Begin launcher.backupAutoexec", util.LOG_LEVEL_INFO) if os.path.isfile(fName): newFileName = os.path.join(util.getAddonDataPath(), 'autoexec.py.bak') if os.path.isfile(newFileName): Logutil.log("Cannot backup autoexec.py: File exists.", util.LOG_LEVEL_ERROR) return try: os.rename(fName, newFileName) except Exception, (exc): Logutil.log("Cannot rename autoexec.py: " + str(exc), util.LOG_LEVEL_ERROR) return rcbSetting = helper.getRCBSetting(gdb) if (rcbSetting == None): Logutil.log("rcbSetting == None in backupAutoexec", util.LOG_LEVEL_WARNING) return RCBSetting(gdb).update(('autoexecBackupPath', ), (newFileName, ), rcbSetting[util.ROW_ID], True) gdb.commit()
def prepare_solomode(self, romCollection, cmd): # solo mode if romCollection.useEmuSolo: self.__copyLauncherScriptsToUserdata() # communicate with service via settings __addon__.setSetting(util.SETTING_RCB_LAUNCHONSTARTUP, 'true') # invoke script file that kills xbmc before launching the emulator basePath = os.path.join(util.getAddonDataPath(), 'scriptfiles') if self.env == "win32": if __addon__.getSetting( util.SETTING_RCB_USEVBINSOLOMODE).lower() == 'true': # There is a problem with quotes passed as argument to windows command shell. This only works with "call" # use vb script to restart xbmc cmd = 'call \"' + os.path.join( basePath, 'applaunch-vbs.bat') + '\" ' + cmd else: # There is a problem with quotes passed as argument to windows command shell. This only works with "call" cmd = 'call \"' + os.path.join( basePath, 'applaunch.bat') + '\" ' + cmd else: cmd = os.path.join(basePath, 'applaunch.sh ') + cmd else: # use call to support paths with whitespaces if self.env == "win32": cmd = 'call ' + cmd return cmd
def createXboxCutFile(emuCommandLine, filenameRows, romCollection): Logutil.log("Begin launcher.createXboxCutFile", util.LOG_LEVEL_INFO) cutFile = os.path.join(util.getAddonDataPath(), 'temp.cut') # Write new temp.cut try: fh = open(cutFile, 'w') # truncate to 0 fh.write("<shortcut>\n") fh.write("<path>%s</path>\n" % emuCommandLine) if (romCollection.xboxCreateShortcutAddRomfile): filename = getRomfilenameForXboxCutfile(filenameRows, romCollection) if (filename == ""): return "" fh.write("<custom>\n") fh.write("<game>%s</game>\n" % filename) fh.write("</custom>\n") fh.write("</shortcut>\n") fh.write("\n") fh.close() except Exception, (exc): Logutil.log("Cannot write to temp.cut: " + str(exc), util.LOG_LEVEL_ERROR) return ""
def backupConfigXml(self): # backup config.xml for later use (will be overwritten in case of an addon update) configXml = util.getConfigXmlPath() configXmlBackup = os.path.join(util.getAddonDataPath(), 'config.xml.backup') if xbmcvfs.exists(configXmlBackup): try: xbmcvfs.delete(configXmlBackup) except Exception, (exc): Logutil.log("Cannot remove config.xml backup: " + str(exc), util.LOG_LEVEL_ERROR) return
def backupConfigXml(self): # backup config.xml for later use (will be overwritten in case of an addon update) configXml = util.getConfigXmlPath() configXmlBackup = os.path.join(util.getAddonDataPath(), 'config.xml.backup') if xbmcvfs.exists(configXmlBackup): try: xbmcvfs.delete(configXmlBackup) except Exception, (exc): Logutil.log("Cannot remove config.xml backup: " + str(exc), util.LOG_LEVEL_ERROR) return
def launchGame(self, param): import launcher, util from gamedatabase import GameDataBase from config import Config gdb = GameDataBase(util.getAddonDataPath()) gdb.connect() gameId = int(param.replace('launchid=', '')) config = Config(None) statusOk, errorMsg = config.readXml() settings = util.getSettings() gui = dummyGUI() launcher.launchEmu(gdb, gui, gameId, config, settings, None)
def openDbConnection(self): xbmc.log('RCB widget: openDbConnection') gdb = GameDataBase(util.getAddonDataPath()) gdb.connect() doImport, errorMsg = gdb.checkDBStructure() if (doImport) > 0: xbmc.log( "RCB widget: No database available. Won't gather any data.") gdb.close() return elif (doImport < 0): xbmc.log( "RCB widget: Error occured while checking db structure: {0}" % errorMsg) return gdb
def launchGame(self, param): import util from launcher import RCBLauncher from gamedatabase import GameDataBase from config import Config gdb = GameDataBase(util.getAddonDataPath()) gdb.connect() #HACK if invoked from widget addon there is an additional ? in param param = param.replace('?', '') gameId = int(param.replace('launchid=', '')) config = Config(None) config.readXml() gui = dummyGUI() RCBLauncher().launchEmu(gdb, gui, gameId, config, None)
def launchGame(self, param): import util from launcher import RCBLauncher from gamedatabase import GameDataBase from config import Config gdb = GameDataBase(util.getAddonDataPath()) gdb.connect() #HACK if invoked from widget addon there is an additional ? in param param = param.replace('?', '') gameId = int(param.replace('launchid=', '')) config = Config(None) statusOk, errorMsg = config.readXml() gui = dummyGUI() RCBLauncher().launchEmu(gdb, gui, gameId, config, None)
def __copyLauncherScriptsToUserdata(self): log.info('__copyLauncherScriptsToUserdata') oldBasePath = os.path.join(util.getAddonInstallPath(), 'resources', 'scriptfiles') newBasePath = os.path.join(util.getAddonDataPath(), 'scriptfiles') files = [] # Copy applaunch shell script/batch file if self.env == 'win32': files.append('applaunch.bat') else: files.append('applaunch.sh') # Copy VBS files if self.env == 'win32' and __addon__.getSetting(util.SETTING_RCB_USEVBINSOLOMODE).lower() == 'true': files += ['applaunch-vbs.bat', 'LaunchKodi.vbs', 'Sleep.vbs'] for f in files: if not xbmcvfs.exists(os.path.join(newBasePath, f)): log.debug("Copying file {0} from {1} to {2}".format(f, oldBasePath, newBasePath)) if not xbmcvfs.copy(os.path.join(oldBasePath, f), os.path.join(newBasePath, f)): log.warn("Error copying file")
def backupAutoexec(gdb, fName): Logutil.log("Begin launcher.backupAutoexec", util.LOG_LEVEL_INFO) if os.path.isfile(fName): newFileName = os.path.join(util.getAddonDataPath(), 'autoexec.py.bak') if os.path.isfile(newFileName): Logutil.log("Cannot backup autoexec.py: File exists.", util.LOG_LEVEL_ERROR) return try: os.rename(fName, newFileName) except Exception, (exc): Logutil.log("Cannot rename autoexec.py: " +str(exc), util.LOG_LEVEL_ERROR) return rcbSetting = helper.getRCBSetting(gdb) if (rcbSetting == None): Logutil.log("rcbSetting == None in backupAutoexec", util.LOG_LEVEL_WARNING) return RCBSetting(gdb).update(('autoexecBackupPath',), (newFileName,), rcbSetting[util.ROW_ID], True) gdb.commit()
def launchEmu(gdb, gui, gameId, config, settings, listitem): Logutil.log("Begin launcher.launchEmu", util.LOG_LEVEL_INFO) gameRow = Game(gdb).getObjectById(gameId) if (gameRow == None): Logutil.log("Game with id %s could not be found in database" % gameId, util.LOG_LEVEL_ERROR) return romCollection = None try: romCollection = config.romCollections[str( gameRow[util.GAME_romCollectionId])] except: Logutil.log( 'Cannot get rom collection with id: ' + str(gameRow[util.GAME_romCollectionId]), util.LOG_LEVEL_ERROR) gui.writeMsg(util.localize(32034)) return gui.writeMsg(util.localize(32163) + " " + gameRow[util.ROW_NAME]) # Remember viewstate gui.saveViewState(False) cmd = "" precmd = "" postcmd = "" #get environment OS env = util.getEnvironment() filenameRows = File(gdb).getRomsByGameId(gameRow[util.ROW_ID]) Logutil.log("files for current game: " + str(filenameRows), util.LOG_LEVEL_INFO) escapeCmd = settings.getSetting( util.SETTING_RCB_ESCAPECOMMAND).upper() == 'TRUE' cmd, precmd, postcmd, roms = buildCmd(filenameRows, romCollection, gameRow, escapeCmd, False) if (not romCollection.useBuiltinEmulator): if (cmd == ''): Logutil.log('No cmd created. Game will not be launched.', util.LOG_LEVEL_INFO) return if (precmd.strip() == '' or precmd.strip() == 'call'): Logutil.log('No precmd created.', util.LOG_LEVEL_INFO) if (postcmd.strip() == '' or postcmd.strip() == 'call'): Logutil.log('No postcmd created.', util.LOG_LEVEL_INFO) #solo mode if (romCollection.useEmuSolo): copyLauncherScriptsToUserdata(settings) #check if we should use xbmc.service (Eden) or autoexec.py (Dharma) if (not gui.useRCBService): #try to create autoexec.py writeAutoexec(gdb) else: #communicate with service via settings settings.setSetting(util.SETTING_RCB_LAUNCHONSTARTUP, 'true') #invoke script file that kills xbmc before launching the emulator basePath = os.path.join(util.getAddonDataPath(), 'scriptfiles') #xbmc needs other script files than kodi xbmcFilenameSuffix = "_xbmc" if KodiVersions().getKodiVersion() >= KodiVersions.HELIX: xbmcFilenameSuffix = "" if (env == "win32"): if (settings.getSetting( util.SETTING_RCB_USEVBINSOLOMODE).lower() == 'true'): #There is a problem with quotes passed as argument to windows command shell. This only works with "call" #use vb script to restart xbmc cmd = 'call \"' + os.path.join( basePath, 'applaunch-vbs%s.bat' % xbmcFilenameSuffix) + '\" ' + cmd else: #There is a problem with quotes passed as argument to windows command shell. This only works with "call" cmd = 'call \"' + os.path.join( basePath, 'applaunch%s.bat' % xbmcFilenameSuffix) + '\" ' + cmd else: cmd = os.path.join( basePath, 'applaunch%s.sh ' % xbmcFilenameSuffix) + cmd else: #use call to support paths with whitespaces if (env == "win32" and not (os.environ.get("OS", "xbox") == "xbox")): cmd = 'call ' + cmd #update LaunchCount launchCount = gameRow[util.GAME_launchCount] Game(gdb).update(('launchCount', ), (launchCount + 1, ), gameRow[util.ROW_ID], True) gdb.commit() Logutil.log("cmd: " + cmd, util.LOG_LEVEL_INFO) Logutil.log("precmd: " + precmd, util.LOG_LEVEL_INFO) Logutil.log("postcmd: " + postcmd, util.LOG_LEVEL_INFO) try: if (os.environ.get("OS", "xbox") == "xbox"): launchXbox(gui, gdb, cmd, romCollection, filenameRows) else: launchNonXbox(cmd, romCollection, gameRow, settings, precmd, postcmd, roms, gui, listitem) gui.writeMsg("") except Exception, (exc): Logutil.log("Error while launching emu: " + str(exc), util.LOG_LEVEL_ERROR) gui.writeMsg(util.localize(32035) + ": " + str(exc))
def logfile_dir(self): return util.getAddonDataPath()
def launchEmu(self, gdb, gui, gameId, config, listitem): log.info("Begin launcher.launchEmu") gameRow = Game(gdb).getObjectById(gameId) if gameRow is None: log.error("Game with id %s could not be found in database" % gameId) return try: self.romCollection = config.romCollections[str(gameRow[util.GAME_romCollectionId])] except KeyError: log.error("Cannot get rom collection with id: " + str(gameRow[util.GAME_romCollectionId])) gui.writeMsg(util.localize(32034)) return gui.writeMsg(util.localize(32163) + " " + gameRow[util.ROW_NAME]) # Remember viewstate gui.saveViewState(False) cmd = "" precmd = "" postcmd = "" filenameRows = File(gdb).getRomsByGameId(gameRow[util.ROW_ID]) log.info("files for current game: " + str(filenameRows)) cmd, precmd, postcmd, roms = self.__buildCmd(gui, filenameRows, gameRow, False) if not self.romCollection.useBuiltinEmulator: if cmd == '': log.info("No cmd created. Game will not be launched.") return if precmd.strip() == '' or precmd.strip() == 'call': log.info("No precmd created.") if postcmd.strip() == '' or postcmd.strip() == 'call': log.info("No postcmd created.") # solo mode if self.romCollection.useEmuSolo: self.__copyLauncherScriptsToUserdata() # communicate with service via settings __addon__.setSetting(util.SETTING_RCB_LAUNCHONSTARTUP, 'true') # invoke script file that kills xbmc before launching the emulator basePath = os.path.join(util.getAddonDataPath(), 'scriptfiles') if self.env == "win32": if __addon__.getSetting(util.SETTING_RCB_USEVBINSOLOMODE).lower() == 'true': # There is a problem with quotes passed as argument to windows command shell. This only works with "call" # use vb script to restart xbmc cmd = 'call \"' + os.path.join(basePath, 'applaunch-vbs.bat') + '\" ' + cmd else: # There is a problem with quotes passed as argument to windows command shell. This only works with "call" cmd = 'call \"' + os.path.join(basePath, 'applaunch.bat') + '\" ' + cmd else: cmd = os.path.join(basePath, 'applaunch.sh ') + cmd else: # use call to support paths with whitespaces if self.env == "win32": cmd = 'call ' + cmd # update LaunchCount launchCount = gameRow[util.GAME_launchCount] Game(gdb).update(('launchCount',), (launchCount + 1,), gameRow[util.ROW_ID], True) gdb.commit() log.info("cmd: " + cmd) log.info("precmd: " + precmd) log.info("postcmd: " + postcmd) try: self.__launchNonXbox(cmd, gameRow, precmd, postcmd, roms, gui, listitem) gui.writeMsg("") except Exception, (exc): log.error("Error while launching emu: " + str(exc)) gui.writeMsg(util.localize(32035) + ": " + str(exc))
def gatherWidgetData(self, param): xbmc.log('start gatherWidgetData') import util, helper from gamedatabase import Game, GameDataBase, File from config import Config gdb = GameDataBase(util.getAddonDataPath()) gdb.connect() doImport, errorMsg = gdb.checkDBStructure() if (doImport) > 0: xbmc.log("RCB: No database available. Won't gather any data.") gdb.close() return elif (doImport < 0): xbmc.log("RCB: Error occured while checking db structure: {0}" % errorMsg) limit = param.replace('limit=', '') query = 'Select * From GameView Where launchCount > 0 Order by launchCount desc Limit %s;' % str( limit) games = Game(gdb).getGamesByQueryNoArgs(query) xbmc.log('most played games: %s' % games) config = Config(None) statusOk, errorMsg = config.readXml() if (not statusOk): xbmc.log('RCB: Error reading config.xml: {0}' % errorMsg) return mediaDict = {} mediaDict = helper.cacheMediaPathsForSelection(0, mediaDict, config) import xbmcgui count = 0 for game in games: count += 1 try: xbmc.log("RCB widget: Gathering data for rom no %i: %s" % (count, game.name)) romCollection = config.romCollections[str( game.romCollectionId)] gamenameFromFile = romCollection.getGamenameFromFilename( game.firstRom) mediaPathsDict = mediaDict[str(game.romCollectionId)] #get artwork that is chosen to be shown in gamelist thumb = helper.getFileForControl( romCollection.imagePlacingMain.fileTypesForGameList, romCollection, mediaPathsDict, gamenameFromFile, False) fanart = helper.getFileForControl( romCollection.imagePlacingMain. fileTypesForMainViewBackground, romCollection, mediaPathsDict, gamenameFromFile, False) url = "plugin://script.games.rom.collection.browser/?launchid=%s" % game.id xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Id" % count, str(game.id)) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Console" % count, romCollection.name) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Title" % count, game.name) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Thumb" % count, thumb) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Fanart" % count, fanart) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Plot" % count, game.plot) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Year" % count, game.year) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Publisher" % count, game.publisher) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Developer" % count, game.developer) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Genre" % count, game.genre) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Maxplayers" % count, game.maxplayers) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Region" % count, game.region) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Media" % count, game.media) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Perspective" % count, game.perspective) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Controllertype" % count, game.controllertype) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Playcount" % count, game.playcount) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Rating" % count, game.rating) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Votes" % count, game.votes) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Url" % count, url) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Originaltitle" % count, game.originalTitle) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Alternatetitle" % count, game.alternateTitle) xbmcgui.Window(10000).setProperty( "MostPlayedROM.%d.Version" % count, game.version) except Exception, (exc): xbmc.log('RCB: Error while getting most played games: ' + str(exc))
def gatherWidgetData(self, param): print 'start gatherWidgetData' import util, helper from gamedatabase import Game, GameDataBase, File from config import Config, RomCollection gdb = GameDataBase(util.getAddonDataPath()) gdb.connect() doImport, errorMsg = gdb.checkDBStructure() if(doImport) > 0: print "RCB: No database available. Won't gather any data." gdb.close() return #cache lookup tables yearDict = helper.cacheYears(gdb) publisherDict = helper.cachePublishers(gdb) developerDict = helper.cacheDevelopers(gdb) reviewerDict = helper.cacheReviewers(gdb) genreDict = helper.cacheGenres(gdb) limit = int(param.replace('limit=', '')) games = Game(gdb).getMostPlayedGames(limit) print 'most played games: %s' %games config = Config(None) statusOk, errorMsg = config.readXml() settings = util.getSettings() import xbmcgui count = 0 for gameRow in games: count += 1 try: print "Gathering data for rom no %i: %s" %(count, gameRow[util.ROW_NAME]) romCollection = config.romCollections[str(gameRow[util.GAME_romCollectionId])] #get artwork that is chosen to be shown in gamelist files = File(gdb).getFilesByParentIds(gameRow[util.ROW_ID], gameRow[util.GAME_romCollectionId], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId]) fileDict = helper.cacheFiles(files) files = helper.getFilesByControl_Cached(gdb, romCollection.imagePlacingMain.fileTypesForGameList, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict) if(files != None and len(files) != 0): thumb = files[0] else: thumb = "" files = helper.getFilesByControl_Cached(gdb, romCollection.imagePlacingMain.fileTypesForMainViewBackground, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict) if(files != None and len(files) != 0): fanart = files[0] else: fanart = "" description = gameRow[util.GAME_description] if(description == None): description = "" year = helper.getPropertyFromCache(gameRow, yearDict, util.GAME_yearId, util.ROW_NAME) publisher = helper.getPropertyFromCache(gameRow, publisherDict, util.GAME_publisherId, util.ROW_NAME) developer = helper.getPropertyFromCache(gameRow, developerDict, util.GAME_developerId, util.ROW_NAME) genre = genreDict[gameRow[util.ROW_ID]] maxplayers = helper.saveReadString(gameRow[util.GAME_maxPlayers]) rating = helper.saveReadString(gameRow[util.GAME_rating]) votes = helper.saveReadString(gameRow[util.GAME_numVotes]) url = helper.saveReadString(gameRow[util.GAME_url]) region = helper.saveReadString(gameRow[util.GAME_region]) media = helper.saveReadString(gameRow[util.GAME_media]) perspective = helper.saveReadString(gameRow[util.GAME_perspective]) controllertype = helper.saveReadString(gameRow[util.GAME_controllerType]) originaltitle = helper.saveReadString(gameRow[util.GAME_originalTitle]) alternatetitle = helper.saveReadString(gameRow[util.GAME_alternateTitle]) translatedby = helper.saveReadString(gameRow[util.GAME_translatedBy]) version = helper.saveReadString(gameRow[util.GAME_version]) playcount = helper.saveReadString(gameRow[util.GAME_launchCount]) #get launch command filenameRows = File(gdb).getRomsByGameId(gameRow[util.ROW_ID]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Id" %count, str(gameRow[util.ROW_ID])) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Console" %count, romCollection.name) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Title" %count, gameRow[util.ROW_NAME]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Thumb" %count, thumb) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Fanart" %count, fanart) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Plot" %count, description) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Year" %count, year) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Publisher" %count, publisher) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Developer" %count, developer) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Genre" %count, genre) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Maxplayers" %count, maxplayers) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Region" %count, region) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Media" %count, media) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Perspective" %count, perspective) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Controllertype" %count, controllertype) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Playcount" %count, playcount) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Rating" %count, rating) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Votes" %count, votes) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Url" %count, url) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Originaltitle" %count, originaltitle) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Alternatetitle" %count, alternatetitle) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Translatedby" %count, translatedby) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Version" %count, version) except Exception, (exc): print 'RCB: Error while getting most played games: ' +str(exc)
def gatherWidgetData(self, param): xbmc.log('start gatherWidgetData') import util, helper from gamedatabase import DataBaseObject, GameView, GameDataBase from config import Config gdb = GameDataBase(util.getAddonDataPath()) gdb.connect() doImport, errorMsg = gdb.checkDBStructure() if (doImport) > 0: xbmc.log("RCB: No database available. Won't gather any data.") gdb.close() return elif (doImport < 0): xbmc.log("RCB: Error occured while checking db structure: {0}" % errorMsg) limit = param.replace('limit=', '') query = 'Select * From GameView Where launchCount > 0 Order by launchCount desc Limit %s;' % str(limit) games = GameView(gdb).getGamesByQueryNoArgs(query) xbmc.log('most played games: %s' % games) config = Config(None) statusOk, errorMsg = config.readXml() if (not statusOk): xbmc.log('RCB: Error reading config.xml: {0}' % errorMsg) return import xbmcgui count = 0 for game in games: count += 1 try: xbmc.log("RCB widget: Gathering data for rom no %i: %s" % (count, game[GameView.COL_NAME])) romCollection = config.romCollections[str(game[GameView.COL_romCollectionId])] #get artwork that is chosen to be shown in gamelist thumb = helper.get_file_for_control_from_db( romCollection.imagePlacingMain.fileTypesForGameList, game) fanart = helper.get_file_for_control_from_db( romCollection.imagePlacingMain.fileTypesForMainViewBackground, game) url = "plugin://script.games.rom.collection.browser/?launchid=%s" % game[GameView.COL_ID] xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Id" % count, str(game[GameView.COL_ID])) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Console" % count, romCollection.name) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Title" % count, game[GameView.COL_NAME]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Thumb" % count, thumb) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Fanart" % count, fanart) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Plot" % count, game[GameView.COL_description]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Year" % count, game[GameView.COL_year]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Publisher" % count, game[GameView.COL_publisher]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Developer" % count, game[GameView.COL_developer]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Genre" % count, game[GameView.COL_genre]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Maxplayers" % count, game[GameView.COL_maxPlayers]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Region" % count, game[GameView.COL_region]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Media" % count, game[GameView.COL_description]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Perspective" % count, game[GameView.COL_perspective]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Controllertype" % count, game[GameView.COL_controllerType]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Playcount" % count, game[GameView.COL_launchCount]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Rating" % count, game[GameView.COL_rating]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Votes" % count, game[GameView.COL_numVotes]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Url" % count, game[GameView.COL_url]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Originaltitle" % count, game[GameView.COL_originalTitle]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Alternatetitle" % count, game[GameView.COL_alternateTitle]) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Version" % count, game[GameView.COL_version]) except Exception as exc: xbmc.log('RCB: Error while getting most played games: ' + str(exc)) gdb.close()
def logfile_dir(self): return util.getAddonDataPath()
def updateDB(self, gdb, gui, updateOption, romCollections, settings, isRescrape): self.gdb = gdb self.Settings = settings #self.scrapeResultsFile = self.openFile(os.path.join(util.getAddonDataPath(), 'scrapeResults.txt')) self.missingDescFile = self.openFile(os.path.join(util.getAddonDataPath(), 'scrapeResult_missingDesc.txt')) self.missingArtworkFile = self.openFile(os.path.join(util.getAddonDataPath(), 'scrapeResult_missingArtwork.txt')) self.possibleMismatchFile = self.openFile(os.path.join(util.getAddonDataPath(), 'scrapeResult_possibleMismatches.txt')) Logutil.log("Start Update DB", util.LOG_LEVEL_INFO) Logutil.log("Iterating Rom Collections", util.LOG_LEVEL_INFO) rccount = 1 #get fuzzyFactor before scraping matchingRatioIndex = self.Settings.getSetting(util.SETTING_RCB_FUZZYFACTOR) if (matchingRatioIndex == ''): matchingRatioIndex = 2 matchingRatioIndex = self.Settings.getSetting(util.SETTING_RCB_FUZZYFACTOR) Logutil.log("matchingRatioIndex: " +str(matchingRatioIndex), util.LOG_LEVEL_INFO) fuzzyFactor = util.FUZZY_FACTOR_ENUM[int(matchingRatioIndex)] Logutil.log("fuzzyFactor: " +str(fuzzyFactor), util.LOG_LEVEL_INFO) #always do full reimports when in rescrape-mode enableFullReimport = isRescrape or self.Settings.getSetting(util.SETTING_RCB_ENABLEFULLREIMPORT).upper() == 'TRUE' Logutil.log("enableFullReimport: " +str(enableFullReimport), util.LOG_LEVEL_INFO) continueUpdate = True #Added variable to allow user to continue on errors ignoreErrors = False for romCollection in romCollections.values(): #timestamp1 = time.clock() #check if import was canceled if(not continueUpdate): Logutil.log('Game import canceled', util.LOG_LEVEL_INFO) break #prepare Header for ProgressDialog progDialogRCHeader = util.localize(40022) +" (%i / %i): %s" %(rccount, len(romCollections), romCollection.name) rccount = rccount + 1 Logutil.log("current Rom Collection: " +romCollection.name, util.LOG_LEVEL_INFO) #self.scrapeResultsFile.write('~~~~~~~~~~~~~~~~~~~~~~~~\n' +romCollection.name +'\n' +'~~~~~~~~~~~~~~~~~~~~~~~~\n') self.missingDescFile.write('~~~~~~~~~~~~~~~~~~~~~~~~\n' +romCollection.name +'\n' +'~~~~~~~~~~~~~~~~~~~~~~~~\n') self.missingArtworkFile.write('~~~~~~~~~~~~~~~~~~~~~~~~\n' +romCollection.name +'\n' +'~~~~~~~~~~~~~~~~~~~~~~~~\n') self.possibleMismatchFile.write('~~~~~~~~~~~~~~~~~~~~~~~~\n' +romCollection.name +'\n' +'~~~~~~~~~~~~~~~~~~~~~~~~\n') self.possibleMismatchFile.write('gamename, filename\n') #Read settings for current Rom Collection Logutil.log("ignoreOnScan: " +str(romCollection.ignoreOnScan), util.LOG_LEVEL_INFO) if(romCollection.ignoreOnScan): Logutil.log("current Rom Collection will be ignored.", util.LOG_LEVEL_INFO) #self.scrapeResultsFile.write('Rom Collection will be ignored.\n') continue Logutil.log("update is allowed for current rom collection: " +str(romCollection.allowUpdate), util.LOG_LEVEL_INFO) Logutil.log("max folder depth: " +str(romCollection.maxFolderDepth), util.LOG_LEVEL_INFO) firstScraper = romCollection.scraperSites[0] #check if we are in local artwork mode if(len(romCollection.scraperSites) == 1 and firstScraper.name == util.localize(40053)): Logutil.log("Forcing enableFullReimport because we are in local artwork mode", util.LOG_LEVEL_INFO) enableFullReimport = True files = self.getRomFilesByRomCollection(romCollection, enableFullReimport) #itemCount is used for percentage in ProgressDialogGUI gui.itemCount = len(files) +1 #check if first scraper is a multigame scraper if(not firstScraper.descFilePerGame): #build file hash tables (key = gamename or crc, value = romfiles) Logutil.log("Start building file dict", util.LOG_LEVEL_INFO) fileDict = self.buildFileDict(gui, progDialogRCHeader, files, romCollection, firstScraper) try: fileCount = 0 gamenameFromDesc = '' #TODO move to to check preconditions #first scraper must be the one for multiple games if(len(firstScraper.scrapers) == 0): Logutil.log('Configuration error: Configured scraper site does not contain any scrapers', util.LOG_LEVEL_ERROR) continue scraper = firstScraper.scrapers[0] Logutil.log("start parsing with multi game scraper: " +str(firstScraper.name), util.LOG_LEVEL_INFO) Logutil.log("using parser file: " +scraper.parseInstruction, util.LOG_LEVEL_INFO) Logutil.log("using game description: " +scraper.source, util.LOG_LEVEL_INFO) parser = DescriptionParserFactory.getParser(str(scraper.parseInstruction)) #parse description for result in parser.scanDescription(scraper.source, str(scraper.parseInstruction), scraper.encoding): try: gamenameFromDesc = result['Game'][0] #find parsed game in Rom Collection filenamelist = self.matchDescriptionWithRomfiles(firstScraper, result, fileDict, gamenameFromDesc) artScrapers = {} if(filenamelist != None and len(filenamelist) > 0): gamenameFromFile = helper.getGamenameFromFilename(filenamelist[0], romCollection) foldername = self.getFoldernameFromRomFilename(filenamelist[0]) fileCount = fileCount +1 continueUpdate = gui.writeMsg(progDialogRCHeader, util.localize(40023) +": " +str(gamenameFromDesc), "", fileCount) if(not continueUpdate): Logutil.log('Game import canceled by user', util.LOG_LEVEL_INFO) break Logutil.log('Start scraping info for game: ' +str(gamenameFromFile), LOG_LEVEL_INFO) #check if this file already exists in DB continueUpdate, isUpdate, gameId = self.checkRomfileAlreadyExists(filenamelist[0], enableFullReimport, False) if(not continueUpdate): continue #use additional scrapers if(len(romCollection.scraperSites) > 1): result, artScrapers = self.useSingleScrapers(result, romCollection, 1, gamenameFromFile, foldername, filenamelist[0], fuzzyFactor, updateOption, gui, progDialogRCHeader, fileCount) else: Logutil.log("game " +gamenameFromDesc +" was found in parsed results but not in your rom collection.", util.LOG_LEVEL_WARNING) continue dialogDict = {'dialogHeaderKey':progDialogRCHeader, 'gameNameKey':gamenameFromFile, 'scraperSiteKey':artScrapers, 'fileCountKey':fileCount} gameId, continueUpdate = self.insertGameFromDesc(result, gamenameFromFile, romCollection, filenamelist, foldername, isUpdate, gameId, gui, False, dialogDict) if(not continueUpdate): break #remove found files from file list if(gameId != None): for filename in filenamelist: files.remove(filename) #stop import if no files are left if(len(files) == 0): Logutil.log("All games are imported", util.LOG_LEVEL_INFO) break except Exception, (exc): Logutil.log("an error occured while adding game " +gamenameFromDesc, util.LOG_LEVEL_WARNING) Logutil.log("Error: " +str(exc), util.LOG_LEVEL_WARNING) continue #all files still available files-list, are missing entries for filename in files: gamenameFromFile = helper.getGamenameFromFilename(filename, romCollection) try: self.missingDescFile.write('%s\n' %gamenameFromFile) except: self.missingDescFile.write('%s\n' %gamenameFromFile.encode('utf-8')) except Exception, (exc): Logutil.log("an error occured while adding game " +gamenameFromDesc, util.LOG_LEVEL_WARNING) Logutil.log("Error: " +str(exc), util.LOG_LEVEL_WARNING) try: self.missingDescFile.write('%s\n' %gamenameFromDesc) except: self.missingDescFile.write('%s\n' %gamenameFromDesc.encode('utf-8')) continue
def gatherWidgetData(self, param): xbmc.log('start gatherWidgetData') import util, helper from gamedatabase import Game, GameDataBase, File from config import Config gdb = GameDataBase(util.getAddonDataPath()) gdb.connect() doImport, errorMsg = gdb.checkDBStructure() if(doImport) > 0: xbmc.log("RCB: No database available. Won't gather any data.") gdb.close() return elif(doImport < 0): xbmc.log("RCB: Error occured while checking db structure: {0}" % errorMsg) limit = param.replace('limit=', '') query = 'Select * From GameView Where launchCount > 0 Order by launchCount desc Limit %s;' %str(limit) games = Game(gdb).getGamesByQueryNoArgs(query) xbmc.log('most played games: %s' % games) config = Config(None) statusOk, errorMsg = config.readXml() if(not statusOk): xbmc.log('RCB: Error reading config.xml: {0}' % errorMsg) return mediaDict = {} mediaDict = helper.cacheMediaPathsForSelection(0, mediaDict, config) import xbmcgui count = 0 for game in games: count += 1 try: xbmc.log("RCB widget: Gathering data for rom no %i: %s" % (count, game.name)) romCollection = config.romCollections[str(game.romCollectionId)] gamenameFromFile = romCollection.getGamenameFromFilename(game.firstRom) mediaPathsDict = mediaDict[str(game.romCollectionId)] #get artwork that is chosen to be shown in gamelist thumb = helper.getFileForControl(romCollection.imagePlacingMain.fileTypesForGameList, romCollection, mediaPathsDict, gamenameFromFile, False) fanart = helper.getFileForControl(romCollection.imagePlacingMain.fileTypesForMainViewBackground, romCollection, mediaPathsDict, gamenameFromFile, False) url = "plugin://script.games.rom.collection.browser/?launchid=%s" % game.id xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Id" % count, str(game.id)) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Console" % count, romCollection.name) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Title" % count, game.name) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Thumb" % count, thumb) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Fanart" % count, fanart) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Plot" % count, game.plot) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Year" % count, game.year) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Publisher" % count, game.publisher) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Developer" % count, game.developer) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Genre" % count, game.genre) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Maxplayers" % count, game.maxplayers) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Region" % count, game.region) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Media" % count, game.media) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Perspective" % count, game.perspective) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Controllertype" % count, game.controllertype) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Playcount" % count, game.playcount) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Rating" % count, game.rating) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Votes" % count, game.votes) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Url" % count, url) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Originaltitle" % count, game.originalTitle) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Alternatetitle" % count, game.alternateTitle) xbmcgui.Window(10000).setProperty("MostPlayedROM.%d.Version" % count, game.version) except Exception, (exc): xbmc.log('RCB: Error while getting most played games: ' + str(exc))
def launchEmu(self, gdb, gui, gameId, config, listitem): log.info("Begin launcher.launchEmu") gameRow = Game(gdb).getObjectById(gameId) if gameRow is None: log.error("Game with id %s could not be found in database" % gameId) return try: self.romCollection = config.romCollections[str( gameRow[util.GAME_romCollectionId])] except KeyError: log.error("Cannot get rom collection with id: " + str(gameRow[util.GAME_romCollectionId])) gui.writeMsg(util.localize(32034)) return gui.writeMsg(util.localize(32163) + " " + gameRow[util.ROW_NAME]) # Remember viewstate gui.saveViewState(False) cmd = "" precmd = "" postcmd = "" filenameRows = File(gdb).getRomsByGameId(gameRow[util.ROW_ID]) log.info("files for current game: " + str(filenameRows)) cmd, precmd, postcmd, roms = self.__buildCmd(gui, filenameRows, gameRow, False) if not self.romCollection.useBuiltinEmulator: if cmd == '': log.info("No cmd created. Game will not be launched.") return if precmd.strip() == '' or precmd.strip() == 'call': log.info("No precmd created.") if postcmd.strip() == '' or postcmd.strip() == 'call': log.info("No postcmd created.") # solo mode if self.romCollection.useEmuSolo: self.__copyLauncherScriptsToUserdata() # communicate with service via settings __addon__.setSetting(util.SETTING_RCB_LAUNCHONSTARTUP, 'true') # invoke script file that kills xbmc before launching the emulator basePath = os.path.join(util.getAddonDataPath(), 'scriptfiles') if self.env == "win32": if __addon__.getSetting(util.SETTING_RCB_USEVBINSOLOMODE ).lower() == 'true': # There is a problem with quotes passed as argument to windows command shell. This only works with "call" # use vb script to restart xbmc cmd = 'call \"' + os.path.join( basePath, 'applaunch-vbs.bat') + '\" ' + cmd else: # There is a problem with quotes passed as argument to windows command shell. This only works with "call" cmd = 'call \"' + os.path.join( basePath, 'applaunch.bat') + '\" ' + cmd else: cmd = os.path.join(basePath, 'applaunch.sh ') + cmd else: # use call to support paths with whitespaces if self.env == "win32": cmd = 'call ' + cmd # update LaunchCount launchCount = gameRow[util.GAME_launchCount] Game(gdb).update(('launchCount', ), (launchCount + 1, ), gameRow[util.ROW_ID], True) gdb.commit() log.info("cmd: " + cmd) log.info("precmd: " + precmd) log.info("postcmd: " + postcmd) try: self.__launchNonXbox(cmd, gameRow, precmd, postcmd, roms, gui, listitem) gui.writeMsg("") except Exception, (exc): log.error("Error while launching emu: " + str(exc)) gui.writeMsg(util.localize(32035) + ": " + str(exc))
def launchEmu(gdb, gui, gameId, config, settings, listitem): Logutil.log("Begin launcher.launchEmu", util.LOG_LEVEL_INFO) gameRow = Game(gdb).getObjectById(gameId) if(gameRow == None): Logutil.log("Game with id %s could not be found in database" %gameId, util.LOG_LEVEL_ERROR) return romCollection = None try: romCollection = config.romCollections[str(gameRow[util.GAME_romCollectionId])] except: Logutil.log('Cannot get rom collection with id: ' +str(gameRow[util.GAME_romCollectionId]), util.LOG_LEVEL_ERROR) gui.writeMsg(util.localize(32034)) return gui.writeMsg(util.localize(32163)+ " " +gameRow[util.ROW_NAME]) # Remember viewstate gui.saveViewState(False) cmd = "" precmd = "" postcmd = "" #get environment OS env = util.getEnvironment() filenameRows = File(gdb).getRomsByGameId(gameRow[util.ROW_ID]) Logutil.log("files for current game: " +str(filenameRows), util.LOG_LEVEL_INFO) escapeCmd = settings.getSetting(util.SETTING_RCB_ESCAPECOMMAND).upper() == 'TRUE' cmd, precmd, postcmd, roms = buildCmd(filenameRows, romCollection, gameRow, escapeCmd, False) if (not romCollection.useBuiltinEmulator): if(cmd == ''): Logutil.log('No cmd created. Game will not be launched.', util.LOG_LEVEL_INFO) return if(precmd.strip() == '' or precmd.strip() == 'call'): Logutil.log('No precmd created.', util.LOG_LEVEL_INFO) if(postcmd.strip() == '' or postcmd.strip() == 'call'): Logutil.log('No postcmd created.', util.LOG_LEVEL_INFO) #solo mode if (romCollection.useEmuSolo): copyLauncherScriptsToUserdata(settings) #check if we should use xbmc.service (Eden) or autoexec.py (Dharma) if(not gui.useRCBService): #try to create autoexec.py writeAutoexec(gdb) else: #communicate with service via settings settings.setSetting(util.SETTING_RCB_LAUNCHONSTARTUP, 'true') #invoke script file that kills xbmc before launching the emulator basePath = os.path.join(util.getAddonDataPath(), 'scriptfiles') #xbmc needs other script files than kodi xbmcFilenameSuffix = "_xbmc" if(int(gui.xbmcversionNo) >= util.XBMC_VERSION_HELIX): xbmcFilenameSuffix = "" if(env == "win32"): if(settings.getSetting(util.SETTING_RCB_USEVBINSOLOMODE).lower() == 'true'): #There is a problem with quotes passed as argument to windows command shell. This only works with "call" #use vb script to restart xbmc cmd = 'call \"' +os.path.join(basePath, 'applaunch-vbs%s.bat' %xbmcFilenameSuffix) +'\" ' +cmd else: #There is a problem with quotes passed as argument to windows command shell. This only works with "call" cmd = 'call \"' +os.path.join(basePath, 'applaunch%s.bat' %xbmcFilenameSuffix) +'\" ' +cmd else: cmd = os.path.join(basePath, 'applaunch%s.sh ' %xbmcFilenameSuffix) +cmd else: #use call to support paths with whitespaces if(env == "win32" and not (os.environ.get( "OS", "xbox" ) == "xbox")): cmd = 'call ' +cmd #update LaunchCount launchCount = gameRow[util.GAME_launchCount] Game(gdb).update(('launchCount',), (launchCount +1,) , gameRow[util.ROW_ID], True) gdb.commit() Logutil.log("cmd: " +cmd, util.LOG_LEVEL_INFO) Logutil.log("precmd: " +precmd, util.LOG_LEVEL_INFO) Logutil.log("postcmd: " +postcmd, util.LOG_LEVEL_INFO) try: if (os.environ.get( "OS", "xbox" ) == "xbox"): launchXbox(gui, gdb, cmd, romCollection, filenameRows) else: launchNonXbox(cmd, romCollection, gameRow, settings, precmd, postcmd, roms, gui, listitem) gui.writeMsg("") except Exception, (exc): Logutil.log("Error while launching emu: " +str(exc), util.LOG_LEVEL_ERROR) gui.writeMsg(util.localize(32035) +": " +str(exc))