Esempio n. 1
0
	def __checkGameHasSaveStates(self, gameRow, filenameRows):

		if self.romCollection.saveStatePath == '':
			log.debug("No save state path set")
			return ''

		rom = filenameRows[0][0]
		saveStatePath = self.__replacePlaceholdersInParams(self.romCollection.saveStatePath, rom, gameRow)

		saveStateFiles = glob.glob(saveStatePath)

		if len(saveStateFiles) == 0:
			log.debug("No save state files found")
			return ''

		log.info('saveStateFiles found: ' + str(saveStateFiles))

		# don't select savestatefile if ASKNUM is requested in Params
		if re.search('(?i)%ASKNUM%', self.romCollection.saveStateParams):
			return saveStateFiles[0]

		options = [util.localize(32165)]
		for f in saveStateFiles:
			options.append(os.path.basename(f))
		selectedFile = xbmcgui.Dialog().select(util.localize(32166), options)
		# If selections is canceled or "Don't launch statefile" option
		if selectedFile < 1:
			return ''

		return saveStateFiles[selectedFile - 1]
def launchXbox(gui, gdb, cmd, romCollection, filenameRows):
	Logutil.log("launchEmu on xbox", util.LOG_LEVEL_INFO)
	
	#on xbox emucmd must be the path to an executable or cut file
	if (not os.path.isfile(cmd)):
		Logutil.log("Error while launching emu: File %s does not exist!" %cmd, util.LOG_LEVEL_ERROR)
		gui.writeMsg(util.localize(32037) %cmd)
		return
					
	if (romCollection.xboxCreateShortcut):
		Logutil.log("creating cut file", util.LOG_LEVEL_INFO)
		
		cutFile = createXboxCutFile(cmd, filenameRows, romCollection)
		if(cutFile == ""):
			Logutil.log("Error while creating .cut file. Check xbmc.log for details.", util.LOG_LEVEL_ERROR)
			gui.writeMsg(util.localize(32038))
			return
			
		cmd = cutFile
		Logutil.log("cut file created: " +cmd, util.LOG_LEVEL_INFO)			
	
	#RunXbe always terminates XBMC. So we have to write autoexec here	
	writeAutoexec(gdb)
		
	Logutil.log("RunXbe", util.LOG_LEVEL_INFO)
	xbmc.executebuiltin("XBMC.Runxbe(%s)" %cmd)
	Logutil.log("RunXbe done", util.LOG_LEVEL_INFO)
	time.sleep(1000)
Esempio n. 3
0
	def updateConfig(self, gui):
		
		if(not os.path.isfile(self.configFile)):
			return False, util.localize(32003)
		
		
		tree = ElementTree().parse(self.configFile)
		if(tree == None):
			Logutil.log('Could not read config.xml', util.LOG_LEVEL_ERROR)
			return False, util.localize(32004)
		
		self.tree = tree
	
		configVersion = tree.attrib.get('version')
		Logutil.log('Reading config version from config.xml: ' +str(configVersion), util.LOG_LEVEL_INFO)
		if(configVersion == None):
			#set to previous version
			configVersion = '0.7.4'
		
		#nothing to do
		if(configVersion == util.CURRENT_CONFIG_VERSION):
			Logutil.log('Config file is up to date', util.LOG_LEVEL_INFO)
			return True, ''
		
		Logutil.log('Config file is out of date. Start update', util.LOG_LEVEL_INFO)
		
		#backup config.xml
		newFileName = self.configFile +'.backup ' +configVersion
		if not os.path.isfile(newFileName):
			try:
				shutil.copy(str(self.configFile), str(newFileName))
			except Exception, (exc):
				return False, util.localize(32007) +": " +str(exc)
Esempio n. 4
0
	def readFileType(self, name, tree):
		
		fileTypeRow = None 
		fileTypeRows = tree.findall('FileTypes/FileType')
		for element in fileTypeRows:
			if(element.attrib.get('name') == name):
				fileTypeRow = element
				break
			
		if(fileTypeRow == None):
			Logutil.log('Configuration error. FileType %s does not exist in config.xml' %name, util.LOG_LEVEL_ERROR)
			return None, util.localize(35005)
			
		fileType = FileType()
		fileType.name = name
		
		id = fileTypeRow.attrib.get('id')
		if(id == ''):
			Logutil.log('Configuration error. FileType %s must have an id' %name, util.LOG_LEVEL_ERROR)
			return None, util.localize(35005)
			
		fileType.id = id
		
		type = fileTypeRow.find('type')
		if(type != None):
			fileType.type = type.text
			
		parent = fileTypeRow.find('parent')
		if(parent != None):
			fileType.parent = parent.text
			
		return fileType, ''
def checkGameHasSaveStates(romCollection, gameRow, filenameRows, escapeCmd):
	
	if(romCollection.saveStatePath == ''):
		return ''
		
	rom = filenameRows[0][0]
	saveStatePath = replacePlaceholdersInParams(romCollection.saveStatePath, rom, romCollection, gameRow, escapeCmd)
		
	saveStateFiles = glob.glob(saveStatePath)
	
	stateFile = ''
	if(len(saveStateFiles) == 0):
		return ''
	elif(len(saveStateFiles) >= 1):
		Logutil.log('saveStateFiles found: ' +str(saveStateFiles), util.LOG_LEVEL_INFO)
		
		#don't select savestatefile if ASKNUM is requested in Params
		if(re.search('(?i)%ASKNUM%', romCollection.saveStateParams)):
			return saveStateFiles[0]
				
		options = [util.localize(32165)]
		for file in saveStateFiles:
			options.append(os.path.basename(file))
		selectedFile = xbmcgui.Dialog().select(util.localize(32166), options)
		#If selections is canceled or "Don't launch statefile" option
		if(selectedFile < 1):
			return ''
		else:
			stateFile = saveStateFiles[selectedFile -1]
	
	return stateFile
	def addScraperToSiteList(self, controlId, sites, romCollection):

		log.info("addScraperToSiteList")

		control = self.getControlById(controlId)
		scraperItem = control.getSelectedItem()
		scraper = scraperItem.getLabel()

		if scraper == util.localize(32854):
			return sites

		#check if this site is already available for current RC
		for site in romCollection.scraperSites:
			if site.name == scraper:
				sites.append(site)
				return sites

		siteRow = None
		siteRows = self.gui.config.tree.findall('Scrapers/Site')
		for element in siteRows:
			if element.attrib.get('name') == scraper:
				siteRow = element
				break

		if siteRow is None:
			xbmcgui.Dialog().ok(util.localize(32021), util.localize(32022) % scraper)
			return None

		site, errorMsg = self.gui.config.readScraper(siteRow, romCollection.name, '', '', True, self.gui.config.tree)
		if site is not None:
			sites.append(site)

		return sites
	def readFileType(self, name, tree):
		fileTypeRows = tree.findall('FileTypes/FileType')

		fileTypeRow = next((element for element in fileTypeRows if element.attrib.get('name') == name), None)
		if fileTypeRow is None:
			Logutil.log('Configuration error. FileType %s does not exist in config.xml' %name, util.LOG_LEVEL_ERROR)
			return None, util.localize(32005)
			
		fileType = FileType()
		fileType.name = name

		if 'id' not in fileTypeRow.attrib:
			Logutil.log('Configuration error. FileType %s must have an id' %name, util.LOG_LEVEL_ERROR)
			return None, util.localize(32005)
		fileType.id = fileTypeRow.attrib.get('id')
		
		type = fileTypeRow.find('type')
		if(type != None):
			fileType.type = type.text
			
		parent = fileTypeRow.find('parent')
		if(parent != None):
			fileType.parent = parent.text
			
		return fileType, ''
Esempio n. 8
0
	def addScraperToSiteList(self, controlId, sites, romCollection):				

		Logutil.log('addScraperToSiteList', util.LOG_LEVEL_INFO)
		
		control = self.getControlById(controlId)
		scraperItem = control.getSelectedItem()
		scraper = scraperItem.getLabel()
		
		if(scraper == util.localize(56004)):
			return sites
		
		#check if this site is already available for current RC
		for site in romCollection.scraperSites:
			if(site.name == scraper):
				sites.append(site)
				return sites
		
		siteRow = None
		siteRows = self.gui.config.tree.findall('Scrapers/Site')
		for element in siteRows:
			if(element.attrib.get('name') == scraper):
				siteRow = element
				break
		
		if(siteRow == None):
			xbmcgui.Dialog().ok(util.localize(35021), util.localize(35022) %scraper)
			return None
		
		site, errorMsg = self.gui.config.readScraper(siteRow, romCollection.name, '', '', True, self.gui.config.tree)
		if(site != None):
			sites.append(site)
			
		return sites
Esempio n. 9
0
	def initXml(self):
		Logutil.log('initXml', util.LOG_LEVEL_INFO)

		if(not self.configFile):
			self.configFile = util.getConfigXmlPath()

		if(not xbmcvfs.exists(self.configFile)):
			Logutil.log('File config.xml does not exist. Place a valid config file here: %s' % self.configFile, util.LOG_LEVEL_ERROR)
			return None, False, util.localize(32003)

		# force utf-8
		tree = ElementTree()
		if sys.version_info >= (2, 7):
			parser = XMLParser(encoding='utf-8')
		else:
			parser = XMLParser()

		tree.parse(self.configFile, parser)
		if(tree == None):
			Logutil.log('Could not read config.xml', util.LOG_LEVEL_ERROR)
			return None, False, util.localize(32004)

		self.tree = tree

		return tree, True, ''
Esempio n. 10
0
def builMissingFilterStatement(config):

	if(config.showHideOption.lower() == util.localize(32157)):
		return ''
		
	statement = ''
	
	andStatementInfo = buildInfoStatement(config.missingFilterInfo.andGroup, ' AND ')
	if(andStatementInfo != ''):
		statement = andStatementInfo
		
	orStatementInfo =  buildInfoStatement(config.missingFilterInfo.orGroup, ' OR ')
	if(orStatementInfo != ''):
		if (statement != ''):
			statement = statement +' OR '
		statement = statement + orStatementInfo
		
	andStatementArtwork = buildArtworkStatement(config, config.missingFilterArtwork.andGroup, ' AND ')
	if(andStatementArtwork != ''):
		if (statement != ''):
			statement = statement +' OR '
		statement = statement + andStatementArtwork
	
	orStatementArtwork =  buildArtworkStatement(config, config.missingFilterArtwork.orGroup, ' OR ')
	if(orStatementArtwork != ''):
		if (statement != ''):
			statement = statement +' OR '
		statement = statement + orStatementArtwork
	
	if(statement != ''):
		statement = '(%s)' %(statement)
		if(config.showHideOption.lower() == util.localize(32161)):
			statement = 'NOT ' +statement
	
	return statement
def getNames7z(filepath):
	
	try:
		import py7zlib
	except Exception, (exc):
		xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(32039), util.localize(32129))
		Logutil.log("You have tried to launch a .7z file but you are missing required libraries to extract the file. You can download the latest RCB version from RCBs project page. It contains all required libraries.", util.LOG_LEVEL_ERROR)
		Logutil.log("Error: " +str(exc), util.LOG_LEVEL_ERROR)
		return None
def replacePlaceholdersInParams(emuParams, rom, romCollection, gameRow, escapeCmd):
		
	if(escapeCmd):
		rom = re.escape(rom)
		
	#TODO: Wanted to do this with re.sub:
	#emuParams = re.sub(r'(?i)%rom%', rom, emuParams)
	#--> but this also replaces \r \n with linefeed and newline etc.
	
	#full rom path ("C:\Roms\rom.zip")	
	emuParams = emuParams.replace('%rom%', rom) 
	emuParams = emuParams.replace('%ROM%', rom)
	emuParams = emuParams.replace('%Rom%', rom)
	
	#romfile ("rom.zip")
	romfile = os.path.basename(rom)
	emuParams = emuParams.replace('%romfile%', romfile)
	emuParams = emuParams.replace('%ROMFILE%', romfile)
	emuParams = emuParams.replace('%Romfile%', romfile)
	
	#romname ("rom")
	romname = os.path.splitext(os.path.basename(rom))[0]
	emuParams = emuParams.replace('%romname%', romname)
	emuParams = emuParams.replace('%ROMNAME%', romname)
	emuParams = emuParams.replace('%Romname%', romname)
	
	#gamename	
	gamename = unicode(gameRow[util.ROW_NAME])
	emuParams = emuParams.replace('%game%', gamename)
	emuParams = emuParams.replace('%GAME%', gamename)
	emuParams = emuParams.replace('%Game%', gamename)
	
	#ask num
	if(re.search('(?i)%ASKNUM%', emuParams)):
		options = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
		number = unicode(xbmcgui.Dialog().select(util.localize(32167), options))
		emuParams = emuParams.replace('%asknum%', number)
		emuParams = emuParams.replace('%ASKNUM%', number)
		emuParams = emuParams.replace('%Asknum%', number)
		
	#ask text
	if(re.search('(?i)%ASKTEXT%', emuParams)):
		
		keyboard = xbmc.Keyboard()
		keyboard.setHeading(util.localize(32168))
		keyboard.doModal()
		command = ''
		if (keyboard.isConfirmed()):
			command = keyboard.getText()
		
		emuParams = emuParams.replace('%asktext%', command)
		emuParams = emuParams.replace('%ASKTEXT%', command)
		emuParams = emuParams.replace('%Asktext%', command)
		
	
	return emuParams
Esempio n. 13
0
	def getAvailableScrapers(self):
		#Scrapers
		sitesInList = [util.localize(56004), util.localize(40053)]
		#get all scrapers
		scrapers = self.gui.config.tree.findall('Scrapers/Site')
		for scraper in scrapers:
			name = scraper.attrib.get('name')
			if(name != None):
				sitesInList.append(name)
				
		return sitesInList
Esempio n. 14
0
	def showGameList(self):
		
		Logutil.log("Begin showGameList", util.LOG_LEVEL_INFO)
		
		#likeStatement = helper.buildLikeStatement(self.selectedCharacter)
		#games = Game(self.gdb).getFilteredGames(self.selectedConsoleId, self.selectedGenreId, self.selectedYearId, self.selectedPublisherId, likeStatement)				
				
		self.writeMsg(util.localize(40021))
		
		self.clearList()
		
		gameRow = Game(self.gdb).getObjectById(self.selectedGameId)
		
		fileDict = self.getFileDictByGameRow(self.gdb, gameRow)
		
		romCollection = None
		try:
			romCollection = self.config.romCollections[str(gameRow[util.GAME_romCollectionId])]
		except:
			Logutil.log(util.localize(35023) %str(gameRow[util.GAME_romCollectionId]), util.LOG_LEVEL_ERROR)
		
		imageGameList = self.getFileForControl(romCollection.imagePlacingInfo.fileTypesForGameList, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict)
		imageGameListSelected = self.getFileForControl(romCollection.imagePlacingInfo.fileTypesForGameListSelected, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict)
		
		item = xbmcgui.ListItem(gameRow[util.ROW_NAME], str(gameRow[util.ROW_ID]), imageGameList, imageGameListSelected)
		item.setProperty('gameId', str(gameRow[util.ROW_ID]))
				
		#check if we should use autoplay video
		if(romCollection.autoplayVideoInfo):
			item.setProperty('autoplayvideoinfo', 'true')
		else:
			item.setProperty('autoplayvideoinfo', '')
		
		#get video window size
		if (romCollection.imagePlacingInfo.name.startswith('gameinfosmall')):
			item.setProperty('videosizesmall', 'small')
			item.setProperty('videosizebig', '')
		else:
			item.setProperty('videosizebig', 'big')
			item.setProperty('videosizesmall', '')
						
		videos = helper.getFilesByControl_Cached(self.gdb, (self.fileTypeGameplay,), gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict)
		if(videos != None and len(videos) != 0):
			video = videos[0]
			item.setProperty('gameplayinfo', video)
		
		self.addItem(item)
				
		xbmc.executebuiltin("Container.SortDirection")
		self.writeMsg("")
		
		Logutil.log("End showGameList", util.LOG_LEVEL_INFO)
Esempio n. 15
0
	def selectScrapersInList(self, sitesInRomCollection, sitesInList):
		
		if(len(sitesInRomCollection) >= 1):
			self.selectScraperInList(sitesInList, sitesInRomCollection[0].name, CONTROL_LIST_SCRAPER1)			
		else:
			self.selectScraperInList(sitesInList, util.localize(56004), CONTROL_LIST_SCRAPER1)
		if(len(sitesInRomCollection) >= 2):
			self.selectScraperInList(sitesInList, sitesInRomCollection[1].name, CONTROL_LIST_SCRAPER2)
		else:
			self.selectScraperInList(sitesInList, util.localize(56004), CONTROL_LIST_SCRAPER2)
		if(len(sitesInRomCollection) >= 3):
			self.selectScraperInList(sitesInList, sitesInRomCollection[2].name, CONTROL_LIST_SCRAPER3)
		else:
			self.selectScraperInList(sitesInList, util.localize(56004), CONTROL_LIST_SCRAPER3)
	def addMediaPath(self):

		mediaTypes = self.gui.config.tree.findall('FileTypes/FileType')

		mediaTypeList = []

		for mediaType in mediaTypes:
			name = mediaType.attrib.get('name')
			if name is not None:
				type = mediaType.find('type')
				if type is not None and type.text == 'video':
					name = name + ' (video)'

				# check if media type is already in use for selected RC
				isMediaTypeInUse = False
				for mediaPath in self.selectedRomCollection.mediaPaths:
					if mediaPath.fileType.name == name:
						isMediaTypeInUse = True

				if not isMediaTypeInUse:
					mediaTypeList.append(name)

		mediaTypeIndex = xbmcgui.Dialog().select(util.localize(32142), mediaTypeList)
		if mediaTypeIndex == -1:
			return

		mediaType = mediaTypeList[mediaTypeIndex]
		mediaType = mediaType.replace(' (video)', '')

		mediaPathComplete = self.editPathWithFileMask(CONTROL_BUTTON_MEDIAPATH, '%s ' % mediaType + util.localize(32141), CONTROL_BUTTON_MEDIAFILEMASK)
		# TODO: use default value in editFilemask
		control = self.getControlById(CONTROL_BUTTON_MEDIAFILEMASK)
		control.setLabel('%GAME%.*')
		mediaPathComplete = self.editFilemask(CONTROL_BUTTON_MEDIAFILEMASK, util.localize(32618), mediaPathComplete)

		mediaPath = MediaPath()
		fileType = FileType()
		fileType.name = mediaType
		mediaPath.fileType = fileType
		mediaPath.path = mediaPathComplete
		self.selectedRomCollection.mediaPaths.append(mediaPath)

		control = self.getControlById(CONTROL_LIST_MEDIATYPES)
		item = xbmcgui.ListItem(mediaType, '', '', '')
		control.addItem(item)

		self.selectItemInList(mediaType, CONTROL_LIST_MEDIATYPES)

		xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
		self.updateMediaPathControls()
