示例#1
0
文件: Main.py 项目: HuFlungDu/GSEF
    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
示例#2
0
文件: Main.py 项目: HuFlungDu/GSEF
    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
示例#3
0
文件: Main.py 项目: HuFlungDu/GSEF
    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
示例#4
0
文件: Main.py 项目: HuFlungDu/GSEF
        self.changed_this_frame = False
        return self.__state

    def get_type(self):
        return self.__ctype

    def get_name(self):
        return self.__name

    def get_mapping(self):
        return self.__mapping

    def get_digital(self):
        return self.__digital

    def get_sensitivity(self):
        return self.__sensitivity


if __name__ == "__main__":

    Program = GSEF()
    #If the program creates an error, make a popup window about it and close the program
    if not Program.ErrorMsg:
        Program.Run()
    else:
        popup = ErrorPopupWindow("Error", Program.ErrorMsg)
        popup.connect("destroy", Gtk.main_quit)
        popup.show_all()
        Gtk.main()
示例#5
0
文件: Main.py 项目: HuFlungDu/GSEF
    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
示例#6
0
文件: Main.py 项目: HuFlungDu/GSEF
        self.changed_this_frame = False
        return self.__state

    def get_type(self):
        return self.__ctype

    def get_name(self):
        return self.__name

    def get_mapping(self):
        return self.__mapping

    def get_digital(self):
        return self.__digital

    def get_sensitivity(self):
        return self.__sensitivity


if __name__ == "__main__":

    Program = GSEF()
    #If the program creates an error, make a popup window about it and close the program
    if not Program.ErrorMsg:
        Program.Run()
    else:
        popup = ErrorPopupWindow("Error",Program.ErrorMsg)
        popup.connect("destroy", Gtk.main_quit)
        popup.show_all()
        Gtk.main()