def __init__(self, games, cache, scriptDir, collectionVersion, collectionDir, outputDir, conversionType, useGenreSubFolders, conversionConf, fullnameToGameDir, postProcess, logger): self.games = games self.cache = cache self.scriptDir = scriptDir self.collectionVersion = collectionVersion self.isWin3x = (self.collectionVersion == util.EXOWIN3X) self.exoCollectionDir = collectionDir self.logger = logger self.collectionGamesDir = util.getCollectionGamesDir( collectionDir, collectionVersion) self.collectionGamesConfDir = util.getCollectionGamesConfDir( collectionDir, collectionVersion) self.outputDir = outputDir self.conversionType = conversionType self.useGenreSubFolders = useGenreSubFolders self.conversionConf = conversionConf self.metadataHandler = MetadataHandler(collectionDir, collectionVersion, self.cache, self.logger) self.fullnameToGameDir = fullnameToGameDir self.postProcess = postProcess
def copyGameFiles(self): self.logger.log(" copy dosbox conf") # Copy dosbox.conf in game.pc shutil.copy2( os.path.join( util.getCollectionGamesConfDir(self.exoCollectionDir, self.collectionVersion), self.game, "dosbox.conf"), os.path.join(self.getLocalGameDataOutputDir(), "dosbox.conf")) # Create blank file with full game name f = open(os.path.join(self.getLocalGameOutputDir(), util.getCleanGameID(self.metadata, '.txt')), 'w', encoding='utf8') f.write(self.metadata.desc) f.close() # Handle first-game-of-a-serie dependencies needsFirstGame = { 'roadware': ['Roadwar 2000 (1987).zip'], # @mount a .\Games\roadwar -t floppy 'eob2': ['Eye of the Beholder (1991).zip' ], # mount a .\Games\eob1\ -t floppy 'bardtal2': ["Bard's Tale 1, The - Tales Of The Unknown (1987).zip"], # mount a .\Games\bardtal1 -t floppy 'bardtal3': [ "Bard's Tale 1, The - Tales Of The Unknown (1987).zip", # mount a .\Games\bardtal1 -t floppy "Bard's Tale 2, The - The Destiny Knight (1988).zip" ], # @mount b .\Games\bardtal2 -t floppy 'MM2': ['Might and Magic - Book 1 (1986).zip' ], # mount a .\Games\MM1\ -t floppy 'vengexca': ['Spirit of Excalibur (1990).zip' ], # @mount a .\Games\spirexc -t floppy 'WC2DLX': ['Wing Commander (1990).zip'], # mount a .\Games\WC\WING\GAMEDAT\ 'darkdes2': ['Dark Designs I - Grelminars Staff (1990).zip' ], # mount a .\Games\darkdes1 -t floppy 'whalvoy2': ["Whale's Voyage (1993).zip"] # @mount e .\Games\whalvoy1\WVCD } if self.game in needsFirstGame: for previousGameZip in needsFirstGame[self.game]: # unzip game dependency with ZipFile( os.path.join( util.getCollectionGamesDir(self.exoCollectionDir, self.collectionVersion), previousGameZip), 'r') as zipFile: # Extract all the contents of zip file in current directory self.logger.log(" unzipping previous game" + previousGameZip) zipFile.extractall(path=util.getCollectionGamesDir( self.exoCollectionDir, self.collectionVersion)) # copy its directory or directory part to the inside of the second game dir shutil.move( os.path.join( util.getCollectionGamesDir(self.exoCollectionDir, self.collectionVersion), self.fullnameToGameDir.get( os.path.splitext(previousGameZip)[0])), os.path.join(self.getLocalGameOutputDir()))
def __copyGameDataToOutputDir__(self, gGator): # previous method kept for doc purpose # automatic Y, F and N to validate answers to exo's install.bat # fullscreen = true, output=overlay, aspect=true # subprocess.call("cmd /C (echo Y&echo F&echo N) | Install.bat", cwd=os.path.join(self.gamesDosDir, game), # shell=False) # unzip game (xxxx).zip from unzip line in game/install.bat # following options should be set in dosbox.conf / actually do it later in converter # fullscreen = true, output=overlay, aspect=true bats = [ os.path.splitext(filename)[0] for filename in os.listdir( os.path.join(self.collectionGamesConfDir, gGator.game)) if os.path.splitext(filename)[-1].lower() == '.bat' and not os.path.splitext(filename)[0].lower() == 'install' ] gameZip = bats[0] + '.zip' # Unzip game if gameZip is not None: gameZipPath = os.path.join( os.path.join( util.getCollectionGamesDir(self.exoCollectionDir, self.collectionVersion)), gameZip) # If zip of the game is not foung, try to download it if not os.path.exists(gameZipPath): self.logger.log(' <WARNING> %s not found' % gameZipPath, self.logger.WARNING) if self.conversionConf['downloadOnDemand']: util.downloadZip(gameZip, gameZipPath, self.logger) else: self.logger.log( ' <WARNING> Activate Download on demand if you want to download missing games', self.logger.WARNING) self.__unzipGame__(gameZipPath, gGator) else: self.logger.log( " ERROR while trying to find zip file for " + os.path.join(self.collectionGamesConfDir, gGator.game), self.logger.ERROR) self.logger.log(" unzipped") # Handle game update if it exists updateZipPath = os.path.join( util.getCollectionUpdateDir(self.exoCollectionDir, self.collectionVersion), gameZip) if os.path.exists(updateZipPath): self.logger.log(" found an update for the game") self.__unzipGame__(updateZipPath, gGator) # For win3x games, all files / dir / etc in game.pc/game should be moved to game.pc/ and sub game.pc/game deleted # do not use getLocalGameDataOutputDir as game data are in subdir at that point if self.isWin3x: # Needs to rename sub game dir first then move content to .pc folder , then delete sub game dir subDirTempName = gGator.game + '-tempEDC' os.rename( os.path.join(gGator.getLocalGameOutputDir(), gGator.game), os.path.join(gGator.getLocalGameOutputDir(), subDirTempName)) for gameFile in os.listdir( os.path.join(gGator.getLocalGameOutputDir(), subDirTempName)): shutil.move( os.path.join(gGator.getLocalGameOutputDir(), subDirTempName, gameFile), gGator.getLocalGameOutputDir()) # Check if it's empty !! a subdir might be named the same if len( os.listdir( os.path.join(gGator.getLocalGameOutputDir(), subDirTempName))) == 0: shutil.rmtree( os.path.join(gGator.getLocalGameOutputDir(), subDirTempName))