def System_Install_Response(self,FileChooser,Response): SystemSettingsTree = {("",1,("name",),SettingsCheck.SystemNameSanityCheck) :None} if Response == Gtk.ResponseType.ACCEPT: filename = FileChooser.get_filename() SystemArchive = Archive(filename,'r') try: settingsstring = SystemArchive.read("system.xml") SystemXML = ET.XML(settingsstring) ValidSettings = SettingsCheck.check_settings(SystemSettingsTree, SystemXML) if not ValidSettings: raise Exception systemname = SystemXML.get("name") if not os.path.isdir(Globals.DataDir+"Systems/System_"+systemname): os.mkdir(Globals.DataDir+"Systems/System_"+systemname) if not os.path.isdir(Globals.DataDir+"Games/"+systemname): os.mkdir(Globals.DataDir+"Games/"+systemname) SystemArchive.extractall(path=Globals.DataDir+"Systems/System_"+systemname) Globals.Systems.append(systemname) popup = ErrorPopupWindow("System Installed","System installed successfully!") popup.set_transient_for(self) popup.show_all() else: popup = ErrorPopupWindow("System already exists","System already exists, uninstall the system first.") popup.set_transient_for(self) popup.show_all() except: popup = ErrorPopupWindow("Malformed System","Archive containing the system is malformed, try redownloading the archive") popup.set_transient_for(self) popup.show_all() FileChooser.destroy() Globals.OpenWindows &= ~Globals.WINDOWTYPE_FILECHOOSER
def Get_Settings(self): ValidSettings = False SettingsXML = None try: with open(Globals.DataDir + "Settings.xml", "r") as SettingsFile: SettingsText = SettingsFile.read() ValidSettings = True except IOError: SettingsText = DefaultSettings ValidSettings = True #Description to follow through the settings tree for testing sanity SettingsTree = { ("Paths", 1, (), None): { ("LastAccessedSystem", 1, ("path", ), SettingsCheck.DirectoryPathSanityCheck): None, ("LastAccessedCore", 1, ("path", ), SettingsCheck.DirectoryPathSanityCheck): None }, ("Window", 1, ("width", "height"), SettingsCheck.WindowSizeSanityCheck): None, ("AspectRatio", 1, ("keep", ), lambda x: x == "True" or x == "False"): None, ("Hotkeys", 1, (), None): { ("Button", 9, ("Mapping", "name"), None): None }, ("Rewind", 1, ("Frames", "Size", "Enabled", "Compress"), lambda f, s, e, c: f.isdigit( ) and s.isdigit() and (e == "False" or e == "True") and (c == "False" or c == "True")): None } SettingsXML = ET.XML(SettingsText) #Make sure the settings file is valid XML if ValidSettings: try: SettingsXML = ET.XML(SettingsText) except ET.ParseError: ValidSettings = False #Validate the the settings use sane values if ValidSettings: ValidSettings = SettingsCheck.check_settings( SettingsTree, SettingsXML) #If the settings aren't sane, replace them with the standard settings #May change later to only replace the parts that are not sane if not ValidSettings: try: SettingsXML = ET.XML(DefaultSettings) with open(Globals.DataDir + "Settings.xml", "w") as SettingsFile: SettingsFile.write(DefaultSettings) popup = ErrorPopupWindow( "Settings Not Found", "Settings not found or corrupt, using default settings") popup.show_all() except: self.ErrorMsg = "Failed to write to settings file" return SettingsXML
def Core_Install_Response(self, FileChooser, Response): CoreSettingsTree = { ("", 1, ("name", "system"), SettingsCheck.CoreNameSanityCheck): None } if Response == Gtk.ResponseType.ACCEPT: filename = FileChooser.get_filename() SystemArchive = Archive(filename, 'r') try: settingsstring = SystemArchive.read("core.xml") CoreXML = ET.XML(settingsstring) ValidSettings = SettingsCheck.check_settings( CoreSettingsTree, CoreXML) if not ValidSettings: raise Exception("Invalid Core Settings") systemname = CoreXML.get("system") corename = CoreXML.get("name") if os.path.isdir(Globals.DataDir + "Systems/System_" + systemname): if not os.path.isdir(Globals.DataDir + "Systems/System_" + systemname + "/" + corename): os.mkdir(Globals.DataDir + "Systems/System_" + systemname + "/Core_" + corename) SystemArchive.extractall( path=Globals.DataDir + "Systems/System_" + systemname + "/Core_" + corename) Globals.Cores.append(systemname + "/" + corename) popup = ErrorPopupWindow( "Core Installed", "Core installed successfully!") popup.set_transient_for(self) popup.show_all() else: popup = ErrorPopupWindow( "Core already exists", "Core already exists, uninstall the core first.") popup.set_transient_for(self) popup.show_all() else: popup = ErrorPopupWindow( "System not found", "System: " + systemname + " not found, please install the system before the core" ) popup.set_transient_for(self) popup.show_all() except Exception as e: print e popup = ErrorPopupWindow( "Malformed Core", "Archive containing the core is malformed, try redownloading the archive" ) popup.set_transient_for(self) popup.show_all() FileChooser.destroy() Globals.OpenWindows &= ~Globals.WINDOWTYPE_FILECHOOSER
def Get_Settings(self): ValidSettings = False SettingsXML = None try: with open(Globals.DataDir+"Settings.xml", "r") as SettingsFile: SettingsText = SettingsFile.read() ValidSettings = True except IOError: SettingsText = DefaultSettings ValidSettings = True #Description to follow through the settings tree for testing sanity SettingsTree = {("Paths",1,(),None) : {("LastAccessedSystem",1,("path",),SettingsCheck.DirectoryPathSanityCheck):None, ("LastAccessedCore",1,("path",),SettingsCheck.DirectoryPathSanityCheck):None }, ("Window",1,("width","height"),SettingsCheck.WindowSizeSanityCheck) :None, ("AspectRatio",1,("keep",), lambda x: x == "True" or x == "False") : None, ("Hotkeys",1,(),None) : {("Button",9,("Mapping","name"),None) : None}, ("Rewind",1,("Frames","Size","Enabled","Compress"), lambda f, s, e, c: f.isdigit() and s.isdigit() and (e == "False" or e == "True") and (c == "False" or c == "True")) : None } SettingsXML = ET.XML(SettingsText) #Make sure the settings file is valid XML if ValidSettings: try: SettingsXML = ET.XML(SettingsText) except ET.ParseError: ValidSettings = False #Validate the the settings use sane values if ValidSettings: ValidSettings = SettingsCheck.check_settings(SettingsTree,SettingsXML) #If the settings aren't sane, replace them with the standard settings #May change later to only replace the parts that are not sane if not ValidSettings: try: SettingsXML = ET.XML(DefaultSettings) with open(Globals.DataDir+"Settings.xml", "w") as SettingsFile: SettingsFile.write(DefaultSettings) popup = ErrorPopupWindow("Settings Not Found","Settings not found or corrupt, using default settings") popup.show_all() except: self.ErrorMsg = "Failed to write to settings file" return SettingsXML
def System_Install_Response(self, FileChooser, Response): SystemSettingsTree = { ("", 1, ("name", ), SettingsCheck.SystemNameSanityCheck): None } if Response == Gtk.ResponseType.ACCEPT: filename = FileChooser.get_filename() SystemArchive = Archive(filename, 'r') try: settingsstring = SystemArchive.read("system.xml") SystemXML = ET.XML(settingsstring) ValidSettings = SettingsCheck.check_settings( SystemSettingsTree, SystemXML) if not ValidSettings: raise Exception systemname = SystemXML.get("name") if not os.path.isdir(Globals.DataDir + "Systems/System_" + systemname): os.mkdir(Globals.DataDir + "Systems/System_" + systemname) if not os.path.isdir(Globals.DataDir + "Games/" + systemname): os.mkdir(Globals.DataDir + "Games/" + systemname) SystemArchive.extractall(path=Globals.DataDir + "Systems/System_" + systemname) Globals.Systems.append(systemname) popup = ErrorPopupWindow("System Installed", "System installed successfully!") popup.set_transient_for(self) popup.show_all() else: popup = ErrorPopupWindow( "System already exists", "System already exists, uninstall the system first.") popup.set_transient_for(self) popup.show_all() except: popup = ErrorPopupWindow( "Malformed System", "Archive containing the system is malformed, try redownloading the archive" ) popup.set_transient_for(self) popup.show_all() FileChooser.destroy() Globals.OpenWindows &= ~Globals.WINDOWTYPE_FILECHOOSER
def Core_Install_Response(self,FileChooser,Response): CoreSettingsTree = {("",1,("name","system"),SettingsCheck.CoreNameSanityCheck) : None} if Response == Gtk.ResponseType.ACCEPT: filename = FileChooser.get_filename() SystemArchive = Archive(filename,'r') try: settingsstring = SystemArchive.read("core.xml") CoreXML = ET.XML(settingsstring) ValidSettings = SettingsCheck.check_settings(CoreSettingsTree, CoreXML) if not ValidSettings: raise Exception("Invalid Core Settings") systemname = CoreXML.get("system") corename = CoreXML.get("name") if os.path.isdir(Globals.DataDir+"Systems/System_"+systemname): if not os.path.isdir(Globals.DataDir+"Systems/System_"+systemname+"/"+corename): os.mkdir(Globals.DataDir+"Systems/System_"+systemname+"/Core_"+corename) SystemArchive.extractall(path=Globals.DataDir+"Systems/System_"+systemname+"/Core_"+ corename) Globals.Cores.append(systemname+"/"+corename) popup = ErrorPopupWindow("Core Installed","Core installed successfully!") popup.set_transient_for(self) popup.show_all() else: popup = ErrorPopupWindow("Core already exists","Core already exists, uninstall the core first.") popup.set_transient_for(self) popup.show_all() else: popup = ErrorPopupWindow("System not found","System: " + systemname + " not found, please install the system before the core") popup.set_transient_for(self) popup.show_all() except Exception as e: print e popup = ErrorPopupWindow("Malformed Core","Archive containing the core is malformed, try redownloading the archive") popup.set_transient_for(self) popup.show_all() FileChooser.destroy() Globals.OpenWindows &= ~Globals.WINDOWTYPE_FILECHOOSER
def Get_Games(self): ValidGames = False GamesXML = None try: with open(Globals.DataDir + "Games/Games.xml", "r") as GamesFile: GamesText = GamesFile.read() ValidGames = True except IOError: pass #Description to follow through the settings tree for testing sanity GamesTree = { ("System", 0, ("name", ), SettingsCheck.SystemExistSanityCheck): { ("Game", 0, ("name", ), SettingsCheck.GameNameSanityCheck): { ("Patch", 0, ("name", ), SettingsCheck.PatchNameSanityCheck): None } } } GameTree = { ("", 1, ("name", "core", "filename", "system"), SettingsCheck.GameSettingsSanityCheck): { ("Controls", 1, ("inherit", ), None): None } } PatchSanityLam = lambda game, name, format, filename, system: os.path.isfile( Globals.DataDir + "Games/" + system + "/" + game + "/patches/" + name + "/" + filename) PatchTree = { ("", 1, ("game", "name", "format", "filename", "system"), PatchSanityLam): { ("Controls", 1, ("inherit", ), None): None } } #Make sure the settings file is valid XML if ValidGames: try: GamesXML = ET.XML(GamesText) except ET.ParseError: ValidGames = False #Validate the the settings use sane values if ValidGames: ValidGames = SettingsCheck.check_settings(GamesTree, GamesXML) #If the games XML file isn't sane, repopulate it manually if not ValidGames: popup = ErrorPopupWindow( "Games not found", "Game definitions not found, repopulating manually") popup.set_transient_for(self.window) popup.show_all() systemlam = lambda x: os.path.isdir( Globals.DataDir + "Games/" + x) and os.path.isdir( Globals.DataDir + "Systems/System_" + x) gamelam = lambda x: os.path.isdir(Globals.DataDir + "Games/" + system + "/" + x) patchlam = lambda x: os.path.isdir(Globals.DataDir + "Games/" + system + "/" + game + "/" + x) GamesXML = ET.XML("<Games/>") for system in filter(systemlam, os.listdir(Globals.DataDir + "Games")): SystemXML = ET.XML("<System/>") SystemXML.set("name", system) for game in filter( gamelam, os.listdir(Globals.DataDir + "Games/" + system)): try: with open( Globals.DataDir + "Games/" + system + "/" + game + "/game.xml", 'r') as GameSettingsFile: GameSettingsText = GameSettingsFile.read() GameSettingsXML = ET.XML(GameSettingsText) GameSane = SettingsCheck.check_settings( GameTree, GameSettingsXML) if GameSane: GameXML = ET.XML("<Game/>") GameXML.set("name", game) GameXML.set("core", GameSettingsXML.get("core")) for patch in filter( patchlam, os.listdir(Globals.DataDir + "Games/" + system + "/" + game + "/patches")): try: with open( Globals.DataDir + "Games/" + system + "/" + game + "/patches/" + patch + "/patch.xml", 'r') as PatchSettingsFile: PatchSettingsText = PatchSettingsFile.read( ) PatchSettingsXML = ET.XML( PatchSettingsText) PatchSane = SettingsCheck.check_settings( PatchTree, PatchSettingsXML) if PatchSane: PatchXML = ET.XML("<Patch/>") PatchXML.set("name", patch) PatchXML.set( "format", PatchSettingsXML.get("format")) GameXML.append(PatchXML) except: pass SystemXML.append(GameXML) except: pass GamesXML.append(SystemXML) return GamesXML
def __init__(self): #Create data directories. Included in windows even though #the project won't work in windows yet self.frames = 0 self.oldtime = 0 SettingsXML = self.Get_Settings() Globals.SettingsXML = SettingsXML self.window = MainWindow() self.ErrorMsg = None self.system = None Globals.load_game = partial(self.load_game, self) Globals.load_game = self.load_game Globals.Mainwindow = self.window Globals.Mouse = PyMouse() Globals.Joysticks = [ pygame.joystick.Joystick(i) for i in xrange(pygame.joystick.get_count()) ] [i.init() for i in Globals.Joysticks] self.state_slot = 0 if not os.path.isdir(Globals.DataDir + "temp"): os.mkdir(Globals.DataDir + "temp") if not os.path.isdir(Globals.DataDir + "Systems"): os.mkdir(Globals.DataDir + "Systems") if not os.path.isdir(Globals.DataDir + "Games"): os.mkdir(Globals.DataDir + "Games") SystemSettingsTree = { ("", 1, ("name", ), SettingsCheck.SystemExistSanityCheck): None } CoreSettingsTree = { ("", 1, ("name", "system"), SettingsCheck.CoreNameSanityCheck): None } for i in os.listdir(Globals.DataDir + "Systems"): if os.path.isdir(Globals.DataDir + "Systems/" + i): try: with open(Globals.DataDir + "Systems/" + i + "/system.xml", 'r') as settingsfile: SystemXML = ET.XML(settingsfile.read()) if SettingsCheck.check_settings(SystemSettingsTree, SystemXML): Globals.Systems.append((i)[7:]) for j in os.listdir(Globals.DataDir + "Systems/" + i): if os.path.isdir(Globals.DataDir + "Systems/" + i + "/" + j): try: settingsfile = open( Globals.DataDir + "Systems/" + i + "/" + j + "/core.xml", 'r') with open( Globals.DataDir + "Systems/" + i + "/" + j + "/core.xml", 'r') as settingsfile: CoreXML = ET.XML(settingsfile.read()) if SettingsCheck.check_settings( CoreSettingsTree, CoreXML): Globals.Cores.append(i[7:] + "/" + j[5:]) except: pass except: pass self.systemrunning = False GamesXML = self.Get_Games() Globals.GamesXML = GamesXML Globals.Update_Games() Globals.WindowHeight = int( Globals.SettingsXML.find("Window").get("height")) Globals.WindowWidth = int( Globals.SettingsXML.find("Window").get("width")) self.window.set_default_size(Globals.WindowWidth, Globals.WindowHeight) self.window.connect('check-resize', self.Window_Size_Changed) self.window.connect("delete-event", self.on_kill) self.window.connect("destroy", self.on_kill) self.window.show_all() Globals.Hotkeys = self.generateControls( Globals.SettingsXML.find("Hotkeys")) self.timeout = GObject.timeout_add(16, self.runframe)
def Get_Games(self): ValidGames = False GamesXML = None try: with open(Globals.DataDir+"Games/Games.xml", "r") as GamesFile: GamesText = GamesFile.read() ValidGames = True except IOError: pass #Description to follow through the settings tree for testing sanity GamesTree = {("System",0,("name",),SettingsCheck.SystemExistSanityCheck) : {("Game",0,("name",),SettingsCheck.GameNameSanityCheck): {("Patch",0,("name",),SettingsCheck.PatchNameSanityCheck):None} } } GameTree = {("",1,("name","core","filename","system"),SettingsCheck.GameSettingsSanityCheck) : {("Controls",1,("inherit",),None): None } } PatchSanityLam = lambda game,name,format,filename,system: os.path.isfile(Globals.DataDir+"Games/"+system+"/"+game+"/patches/"+name+"/"+filename) PatchTree = {("",1,("game","name","format","filename","system"),PatchSanityLam) : {("Controls",1,("inherit",),None): None } } #Make sure the settings file is valid XML if ValidGames: try: GamesXML = ET.XML(GamesText) except ET.ParseError: ValidGames = False #Validate the the settings use sane values if ValidGames: ValidGames = SettingsCheck.check_settings(GamesTree,GamesXML) #If the games XML file isn't sane, repopulate it manually if not ValidGames: popup = ErrorPopupWindow("Games not found","Game definitions not found, repopulating manually") popup.set_transient_for(self.window) popup.show_all() systemlam = lambda x: os.path.isdir(Globals.DataDir+"Games/"+x) and os.path.isdir(Globals.DataDir+"Systems/System_"+x) gamelam = lambda x: os.path.isdir(Globals.DataDir+"Games/"+system+"/"+x) patchlam = lambda x: os.path.isdir(Globals.DataDir+"Games/"+system+"/"+game+"/"+x) GamesXML = ET.XML("<Games/>") for system in filter(systemlam, os.listdir(Globals.DataDir+"Games")): SystemXML = ET.XML("<System/>") SystemXML.set("name",system) for game in filter(gamelam,os.listdir(Globals.DataDir+"Games/"+system)): try: with open(Globals.DataDir+"Games/"+system+"/"+game+"/game.xml",'r') as GameSettingsFile: GameSettingsText = GameSettingsFile.read() GameSettingsXML = ET.XML(GameSettingsText) GameSane = SettingsCheck.check_settings(GameTree, GameSettingsXML) if GameSane: GameXML = ET.XML("<Game/>") GameXML.set("name",game) GameXML.set("core",GameSettingsXML.get("core")) for patch in filter(patchlam,os.listdir(Globals.DataDir+"Games/"+system+"/"+game+"/patches")): try: with open(Globals.DataDir+"Games/"+system+"/"+game+"/patches/"+patch+"/patch.xml",'r') as PatchSettingsFile: PatchSettingsText = PatchSettingsFile.read() PatchSettingsXML = ET.XML(PatchSettingsText) PatchSane = SettingsCheck.check_settings(PatchTree, PatchSettingsXML) if PatchSane: PatchXML = ET.XML("<Patch/>") PatchXML.set("name",patch) PatchXML.set("format",PatchSettingsXML.get("format")) GameXML.append(PatchXML) except: pass SystemXML.append(GameXML) except: pass GamesXML.append(SystemXML) return GamesXML
def __init__(self): #Create data directories. Included in windows even though #the project won't work in windows yet self.frames= 0 self.oldtime = 0 SettingsXML = self.Get_Settings() Globals.SettingsXML = SettingsXML self.window = MainWindow() self.ErrorMsg = None self.system = None Globals.load_game = partial(self.load_game,self) Globals.load_game = self.load_game Globals.Mainwindow = self.window Globals.Mouse = PyMouse() Globals.Joysticks = [pygame.joystick.Joystick(i) for i in xrange(pygame.joystick.get_count())] [i.init() for i in Globals.Joysticks] self.state_slot = 0 if not os.path.isdir(Globals.DataDir+"temp"): os.mkdir(Globals.DataDir+"temp") if not os.path.isdir(Globals.DataDir+"Systems"): os.mkdir(Globals.DataDir+"Systems") if not os.path.isdir(Globals.DataDir+"Games"): os.mkdir(Globals.DataDir+"Games") SystemSettingsTree = {("",1,("name",), SettingsCheck.SystemExistSanityCheck): None} CoreSettingsTree = {("",1,("name","system"),SettingsCheck.CoreNameSanityCheck) : None} for i in os.listdir(Globals.DataDir+"Systems"): if os.path.isdir(Globals.DataDir+"Systems/"+i): try: with open(Globals.DataDir+"Systems/"+i+"/system.xml",'r') as settingsfile: SystemXML = ET.XML(settingsfile.read()) if SettingsCheck.check_settings(SystemSettingsTree, SystemXML): Globals.Systems.append((i)[7:]) for j in os.listdir(Globals.DataDir+"Systems/"+i): if os.path.isdir(Globals.DataDir+"Systems/"+i+"/"+j): try: settingsfile = open(Globals.DataDir+"Systems/"+i+"/" + j + "/core.xml",'r') with open(Globals.DataDir+"Systems/"+i+"/" + j + "/core.xml",'r') as settingsfile: CoreXML = ET.XML(settingsfile.read()) if SettingsCheck.check_settings(CoreSettingsTree, CoreXML): Globals.Cores.append(i[7:]+"/"+j[5:]) except: pass except: pass self.systemrunning=False GamesXML = self.Get_Games() Globals.GamesXML = GamesXML Globals.Update_Games() Globals.WindowHeight = int(Globals.SettingsXML.find("Window").get("height")) Globals.WindowWidth = int(Globals.SettingsXML.find("Window").get("width")) self.window.set_default_size(Globals.WindowWidth, Globals.WindowHeight) self.window.connect('check-resize', self.Window_Size_Changed) self.window.connect("delete-event", self.on_kill) self.window.connect("destroy", self.on_kill) self.window.show_all() Globals.Hotkeys = self.generateControls(Globals.SettingsXML.find("Hotkeys")) self.timeout = GObject.timeout_add(16,self.runframe)