def getArchives7z(filepath, archiveList):
	
	try:
		import py7zlib
	except:
		xbmcgui.Dialog().ok(util.SCRIPTNAME, util.localize(32039), util.localize(32129))
		Logutil.log("You have tried to launch a .7z file but you are missing required libraries to extract the file. You can download the latest RCB version from RCBs project page. It contains all required libraries.", util.LOG_LEVEL_ERROR)
		return None
	
	fp = open(str(filepath), 'rb')
	archive = py7zlib.Archive7z(fp)
	archivesDecompressed =  [(name, archive.getmember(name).read())for name in archiveList]
	fp.close()
	return archivesDecompressed
	def onClick(self, controlID):
		
		Logutil.log('onClick', util.LOG_LEVEL_INFO)
		
		if (controlID == CONTROL_BUTTON_EXIT): # Close window button
			Logutil.log('close', util.LOG_LEVEL_INFO)
			self.close()
		#OK
		elif (controlID == CONTROL_BUTTON_SAVE):
			Logutil.log('save', util.LOG_LEVEL_INFO)
			#store selectedRomCollection
			if(self.selectedRomCollection != None):
				#Code to Remove Roms
				Logutil.log('Removing Roms', util.LOG_LEVEL_INFO)
				self.setDeleteStatus(True)
				#Code to Remove Collection
				if(self.romDelete == 'RCollection'):
					self.setRCDeleteStatus(True)
					Logutil.log('Removing Rom Collection', util.LOG_LEVEL_INFO)
					configWriterRCDel = ConfigXmlWriter(False)
					RCName = str(self.selectedRomCollection.name)
					success, message = configWriterRCDel.removeRomCollection(RCName)
					if(success == False):
						Logutil.log(message, util.LOG_LEVEL_ERROR)
						xbmcgui.Dialog().ok(util.localize(35019), util.localize(35020))
			Logutil.log('Click Close', util.LOG_LEVEL_INFO)
			self.close()
		#Cancel
		elif (controlID == CONTROL_BUTTON_CANCEL):
			self.close()
		#Rom Collection list
		elif(self.selectedControlId in (CONTROL_BUTTON_RC_DOWN, CONTROL_BUTTON_RC_UP)):						
						
			if(self.selectedRomCollection != None):
				
				#store previous selectedRomCollections state
				self.romCollections[self.selectedRomCollection.id] = self.selectedRomCollection
			
			#HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
			xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
			self.updateControls()
		elif(self.selectedControlId in (CONTROL_BUTTON_DEL_DOWN, CONTROL_BUTTON_DEL_UP)):
			#Check for Remove Roms or Roms and Rom Collection
			control = self.getControlById(CONTROL_LIST_DELETEOPTIONS)
			selectedDeleteOption = str(control.getSelectedItem().getLabel())
			if(selectedDeleteOption == util.localize(40038)):
				self.romDelete = 'Roms'
			else:
				self.romDelete = 'RCollection'
Esempio n. 19
0
	def __replacePlaceholdersInParams(self, emuParams, rom, gameRow):

		if self.escapeCmd:
			rom = re.escape(rom)

		# TODO: Wanted to do this with re.sub:
		# emuParams = re.sub(r'(?i)%rom%', rom, emuParams)
		# --> but this also replaces \r \n with linefeed and newline etc.

		# full rom path ("C:\Roms\rom.zip")
		emuParams = emuParams.replace('%rom%', rom)
		emuParams = emuParams.replace('%ROM%', rom)
		emuParams = emuParams.replace('%Rom%', rom)

		# romfile ("rom.zip")
		romfile = os.path.basename(rom)
		emuParams = emuParams.replace('%romfile%', romfile)
		emuParams = emuParams.replace('%ROMFILE%', romfile)
		emuParams = emuParams.replace('%Romfile%', romfile)

		# romname ("rom")
		romname = os.path.splitext(os.path.basename(rom))[0]
		emuParams = emuParams.replace('%romname%', romname)
		emuParams = emuParams.replace('%ROMNAME%', romname)
		emuParams = emuParams.replace('%Romname%', romname)

		# gamename
		gamename = unicode(gameRow[util.ROW_NAME])
		emuParams = emuParams.replace('%game%', gamename)
		emuParams = emuParams.replace('%GAME%', gamename)
		emuParams = emuParams.replace('%Game%', gamename)

		# ask num
		if re.search('(?i)%ASKNUM%', emuParams):
			options = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
			number = unicode(xbmcgui.Dialog().select(util.localize(32167), options))
			emuParams = emuParams.replace('%asknum%', number)
			emuParams = emuParams.replace('%ASKNUM%', number)
			emuParams = emuParams.replace('%Asknum%', number)

		# ask text
		if re.search('(?i)%ASKTEXT%', emuParams):
			command = xbmcgui.Dialog().input(util.localize(32168), type=xbmcgui.INPUT_ALPHANUM)

			emuParams = emuParams.replace('%asktext%', command)
			emuParams = emuParams.replace('%ASKTEXT%', command)
			emuParams = emuParams.replace('%Asktext%', command)

		return emuParams
	def onInit(self):
		Logutil.log('onInit Remove Rom Collection', util.LOG_LEVEL_INFO)
		
		#Rom Collections
		Logutil.log('build rom collection list', util.LOG_LEVEL_INFO)
		romCollectionList = []
		for rcId in self.romCollections.keys():
			romCollection = self.romCollections[rcId]
			romCollectionList.append(romCollection.name)
		self.addItemsToList(CONTROL_LIST_ROMCOLLECTIONS, romCollectionList)
		
		#Delete Options
		rcDeleteOptions = [util.localize(32137),util.localize(32138)]
		self.addItemsToList(CONTROL_LIST_DELETEOPTIONS, rcDeleteOptions, properties=['RCollection', 'Roms'])
		self.updateControls()
	def setScrapersInConfig(self):
		# Read selected Rom Collection
		control = self.getControlById(CONTROL_LIST_ROMCOLLECTIONS)
		romCollItem = control.getSelectedItem()
		selectedRC = romCollItem.getLabel()

		if self.romCollections is not None:
			romCollections = self.romCollections
		else:
			if selectedRC == util.localize(32120):
				romCollections = self.gui.config.romCollections
			else:
				romCollections = {}
				romCollection = self.gui.config.getRomCollectionByName(selectedRC)
				romCollections[romCollection.id] = romCollection

		for rcId in romCollections.keys():

			romCollection = self.gui.config.romCollections[rcId]

			sites = []
			sites, statusOk = self.addScraperToRomCollection(CONTROL_LIST_SCRAPER1, sites, romCollection)
			if not statusOk:
				return None, False

			romCollection.scraperSites = sites
			romCollections[rcId] = romCollection

		return romCollections, True
	def onInit(self):
		log.info('onInit ImportOptions')
		romCollectionList = [util.localize(32120)] + self.gui.config.getRomCollectionNames()
		log.debug("Adding list of RC names: {0}".format(romCollectionList))
		self.addItemsToList(CONTROL_LIST_ROMCOLLECTIONS, romCollectionList)

		# Deactivate Rom Collection list
		if self.romCollections is not None:
			# Set overwrite flag to false
			xbmc.executebuiltin('Skin.SetBool(%s)' % util.SETTING_RCB_IMPORTOPTIONS_DISABLEROMCOLLECTIONS)
			if not self.isRescrape:
				self.setFocus(self.getControl(CONTROL_BUTTON_SCRAPEINBACKGROUND))
		else:
			xbmc.executebuiltin('Skin.Reset(%s)' % util.SETTING_RCB_IMPORTOPTIONS_DISABLEROMCOLLECTIONS)

		#disable background scraping control when in rescrape-mode
		if self.isRescrape:
			xbmc.executebuiltin('Skin.SetBool(%s)' % util.SETTING_RCB_IMPORTOPTIONS_ISRESCRAPE)
			self.setFocus(self.getControl(CONTROL_BUTTON_SCRAPER_DOWN))
		else:
			xbmc.executebuiltin('Skin.Reset(%s)' % util.SETTING_RCB_IMPORTOPTIONS_ISRESCRAPE)

		sitesInList = self.getAvailableScrapers()

		self.addItemsToList(CONTROL_LIST_SCRAPER1, sitesInList)

		# Set initial scraper values
		sitesInRomCollection = []
		# Use scraper config of first non-MAME rom collection
		for rcid, rc in self.gui.config.romCollections.iteritems():
			if rc.name != 'MAME' or len(self.gui.config.romCollections) == 1:
				sitesInRomCollection = rc.scraperSites
				break

		self.selectScrapersInList(sitesInRomCollection, sitesInList)
Esempio n. 23
0
	def onClick(self, controlID):
		if (controlID == CONTROL_BUTTON_EXIT): # Close window button
			self.close()
		
		#OK
		elif (controlID == CONTROL_BUTTON_OK):
			self.close()
			self.doImport()
		#Cancel
		elif (controlID == CONTROL_BUTTON_CANCEL):
			self.close()
		#Rom Collection list
		elif(self.selectedControlId in (CONTROL_BUTTON_RC_DOWN, CONTROL_BUTTON_RC_UP)):
						
			#HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
			xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
			
			control = self.getControlById(CONTROL_LIST_ROMCOLLECTIONS)
			selectedRomCollection = str(control.getSelectedItem().getLabel())			
			
			#set initial scraper values
			sitesInRomCollection = []
			#get selected Rom Collection
			for rcId in self.gui.config.romCollections.keys():
				romCollection = self.gui.config.romCollections[rcId]
				if((selectedRomCollection == util.localize(40020) and romCollection.name != 'MAME')  or len(self.gui.config.romCollections) == 1 or romCollection.name == selectedRomCollection):
					sitesInRomCollection = romCollection.scraperSites
					break
				
			sitesInList = self.getAvailableScrapers()
			self.selectScrapersInList(sitesInRomCollection, sitesInList)
Esempio n. 24
0
	def readImagePlacing(self, imagePlacingName, tree):

		#fileTypeForRow = None
		fileTypeForRows = tree.findall('ImagePlacing/fileTypeFor')

		fileTypeForRow = next((element for element in fileTypeForRows if element.attrib.get('name') == imagePlacingName), None)
		if fileTypeForRow is None:
			Logutil.log('Configuration error. ImagePlacing/fileTypeFor %s does not exist in config.xml' % str(imagePlacingName), util.LOG_LEVEL_ERROR)
			return None, util.localize(32005)

		imagePlacing = ImagePlacing()

		imagePlacing.name = imagePlacingName

		for attr in ['fileTypesForGameList', 'fileTypesForGameListSelected',
					 'fileTypesForMainView1', 'fileTypesForMainView2', 'fileTypesForMainView3',
					 'fileTypesForMainViewBackground', 'fileTypesForMainViewGameInfoBig',
					 'fileTypesForMainViewGameInfoUpperLeft', 'fileTypesForMainViewGameInfoUpperRight',
					 'fileTypesForMainViewGameInfoLowerLeft', 'fileTypesForMainViewGameInfoLowerRight',
					 'fileTypesForMainViewGameInfoLower', 'fileTypesForMainViewGameInfoUpper',
					 'fileTypesForMainViewGameInfoRight', 'fileTypesForMainViewGameInfoLeft',
					 'fileTypesForMainViewVideoWindowBig', 'fileTypesForMainViewVideoWindowSmall',
					 'fileTypesForMainViewVideoFullscreen']:
			# Hack - class attribute fileTypesForXXX doesn't match XML key fileTypeForXXX
			val = self.readFileTypeForElement(fileTypeForRow, attr.replace('fileTypesFor', 'fileTypeFor'), tree)
			log.debug("Reading imageplacing for {0}: {1}".format(attr, val))
			setattr(imagePlacing, attr, val)

		return imagePlacing, ''
Esempio n. 25
0
	def __handleCompressedFile(self, gui, filext, rom, emuParams):

		log.info("__handleCompressedFile")

		# Note: Trying to delete temporary files (from zip or 7z extraction) from last run
		# Do this before launching a new game. Otherwise game could be deleted before launch
		tempDir = os.path.join(util.getTempDir(), 'extracted', self.romCollection.name)
		# check if folder exists
		if not xbmcvfs.exists(tempDir +'\\'):
			log.info("Create temporary folder: " +tempDir)
			xbmcvfs.mkdir(tempDir)

		try:
			if xbmcvfs.exists(tempDir +'\\'):
				log.info("Trying to delete temporary rom files")
				#can't use xbmcvfs.listdir here as it seems to cache the file list and RetroPlayer won't find newly created files anymore
				files = os.listdir(tempDir)
				for f in files:
					#RetroPlayer places savestate files next to the roms. Don't delete these files.
					fname, ext = os.path.splitext(f)
					if(ext not in ('.sav', '.xml', '.png')):
						xbmcvfs.delete(os.path.join(tempDir, f))
		except Exception, (exc):
			log.error("Error deleting files after launch emu: " + str(exc))
			gui.writeMsg(util.localize(32036) + ": " + str(exc))
Esempio n. 26
0
    def onInit(self):
        Logutil.log("onInit ContextMenu", util.LOG_LEVEL_INFO)

        pos = self.gui.getCurrentListPosition()
        if pos != -1:
            self.selectedGame, self.gameRow = self.gui.getGameByPosition(self.gui.gdb, pos)

            # set mark favorite text
        if self.gameRow != None:
            if self.gameRow[util.GAME_isFavorite] == 1:
                buttonMarkFavorite = self.getControlById(CONTROL_BUTTON_SETFAVORITE_GAME)
                if buttonMarkFavorite != None:
                    buttonMarkFavorite.setLabel(util.localize(40033))
                buttonMarkFavorite = self.getControlById(CONTROL_BUTTON_SETFAVORITE_SELECTION)
                if buttonMarkFavorite != None:
                    buttonMarkFavorite.setLabel(util.localize(40034))
	def editRomFileMask(self):
		
		control = self.getControlById(CONTROL_BUTTON_FILEMASK)
		romFileMask = control.getLabel()
		
		keyboard = xbmc.Keyboard()
		keyboard.setHeading(util.localize(32140))
		keyboard.setDefault(romFileMask)			
		keyboard.doModal()
		if (keyboard.isConfirmed()):
			romFileMask = keyboard.getText()
			if(romFileMask == ''):
				romFileMask = ' '
								
		#HACK: this only handles 1 base rom path
		romPath = self.selectedRomCollection.romPaths[0]
		pathParts = os.path.split(romPath)
		romPath = pathParts[0]
		fileMasks = romFileMask.split(',')
		romPaths = []
		for fileMask in fileMasks:				
			romPathComplete = os.path.join(romPath, fileMask.strip())					
			romPaths.append(romPathComplete)
		
		self.selectedRomCollection.romPaths = romPaths
		control.setLabel(romFileMask)
	def selectScrapersInList(self, sitesInRomCollection, sitesInList):
		
		Logutil.log('selectScrapersInList', util.LOG_LEVEL_INFO)
		
		if(len(sitesInRomCollection) >= 1):
			self.selectItemInList(sitesInRomCollection[0].name, CONTROL_LIST_SCRAPER1)			
		else:
			self.selectItemInList(util.localize(32854), CONTROL_LIST_SCRAPER1)
		if(len(sitesInRomCollection) >= 2):
			self.selectItemInList(sitesInRomCollection[1].name, CONTROL_LIST_SCRAPER2)
		else:
			self.selectItemInList(util.localize(32854), CONTROL_LIST_SCRAPER2)
		if(len(sitesInRomCollection) >= 3):
			self.selectItemInList(sitesInRomCollection[2].name, CONTROL_LIST_SCRAPER3)
		else:
			self.selectItemInList(util.localize(32854), CONTROL_LIST_SCRAPER3)
Esempio n. 29
0
	def useSingleScrapers(self, result, romCollection, startIndex, gamenameFromFile, foldername, firstRomfile, fuzzyFactor, updateOption, gui, progDialogRCHeader, fileCount):
		
		filecrc = ''
		artScrapers = {}
		
		for i in range(startIndex, len(romCollection.scraperSites)):
			scraperSite = romCollection.scraperSites[i]			
			
			gui.writeMsg(progDialogRCHeader, util.localize(40023) +": " +gamenameFromFile, scraperSite.name + " - " +util.localize(40031), fileCount)
			Logutil.log('using scraper: ' +scraperSite.name, util.LOG_LEVEL_INFO)
			
			if(scraperSite.searchGameByCRC and filecrc == ''):
				filecrc = self.getFileCRC(firstRomfile)
			
			urlsFromPreviousScrapers = []
			doContinue = False
			for scraper in scraperSite.scrapers:
				pyScraper = PyScraper()
				result, urlsFromPreviousScrapers, doContinue = pyScraper.scrapeResults(result, scraper, urlsFromPreviousScrapers, gamenameFromFile, foldername, filecrc, firstRomfile, fuzzyFactor, updateOption, romCollection, self.Settings)
			if(doContinue):
				continue
									
			#Find Filetypes and Scrapers for Art Download
			if(len(result) > 0):
				for path in romCollection.mediaPaths:
					thumbKey = 'Filetype' + path.fileType.name 
					if(len(self.resolveParseResult(result, thumbKey)) > 0):
						if((thumbKey in artScrapers) == 0):
							artScrapers[thumbKey] = scraperSite.name
						
		return result, artScrapers
Esempio n. 30
0
	def getThumbFromOnlineSource(self, gamedescription, fileType, fileName, gui, dialogDict, artworkurls):
		Logutil.log("Get thumb from online source", util.LOG_LEVEL_INFO)
		
		try:
			#maybe we got a thumb url from desc parser
			thumbKey = 'Filetype' +fileType
			Logutil.log("using key: " +thumbKey, util.LOG_LEVEL_INFO)
			thumbUrl = self.resolveParseResult(gamedescription, thumbKey)			
			if(thumbUrl == ''):
				return True, artworkurls
			
			artworkurls[fileType] = thumbUrl
			
			Logutil.log("Get thumb from url: " +str(thumbUrl), util.LOG_LEVEL_INFO)
			
			rootExtFile = os.path.splitext(fileName)
			rootExtUrl = os.path.splitext(thumbUrl)
			
			files = []
			if(len(rootExtUrl) == 2 and len(rootExtFile) != 0):
				fileName = rootExtFile[0] + rootExtUrl[1]
				gameName = rootExtFile[0] + ".*"
				files = self.getFilesByWildcard(gameName)
			del rootExtFile, rootExtUrl
			
			#check if folder exists
			dirname = os.path.dirname(fileName)
			#check parent folder
			parent = os.path.dirname(dirname)
			if(not xbmcvfs.exists(parent)):
				try:
					xbmcvfs.mkdir(parent)					
				except Exception, (exc):
					xbmcgui.Dialog().ok(util.localize(32010), util.localize(32011))
					Logutil.log("Could not create directory: '%s'. Error message: '%s'" %(parent, str(exc)), util.LOG_LEVEL_ERROR)
					return False, artworkurls
				del parent
				
			#check artwork specific folders
			if(not xbmcvfs.exists(dirname)):
				try:
					xbmcvfs.mkdir(dirname)
				except Exception, (exc):
					xbmcgui.Dialog().ok(util.localize(32010), util.localize(32011))
					Logutil.log("Could not create directory: '%s'. Error message: '%s'" %(dirname, str(exc)), util.LOG_LEVEL_ERROR)
					del dirname
					return False, artworkurls
