def setUp(self):
     self.snes = Emulator(name='snes', videomode='4', core='pocketsnes', shaders='', ratio='16/9', smooth='2',
                          rewind='false', emulator='libretro')
     self.wswan = Emulator(name='wswan', videomode='4', core='wswan', shaders='defaultshaders', ratio='16/9', smooth='2',
                          rewind='false', emulator='libretro')
     generators.configManager.recalboxFiles.shaderPresetRoot = os.path.abspath(os.path.join(os.path.dirname(__file__), "tmp/"))
     generators.configManager.recalboxFiles.recalboxConf = recalboxConf
     self.manager = ConfigManager()
 def setUp(self):
     self.snes = Emulator(name='snes',
                          videomode='4',
                          core='pocketsnes',
                          shaders='',
                          ratio='16/9',
                          smooth='2',
                          rewind='false',
                          emulator='libretro')
     self.wswan = Emulator(name='wswan',
                           videomode='4',
                           core='wswan',
                           shaders='defaultshaders',
                           ratio='16/9',
                           smooth='2',
                           rewind='false',
                           emulator='libretro')
     generators.configManager.recalboxFiles.shaderPresetRoot = os.path.abspath(
         os.path.join(os.path.dirname(__file__), "tmp/"))
     generators.configManager.recalboxFiles.recalboxConf = recalboxConf
     self.manager = ConfigManager()
    args = parser.parse_args()

    playersControllers = dict()
    if not args.demo:
        # Read the controller configuration
        playersControllers = controllers.loadControllerConfig(args.p1index, args.p1guid, args.p1name, args.p1devicepath,
                                                              args.p2index, args.p2guid, args.p2name, args.p2devicepath,
                                                              args.p3index, args.p3guid, args.p3name, args.p3devicepath,
                                                              args.p4index, args.p4guid, args.p4name, args.p4devicepath,
                                                              args.p5index, args.p5guid, args.p5name, args.p5devicepath)

    systemName = args.system

    # Main Program
    # A generator will configure its emulator, and return a command
    if systemName in emulators:
        system = emulators[systemName]
        systemManager = ConfigManager()

        systemManager.configure(system, args.emulator, args.core)
	# Save dir
	if not os.path.exists(recalboxFiles.savesDir+system.name):
    		os.makedirs(recalboxFiles.savesDir+system.name)

        command = generators[system.config['emulator']].generate(system, args.rom, playersControllers)
        print(command.array)
        exitcode = runner.runCommand(command)
        time.sleep(1)
        exit(exitcode)
                        help="rom absolute path",
                        type=str,
                        required=True)
    parser.add_argument("-demo", help="mode demo", type=bool, required=False)

    args = parser.parse_args()

    playersControllers = dict()
    if not args.demo:
        # Read the controller configuration
        playersControllers = controllers.loadControllerConfig(
            args.p1index, args.p1guid, args.p1name, args.p1devicepath,
            args.p2index, args.p2guid, args.p2name, args.p2devicepath,
            args.p3index, args.p3guid, args.p3name, args.p3devicepath,
            args.p4index, args.p4guid, args.p4name, args.p4devicepath)

    systemName = args.system

    # Main Program
    # A generator will configure its emulator, and return a command
    if systemName in emulators:
        system = emulators[systemName]
        systemManager = ConfigManager()

        systemManager.configure(system)
        command = generators[system.config['emulator']].generate(
            system, args.rom, playersControllers)
        print(command.array)
        runner.runCommand(command)
        time.sleep(1)