Esempio n. 31
0
	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()
Esempio n. 32
0
	def readRomCollections(self, tree):
		
		Logutil.log('Begin readRomCollections', util.LOG_LEVEL_INFO)
		
		romCollections = {}
		
		romCollectionRows = tree.findall('RomCollections/RomCollection')
								
		if (len(romCollectionRows) == 0):
			Logutil.log('Configuration error. config.xml does not contain any RomCollections', util.LOG_LEVEL_ERROR)
			return None, 'Configuration error. See xbmc.log for details'
			
		for romCollectionRow in romCollectionRows:
			
			romCollection = RomCollection()
			romCollection.name = romCollectionRow.attrib.get('name')
			if(romCollection.name == None):
				Logutil.log('Configuration error. RomCollection must have an attribute name', util.LOG_LEVEL_ERROR)
				return None, util.localize(32005)
			
			Logutil.log('current Rom Collection: ' +str(romCollection.name), util.LOG_LEVEL_INFO)
			
			id = romCollectionRow.attrib.get('id')
			if(id == ''):
				Logutil.log('Configuration error. RomCollection %s must have an id' %romCollection.name, util.LOG_LEVEL_ERROR)
				return None, util.localize(32005)
			try:
				rc = romCollections[id]
				Logutil.log('Error while adding RomCollection. Make sure that the id is unique.', util.LOG_LEVEL_ERROR)
				return None, util.localize(32006)
			except:
				pass
			
			romCollection.id = id
			
			#romPath
			romCollection.romPaths = []
			romPathRows = romCollectionRow.findall('romPath')
			for romPathRow in romPathRows:
				Logutil.log('Rom path: ' +romPathRow.text, util.LOG_LEVEL_INFO)
				if(romPathRow.text != None):
					romCollection.romPaths.append(romPathRow.text)
				
			#mediaPath
			romCollection.mediaPaths = []
			mediaPathRows = romCollectionRow.findall('mediaPath')
			
			for mediaPathRow in mediaPathRows:
				mediaPath = MediaPath()
				if(mediaPathRow.text != None):					
					mediaPath.path = mediaPathRow.text
				Logutil.log('Media path: ' +mediaPath.path, util.LOG_LEVEL_INFO)
				fileType, errorMsg = self.readFileType(mediaPathRow.attrib.get('type'), tree)
				if(fileType == None):
					return None, errorMsg
				mediaPath.fileType = fileType
				romCollection.mediaPaths.append(mediaPath)
			
			#Scraper
			romCollection.scraperSites = []
			scraperRows = romCollectionRow.findall('scraper')
			for scraperRow in scraperRows:
				siteName = scraperRow.attrib.get('name')
				Logutil.log('Scraper site: ' +str(siteName), util.LOG_LEVEL_INFO)
				if(siteName == None or siteName == ''):
					Logutil.log('Configuration error. RomCollection/scraper must have an attribute name', util.LOG_LEVEL_ERROR)
					return None, util.localize(32005)
				
				#read additional scraper properties
				replaceKeyString = scraperRow.attrib.get('replaceKeyString')
				if(replaceKeyString == None):
					replaceKeyString = ''
				replaceValueString = scraperRow.attrib.get('replaceValueString')
				if(replaceValueString == None):
					replaceValueString = ''
								
				#elementtree version 1.2.7 does not support xpath like this: Scrapers/Site[@name="%s"] 
				siteRow = None
				siteRows = tree.findall('Scrapers/Site')
				for element in siteRows:
					if(element.attrib.get('name') == siteName):
						siteRow = element
						break
				
				if(siteRow == None):
					Logutil.log('Configuration error. Site %s does not exist in config.xml' %siteName, util.LOG_LEVEL_ERROR)
					return None, util.localize(32005)
								
				scraper, errorMsg = self.readScraper(siteRow, romCollection.name, replaceKeyString, replaceValueString, True, tree)
				if(scraper == None):
					return None, errorMsg
				romCollection.scraperSites.append(scraper)
				
			#imagePlacing - Main window
			romCollection.imagePlacingMain = ImagePlacing()
			imagePlacingRow = romCollectionRow.find('imagePlacingMain')			
			if(imagePlacingRow != None):
				Logutil.log('Image Placing name: ' +str(imagePlacingRow.text), util.LOG_LEVEL_INFO)
				fileTypeFor, errorMsg = self.readImagePlacing(imagePlacingRow.text, tree)
				if(fileTypeFor == None):
					return None, errorMsg
				
				romCollection.imagePlacingMain = fileTypeFor
				
			#imagePlacing - Info window
			romCollection.imagePlacingInfo = ImagePlacing()
			imagePlacingRow = romCollectionRow.find('imagePlacingInfo')			
			if(imagePlacingRow != None):
				Logutil.log('Image Placing name: ' +str(imagePlacingRow.text), util.LOG_LEVEL_INFO)
				fileTypeFor, errorMsg = self.readImagePlacing(imagePlacingRow.text, tree)
				if(fileTypeFor == None):
					return None, errorMsg
				
				romCollection.imagePlacingInfo = fileTypeFor
						
			#all simple RomCollection properties
			romCollection.gameclient = self.readTextElement(romCollectionRow, 'gameclient')
			romCollection.emulatorCmd = self.readTextElement(romCollectionRow, 'emulatorCmd')
			romCollection.preCmd = self.readTextElement(romCollectionRow, 'preCmd')
			romCollection.postCmd = self.readTextElement(romCollectionRow, 'postCmd')
			romCollection.emulatorParams = self.readTextElement(romCollectionRow, 'emulatorParams')
			romCollection.saveStatePath = self.readTextElement(romCollectionRow, 'saveStatePath')
			romCollection.saveStateParams = self.readTextElement(romCollectionRow, 'saveStateParams')
						
			useBuiltinEmulator = self.readTextElement(romCollectionRow, 'useBuiltinEmulator')
			if(useBuiltinEmulator != ''):
				romCollection.useBuiltinEmulator = useBuiltinEmulator.upper() == 'TRUE'
				
			ignoreOnScan = self.readTextElement(romCollectionRow, 'ignoreOnScan')
			if(ignoreOnScan != ''):
				romCollection.ignoreOnScan = ignoreOnScan.upper() == 'TRUE'
			
			allowUpdate = self.readTextElement(romCollectionRow, 'allowUpdate') 			
			if(allowUpdate != ''):
				romCollection.allowUpdate = allowUpdate.upper() == 'TRUE'
				
			useEmuSolo = self.readTextElement(romCollectionRow, 'useEmuSolo') 			
			if(useEmuSolo != ''):
				romCollection.useEmuSolo = useEmuSolo.upper() == 'TRUE'
				
			usePopen = self.readTextElement(romCollectionRow, 'usePopen') 			
			if(usePopen != ''):
				romCollection.usePopen = usePopen.upper() == 'TRUE'
				
			autoplayVideoMain = self.readTextElement(romCollectionRow, 'autoplayVideoMain')
			if(autoplayVideoMain != ''):
				romCollection.autoplayVideoMain = autoplayVideoMain.upper() == 'TRUE'
				
			autoplayVideoInfo = self.readTextElement(romCollectionRow, 'autoplayVideoInfo')
			if(autoplayVideoInfo != ''):
				romCollection.autoplayVideoInfo = autoplayVideoInfo.upper() == 'TRUE'
			
			useFoldernameAsGamename = self.readTextElement(romCollectionRow, 'useFoldernameAsGamename')			
			if(useFoldernameAsGamename != ''):
				romCollection.useFoldernameAsGamename = useFoldernameAsGamename.upper() == 'TRUE'	
			
			maxFolderDepth = self.readTextElement(romCollectionRow, 'maxFolderDepth') 
			if(maxFolderDepth != ''):
				romCollection.maxFolderDepth = int(maxFolderDepth)
				
			doNotExtractZipFiles = self.readTextElement(romCollectionRow, 'doNotExtractZipFiles') 			
			if(doNotExtractZipFiles != ''):
				romCollection.doNotExtractZipFiles = doNotExtractZipFiles.upper() == 'TRUE'
				
			makeLocalCopy = self.readTextElement(romCollectionRow, 'makeLocalCopy')
			if(makeLocalCopy != ''):
				romCollection.makeLocalCopy = makeLocalCopy.upper() == 'TRUE'		
				
			romCollection.diskPrefix = self.readTextElement(romCollectionRow, 'diskPrefix')
				
			xboxCreateShortcut = self.readTextElement(romCollectionRow, 'xboxCreateShortcut')			
			if(xboxCreateShortcut != ''):
				romCollection.xboxCreateShortcut = xboxCreateShortcut.upper() == 'TRUE'
				
			xboxCreateShortcutAddRomfile = self.readTextElement(romCollectionRow, 'xboxCreateShortcutAddRomfile') 			
			if(xboxCreateShortcutAddRomfile != ''):
				romCollection.xboxCreateShortcutAddRomfile = xboxCreateShortcutAddRomfile.upper() == 'TRUE'
				
			xboxCreateShortcutUseShortGamename = self.readTextElement(romCollectionRow, 'xboxCreateShortcutUseShortGamename')			
			if(xboxCreateShortcutUseShortGamename != ''):
				romCollection.xboxCreateShortcutUseShortGamename = xboxCreateShortcutUseShortGamename.upper() == 'TRUE'
			
			romCollections[id] = romCollection
			
		return romCollections, ''
Esempio n. 33
0
    'Virtual Boy': ['38', 'Nintendo Virtual Boy', 'virtualboy'],
    'V.Smile': ['42', '', ''],
    'Wii': ['82', 'Nintendo Wii', ''],
    'Windows': ['3', 'PC', ''],
    'Windows 3.x': ['5', '', ''],
    'WonderSwan': ['48', '', 'wonderswan'],
    'WonderSwan Color': ['49', '', ''],
    'Xbox': ['13', 'Microsoft Xbox', 'xbox'],
    'Xbox 360': ['69', 'Microsoft Xbox 360', ''],
    'Zeebo': ['88', '', ''],
    'Zodiac': ['68', '', 'zod'],
    'ZX Spectr': ['41', 'Sinclair ZX Spectrum', '']
}

missingFilterOptions = {
    util.localize(32157): util.localize(32158),
    util.localize(32159): util.localize(32160),
    util.localize(32161): util.localize(32162)
}


def getPlatformByRomCollection(source, romCollectionName):
    platform = ''
    if (source.find('mobygames.com') != -1):
        try:
            platform = consoleDict[romCollectionName][0]
        except:
            Logutil.log(
                'Could not find platform name for Rom Collection %s' %
                romCollectionName, util.LOG_LEVEL_WARNING)
    elif (source.find('thegamesdb.net') != -1):
Esempio n. 34
0
	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(32122) +" (%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(32153)):
				Logutil.log("Forcing enableFullReimport because we are in local artwork mode", util.LOG_LEVEL_INFO)
				enableFullReimport = True
			
			files = self.getRomFilesByRomCollection(romCollection, enableFullReimport)
			if(len(files) == 0):
				continue
			
			#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(32123) +": " +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)
							del artScrapers, gamenameFromFile, foldername, dialogDict
							if(not continueUpdate):
								break
							
							#remove found files from file list
							if(gameId != None):
								for filename in filenamelist:
									files.remove(filename)
									
							del filenamelist
									
							#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
						
						#flush files every x games. Trying to free some memory.
						if(fileCount % 50 == 0):
							Logutil.log("Flushing files", util.LOG_LEVEL_INFO)
							try:
								self.missingArtworkFile.flush()
								self.missingDescFile.flush()
								self.possibleMismatchFile.flush()
							except Exception, (exc):
								Logutil.log("Error flushing files: " +str(exc), util.LOG_LEVEL_WARNING)
								pass
						
					#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 checkDBStructure(self):

        #returnValues: -1 error, 0=nothing, 1=import Games, 2=idLookupFile created

        dbVersion = ""
        try:
            rcbSettingRows = RCBSetting(self).getAll()
            if rcbSettingRows == None or len(rcbSettingRows) != 1:
                self.createTables()
                self.commit()
                return 1, ""
            rcbSetting = rcbSettingRows[0]

            dbVersion = rcbSetting[RCBSetting.COL_dbVersion]

        except Exception as exc:
            self.createTables()
            self.commit()
            return 1, ""

        #Upgrade to new db layout
        if dbVersion != util.CURRENT_DB_VERSION:

            #backup MyGames.db
            #newFileName = self.dataBasePath + '.backup ' + dbVersion
            newFileName = '{0}{1}{2}'.format(self.dataBasePath, '.backup ', dbVersion)

            if os.path.isfile(newFileName):
                #32030: Error: Cannot backup MyGames.db: Backup File exists.
                return -1, util.localize(32030)
            try:
                self.close()
                shutil.copy(str(self.dataBasePath), str(newFileName))
                self.connect()
            except Exception as exc:
                #32031: Error: Cannot backup MyGames.db
                return -1, util.localize(32031) + ": " + str(exc)

            #execute all upgrade scripts from old db version to current db version
            while True:
                alterTableScript = "SQL_UPGRADE_%s.txt" % dbVersion
                alterTableScript = str(os.path.join(self.sqlDir, alterTableScript))

                if os.path.isfile(alterTableScript):
                    self.executeSQLScript(alterTableScript)
                    self.commit()

                    rcbSettingRows = RCBSetting(self).getAll()
                    dbVersion = rcbSettingRows[0][RCBSetting.COL_dbVersion]

                    if dbVersion == util.CURRENT_DB_VERSION:
                        break
                else:
                    #32032: Error: No Update from version %s to %s.
                    return -1, util.localize(32032) % (dbVersion, util.CURRENT_DB_VERSION)

        # VACUUM database
        self.compact()

        count = Game(self).getCount()
        if (count == 0):
            return 1, ""

        return 0, ""
Esempio n. 36
0
    def updateDB(self, gdb, gui, romCollections, isRescrape):
        self.gdb = gdb
        self._gui = gui

        log.info("Start Update DB")

        #at start, check if we need to create any artwork directories
        if not helper.createArtworkDirectories(romCollections):
            #32010: Error: Could not create artwork directory.
            return False, util.localize(32010)

        log.info("Iterating Rom Collections")
        rccount = 1

        # always do full reimports when in rescrape-mode
        enableFullReimport = isRescrape or __addon__.getSetting(util.SETTING_RCB_ENABLEFULLREIMPORT).upper() == 'TRUE'
        log.info("enableFullReimport: {0}".format(enableFullReimport))

        continueUpdate = True
        # Added variable to allow user to continue on errors
        ignoreErrors = False

        for romCollection in list(romCollections.values()):

            # timestamp1 = time.clock()

            # check if import was canceled
            if not continueUpdate:
                log.info("Game import canceled")
                break

            # prepare Header for ProgressDialog
            # 32122 = Importing Rom Collection
            progDialogRCHeader = util.localize(32122) + " (%i / %i): %s" % (
                rccount, len(romCollections), romCollection.name)
            rccount += 1

            log.info("current Rom Collection: {0}".format(romCollection.name))

            # Read settings for current Rom Collection
            log.info("ignoreOnScan: {0}".format(romCollection.ignoreOnScan))
            if romCollection.ignoreOnScan:
                log.info("current Rom Collection will be ignored.")
                # self.scrapeResultsFile.write('Rom Collection will be ignored.\n')
                continue

            log.info("update is allowed for current rom collection: {0}".format(romCollection.allowUpdate))
            log.info("max folder depth: {0}".format(romCollection.maxFolderDepth))

            files = self.getRomFilesByRomCollection(romCollection, enableFullReimport)
            if len(files) == 0:
                log.info(u"No files found for rom collection {0}, skipping".format(romCollection.name))
                continue

            log.info(u"Found {0} game files for rom collection {1}".format(len(files), romCollection.name))

            # itemCount is used for percentage in ProgressDialogGUI
            self._gui.itemCount = len(files) + 1

            successfulFiles = 0
            lastgamename = ''
            lastGameId = None

            for fileidx, filename in enumerate(files):

                try:
                    #Give kodi a chance to interrupt the process
                    #HACK: we should use monitor.abortRequested() or monitor.waitForAbort()
                    #but for some reason only xbmc.abortRequested returns True
                    if monitor.abortRequested():
                        log.info("Kodi requests abort. Cancel Update.")
                        break

                    log.info("Scraping for %s" % filename)
                    gamenameFromFile = romCollection.getGamenameFromFilename(filename)

                    # check if we are handling one of the additional disks of a multi rom game
                    isMultiRomGame = (gamenameFromFile == lastgamename)
                    lastgamename = gamenameFromFile

                    if isMultiRomGame:
                        # Add this entry as a file under the game ID and move on
                        log.info("Detected %s as a multirom game (previous game was %s)" % (filename, lastgamename))
                        if lastGameId is None:
                            log.error("Game detected as multi rom game, but lastGameId is None.")
                            continue
                        fileType = FileType()
                        fileType.id, fileType.name, fileType.parent = 0, "rcb_rom", "game"
                        self.insertFile(filename, lastGameId, fileType, None, None, None)
                        self.gdb.commit()
                        del fileType
                        continue

                    log.info("Start scraping info for game: %s" % gamenameFromFile)

                    # 32123 = Importing Game
                    msg = "%s: %s" %(util.localize(32123), gamenameFromFile)
                    continueUpdate = self._gui.writeMsg(msg, fileidx + 1)
                    if not continueUpdate:
                        log.info("Game import canceled by user")
                        break

                    # check if this file already exists in DB
                    continueUpdate, isUpdate, gameId = self.checkRomfileAlreadyExists(filename, enableFullReimport)
                    if not continueUpdate:
                        continue

                    foldername = self.getFoldernameFromRomFilename(filename)

                    results, artScrapers = self.useSingleScrapers(romCollection, filename, gamenameFromFile,
                                                                  progDialogRCHeader, fileidx + 1)

                    if len(results) == 0:
                        # lastgamename = ""
                        results = None

                    # Variables to process Art Download Info
                    self._guiDict.update({'dialogHeaderKey': progDialogRCHeader, 'gameNameKey': gamenameFromFile,
                                          'scraperSiteKey': artScrapers, 'fileCountKey': (fileidx + 1)})
                    del artScrapers

                    #Give kodi a chance to interrupt the process
                    #HACK: we should use monitor.abortRequested() or monitor.waitForAbort()
                    #but for some reason only xbmc.abortRequested returns True
                    if monitor.abortRequested():
                        log.info("Kodi requests abort. Cancel Update.")
                        break

                    # Add 'gui' and 'dialogDict' parameters to function
                    lastGameId = self.insertGameFromDesc(results, gamenameFromFile, romCollection, [filename],
                                                         foldername, isUpdate, gameId)
                    del results, foldername

                    if lastGameId is not None:
                        log.info("Successfully added %s" % gamenameFromFile)
                        successfulFiles += 1

                    # Check if all first 10 games have errors - Modified to allow user to continue on errors
                    if fileidx > 9 and successfulFiles == 0 and not ignoreErrors:
                        #32124 = Continue
                        #32125 = Continue and Ignore Errors
                        #32126 = Cancel
                        #32127 = First 10 games could not be imported.
                        options = [util.localize(32124), util.localize(32125), util.localize(32126)]
                        answer = xbmcgui.Dialog().select(util.localize(32127), options)
                        if answer == 1:
                            # Continue and ignore errors
                            ignoreErrors = True
                        elif answer == 2:
                            # Cancel
                            #32128 = Import canceled.
                            #32129 = Please check kodi.log for details.
                            message = "%s[CR]%s" % (util.localize(32128), util.localize(32129))
                            xbmcgui.Dialog().ok(util.SCRIPTNAME, message)
                            continueUpdate = False
                            break

                except ScraperExceededAPIQuoteException:
                    #32128 = Import canceled.
                    #32043 = API quota for current scraper exceeded.
                    xbmcgui.Dialog().ok(util.localize(32128), util.localize(32043))
                    # Abort the scraping entirely
                    break
                except Exception as exc:
                    log.warn(u"An error occurred while adding game %s: %s" % (gamenameFromFile, exc))
                    self.missingDescFile.add_entry(gamenameFromFile)

                    continue

        # timestamp2 = time.clock()
        # diff = (timestamp2 - timestamp1) * 1000
        # print "load %i games in %d ms" % (self.getListSize(), diff)

        self._gui.writeMsg("Done.", self._gui.itemCount)
        log.info("Update finished")
        return True, ''
Esempio n. 37
0
    def useSingleScrapers(self, romCollection, romFile, gamenameFromFile, progDialogRCHeader, fileCount):
        """Scrape site for game metadata

        Args:
            romCollection:
            romFile:
            gamenameFromFile:
            progDialogRCHeader:
            fileCount:

        Returns:
            dict for the game result:
                {'SearchKey': ['Chrono Trigger'],
                 'Publisher': ['Squaresoft'],
                 'Description': ["The millennium. A portal is opened. The chain of time is broken...],
                 'Players': ['1'],
                 'Platform': ['Super Nintendo (SNES)'],
                 'Game': ['Chrono Trigger'],
                 'Filetypeboxfront': ['http://thegamesdb.net/banners/boxart/original/front/1255-1.jpg'],
                 'Filetypeboxback': ['http://thegamesdb.net/banners/boxart/original/back/1255-1.jpg'],
                 'Filetypescreenshot': ['http://thegamesdb.net/banners/screenshots/1255-1.jpg', 'http://thegamesdb.net/banners/screenshots/1255-2.jpg', 'http://thegamesdb.net/banners/screenshots/1255-3.jpg', 'http://thegamesdb.net/banners/screenshots/1255-4.jpg', 'http://thegamesdb.net/banners/screenshots/1255-5.jpg'],
                 'Filetypefanart': ['http://thegamesdb.net/banners/fanart/original/1255-1.jpg', 'http://thegamesdb.net/banners/fanart/original/1255-10.jpg', 'http://thegamesdb.net/banners/fanart/original/1255-11.jpg', 'http://thegamesdb.net/banners/fanart/original/1255-2.jpg', 'http://thegamesdb.net/banners/fanart/original/1255-3.jpg', 'http://thegamesdb.net/banners/fanart/original/1255-4.jpg', 'http://thegamesdb.net/banners/fanart/original/1255-5.jpg', 'http://thegamesdb.net/banners/fanart/original/1255-6.jpg', 'http://thegamesdb.net/banners/fanart/original/1255-7.jpg', 'http://thegamesdb.net/banners/fanart/original/1255-8.jpg', 'http://thegamesdb.net/banners/fanart/original/1255-9.jpg'],
                 'Genre': ['Role-Playing'],
                 'Developer': ['Squaresoft']}
            dict for artwork urls:
                {'Filetypefanart': 'thegamesdb.net', 'Filetypeboxback': 'thegamesdb.net', 'Filetypescreenshot': 'thegamesdb.net', 'Filetypeboxfront': 'thegamesdb.net'}
                Note - this only contains entries for artwork that was found (i.e. is not empty list)
        """
        gameresult = {}
        artScrapers = {}

        scraperSite = None

        #search for default scraper if there are more than one
        for site in romCollection.scraperSites:
            if site.default:
                scraperSite = site
                break

        #if no default site was found, just use the first one
        if not scraperSite:
            if len(romCollection.scraperSites) >= 1:
                scraperSite = romCollection.scraperSites[0]

        try:
            #first check if a local nfo file is available
            nfoscraper = NFO_Scraper()
            nfofile = nfoscraper.get_nfo_path(gamenameFromFile, romCollection.name, romFile)
            if xbmcvfs.exists(nfofile) and __addon__.getSetting(util.SETTING_RCB_PREFERLOCALNFO).upper() == 'TRUE':
                log.info("Found local nfo file. Using this to scrape info.")
                newscraper = nfoscraper
            else:
                newscraper = AbstractScraper().get_scraper_by_name(scraperSite.name)
                #set path to desc file (only useful for offline scrapers)
                newscraper.path = scraperSite.path

            log.info("Using scraper: %s" % newscraper.name)
            # 32123 = Importing Game
            # 32131 = downloading info
            msg = "%s: %s[CR]%s: %s" %(util.localize(32123), gamenameFromFile, newscraper.name, util.localize(32131))
            self._gui.writeMsg(msg, fileCount)

            results = newscraper.search(gamenameFromFile, romCollection.name)
            log.debug(u"Searching for %s - found %s results: %s" % (gamenameFromFile, len(results), results))
        except ScraperExceededAPIQuoteException as ke:
            # API key is invalid - we need to stop scraping
            log.error("Scraper exceeded API key, stopping scraping")
            raise
        except Exception as e:
            log.error("Error searching for %s using scraper %s - %s %s" % (
                gamenameFromFile, scraperSite.name, type(e), e))
            return gameresult, artScrapers

        if results == []:
            log.warn("No search results found for %s using scraper %s" % (gamenameFromFile, scraperSite.name))
            return gameresult, artScrapers

        matched = Matcher().getBestResults(results, gamenameFromFile)
        if matched is None:
            log.error("No matches found for %s, skipping" % gamenameFromFile)
            return gameresult, artScrapers
        log.debug("After matching: %s" % matched)

        try:
            retrievedresult = newscraper.retrieve(matched['id'], romCollection.name)
            log.debug(u"Retrieving %s - found %s" % (matched['id'], retrievedresult))
        except Exception as e:
            # FIXME TODO Catch exceptions specifically
            log.error("Error retrieving %s - %s %s" % (matched['id'], type(e), e))
            return gameresult, artScrapers

        # Update the gameresult with any new fields
        gameresult = self.addNewElements(gameresult, retrievedresult)

        # Find Filetypes and Scrapers for Art Download
        # FIXME TODO The following is kept to keep artwork downloading working as it currently is. We already have
        # the URLs and so could handle/download here, rather than deferring
        if len(gameresult) > 0:
            for path in romCollection.mediaPaths:
                thumbKey = 'Filetype' + path.fileType.name
                if len(self.resolveParseResult(gameresult, thumbKey)) > 0:
                    if (thumbKey in artScrapers) == 0:
                        artScrapers[thumbKey] = scraperSite.name

        log.debug(u"After scraping, result = %s, artscrapers = %s" % (gameresult, artScrapers))
        return gameresult, artScrapers
    def onClick(self, controlID):

        Logutil.log('onClick', util.LOG_LEVEL_INFO)

        if (controlID == CONTROL_BUTTON_EXIT):  # Close window button
            Logutil.log('close', util.LOG_LEVEL_INFO)
            self.close()
        #OK
        elif (controlID == CONTROL_BUTTON_SAVE):
            Logutil.log('save', util.LOG_LEVEL_INFO)
            #store selectedRomCollection
            if (self.selectedRomCollection != None):
                self.updateSelectedRomCollection()
                self.romCollections[
                    self.selectedRomCollection.id] = self.selectedRomCollection

            configWriter = ConfigXmlWriter(False)
            success, message = configWriter.writeRomCollections(
                self.romCollections, True)

            if not success:
                xbmcgui.Dialog().ok(util.localize(32021), message)
            self.close()

        #Cancel
        elif (controlID == CONTROL_BUTTON_CANCEL):
            self.close()
        #Rom Collection list
        elif (self.selectedControlId
              in (CONTROL_BUTTON_RC_DOWN, CONTROL_BUTTON_RC_UP)):
            if (self.selectedRomCollection != None):
                #save current values to selected Rom Collection
                self.updateSelectedRomCollection()
                #store previous selectedRomCollections state
                self.romCollections[
                    self.selectedRomCollection.id] = self.selectedRomCollection

            #HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
            xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
            self.updateRomCollectionControls()

        #Media Path
        elif (self.selectedControlId
              in (CONTROL_BUTTON_MEDIA_DOWN, CONTROL_BUTTON_MEDIA_UP)):
            #HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
            xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
            self.updateMediaPathControls()

        elif (controlID == CONTROL_BUTTON_GAMECLIENT):
            success, gameclient = helper.selectlibretrocore(
                self.selectedRomCollection.name)
            if success:
                self.selectedRomCollection.gameclient = gameclient

            control = self.getControlById(CONTROL_BUTTON_GAMECLIENT)
            if (gameclient == ""):
                control.setLabel("None")
            else:
                control.setLabel(gameclient)

        elif (controlID == CONTROL_BUTTON_EMUCMD):

            #maybe there is autoconfig support
            preconfiguredEmulator = None
            emulatorPath = ''
            dialog = xbmcgui.Dialog()

            if (self.selectedRomCollection.name == 'Linux'
                    or self.selectedRomCollection.name == 'Macintosh'
                    or self.selectedRomCollection.name == 'Windows'):
                emulatorPath = self.editTextProperty(CONTROL_BUTTON_EMUCMD,
                                                     util.localize(32624))
            else:
                if (xbmc.getCondVisibility('System.Platform.Android')):

                    autoconfig = EmulatorAutoconfig(
                        util.getEmuAutoConfigPath())

                    Logutil.log(
                        'Running on Android. Trying to find emulator per autoconfig.',
                        util.LOG_LEVEL_INFO)
                    emulators = autoconfig.findEmulators(
                        'Android', self.selectedRomCollection.name, True)
                    emulist = []
                    if (emulators):
                        for emulator in emulators:
                            if (emulator.isInstalled):
                                emulist.append(
                                    util.localize(32202) % emulator.name)
                            else:
                                emulist.append(emulator.name)
                    if (len(emulist) > 0):
                        emuIndex = dialog.select(util.localize(32203), emulist)
                        Logutil.log('emuIndex: ' + str(emuIndex),
                                    util.LOG_LEVEL_INFO)
                        if (emuIndex == -1):
                            Logutil.log('No Emulator selected.',
                                        util.LOG_LEVEL_INFO)
                        else:
                            preconfiguredEmulator = emulators[emuIndex]

                if (preconfiguredEmulator):
                    emulatorPath = preconfiguredEmulator.emuCmd
                    self.selectedRomCollection.emulatorParams = preconfiguredEmulator.emuParams
                    control = self.getControlById(CONTROL_BUTTON_PARAMS)
                    control.setLabel(self.selectedRomCollection.emulatorParams)
                else:
                    emulatorPath = dialog.browse(
                        1, '%s ' % self.selectedRomCollection.name +
                        util.localize(32139), 'files')
                    if (emulatorPath == ''):
                        return

            self.selectedRomCollection.emulatorCmd = emulatorPath
            control = self.getControlById(CONTROL_BUTTON_EMUCMD)
            control.setLabel(emulatorPath)

        elif (controlID == CONTROL_BUTTON_PARAMS):
            emulatorParams = self.editTextProperty(CONTROL_BUTTON_PARAMS,
                                                   util.localize(32625))
            self.selectedRomCollection.emulatorParams = emulatorParams

        elif (controlID == CONTROL_BUTTON_ROMPATH):
            self.editRomPath()

        elif (controlID == CONTROL_BUTTON_FILEMASK):
            self.editRomFileMask()

        elif (controlID == CONTROL_BUTTON_MEDIAPATH):
            self.editMediaPath()

        elif (controlID == CONTROL_BUTTON_MEDIAFILEMASK):
            self.editMediaFileMask()

        elif (controlID == CONTROL_BUTTON_ADDMEDIAPATH):
            self.addMediaPath()

        elif (controlID == CONTROL_BUTTON_REMOVEMEDIAPATH):
            self.removeMediaPath()

        elif (controlID == CONTROL_BUTTON_MAXFOLDERDEPTH):
            maxFolderDepth = self.editTextProperty(
                CONTROL_BUTTON_MAXFOLDERDEPTH, util.localize(32610))
            self.selectedRomCollection.maxFolderDepth = maxFolderDepth

        elif (controlID == CONTROL_BUTTON_DISKINDICATOR):
            diskIndicator = self.editTextProperty(CONTROL_BUTTON_DISKINDICATOR,
                                                  util.localize(32611))
            self.selectedRomCollection.diskPrefix = diskIndicator

        elif (controlID == CONTROL_BUTTON_SAVESTATEPATH):
            saveStatePathComplete = self.editPathWithFileMask(
                CONTROL_BUTTON_SAVESTATEPATH,
                '%s ' % self.selectedRomCollection.name + util.localize(32629),
                CONTROL_BUTTON_SAVESTATEMASK)
            if (saveStatePathComplete != ''):
                self.selectedRomCollection.saveStatePath = saveStatePathComplete

        elif (controlID == CONTROL_BUTTON_SAVESTATEMASK):
            self.selectedRomCollection.saveStatePath = self.editFilemask(
                CONTROL_BUTTON_SAVESTATEMASK, util.localize(32630),
                self.selectedRomCollection.saveStatePath)

        elif (controlID == CONTROL_BUTTON_SAVESTATEPARAMS):
            saveStateParams = self.editTextProperty(
                CONTROL_BUTTON_SAVESTATEPARAMS, util.localize(32631))
            self.selectedRomCollection.saveStateParams = saveStateParams

        elif (controlID == CONTROL_BUTTON_PRECMD):
            preCmd = self.editTextProperty(CONTROL_BUTTON_PRECMD,
                                           util.localize(32632))
            self.selectedRomCollection.preCmd = preCmd
            Logutil.log(
                'OnClick: precmd = ' + self.selectedRomCollection.preCmd,
                util.LOG_LEVEL_INFO)

        elif (controlID == CONTROL_BUTTON_POSTCMD):
            postCmd = self.editTextProperty(CONTROL_BUTTON_POSTCMD,
                                            util.localize(32633))
            self.selectedRomCollection.postCmd = postCmd
Esempio n. 39
0
			'Vectrex' : ['37', '', 'vectrex'],
			'VIC-20' : ['43', '', 'vic20'],
			'Virtual Boy' : ['38', 'Nintendo Virtual Boy', 'virtualboy'],  
			'V.Smile' : ['42', '', ''],
			'Wii' : ['82', 'Nintendo Wii', ''],
			'Windows' : ['3', 'PC', ''], 
			'Windows 3.x' : ['5', '', ''],
			'WonderSwan' : ['48', '', 'wonderswan'],
			'WonderSwan Color' : ['49', '', ''],  
			'Xbox' : ['13', 'Microsoft Xbox', 'xbox'],
			'Xbox 360' : ['69', 'Microsoft Xbox 360', ''],
			'Zeebo' : ['88', '', ''],
			'Zodiac' : ['68', '', 'zod'],
			'ZX Spectr' : ['41', 'Sinclair ZX Spectrum', '']}

missingFilterOptions = {util.localize(32157) : util.localize(32158),
					util.localize(32159) : util.localize(32160),
					util.localize(32161) : util.localize(32162)}