class ConfigManagerTest(unittest.TestCase):
    def setUp(self):
        self.snes = Emulator(name='snes', videomode='4', core='pocketsnes', shaders='', ratio='16/9', smooth='2',
                             rewind='false', emulator='libretro')
        self.wswan = Emulator(name='wswan', videomode='4', core='wswan', shaders='defaultshaders', ratio='16/9', smooth='2',
                             rewind='false', emulator='libretro')
        generators.configManager.recalboxFiles.shaderPresetRoot = os.path.abspath(os.path.join(os.path.dirname(__file__), "tmp/"))
        generators.configManager.recalboxFiles.recalboxConf = recalboxConf
        self.manager = ConfigManager()

    def test_globalOverrideSystemConfig(self):
        globalConf = {'shaders':'myshaders'}
        self.manager.updateConfiguration(self.wswan, globalConf)
        self.assertEquals(self.wswan.config['shaders'], 'myshaders')


    def test_autoRatio(self):
        globalConf = {'ratio':'auto'}
        self.manager.updateConfiguration(self.snes, globalConf)
        self.assertEquals(self.snes.config['ratio'], '16/9')


    def test_globalShaderSet(self):
        self.manager.configure(self.wswan)
        self.assertEquals(self.wswan.config['shaders'], '/path/to/my/scanline/wswan/shader/from/configfile.cfg')

    def test_specificShaderOverrideGlobalShader(self):
        self.manager.configure(self.snes)
        self.assertEquals(self.snes.config['shaders'], 'myshaderfile.gplsp')


    def test_specificShaderOverrideglobalShaderSet(self):
        self.manager.configure(self.snes)
        self.assertEquals(self.snes.config['shaders'], 'myshaderfile.gplsp')


    def test_shaderSetNone(self):
        self.manager.updateShaders(self.wswan, "none")
        self.assertEquals(self.wswan.config['shaders'], 'defaultshaders')

    def test_menues_change_specials_entry(self):
        self.manager.configure(self.wswan)
        self.assertEquals(self.wswan.config['specials'], 'default')

    def test_specials_entry(self):
        UnixSettings(recalboxConf).save('system.emulators.specialkeys', 'default')
        self.manager.configure(self.wswan)
        self.assertEquals(self.wswan.config['specials'], 'default')

    def test_menues_change_specials_entry(self):
        UnixSettings(recalboxConf).save('system.emulators.specialkeys', 'none')
        self.manager.configure(self.wswan)
        self.assertEquals(self.wswan.config['specials'], 'none')

    def testNoShaderSetInConfig(self):
        pass
    parser.add_argument("-p4guid", help="player4 controller SDL2 guid", type=str, required=False)
    parser.add_argument("-p4name", help="player4 controller name", type=str, required=False)
    parser.add_argument("-p4devicepath", help="player4 controller device", type=str, required=False)
    parser.add_argument("-system", help="select the system to launch", type=str, required=True)
    parser.add_argument("-rom", help="rom absolute path", type=str, required=True)
    parser.add_argument("-demo", help="mode demo", type=bool, required=False)

    args = parser.parse_args()

    playersControllers = dict()
    if not args.demo:
        # Read the controller configuration
        playersControllers = controllers.loadControllerConfig(args.p1index, args.p1guid, args.p1name, args.p1devicepath,
                                                              args.p2index, args.p2guid, args.p2name, args.p2devicepath,
                                                              args.p3index, args.p3guid, args.p3name, args.p3devicepath,
                                                              args.p4index, args.p4guid, args.p4name, args.p4devicepath)

    systemName = args.system

    # Main Program
    # A generator will configure its emulator, and return a command
    if systemName in emulators:
        system = emulators[systemName]
        systemManager = ConfigManager()

        systemManager.configure(system)
        command = generators[system.config['emulator']].generate(system, args.rom, playersControllers)
        print(command.array)
        runner.runCommand(command)
        time.sleep(1)
class ConfigManagerTest(unittest.TestCase):
    def setUp(self):
        self.snes = Emulator(name='snes',
                             videomode='4',
                             core='pocketsnes',
                             shaders='',
                             ratio='16/9',
                             smooth='2',
                             rewind='false',
                             emulator='libretro')
        self.wswan = Emulator(name='wswan',
                              videomode='4',
                              core='wswan',
                              shaders='defaultshaders',
                              ratio='16/9',
                              smooth='2',
                              rewind='false',
                              emulator='libretro')
        generators.configManager.recalboxFiles.shaderPresetRoot = os.path.abspath(
            os.path.join(os.path.dirname(__file__), "tmp/"))
        generators.configManager.recalboxFiles.recalboxConf = recalboxConf
        self.manager = ConfigManager()

    def test_globalOverrideSystemConfig(self):
        globalConf = {'shaders': 'myshaders'}
        self.manager.updateConfiguration(self.wswan, globalConf)
        self.assertEquals(self.wswan.config['shaders'], 'myshaders')

    def test_autoRatio(self):
        globalConf = {'ratio': 'auto'}
        self.manager.updateConfiguration(self.snes, globalConf)
        self.assertEquals(self.snes.config['ratio'], '16/9')

    def test_globalShaderSet(self):
        self.manager.configure(self.wswan)
        self.assertEquals(
            self.wswan.config['shaders'],
            '/path/to/my/scanline/wswan/shader/from/configfile.cfg')

    def test_specificShaderOverrideGlobalShader(self):
        self.manager.configure(self.snes)
        self.assertEquals(self.snes.config['shaders'], 'myshaderfile.gplsp')

    def test_specificShaderOverrideglobalShaderSet(self):
        self.manager.configure(self.snes)
        self.assertEquals(self.snes.config['shaders'], 'myshaderfile.gplsp')

    def test_shaderSetNone(self):
        self.manager.updateShaders(self.wswan, "none")
        self.assertEquals(self.wswan.config['shaders'], 'defaultshaders')

    def test_menues_change_specials_entry(self):
        self.manager.configure(self.wswan)
        self.assertEquals(self.wswan.config['specials'], 'default')

    def test_specials_entry(self):
        UnixSettings(recalboxConf).save('system.emulators.specialkeys',
                                        'default')
        self.manager.configure(self.wswan)
        self.assertEquals(self.wswan.config['specials'], 'default')

    def test_menues_change_specials_entry(self):
        UnixSettings(recalboxConf).save('system.emulators.specialkeys', 'none')
        self.manager.configure(self.wswan)
        self.assertEquals(self.wswan.config['specials'], 'none')

    def testNoShaderSetInConfig(self):
        pass