def getPlatformByRomCollection(source, romCollectionName):
	platform = ''
	if(source.find('mobygames.com') != -1):
		try:
			platform = consoleDict[romCollectionName][0]
		except:
			Logutil.log('Could not find platform name for Rom Collection %s' %romCollectionName, util.LOG_LEVEL_WARNING)
	elif(source.find('thegamesdb.net') != -1):
		try:
			platform = consoleDict[romCollectionName][1]
    def onClick(self, controlID):
        log.info("onClick")

        if controlID == CONTROL_BUTTON_EXIT:  # Close window button
            log.info("close")
            self.close()
        # OK
        elif controlID == CONTROL_BUTTON_SAVE:
            log.info("save")
            # Store selectedRomCollection
            if self.selectedRomCollection is not None:
                self.updateSelectedRomCollection()
                self.romCollections[
                    self.selectedRomCollection.id] = self.selectedRomCollection

            configWriter = ConfigXmlWriter(False)
            success, message = configWriter.writeRomCollections(
                self.romCollections, True)

            if not success:
                xbmcgui.Dialog().ok(util.localize(32021), message)
            self.close()

        # Cancel
        elif controlID == CONTROL_BUTTON_CANCEL:
            self.close()
        elif controlID == CONTROL_BUTTON_ADD_RC:
            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
            self.gui.config = Config(None)
            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

            self.addItemsToList(CONTROL_LIST_ROMCOLLECTIONS,
                                self.gui.config.getRomCollectionNames())
            self.updateRomCollectionControls()

        elif controlID == CONTROL_BUTTON_REMOVE_RC:
            constructorParam = "720p"
            try:
                removeRCDialog = dialogdeleteromcollection.RemoveRCDialog(
                    "script-RCB-removeRC.xml",
                    util.getAddonInstallPath(),
                    util.getConfiguredSkin(),
                    constructorParam,
                    gui=self.gui)
            except:
                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

            self.gui.config = Config(None)
            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

            self.addItemsToList(CONTROL_LIST_ROMCOLLECTIONS,
                                self.gui.config.getRomCollectionNames())
            self.updateRomCollectionControls()

        # Rom Collection list
        elif self.selectedControlId in (CONTROL_BUTTON_RC_DOWN,
                                        CONTROL_BUTTON_RC_UP):
            if self.selectedRomCollection is not None:
                # Save current values to selected Rom Collection
                self.updateSelectedRomCollection()
                # Store previous selectedRomCollections state
                self.romCollections[
                    self.selectedRomCollection.id] = self.selectedRomCollection

            # HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
            xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
            self.updateRomCollectionControls()

        # Media Path
        elif self.selectedControlId in (CONTROL_BUTTON_MEDIA_DOWN,
                                        CONTROL_BUTTON_MEDIA_UP):
            # HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
            xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
            self.updateMediaPathControls()

        elif controlID == CONTROL_LIST_OFFLINE_SCRAPER:
            self.editOfflineScraper()

        elif controlID == CONTROL_BUTTON_GAMECLIENT:
            success, gameclient = helper.selectlibretrocore(
                self.selectedRomCollection.name)
            if success:
                self.selectedRomCollection.gameclient = gameclient

            control = self.getControlById(CONTROL_BUTTON_GAMECLIENT)
            if gameclient == "":
                control.setLabel("None")
            else:
                control.setLabel(gameclient)

        elif controlID == CONTROL_BUTTON_EMUCMD:
            self.editEmuCmd()

        elif controlID == CONTROL_BUTTON_PARAMS:
            emulatorParams = self.editTextProperty(CONTROL_BUTTON_PARAMS,
                                                   util.localize(32625))
            self.selectedRomCollection.emulatorParams = emulatorParams

        elif controlID == CONTROL_BUTTON_ROMPATH:
            self.editRomPath()

        elif controlID == CONTROL_BUTTON_FILEMASK:
            self.editRomFileMask()

        elif controlID == CONTROL_BUTTON_MEDIAPATH:
            self.editMediaPath()

        elif controlID == CONTROL_BUTTON_MEDIAFILEMASK:
            self.editMediaFileMask()

        elif controlID == CONTROL_BUTTON_ADDMEDIAPATH:
            self.addMediaPath()

        elif controlID == CONTROL_BUTTON_REMOVEMEDIAPATH:
            self.removeMediaPath()

        elif controlID == CONTROL_BUTTON_MAXFOLDERDEPTH:
            maxFolderDepth = self.editTextProperty(
                CONTROL_BUTTON_MAXFOLDERDEPTH, util.localize(32610))
            self.selectedRomCollection.maxFolderDepth = maxFolderDepth

        elif controlID == CONTROL_BUTTON_DISKINDICATOR:
            diskIndicator = self.editTextProperty(CONTROL_BUTTON_DISKINDICATOR,
                                                  util.localize(32611))
            self.selectedRomCollection.diskPrefix = diskIndicator

        elif controlID == CONTROL_BUTTON_SAVESTATEPATH:
            saveStatePathComplete = self.editPathWithFileMask(
                CONTROL_BUTTON_SAVESTATEPATH,
                '%s ' % self.selectedRomCollection.name + util.localize(32629),
                CONTROL_BUTTON_SAVESTATEMASK)
            if saveStatePathComplete != '':
                self.selectedRomCollection.saveStatePath = saveStatePathComplete

        elif controlID == CONTROL_BUTTON_SAVESTATEMASK:
            self.selectedRomCollection.saveStatePath = self.editFilemask(
                CONTROL_BUTTON_SAVESTATEMASK, util.localize(32630),
                self.selectedRomCollection.saveStatePath)

        elif controlID == CONTROL_BUTTON_SAVESTATEPARAMS:
            saveStateParams = self.editTextProperty(
                CONTROL_BUTTON_SAVESTATEPARAMS, util.localize(32631))
            self.selectedRomCollection.saveStateParams = saveStateParams

        elif controlID == CONTROL_BUTTON_PRECMD:
            preCmd = self.editTextProperty(CONTROL_BUTTON_PRECMD,
                                           util.localize(32632))
            self.selectedRomCollection.preCmd = preCmd
            log.info("OnClick: precmd = {0}".format(
                self.selectedRomCollection.preCmd))

        elif controlID == CONTROL_BUTTON_POSTCMD:
            postCmd = self.editTextProperty(CONTROL_BUTTON_POSTCMD,
                                            util.localize(32633))
            self.selectedRomCollection.postCmd = postCmd
Esempio n. 41
0
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(35034))
		return
			
	gui.writeMsg(util.localize(40063)+ " " +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')			
			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.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(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(35035) +": " +str(exc))
    def showGameList(self):

        Logutil.log("Begin showGameList", util.LOG_LEVEL_INFO)

        #likeStatement = helper.buildLikeStatement(self.selectedCharacter)
        #games = Game(self.gdb).getFilteredGames(self.selectedConsoleId, self.selectedGenreId, self.selectedYearId, self.selectedPublisherId, likeStatement)

        self.writeMsg(util.localize(32121))

        self.clearList()

        gameRow = Game(self.gdb).getObjectById(self.selectedGameId)

        fileDict = self.getFileDictByGameRow(self.gdb, gameRow)

        romCollection = None
        try:
            romCollection = self.config.romCollections[str(
                gameRow[util.GAME_romCollectionId])]
        except:
            Logutil.log(
                util.localize(32023) % str(gameRow[util.GAME_romCollectionId]),
                util.LOG_LEVEL_ERROR)

        imageGameList = self.getFileForControl(
            romCollection.imagePlacingInfo.fileTypesForGameList,
            gameRow[util.ROW_ID], gameRow[util.GAME_publisherId],
            gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId],
            fileDict)
        imageGameListSelected = self.getFileForControl(
            romCollection.imagePlacingInfo.fileTypesForGameListSelected,
            gameRow[util.ROW_ID], gameRow[util.GAME_publisherId],
            gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId],
            fileDict)

        item = xbmcgui.ListItem(gameRow[util.ROW_NAME],
                                str(gameRow[util.ROW_ID]), imageGameList,
                                imageGameListSelected)
        item.setProperty('gameId', str(gameRow[util.ROW_ID]))

        #check if we should use autoplay video
        if (romCollection.autoplayVideoInfo):
            item.setProperty('autoplayvideoinfo', 'true')
        else:
            item.setProperty('autoplayvideoinfo', '')

        #get video window size
        if (romCollection.imagePlacingInfo.name.startswith('gameinfosmall')):
            item.setProperty('videosizesmall', 'small')
            item.setProperty('videosizebig', '')
        else:
            item.setProperty('videosizebig', 'big')
            item.setProperty('videosizesmall', '')

        videos = helper.getFilesByControl_Cached(
            self.gdb, (self.fileTypeGameplay, ), gameRow[util.ROW_ID],
            gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId],
            gameRow[util.GAME_romCollectionId], fileDict)
        if (videos != None and len(videos) != 0):
            video = videos[0]
            item.setProperty('gameplayinfo', video)

        self.addItem(item)

        xbmc.executebuiltin("Container.SortDirection")
        self.writeMsg("")

        Logutil.log("End showGameList", util.LOG_LEVEL_INFO)
Esempio n. 43
0
            dbVersion = rcbSetting[RCBSetting.COL_dbVersion]

        except Exception, (exc):
            self.createTables()
            self.commit()
            return 1, ""

        #Upgrade to new db layout
        if dbVersion != util.CURRENT_DB_VERSION:

            #backup MyGames.db
            newFileName = self.dataBasePath + '.backup ' + dbVersion

            if os.path.isfile(newFileName):
                #32030: Error: Cannot backup MyGames.db: Backup File exists.
                return -1, util.localize(32030)
            try:
                self.close()
                shutil.copy(str(self.dataBasePath), str(newFileName))
                self.connect()
            except Exception, (exc):
                #32031: Error: Cannot backup MyGames.db
                return -1, util.localize(32031) + ": " + str(exc)

            #execute all upgrade scripts from old db version to current db version
            while True:
                alterTableScript = "SQL_UPGRADE_%s.txt" % dbVersion
                alterTableScript = str(
                    os.path.join(self.sqlDir, alterTableScript))

                if os.path.isfile(alterTableScript):
Esempio n. 44
0
    def __handleCompressedFile(self, gui, filext, rom, emuParams):

        log.info("__handleCompressedFile")

        # Note: Trying to delete temporary files (from zip or 7z extraction) from last run
        # Do this before launching a new game. Otherwise game could be deleted before launch
        tempDir = os.path.join(util.getTempDir(), 'extracted', self.romCollection.name)
        # check if folder exists
        if not xbmcvfs.exists(tempDir + '\\'):
            log.info("Create temporary folder: " + tempDir)
            xbmcvfs.mkdir(tempDir)

        try:
            if xbmcvfs.exists(tempDir + '\\'):
                log.info("Trying to delete temporary rom files")
                #can't use xbmcvfs.listdir here as it seems to cache the file list and RetroPlayer won't find newly created files anymore
                files = os.listdir(tempDir)
                for f in files:
                    #RetroPlayer places savestate files next to the roms. Don't delete these files.
                    fname, ext = os.path.splitext(f)
                    if ext not in ('.sav', '.xml', '.png'):
                        xbmcvfs.delete(os.path.join(tempDir, f))
        except Exception as exc:
            log.error("Error deleting files after launch emu: " + str(exc))
            gui.writeMsg(util.localize(32036) + ": " + str(exc))

        roms = []

        log.info("Treating file as a compressed archive")

        try:
            names = self.__getNames(filext, rom)
        except Exception as exc:
            log.error("Error handling compressed file: " + str(exc))
            return []

        if names is None:
            log.error("Error handling compressed file")
            return []

        chosenROM = -1

        # check if we should handle multiple roms
        match = False
        if self.romCollection.diskPrefix != '':
            match = re.search(self.romCollection.diskPrefix.lower(), str(names).lower())

        if '%I%' in emuParams and match:
            log.info("Loading %d archives" % len(names))

            try:
                archives = self.__getArchives(filext, rom, names)
            except Exception as exc:
                log.error("Error handling compressed file: " + str(exc))
                return []

            if archives is None:
                log.warning("Error handling compressed file")
                return []
            for archive in archives:
                newPath = os.path.join(tempDir, archive[0])
                fp = open(newPath, 'wb')
                fp.write(archive[1])
                fp.close()
                roms.append(newPath)

        elif len(names) > 1:
            log.info("The Archive has %d files" % len(names))
            chosenROM = xbmcgui.Dialog().select('Choose a ROM', names)
        elif len(names) == 1:
            log.info("Archive only has one file inside; picking that one")
            chosenROM = 0
        else:
            log.error("Archive had no files inside!")
            return []

        if chosenROM != -1:
            # Extract all files to %TMP%
            archives = self.__getArchives(filext, rom, names)
            if archives is None:
                log.warn("Error handling compressed file")
                return []
            for archive in archives:
                newPath = os.path.join(tempDir, archive[0])
                log.info("Putting extracted file in %s" % newPath)
                fo = open(str(newPath), 'wb')
                fo.write(archive[1])
                fo.close()

            # Point file name to the chosen file and continue as usual
            roms = [os.path.join(tempDir, names[chosenROM])]

        return roms
Esempio n. 45
0
    def onClick(self, controlID):

        Logutil.log('onClick', util.LOG_LEVEL_INFO)

        if (controlID == CONTROL_BUTTON_EXIT):  # Close window button
            Logutil.log('close', util.LOG_LEVEL_INFO)
            self.close()
        #OK
        elif (controlID == CONTROL_BUTTON_SAVE):
            Logutil.log('save', util.LOG_LEVEL_INFO)

            #store selectedOfflineScraper
            if (self.selectedOfflineScraper != None):
                self.updateSelectedOfflineScraper()
                self.scraperSites[self.selectedOfflineScraper.
                                  name] = self.selectedOfflineScraper

            configWriter = ConfigXmlWriter(False)
            success, message = configWriter.writeScrapers(self.scraperSites)

            self.close()
        #Cancel
        elif (controlID == CONTROL_BUTTON_CANCEL):
            self.close()

        #Offline Scraper
        elif (self.selectedControlId
              in (CONTROL_BUTTON_SCRAPERS_UP, CONTROL_BUTTON_SCRAPERS_DOWN)):

            if (self.selectedOfflineScraper != None):
                #save current values to selected ScraperSite
                self.updateSelectedOfflineScraper()

                #store previous selectedOfflineScrapers state
                self.scraperSites[self.selectedOfflineScraper.
                                  name] = self.selectedOfflineScraper

            #HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
            xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
            self.updateOfflineScraperControls()

        elif (controlID == CONTROL_BUTTON_GAMEDESCPATH):

            #check value of descfilepergame
            control = self.getControlById(CONTROL_BUTTON_DESCPERGAME)
            if (control.isSelected()):
                gamedescPathComplete = self.editPathWithFileMask(
                    CONTROL_BUTTON_GAMEDESCPATH,
                    '%s ' % self.selectedOfflineScraper.name +
                    util.localize(53003), CONTROL_BUTTON_GAMEDESCMASK)
                if (gamedescPathComplete != ''):
                    #HACK: only use source and parser from 1st scraper
                    if (len(self.selectedOfflineScraper.scrapers) >= 1):
                        self.selectedOfflineScraper.scrapers[
                            0].source = gamedescPathComplete
            else:
                dialog = xbmcgui.Dialog()
                gamedescPath = dialog.browse(
                    1, '%s ' % self.selectedOfflineScraper.name +
                    util.localize(53003), 'files', '', False, False,
                    self.selectedOfflineScraper.scrapers[0].source)
                if (gamedescPath == ''):
                    return

                if (len(self.selectedOfflineScraper.scrapers) >= 1):
                    self.selectedOfflineScraper.scrapers[
                        0].source = gamedescPath

                control = self.getControlById(CONTROL_BUTTON_GAMEDESCPATH)
                control.setLabel(gamedescPath)

        elif (controlID == CONTROL_BUTTON_GAMEDESCMASK):

            if (len(self.selectedOfflineScraper.scrapers) >= 1):
                self.selectedOfflineScraper.scrapers[
                    0].source = self.editFilemask(
                        CONTROL_BUTTON_GAMEDESCMASK, util.localize(53004),
                        self.selectedOfflineScraper.scrapers[0].source)

        elif (controlID == CONTROL_BUTTON_DESCPERGAME):
            #set value of gamedesc path and mask
            self.toggleGameDescPath()

        elif (controlID == CONTROL_BUTTON_PARSEINSTRUCTION):

            dialog = xbmcgui.Dialog()

            parseInstruction = dialog.browse(
                1, '%s ' % self.selectedOfflineScraper.name +
                util.localize(53005), 'files')
            if (parseInstruction == ''):
                return

            control = self.getControlById(CONTROL_BUTTON_PARSEINSTRUCTION)
            control.setLabel(parseInstruction)

            if (len(self.selectedOfflineScraper.scrapers) >= 1):
                self.selectedOfflineScraper.scrapers[
                    0].parseInstruction = parseInstruction

        elif (controlID == CONTROL_BUTTON_ADDSCRAPER):

            #get list of all rc names that are not in use
            names = []
            for romCollection in self.gui.config.romCollections.values():
                scraperInUse = False
                for scraper in self.gui.config.scraperSites:
                    if (romCollection.name == scraper):
                        scraperInUse = True
                        break

                if not scraperInUse:
                    names.append(romCollection.name)

            dialog = xbmcgui.Dialog()

            if (len(names) == 0):
                dialog.ok(util.SCRIPTNAME, util.localize(40044),
                          util.localize(40045))
                return

            #select name
            scraperIndex = dialog.select(util.localize(40046), names)
            if (scraperIndex == -1):
                return

            name = names[scraperIndex]
            if (name == ''):
                return

            site = Site()
            site.name = name
            site.scrapers = []
            scraper = Scraper()
            scraper.encoding = 'iso-8859-1'

            #select game desc
            gamedescPath = dialog.browse(1,
                                         '%s ' % name + util.localize(53003),
                                         'files')
            if (gamedescPath == ''):
                return

            scraper.source = gamedescPath

            #select parse instruction
            parseInstruction = dialog.browse(
                1, '%s ' % self.selectedOfflineScraper.name +
                util.localize(53005), 'files')
            if (parseInstruction == ''):
                return

            scraper.parseInstruction = parseInstruction

            site.scrapers.append(scraper)
            self.scraperSites[name] = site

            #add scraper to list
            control = self.getControlById(CONTROL_LIST_SCRAPERS)
            item = xbmcgui.ListItem(name, '', '', '')
            control.addItem(item)

            self.selectItemInList(name, CONTROL_LIST_SCRAPERS)

            if (self.selectedOfflineScraper != None):
                #save current values to selected ScraperSite
                self.updateSelectedOfflineScraper()

                #store previous selectedOfflineScrapers state
                self.scraperSites[self.selectedOfflineScraper.
                                  name] = self.selectedOfflineScraper

            #HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
            xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
            self.updateOfflineScraperControls()

        elif (controlID == CONTROL_BUTTON_REMOVESCRAPER):

            scraperSites = self.getAvailableScrapers(True)

            scraperIndex = xbmcgui.Dialog().select(util.localize(40047),
                                                   scraperSites)
            if (scraperIndex == -1):
                return

            scraperSite = scraperSites[scraperIndex]

            #check if scraper is in use
            for romCollection in self.gui.config.romCollections.values():
                for scraper in romCollection.scraperSites:
                    if (scraper.name == scraperSite):
                        xbmcgui.Dialog().ok(
                            util.localize(35019),
                            util.localize(40048) % scraper.name)
                        return

            scraperSites.remove(scraperSite)
            del self.scraperSites[scraperSite]

            if (len(scraperSites) == 0):
                scraperSites.append(util.localize(56004))
                site = Site()
                site.name = util.localize(56004)
                site.scrapers = []
                self.scraperSites[util.localize(56004)] = site

            control = self.getControlById(CONTROL_LIST_SCRAPERS)
            control.reset()
            self.addItemsToList(CONTROL_LIST_SCRAPERS, scraperSites)

            self.updateOfflineScraperControls()
    def updateConfig(self, configFile):

        if not os.path.isfile(configFile):
            return False, util.localize(32003)

        tree = ElementTree().parse(configFile)
        if tree == None:
            Logutil.log('Could not read config.xml', util.LOG_LEVEL_ERROR)
            return False, util.localize(32004)

        self.tree = tree

        configVersion = tree.attrib.get('version')
        Logutil.log(
            'Reading config version from config.xml: ' + str(configVersion),
            util.LOG_LEVEL_INFO)
        if configVersion == None:
            #set to previous version
            configVersion = '0.7.4'

        #nothing to do
        if (configVersion == util.CURRENT_CONFIG_VERSION):
            Logutil.log('Config file is up to date', util.LOG_LEVEL_INFO)
            return True, ''

        Logutil.log('Config file is out of date. Start update',
                    util.LOG_LEVEL_INFO)

        #backup config.xml
        newFileName = configFile + '.backup ' + configVersion
        if not os.path.isfile(newFileName):
            try:
                shutil.copy(str(configFile), str(newFileName))
            except Exception as exc:
                return False, util.localize(32007) + ": " + str(exc)

        #write current version to config
        self.tree.attrib['version'] = util.CURRENT_CONFIG_VERSION

        if configVersion == '0.7.4':
            success, message = self.update_074_to_086()
            configVersion = '0.8.6'
            if not success:
                return False, message

        if configVersion == '0.8.6':
            success, message = self.update_086_to_0810()
            configVersion = '0.8.10'
            if not success:
                return False, message

        if configVersion == '0.8.10':
            success, message = self.update_0810_to_090()
            configVersion = '0.9.0'
            if not success:
                return False, message

        if configVersion == '0.9.0':
            success, message = self.update_090_to_095()
            configVersion = '0.9.5'
            if not success:
                return False, message

        if configVersion == '0.9.5':
            success, message = self.update_095_to_106()
            configVersion = '1.0.6'
            if not success:
                return False, message

        if configVersion == '1.0.6':
            success, message = self.update_106_to_208()
            configVersion = '2.0.8'
            if not success:
                return False, message

        if configVersion == '2.0.8':
            success, message = self.update_208_to_214()
            configVersion = '2.1.4'
            if not success:
                return False, message

        if configVersion == '2.1.4':
            success, message = self.update_214_to_220()
            configVersion = '2.2.0'
            if not success:
                return False, message

        #write file
        success, message = self.writeFile(configFile)

        return success, message
Esempio n. 47
0
    def readRomCollections(self, tree):
        """
		Parses the config XML tree and extract the RomCollection objects into a dict.

		Args:
		    tree: XML tree parsed from config.xml in the user's addon directory

		Returns:
		    A dict of the rom collections, with the id attribute as the key. If an error occurs
		    parsing the tree, None is returned

		"""
        Logutil.log('Begin readRomCollections', util.LOG_LEVEL_INFO)

        romCollections = {}

        romCollectionRows = tree.findall('RomCollections/RomCollection')

        if len(romCollectionRows) == 0:
            Logutil.log(
                'Configuration error. config.xml does not contain any RomCollections',
                util.LOG_LEVEL_ERROR)
            return None, 'Configuration error. See xbmc.log for details'

        for romCollectionRow in romCollectionRows:

            romCollection = RomCollection()
            romCollection.name = romCollectionRow.attrib.get('name')
            if romCollection.name is None:
                Logutil.log(
                    'Configuration error. RomCollection must have an attribute name',
                    util.LOG_LEVEL_ERROR)
                return None, util.localize(32005)

            Logutil.log('current Rom Collection: ' + str(romCollection.name),
                        util.LOG_LEVEL_INFO)

            id = romCollectionRow.attrib.get('id', '')
            if id == '':
                Logutil.log(
                    'Configuration error. RomCollection %s must have an id' %
                    romCollection.name, util.LOG_LEVEL_ERROR)
                return None, util.localize(32005)

            if id in romCollections:
                Logutil.log(
                    'Error while adding RomCollection. Make sure that the id is unique.',
                    util.LOG_LEVEL_ERROR)
                return None, util.localize(32006)

            romCollection.id = id

            # romPath
            for romPathRow in romCollectionRow.findall('romPath'):
                Logutil.log('Rom path: ' + romPathRow.text,
                            util.LOG_LEVEL_INFO)
                if romPathRow.text is not None:
                    romCollection.romPaths.append(romPathRow.text)

            # mediaPath
            for mediaPathRow in romCollectionRow.findall('mediaPath'):
                mediaPath = MediaPath()
                if mediaPathRow.text is not None:
                    mediaPath.path = mediaPathRow.text
                Logutil.log('Media path: ' + mediaPath.path,
                            util.LOG_LEVEL_INFO)
                fileType, errorMsg = self.readFileType(
                    mediaPathRow.attrib.get('type'), tree)
                if fileType is None:
                    return None, errorMsg
                mediaPath.fileType = fileType
                romCollection.mediaPaths.append(mediaPath)

            #Scraper
            for scraperRow in romCollectionRow.findall('scraper'):
                if 'name' not in scraperRow.attrib:
                    Logutil.log(
                        'Configuration error. RomCollection/scraper must have an attribute name',
                        util.LOG_LEVEL_ERROR)
                    return None, util.localize(32005)

                site = Site()
                site.name = scraperRow.attrib.get('name')
                site.path = scraperRow.attrib.get('path')
                default = scraperRow.attrib.get('default')
                if default:
                    site.default = default.upper() == 'TRUE'
                else:
                    site.default = False

                romCollection.scraperSites.append(site)

            # ImagePlacing - Main window
            romCollection.imagePlacingMain = ImagePlacing()
            imagePlacingRow = romCollectionRow.find('imagePlacingMain')
            if imagePlacingRow is not None:
                Logutil.log('Image Placing name: ' + str(imagePlacingRow.text),
                            util.LOG_LEVEL_INFO)
                fileTypeFor, errorMsg = self.readImagePlacing(
                    imagePlacingRow.text, tree)
                if fileTypeFor is None:
                    return None, errorMsg

                romCollection.imagePlacingMain = fileTypeFor

            # ImagePlacing - Info window
            romCollection.imagePlacingInfo = ImagePlacing()
            imagePlacingRow = romCollectionRow.find('imagePlacingInfo')
            if imagePlacingRow is not None:
                Logutil.log('Image Placing name: ' + str(imagePlacingRow.text),
                            util.LOG_LEVEL_INFO)
                fileTypeFor, errorMsg = self.readImagePlacing(
                    imagePlacingRow.text, tree)
                if fileTypeFor is None:
                    return None, errorMsg

                romCollection.imagePlacingInfo = fileTypeFor

            # RomCollection properties
            for var in [
                    'gameclient', 'emulatorCmd', 'preCmd', 'postCmd',
                    'emulatorParams', 'saveStatePath', 'saveStateParams',
                    'diskPrefix'
            ]:
                romCollection.__setattr__(var,
                                          romCollectionRow.findtext(var, ''))

            # RomCollection int properties
            for var in ['maxFolderDepth']:
                romCollection.__setattr__(
                    var, int(romCollectionRow.findtext(var, '')))

            # RomCollection bool properties
            for var in [
                    'useBuiltinEmulator', 'ignoreOnScan', 'allowUpdate',
                    'useEmuSolo', 'usePopen', 'autoplayVideoMain',
                    'autoplayVideoInfo', 'useFoldernameAsGamename',
                    'doNotExtractZipFiles', 'makeLocalCopy'
            ]:
                romCollection.__setattr__(
                    var,
                    romCollectionRow.findtext(var, '').upper() == 'TRUE')

            # Add to dict
            romCollections[id] = romCollection

        return romCollections, ''
    def update_074_to_086(self):

        #update scrapers
        scraperSitesXml = self.tree.findall('Scrapers/Site')
        for scraperSiteXml in scraperSitesXml:
            siteName = scraperSiteXml.attrib.get('name')

            #handle online scrapers
            if (siteName == util.localize(32154)):
                scraperSiteXml.attrib['descFilePerGame'] = 'True'
                scraperSiteXml.attrib['searchGameByCRC'] = 'False'
            elif (siteName == 'thegamesdb.net'):
                scraperSiteXml.attrib['descFilePerGame'] = 'True'
                scraperSiteXml.attrib['searchGameByCRC'] = 'False'
            elif (siteName == 'archive.vg'):
                scraperSiteXml.attrib['descFilePerGame'] = 'True'
                scraperSiteXml.attrib['searchGameByCRC'] = 'False'
            elif (siteName == 'giantbomb.com'):
                scraperSiteXml.attrib['descFilePerGame'] = 'True'
                scraperSiteXml.attrib['searchGameByCRC'] = 'False'
            elif (siteName == 'mobygames.com'):
                scraperSiteXml.attrib['descFilePerGame'] = 'True'
                scraperSiteXml.attrib['searchGameByCRC'] = 'False'
            elif (siteName == 'maws.mameworld.info'):
                scraperSiteXml.attrib['descFilePerGame'] = 'True'
                scraperSiteXml.attrib['searchGameByCRC'] = 'False'

            #handle offline scrapers
            else:
                #search for rom collection that uses current scraper
                romCollectionsXml = self.tree.findall(
                    'RomCollections/RomCollection')
                for romCollectionXml in romCollectionsXml:
                    scraperXml = romCollectionXml.find('scraper')
                    scraperName = scraperXml.attrib.get('name')

                    if (scraperName != siteName):
                        continue

                    descFilePerGame = self.readTextElement(
                        romCollectionXml, 'descFilePerGame')
                    if (descFilePerGame != ''):
                        scraperSiteXml.attrib[
                            'descFilePerGame'] = descFilePerGame

                    searchGameByCRC = self.readTextElement(
                        romCollectionXml, 'searchGameByCRC')
                    if (searchGameByCRC != ''):
                        scraperSiteXml.attrib[
                            'searchGameByCRC'] = searchGameByCRC

                    useFoldernameAsCRC = self.readTextElement(
                        romCollectionXml, 'useFoldernameAsCRC')
                    if (useFoldernameAsCRC != ''):
                        scraperSiteXml.attrib[
                            'useFoldernameAsCRC'] = useFoldernameAsCRC

                    useFilenameAsCRC = self.readTextElement(
                        romCollectionXml, 'useFilenameAsCRC')
                    if (useFilenameAsCRC != ''):
                        scraperSiteXml.attrib[
                            'useFilenameAsCRC'] = useFilenameAsCRC

            #remove obsolete entries from rom collections
            romCollectionsXml = self.tree.findall(
                'RomCollections/RomCollection')
            for romCollectionXml in romCollectionsXml:
                self.removeElement(romCollectionXml, 'descFilePerGame')
                self.removeElement(romCollectionXml, 'searchGameByCRC')
                self.removeElement(romCollectionXml, 'useFoldernameAsCRC')
                self.removeElement(romCollectionXml, 'useFilenameAsCRC')
                self.removeElement(romCollectionXml,
                                   'searchGameByCRCIgnoreRomName')

        return True, ''
class MissingInfoDialog(DialogBase):

	artworkAndList = []
	artworkOrList = []
	infoAndList = []
	infoOrList = []

	saveConfig = False

	#32157 = ignore
	#32158 = Ignore filter
	#32159 = show
	#32160 = Show only games with missing items
	#32161 = hide
	#32162 = Hide games with missing items
	missingFilterOptions = {util.localize(32157): util.localize(32158),
							util.localize(32159): util.localize(32160),
							util.localize(32161): util.localize(32162)}

	def __init__(self, *args, **kwargs):
		Logutil.log('init dialog missing info', util.LOG_LEVEL_INFO)

		self.gui = kwargs[ "gui" ]

		self.doModal()


	def onInit(self):
		Logutil.log('onInit dialog missing info', util.LOG_LEVEL_INFO)

		self.artworkAndList = self.gui.config.missingFilterArtwork.andGroup
		label = self.getControlById(CONTROL_LABEL_ARTWORK_ANDGROUP)
		label.setLabel(', '.join(self.artworkAndList))

		self.artworkOrList = self.gui.config.missingFilterArtwork.orGroup
		label = self.getControlById(CONTROL_LABEL_ARTWORK_ORGROUP)
		label.setLabel(', '.join(self.artworkOrList))

		self.infoAndList = self.gui.config.missingFilterInfo.andGroup
		label = self.getControlById(CONTROL_LABEL_INFO_ANDGROUP)
		label.setLabel(', '.join(self.infoAndList))

		self.infoOrList = self.gui.config.missingFilterInfo.orGroup
		label = self.getControlById(CONTROL_LABEL_INFO_ORGROUP)
		label.setLabel(', '.join(self.infoOrList))

		Logutil.log('add show/hide missing info options', util.LOG_LEVEL_INFO)
		#showHideOptions = ['Ignore filter', 'Show only games with missing items', 'Hide games with missing items']
		self.addItemsToList(CONTROL_LIST_SHOWHIDEMISSING, self.missingFilterOptions.values())

		for i in range(0, len(self.missingFilterOptions.keys())):
			key = self.missingFilterOptions.keys()[i]
			if(key == self.gui.config.showHideOption):
				listShowHide = self.getControlById(CONTROL_LIST_SHOWHIDEMISSING)
				listShowHide.selectItem(i)


	def onAction(self, action):
		if (action.getId() in ACTION_CANCEL_DIALOG):
			self.close()


	def onClick(self, controlID):

		Logutil.log('onClick', util.LOG_LEVEL_INFO)

		if (controlID == CONTROL_BUTTON_EXIT): # Close window button
			Logutil.log('close', util.LOG_LEVEL_INFO)
			self.close()
		elif (controlID == CONTROL_BUTTON_ADD_ARTWORK_ORGROUP):
			Logutil.log('Add artwork or', util.LOG_LEVEL_INFO)
			self.artworkOrList = self.addItemToMissingArtworkList(self.artworkOrList, CONTROL_LABEL_ARTWORK_ORGROUP)

		elif (controlID == CONTROL_BUTTON_REMOVE_ARTWORK_ORGROUP):
			Logutil.log('Remove artwork or', util.LOG_LEVEL_INFO)
			self.artworkOrList = self.removeFromMissingList(self.artworkOrList, CONTROL_LABEL_ARTWORK_ORGROUP)

		elif (controlID == CONTROL_BUTTON_ADD_ARTWORK_ANDGROUP):
			Logutil.log('Add artwork and', util.LOG_LEVEL_INFO)
			self.artworkAndList = self.addItemToMissingArtworkList(self.artworkAndList, CONTROL_LABEL_ARTWORK_ANDGROUP)

		elif (controlID == CONTROL_BUTTON_REMOVE_ARTWORK_ANDGROUP):
			Logutil.log('Remove artwork and', util.LOG_LEVEL_INFO)
			self.artworkAndList = self.removeFromMissingList(self.artworkAndList, CONTROL_LABEL_ARTWORK_ANDGROUP)

		elif (controlID == CONTROL_BUTTON_ADD_INFO_ORGROUP):
			Logutil.log('Add info or', util.LOG_LEVEL_INFO)
			self.infoOrList = self.addItemToMissingInfoList(self.infoOrList, CONTROL_LABEL_INFO_ORGROUP)

		elif (controlID == CONTROL_BUTTON_REMOVE_INFO_ORGROUP):
			Logutil.log('Remove info and', util.LOG_LEVEL_INFO)
			self.infoOrList = self.removeFromMissingList(self.infoOrList, CONTROL_LABEL_INFO_ORGROUP)

		elif (controlID == CONTROL_BUTTON_ADD_INFO_ANDGROUP):
			Logutil.log('Add info and', util.LOG_LEVEL_INFO)
			self.infoAndList = self.addItemToMissingInfoList(self.infoAndList, CONTROL_LABEL_INFO_ANDGROUP)

		elif (controlID == CONTROL_BUTTON_REMOVE_INFO_ANDGROUP):
			Logutil.log('Remove info and', util.LOG_LEVEL_INFO)
			self.infoAndList = self.removeFromMissingList(self.infoAndList, CONTROL_LABEL_INFO_ANDGROUP)


		#Save
		elif (controlID == CONTROL_BUTTON_SAVE):
			Logutil.log('save', util.LOG_LEVEL_INFO)

			showHideList = self.getControlById(CONTROL_LIST_SHOWHIDEMISSING)
			index = showHideList.getSelectedPosition()
			showHideOptions = self.missingFilterOptions.keys()
			showHideOption = showHideOptions[index]

			configWriter = ConfigXmlWriter(False)
			success, message = configWriter.writeMissingFilter(showHideOption, self.artworkOrList, self.artworkAndList, self.infoOrList, self.infoAndList)

			if(success):
				self.saveConfig = True
			self.close()

		#Cancel
		elif (controlID == CONTROL_BUTTON_CANCEL):
			Logutil.log('cancel', util.LOG_LEVEL_INFO)
			self.close()


	def onFocus(self, controlId):
		pass


	def addItemToMissingArtworkList(self, inList, labelId):
		tempList = []

		for item in ['clearlogo', 'gamelist']:
			if not item in inList:
				tempList.append(item)

		dialog = xbmcgui.Dialog()
		#32155 = Select Artwork type
		index = dialog.select(util.localize(32155), tempList)
		del dialog
		if(index == -1):
			return inList

		inList.append(tempList[index])
		label = self.getControlById(labelId)
		label.setLabel(', '.join(inList))

		return inList


	def addItemToMissingInfoList(self, inList, labelId):

		tempList = []
		keys = config.gameproperties.keys()
		keys.sort()
		for item in keys:
			if(not item in tempList and not item in inList):
				tempList.append(item)

		dialog = xbmcgui.Dialog()
		index = dialog.select(util.localize(32156), tempList)
		del dialog
		if(index == -1):
			return inList

		inList.append(tempList[index])
		label = self.getControlById(labelId)
		label.setLabel(', '.join(inList))

		return inList


	def removeFromMissingList(self, inList, labelId):
		dialog = xbmcgui.Dialog()
		index = dialog.select(util.localize(32856), inList)
		del dialog
		if(index == -1):
			return inList
		inList.remove(inList[index])
		label = self.getControlById(labelId)
		label.setLabel(', '.join(inList))

		return inList
Esempio n. 50
0
    def launchEmu(self, gdb, gui, gameId, config, listitem):
        log.info("Begin launcher.launchEmu")

        gameRow = GameView(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[GameView.COL_romCollectionId])]
        except KeyError:
            log.error("Cannot get rom collection with id: " +
                      str(gameRow[GameView.COL_romCollectionId]))
            gui.writeMsg(util.localize(32034))
            return

        gui.writeMsg(
            util.localize(32163) + " " + gameRow[DataBaseObject.COL_NAME])

        # Remember viewstate
        gui.saveViewState(False)

        filenameRows = File(gdb).getRomsByGameId(
            gameRow[DataBaseObject.COL_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[GameView.COL_launchCount]
        Game(gdb).update(('launchCount', ), (launchCount + 1, ),
                         gameRow[Game.COL_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))
Esempio n. 51
0
						if(isMultiRomGame):
							if(lastGameId == None):
								Logutil.log('Game detected as multi rom game, but lastGameId is None.', util.LOG_LEVEL_ERROR)
								continue
							fileType = FileType()
							fileType.id = 0
							fileType.name = "rcb_rom"
							fileType.parent = "game"
							self.insertFile(filename, lastGameId, fileType, None, None, None)
							del fileType
							continue
						
						Logutil.log('Start scraping info for game: ' + gamenameFromFile, LOG_LEVEL_INFO)						
						
						fileCount = fileCount +1
						continueUpdate = gui.writeMsg(progDialogRCHeader, util.localize(32123) +": " +gamenameFromFile, "", fileCount)
						if(not continueUpdate):				
							Logutil.log('Game import canceled by user', util.LOG_LEVEL_INFO)
							break
						
						#check if we are in local artwork mode
						isLocalArtwork = (firstScraper.name == util.localize(32153))
						
						#check if this file already exists in DB
						continueUpdate, isUpdate, gameId = self.checkRomfileAlreadyExists(filename, enableFullReimport, isLocalArtwork)
						if(not continueUpdate):
							continue										
						
						results = {}
						foldername = self.getFoldernameFromRomFilename(filename)
																		
Esempio n. 52
0
    def exportLibrary(self, gui):
        Logutil.log("Begin exportLibrary", util.LOG_LEVEL_INFO)

        gdb = gui.gdb
        romCollections = gui.config.romCollections

        progressDialog = dialogprogress.ProgressDialogGUI()
        progressDialog.writeMsg(util.localize(32169), "", "")
        continueExport = True
        rccount = 1

        for romCollection in gui.config.romCollections.values():

            progDialogRCHeader = util.localize(32170) + " (%i / %i): %s" % (
                rccount, len(romCollections), romCollection.name)
            rccount = rccount + 1

            Logutil.log("export Rom Collection: " + romCollection.name,
                        util.LOG_LEVEL_INFO)
            gameCount = 1

            #get all games for this Rom Collection
            games = Game(gdb).getFilteredGames(romCollection.id, 0, 0, 0,
                                               False, '0 = 0')
            progressDialog.itemCount = len(games) + 1

            for gameRow in games:

                gamename = self.getGameProperty(gameRow[util.ROW_NAME])

                continueExport = progressDialog.writeMsg(
                    progDialogRCHeader,
                    util.localize(32171) + ": " + str(gamename), "", gameCount)
                if (not continueExport):
                    Logutil.log('Game export canceled by user',
                                util.LOG_LEVEL_INFO)
                    break

                gameCount = gameCount + 1

                plot = self.getGameProperty(gameRow[util.GAME_description])

                publisher = self.getGamePropertyFromCache(
                    gameRow, gui.publisherDict, util.GAME_publisherId,
                    util.ROW_NAME)
                developer = self.getGamePropertyFromCache(
                    gameRow, gui.developerDict, util.GAME_developerId,
                    util.ROW_NAME)
                year = self.getGamePropertyFromCache(gameRow, gui.yearDict,
                                                     util.GAME_yearId,
                                                     util.ROW_NAME)

                genreList = []
                try:
                    cachingOptionStr = self.Settings.getSetting(
                        util.SETTING_RCB_CACHINGOPTION)
                    if (cachingOptionStr == 'CACHEALL'):
                        genre = gui.genreDict[gameRow[util.ROW_ID]]
                    else:
                        genres = Genre(gdb).getGenresByGameId(
                            gameRow[util.ROW_ID])
                        if (genres != None):
                            for i in range(0, len(genres)):
                                genreRow = genres[i]
                                genreList.append(genreRow[util.ROW_NAME])
                except:
                    pass

                players = self.getGameProperty(gameRow[util.GAME_maxPlayers])
                rating = self.getGameProperty(gameRow[util.GAME_rating])
                votes = self.getGameProperty(gameRow[util.GAME_numVotes])
                url = self.getGameProperty(gameRow[util.GAME_url])
                region = self.getGameProperty(gameRow[util.GAME_region])
                media = self.getGameProperty(gameRow[util.GAME_media])
                perspective = self.getGameProperty(
                    gameRow[util.GAME_perspective])
                controller = self.getGameProperty(
                    gameRow[util.GAME_controllerType])
                originalTitle = self.getGameProperty(
                    gameRow[util.GAME_originalTitle])
                alternateTitle = self.getGameProperty(
                    gameRow[util.GAME_alternateTitle])
                version = self.getGameProperty(gameRow[util.GAME_version])

                #user settings
                isFavorite = self.getGameProperty(
                    gameRow[util.GAME_isFavorite])
                launchCount = self.getGameProperty(
                    gameRow[util.GAME_launchCount])

                romFiles = File(gdb).getRomsByGameId(gameRow[util.ROW_ID])
                romFile = ''
                if (romFiles != None and len(romFiles) > 0):
                    romFile = romFiles[0][0]
                gamenameFromFile = helper.getGamenameFromFilename(
                    romFile, romCollection)
                artworkfiles = {}
                artworkurls = []

                self.createNfoFromDesc(
                    gamename, plot, romCollection.name, publisher, developer,
                    year, players, rating, votes, url, region, media,
                    perspective, controller, originalTitle, alternateTitle,
                    version, genreList, isFavorite, launchCount, romFile,
                    gamenameFromFile, artworkfiles, artworkurls)

        progressDialog.writeMsg("", "", "", -1)
        del progressDialog
Esempio n. 53
0
    def _buildCmd(self, gui, filenameRows, gameRow, calledFromSkin):
        log.info("launcher.buildCmd")

        compressedExtensions = ['7z', 'zip']

        cmd = ""
        precmd = ""
        postcmd = ""
        roms = []

        emuCommandLine = self.romCollection.emulatorCmd
        log.info("emuCommandLine: " + emuCommandLine)
        log.info("preCmdLine: " + self.romCollection.preCmd)
        log.info("postCmdLine: " + self.romCollection.postCmd)

        # handle savestates
        stateFile = self.__checkGameHasSaveStates(gameRow, filenameRows)

        if stateFile == '':
            emuParams = self.romCollection.emulatorParams
        else:
            emuParams = self.romCollection.saveStateParams
            if self.escapeCmd:
                stateFile = re.escape(stateFile)
            emuParams = emuParams.replace('%statefile%', stateFile)
            emuParams = emuParams.replace('%STATEFILE%', stateFile)
            emuParams = emuParams.replace('%Statefile%', stateFile)

        # params could be: {-%I% %ROM%}
        # we have to repeat the part inside the brackets and replace the %I% with the current index
        emuParams, partToRepeat = self.__prepareMultiRomCommand(emuParams)

        # ask for disc number if multidisc game
        diskName = ""
        if self.romCollection.diskPrefix != '' and '%I%' not in emuParams:
            log.info("Getting Multiple Disc Parameter")
            options = []
            for disk in filenameRows:
                gamename = os.path.basename(disk[0])
                match = re.search(self.romCollection.diskPrefix.lower(),
                                  str(gamename).lower())
                if match:
                    disk = gamename[match.start():match.end()]
                    options.append(disk)
            if len(options) > 1 and not calledFromSkin:
                diskNum = xbmcgui.Dialog().select(
                    util.localize(32164) + ': ', options)
                if diskNum < 0:
                    # don't launch game
                    log.info("No disc was chosen. Won't launch game")
                    return "", "", "", None
                else:
                    diskName = options[diskNum]
                    log.info("Chosen Disc: %s" % diskName)

        # insert game specific command
        gameCmd = ''
        if gameRow[GameView.COL_gameCmd] is not None:
            gameCmd = str(gameRow[GameView.COL_gameCmd])
        # be case insensitive with (?i)
        emuParams = re.sub('(?i)%gamecmd%', gameCmd, emuParams)

        log.info("emuParams: " + emuParams)

        fileindex = int(0)
        for fileNameRow in filenameRows:
            rom = fileNameRow[0]
            log.info("rom: " + str(rom))

            if self.romCollection.makeLocalCopy:
                localDir = os.path.join(util.getTempDir(),
                                        self.romCollection.name)
                if xbmcvfs.exists(localDir + '\\'):
                    log.info("Trying to delete local rom files")
                    dirs, files = xbmcvfs.listdir(localDir)
                    for f in files:
                        xbmcvfs.delete(os.path.join(localDir, f))
                localRom = os.path.join(localDir, os.path.basename(str(rom)))
                log.info("Creating local copy: " + str(localRom))
                if xbmcvfs.copy(rom, localRom):
                    log.info("Local copy created")
                rom = localRom

            # If it's a .7z file
            # Don't extract zip files in case of savestate handling and when called From skin
            filext = rom.split('.')[-1]
            roms = [rom]
            if filext in compressedExtensions and not self.romCollection.doNotExtractZipFiles and stateFile == '' and not calledFromSkin:
                roms = self.__handleCompressedFile(gui, filext, rom, emuParams)
                log.debug("roms compressed = " + str(roms))
                if len(roms) == 0:
                    return "", "", "", None

            # no use for complete cmd as we just need the game name
            if self.romCollection.useBuiltinEmulator:
                log.debug("roms = " + str(roms))
                return "", "", "", roms

            del rom

            for rom in roms:
                if fileindex == 0:
                    emuParams = self.__replacePlaceholdersInParams(
                        emuParams, rom, gameRow)
                    if self.escapeCmd:
                        emuCommandLine = re.escape(emuCommandLine)

                    if self.romCollection.name in [
                            'Linux', 'Macintosh', 'Windows'
                    ]:
                        cmd = self.__replacePlaceholdersInParams(
                            emuCommandLine, rom, gameRow)
                    else:
                        cmd = '\"' + emuCommandLine + '\" ' + emuParams.replace(
                            '%I%', str(fileindex))
                else:
                    newrepl = partToRepeat
                    newrepl = self.__replacePlaceholdersInParams(
                        newrepl, rom, gameRow)
                    if self.escapeCmd:
                        emuCommandLine = re.escape(emuCommandLine)

                    newrepl = newrepl.replace('%I%', str(fileindex))
                    if newrepl:
                        cmd += ' ' + newrepl

                cmdprefix = ''

                if self.env == "win32":
                    cmdprefix = 'call '

                precmd = cmdprefix + self.__replacePlaceholdersInParams(
                    self.romCollection.preCmd, rom, gameRow)
                postcmd = cmdprefix + self.__replacePlaceholdersInParams(
                    self.romCollection.postCmd, rom, gameRow)

                fileindex += 1

        # A disk was chosen by the user, select it here
        if diskName:
            log.info("Choosing Disk: " + str(diskName))
            match = re.search(self.romCollection.diskPrefix.lower(),
                              cmd.lower())
            replString = cmd[match.start():match.end()]
            cmd = cmd.replace(replString, diskName)

        return cmd, precmd, postcmd, roms
Esempio n. 54
0
	def editMediaPath(self):
		
		#get selected medias type			
		control = self.getControlById(CONTROL_LIST_MEDIATYPES)
		selectedMediaType = str(control.getSelectedItem().getLabel())
		
		#get current media path
		currentMediaPath = None
		currentMediaPathIndex = -1;
		for i in range(0, len(self.selectedRomCollection.mediaPaths)):
			mediaPath = self.selectedRomCollection.mediaPaths[i]
			if(mediaPath.fileType.name == selectedMediaType):
				currentMediaPath = mediaPath
				currentMediaPathIndex = i
				break
		
		mediaPathComplete = self.editPathWithFileMask(CONTROL_BUTTON_MEDIAPATH, '%s ' %currentMediaPath.fileType.name +util.localize(32141), CONTROL_BUTTON_MEDIAFILEMASK)
		
		if(mediaPathComplete != ''):
			currentMediaPath.path = mediaPathComplete
			self.selectedRomCollection.mediaPaths[currentMediaPathIndex] = currentMediaPath
Esempio n. 55
0
	def showGameInfo(self):
		
		Logutil.log("Begin showGameInfo", util.LOG_LEVEL_INFO)
		
		#stop Player (if playing)
		if(xbmc.Player().isPlayingVideo()):
			xbmc.Player().stop()
		
		pos = self.getCurrentListPosition()
		if(pos == -1):
			pos = 0	
		
		selectedGame = self.getListItem(pos)		

		if(selectedGame == None):
			Logutil.log("selectedGame == None in showGameInfo", util.LOG_LEVEL_WARNING)
			return
		
		gameRow = Game(self.gdb).getObjectById(self.selectedGameId)
		if(gameRow == None):
			self.writeMsg(util.localize(32024))
			return
		
		genreString = ""
		genres = Genre(self.gdb).getGenresByGameId(gameRow[0])
		if (genres != None):
			for i in range(0, len(genres)):
				genre = genres[i]
				genreString += genre[util.ROW_NAME]
				if(i < len(genres) -1):
					genreString += ", "
				
		year = self.getItemName(Year(self.gdb), gameRow[util.GAME_yearId])
		publisher = self.getItemName(Publisher(self.gdb), gameRow[util.GAME_publisherId])
		developer = self.getItemName(Developer(self.gdb), gameRow[util.GAME_developerId])
		
						
		selectedGame.setProperty('year', year)
		selectedGame.setProperty('publisher', publisher)
		selectedGame.setProperty('developer', developer)
		selectedGame.setProperty('genre', genreString)
		
		selectedGame.setProperty('maxplayers', self.getGameProperty(gameRow[util.GAME_maxPlayers]))				
		selectedGame.setProperty('rating', self.getGameProperty(gameRow[util.GAME_rating]))
		selectedGame.setProperty('votes', self.getGameProperty(gameRow[util.GAME_numVotes]))		
		selectedGame.setProperty('url', self.getGameProperty(gameRow[util.GAME_url]))
		selectedGame.setProperty('region', self.getGameProperty(gameRow[util.GAME_region]))
		selectedGame.setProperty('media', self.getGameProperty(gameRow[util.GAME_media]))
		selectedGame.setProperty('perspective', self.getGameProperty(gameRow[util.GAME_perspective]))					
		selectedGame.setProperty('controllertype', self.getGameProperty(gameRow[util.GAME_controllerType]))
		selectedGame.setProperty('originaltitle', self.getGameProperty(gameRow[util.GAME_originalTitle]))
		selectedGame.setProperty('alternatetitle', self.getGameProperty(gameRow[util.GAME_alternateTitle]))
		selectedGame.setProperty('translatedby', self.getGameProperty(gameRow[util.GAME_translatedBy]))
		selectedGame.setProperty('version', self.getGameProperty(gameRow[util.GAME_version]))
			
		selectedGame.setProperty('playcount', self.getGameProperty(gameRow[util.GAME_launchCount]))
		
		isFavorite = self.getGameProperty(gameRow[util.GAME_isFavorite])
		if(isFavorite == '1'):
			selectedGame.setProperty('isfavorite', '1')
		else:
			selectedGame.setProperty('isfavorite', '')		
		
		description = gameRow[util.GAME_description]
		if(description == None):
			description = ""
		selectedGame.setProperty('plot', description)
		
		fileDict = self.getFileDictByGameRow(self.gdb, gameRow)
		
		romCollection = None
		try:
			romCollection = self.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)
				
		try:			
			selectedGame.setProperty('romcollection', romCollection.name)			
			selectedGame.setProperty('console', romCollection.name)
		except:
			pass

		selectedGame.setArt({
			IMAGE_CONTROL_BACKGROUND: self.getFileForControl(romCollection.imagePlacingMain.fileTypesForMainViewBackground, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict),
			IMAGE_CONTROL_GAMEINFO_BIG: self.getFileForControl(romCollection.imagePlacingMain.fileTypesForMainViewGameInfoBig, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict),

			IMAGE_CONTROL_GAMEINFO_UPPERLEFT: self.getFileForControl(romCollection.imagePlacingMain.fileTypesForMainViewGameInfoUpperLeft, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict),
			IMAGE_CONTROL_GAMEINFO_UPPERRIGHT: self.getFileForControl(romCollection.imagePlacingMain.fileTypesForMainViewGameInfoUpperRight, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict),
			IMAGE_CONTROL_GAMEINFO_LOWERLEFT: self.getFileForControl(romCollection.imagePlacingMain.fileTypesForMainViewGameInfoLowerLeft, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict),
			IMAGE_CONTROL_GAMEINFO_LOWERRIGHT: self.getFileForControl(romCollection.imagePlacingMain.fileTypesForMainViewGameInfoLowerRight, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict),

			IMAGE_CONTROL_GAMEINFO_UPPER: self.getFileForControl(romCollection.imagePlacingMain.fileTypesForMainViewGameInfoUpper, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict),
			IMAGE_CONTROL_GAMEINFO_LOWER: self.getFileForControl(romCollection.imagePlacingMain.fileTypesForMainViewGameInfoLower, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict),
			IMAGE_CONTROL_GAMEINFO_LEFT: self.getFileForControl(romCollection.imagePlacingMain.fileTypesForMainViewGameInfoLeft, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict),
			IMAGE_CONTROL_GAMEINFO_RIGHT: self.getFileForControl(romCollection.imagePlacingMain.fileTypesForMainViewGameInfoRight, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict),

			IMAGE_CONTROL_1: self.getFileForControl(romCollection.imagePlacingMain.fileTypesForMainView1, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict),
			IMAGE_CONTROL_2: self.getFileForControl(romCollection.imagePlacingMain.fileTypesForMainView2, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict),
			IMAGE_CONTROL_3: self.getFileForControl(romCollection.imagePlacingMain.fileTypesForMainView3, gameRow[util.ROW_ID], gameRow[util.GAME_publisherId], gameRow[util.GAME_developerId], gameRow[util.GAME_romCollectionId], fileDict),

		})
		
		Logutil.log("End showGameInfo", util.LOG_LEVEL_INFO)
	def onClick(self, controlID):
		log.info("onClick")

		if controlID == CONTROL_BUTTON_EXIT:  # Close window button
			log.info("close")
			self.close()
		# OK
		elif controlID == CONTROL_BUTTON_SAVE:
			log.info("save")
			# Store selectedRomCollection
			if self.selectedRomCollection is not None:
				self.updateSelectedRomCollection()
				self.romCollections[self.selectedRomCollection.id] = self.selectedRomCollection

			configWriter = ConfigXmlWriter(False)
			success, message = configWriter.writeRomCollections(self.romCollections, True)

			if not success:
				xbmcgui.Dialog().ok(util.localize(32021), message)
			self.close()

		# Cancel
		elif controlID == CONTROL_BUTTON_CANCEL:
			self.close()
		# Rom Collection list
		elif self.selectedControlId in (CONTROL_BUTTON_RC_DOWN, CONTROL_BUTTON_RC_UP):
			if self.selectedRomCollection is not None:
				# Save current values to selected Rom Collection
				self.updateSelectedRomCollection()
				# Store previous selectedRomCollections state
				self.romCollections[self.selectedRomCollection.id] = self.selectedRomCollection

			# HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
			xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
			self.updateRomCollectionControls()

		# Media Path
		elif self.selectedControlId in (CONTROL_BUTTON_MEDIA_DOWN, CONTROL_BUTTON_MEDIA_UP):
			# HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
			xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
			self.updateMediaPathControls()

		elif controlID == CONTROL_LIST_OFFLINE_SCRAPER:
			self.editOfflineScraper()

		elif controlID == CONTROL_BUTTON_GAMECLIENT:
			success, gameclient = helper.selectlibretrocore(self.selectedRomCollection.name)
			if success:
				self.selectedRomCollection.gameclient = gameclient

			control = self.getControlById(CONTROL_BUTTON_GAMECLIENT)
			if gameclient == "":
				control.setLabel("None")
			else:
				control.setLabel(gameclient)

		elif controlID == CONTROL_BUTTON_EMUCMD:
			self.editEmuCmd()

		elif controlID == CONTROL_BUTTON_PARAMS:
			emulatorParams = self.editTextProperty(CONTROL_BUTTON_PARAMS, util.localize(32625))
			self.selectedRomCollection.emulatorParams = emulatorParams

		elif controlID == CONTROL_BUTTON_ROMPATH:
			self.editRomPath()

		elif controlID == CONTROL_BUTTON_FILEMASK:
			self.editRomFileMask()

		elif controlID == CONTROL_BUTTON_MEDIAPATH:
			self.editMediaPath()

		elif controlID == CONTROL_BUTTON_MEDIAFILEMASK:
			self.editMediaFileMask()

		elif controlID == CONTROL_BUTTON_ADDMEDIAPATH:
			self.addMediaPath()

		elif controlID == CONTROL_BUTTON_REMOVEMEDIAPATH:
			self.removeMediaPath()

		elif controlID == CONTROL_BUTTON_MAXFOLDERDEPTH:
			maxFolderDepth = self.editTextProperty(CONTROL_BUTTON_MAXFOLDERDEPTH, util.localize(32610))
			self.selectedRomCollection.maxFolderDepth = maxFolderDepth

		elif controlID == CONTROL_BUTTON_DISKINDICATOR:
			diskIndicator = self.editTextProperty(CONTROL_BUTTON_DISKINDICATOR, util.localize(32611))
			self.selectedRomCollection.diskPrefix = diskIndicator

		elif controlID == CONTROL_BUTTON_SAVESTATEPATH:
			saveStatePathComplete = self.editPathWithFileMask(CONTROL_BUTTON_SAVESTATEPATH, '%s ' % self.selectedRomCollection.name + util.localize(32629), CONTROL_BUTTON_SAVESTATEMASK)
			if saveStatePathComplete != '':
				self.selectedRomCollection.saveStatePath = saveStatePathComplete

		elif controlID == CONTROL_BUTTON_SAVESTATEMASK:
			self.selectedRomCollection.saveStatePath = self.editFilemask(CONTROL_BUTTON_SAVESTATEMASK, util.localize(32630), self.selectedRomCollection.saveStatePath)

		elif controlID == CONTROL_BUTTON_SAVESTATEPARAMS:
			saveStateParams = self.editTextProperty(CONTROL_BUTTON_SAVESTATEPARAMS, util.localize(32631))
			self.selectedRomCollection.saveStateParams = saveStateParams

		elif controlID == CONTROL_BUTTON_PRECMD:
			preCmd = self.editTextProperty(CONTROL_BUTTON_PRECMD, util.localize(32632))
			self.selectedRomCollection.preCmd = preCmd
			log.info("OnClick: precmd = {0}".format(self.selectedRomCollection.preCmd))

		elif controlID == CONTROL_BUTTON_POSTCMD:
			postCmd = self.editTextProperty(CONTROL_BUTTON_POSTCMD, util.localize(32633))
			self.selectedRomCollection.postCmd = postCmd
Esempio n. 57
0
    def onClick(self, controlID):

        Logutil.log('onClick', util.LOG_LEVEL_INFO)

        if (controlID == CONTROL_BUTTON_EXIT):  # Close window button
            Logutil.log('close', util.LOG_LEVEL_INFO)
            self.close()
        #OK
        elif (controlID == CONTROL_BUTTON_SAVE):
            Logutil.log('save', util.LOG_LEVEL_INFO)
            #store selectedRomCollection
            if (self.selectedRomCollection != None):
                self.updateSelectedRomCollection()
                self.romCollections[
                    self.selectedRomCollection.id] = self.selectedRomCollection

            configWriter = ConfigXmlWriter(False)
            success, message = configWriter.writeRomCollections(
                self.romCollections, True)

            if not success:
                xbmcgui.Dialog().ok(util.localize(35021), message)
            self.close()

        #Cancel
        elif (controlID == CONTROL_BUTTON_CANCEL):
            self.close()
        #Rom Collection list
        elif (self.selectedControlId
              in (CONTROL_BUTTON_RC_DOWN, CONTROL_BUTTON_RC_UP)):
            if (self.selectedRomCollection != None):
                #save current values to selected Rom Collection
                self.updateSelectedRomCollection()
                #store previous selectedRomCollections state
                self.romCollections[
                    self.selectedRomCollection.id] = self.selectedRomCollection

            #HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
            xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
            self.updateRomCollectionControls()

        #Media Path
        elif (self.selectedControlId
              in (CONTROL_BUTTON_MEDIA_DOWN, CONTROL_BUTTON_MEDIA_UP)):
            #HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
            xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
            self.updateMediaPathControls()

        elif (controlID == CONTROL_BUTTON_EMUCMD):
            if (self.selectedRomCollection.name == 'Linux'
                    or self.selectedRomCollection.name == 'Macintosh'
                    or self.selectedRomCollection.name == 'Windows'):
                emulatorPath = self.editTextProperty(CONTROL_BUTTON_EMUCMD,
                                                     util.localize(52024))
            else:
                dialog = xbmcgui.Dialog()

                emulatorPath = dialog.browse(
                    1, '%s ' % self.selectedRomCollection.name +
                    util.localize(40039), 'files')
                if (emulatorPath == ''):
                    return

            self.selectedRomCollection.emulatorCmd = emulatorPath
            control = self.getControlById(CONTROL_BUTTON_EMUCMD)
            control.setLabel(emulatorPath)

        elif (controlID == CONTROL_BUTTON_PARAMS):
            emulatorParams = self.editTextProperty(CONTROL_BUTTON_PARAMS,
                                                   util.localize(52025))
            self.selectedRomCollection.emulatorParams = emulatorParams

        elif (controlID == CONTROL_BUTTON_ROMPATH):
            self.editRomPath()

        elif (controlID == CONTROL_BUTTON_FILEMASK):
            self.editRomFileMask()

        elif (controlID == CONTROL_BUTTON_MEDIAPATH):
            self.editMediaPath()

        elif (controlID == CONTROL_BUTTON_MEDIAFILEMASK):
            self.editMediaFileMask()

        elif (controlID == CONTROL_BUTTON_ADDMEDIAPATH):
            self.addMediaPath()

        elif (controlID == CONTROL_BUTTON_REMOVEMEDIAPATH):
            self.removeMediaPath()

        elif (controlID == CONTROL_BUTTON_MAXFOLDERDEPTH):
            maxFolderDepth = self.editTextProperty(
                CONTROL_BUTTON_MAXFOLDERDEPTH, util.localize(52010))
            self.selectedRomCollection.maxFolderDepth = maxFolderDepth

        elif (controlID == CONTROL_BUTTON_DISKINDICATOR):
            diskIndicator = self.editTextProperty(CONTROL_BUTTON_DISKINDICATOR,
                                                  util.localize(52011))
            self.selectedRomCollection.diskPrefix = diskIndicator

        elif (controlID == CONTROL_BUTTON_SAVESTATEPATH):
            saveStatePathComplete = self.editPathWithFileMask(
                CONTROL_BUTTON_SAVESTATEPATH,
                '%s ' % self.selectedRomCollection.name + util.localize(52029),
                CONTROL_BUTTON_SAVESTATEMASK)
            if (saveStatePathComplete != ''):
                self.selectedRomCollection.saveStatePath = saveStatePathComplete

        elif (controlID == CONTROL_BUTTON_SAVESTATEMASK):
            self.selectedRomCollection.saveStatePath = self.editFilemask(
                CONTROL_BUTTON_SAVESTATEMASK, util.localize(52030),
                self.selectedRomCollection.saveStatePath)

        elif (controlID == CONTROL_BUTTON_SAVESTATEPARAMS):
            saveStateParams = self.editTextProperty(
                CONTROL_BUTTON_SAVESTATEPARAMS, util.localize(52031))
            self.selectedRomCollection.saveStateParams = saveStateParams

        elif (controlID == CONTROL_BUTTON_PRECMD):
            preCmd = self.editTextProperty(CONTROL_BUTTON_PRECMD,
                                           util.localize(52032))
            self.selectedRomCollection.preCmd = preCmd

        elif (controlID == CONTROL_BUTTON_POSTCMD):
            postCmd = self.editTextProperty(CONTROL_BUTTON_POSTCMD,
                                            util.localize(52033))
            self.selectedRomCollection.postCmd = postCmd
	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()
Esempio n. 59
0
def buildCmd(filenameRows, romCollection, gameRow, escapeCmd, calledFromSkin):		
	Logutil.log('launcher.buildCmd', util.LOG_LEVEL_INFO)
		
	compressedExtensions = ['7z', 'zip']
	
	cmd = ""
	precmd = ""
	postcmd = ""
	
	emuCommandLine = romCollection.emulatorCmd
	Logutil.log('emuCommandLine: ' +emuCommandLine, util.LOG_LEVEL_INFO)
	Logutil.log('preCmdLine: ' +romCollection.preCmd, util.LOG_LEVEL_INFO)
	Logutil.log('postCmdLine: ' +romCollection.postCmd, util.LOG_LEVEL_INFO)

	#handle savestates	
	stateFile = checkGameHasSaveStates(romCollection, gameRow, filenameRows, escapeCmd)
		
	if(stateFile == ''):
		emuParams = romCollection.emulatorParams
	else:		
		emuParams = romCollection.saveStateParams
		if(escapeCmd):
			stateFile = re.escape(stateFile)
		emuParams = emuParams.replace('%statefile%', stateFile)
		emuParams = emuParams.replace('%STATEFILE%', stateFile)
		emuParams = emuParams.replace('%Statefile%', stateFile)
	
	#params could be: {-%I% %ROM%}
	#we have to repeat the part inside the brackets and replace the %I% with the current index
	emuParams, partToRepeat = prepareMultiRomCommand(emuParams)

	#ask for disc number if multidisc game
	diskName = ""
	if(romCollection.diskPrefix != '' and not '%I%' in emuParams):
		Logutil.log("Getting Multiple Disc Parameter", util.LOG_LEVEL_INFO)
		options = []
		for disk in filenameRows:
			gamename = os.path.basename(disk[0])
			match = re.search(romCollection.diskPrefix.lower(), str(gamename).lower())
			if(match):
				disk = gamename[match.start():match.end()]
				options.append(disk)
		if(len(options) > 1 and not calledFromSkin):
			diskNum = xbmcgui.Dialog().select(util.localize(40064) +': ', options)
			if(diskNum < 0):
				#don't launch game
				Logutil.log("No disc was chosen. Won't launch game", util.LOG_LEVEL_INFO)
				return "", "", "", None
			else:
				diskName = options[diskNum]
				Logutil.log('Chosen Disc: %s' % diskName, util.LOG_LEVEL_INFO)

	#insert game specific command
	gameCmd = ''
	if(gameRow[util.GAME_gameCmd] != None):
		gameCmd = str(gameRow[util.GAME_gameCmd])
	#be case insensitive with (?i)
	emuParams = re.sub('(?i)%gamecmd%', gameCmd, emuParams)
	
	Logutil.log('emuParams: ' +emuParams, util.LOG_LEVEL_INFO)
	
	fileindex = int(0)
	for fileNameRow in filenameRows:
		rom = fileNameRow[0]
		Logutil.log('rom: ' +str(rom), util.LOG_LEVEL_INFO)

		# If it's a .7z file
		# Don't extract zip files in case of savestate handling and when called From skin
		filext = rom.split('.')[-1]
		roms = [rom]
		if filext in compressedExtensions and not romCollection.doNotExtractZipFiles and stateFile == '' and not calledFromSkin:
			roms = handleCompressedFile(filext, rom, romCollection, emuParams)
			print "roms compressed = " +str(roms)
			if len(roms) == 0:
				return "", "", "", None
			
		#no use for complete cmd as we just need the game name
		if (romCollection.useBuiltinEmulator):
			print "roms = " +str(roms)
			return "", "", "", roms
		
		del rom
				
		for rom in roms:
			precmd = ""
			postcmd = ""
			if fileindex == 0:
				emuParams = replacePlaceholdersInParams(emuParams, rom, romCollection, gameRow, escapeCmd)
				if (escapeCmd):
					emuCommandLine = re.escape(emuCommandLine)				
				
				if (os.environ.get( "OS", "xbox" ) == "xbox"):
					cmd = replacePlaceholdersInParams(emuCommandLine, rom, romCollection, gameRow, escapeCmd)
				elif (romCollection.name == 'Linux' or romCollection.name == 'Macintosh' or romCollection.name == 'Windows'):
					cmd = replacePlaceholdersInParams(emuCommandLine, rom, romCollection, gameRow, escapeCmd)
				else:
					cmd = '\"' +emuCommandLine +'\" ' +emuParams.replace('%I%', str(fileindex))
			else:
				newrepl = partToRepeat
				newrepl = replacePlaceholdersInParams(newrepl, rom, romCollection, gameRow, escapeCmd)
				if (escapeCmd):
					emuCommandLine = re.escape(emuCommandLine)

				newrepl = newrepl.replace('%I%', str(fileindex))
				cmd += ' ' +newrepl
				
			cmdprefix = ''
			env = ( os.environ.get( "OS", "win32" ), "win32", )[ os.environ.get( "OS", "win32" ) == "xbox" ]
			if(env == "win32"):
				cmdprefix = 'call '
				
			precmd = cmdprefix + replacePlaceholdersInParams(romCollection.preCmd, rom, romCollection, gameRow, escapeCmd)
			postcmd = cmdprefix + replacePlaceholdersInParams(romCollection.postCmd, rom, romCollection, gameRow, escapeCmd)
						
			fileindex += 1

	#A disk was chosen by the user, select it here
	if (diskName):
		Logutil.log("Choosing Disk: " +str(diskName),util.LOG_LEVEL_INFO)
		match = re.search(romCollection.diskPrefix.lower(), cmd.lower())
		replString = cmd[match.start():match.end()]
		cmd = cmd.replace(replString, diskName)
		
			
	return cmd, precmd, postcmd, roms
Esempio n. 60
0
	def readScraper(self, siteRow, romCollectionName, inReplaceKeyString, inReplaceValueString, replaceValues, tree):
		
		site = Site()
		site.name = siteRow.attrib.get('name')
		Logutil.log('Scraper Site: ' +str(site.name), util.LOG_LEVEL_INFO)
		
		descFilePerGame = siteRow.attrib.get('descFilePerGame')
		if(descFilePerGame != None and descFilePerGame != ''):
			site.descFilePerGame = descFilePerGame.upper() == 'TRUE'
			Logutil.log('Scraper descFilePerGame: ' +str(site.descFilePerGame), util.LOG_LEVEL_INFO)
		
		searchGameByCRC = siteRow.attrib.get('searchGameByCRC')
		if(searchGameByCRC != None and searchGameByCRC != ''):
			site.searchGameByCRC = searchGameByCRC.upper() == 'TRUE'
			
		searchGameByCRCIgnoreRomName = siteRow.attrib.get('searchGameByCRCIgnoreRomName')
		if(searchGameByCRCIgnoreRomName != None and searchGameByCRCIgnoreRomName != ''):
			site.searchGameByCRCIgnoreRomName = searchGameByCRCIgnoreRomName.upper() == 'TRUE'
			
		useFoldernameAsCRC = siteRow.attrib.get('useFoldernameAsCRC')
		if(useFoldernameAsCRC != None and useFoldernameAsCRC != ''):
			site.useFoldernameAsCRC = useFoldernameAsCRC.upper() == 'TRUE'
			
		useFilenameAsCRC = siteRow.attrib.get('useFilenameAsCRC')
		if(useFilenameAsCRC != None and useFilenameAsCRC != ''):
			site.useFilenameAsCRC = useFilenameAsCRC.upper() == 'TRUE'
		
		scrapers = []
		
		scraperRows = siteRow.findall('Scraper')
		for scraperRow in scraperRows:
			scraper = Scraper()
			
			parseInstruction = scraperRow.attrib.get('parseInstruction')
			if(parseInstruction != None and parseInstruction != ''):
				if(not os.path.isabs(parseInstruction)):
					#if it is a relative path, search in RCBs home directory
					parseInstruction = os.path.join(util.RCBHOME, 'resources', 'scraper', parseInstruction)
				
				if(not os.path.isfile(parseInstruction)):
					Logutil.log('Configuration error. parseInstruction file %s does not exist.' %parseInstruction, util.LOG_LEVEL_ERROR)
					return None, util.localize(32005)
				
				scraper.parseInstruction = parseInstruction
				
			source = scraperRow.attrib.get('source')
			if(source != None and source != ''):
				if(replaceValues):
					platform = getPlatformByRomCollection(source, romCollectionName)
					platform = urllib.quote(platform, safe='')
					source = source.replace('%PLATFORM%', platform)
				scraper.source = source
			
			encoding = scraperRow.attrib.get('encoding')
			if(encoding != None and encoding != 'utf-8'):
				scraper.encoding = encoding
			
			returnUrl = scraperRow.attrib.get('returnUrl')
			if(returnUrl != None and returnUrl != ''):
				scraper.returnUrl = returnUrl.upper() == 'TRUE'
				
			sourceAppend = scraperRow.attrib.get('sourceAppend')
			if(sourceAppend != None and sourceAppend != ''):
				scraper.sourceAppend = sourceAppend
				
			scraper.replaceKeyString = inReplaceKeyString
			scraper.replaceValueString = inReplaceValueString
			
			scrapers.append(scraper)
			
		site.scrapers = scrapers
			
		return site, ''