示例#1
0
        public bool CreateInstance( bool suppressXmb )
        {
            EmulationParameters emulationParams = new EmulationParameters();

            Dictionary<KeyValuePair<string, int>, ComponentParameters> parameters = new Dictionary<KeyValuePair<string, int>, ComponentParameters>();

            Settings[] settingsList = _componentSettings.GetValue<Settings[]>( "settingsList" );
            if( settingsList != null )
            {
                foreach( Settings settings in settingsList )
                {
                    string componentName = settings.GetValue<string>( "componentName" );
                    int index = settings.GetValue<int>( "componentIndex" );
                    ComponentParameters p = settings.GetValue<ComponentParameters>( "parameters" );
                    parameters.Add( new KeyValuePair<string, int>( componentName, index ), p );
                }
            }

            Settings[] pickedComponents = _componentSettings.GetValue<Settings[]>( "pickedComponents" );
            if( pickedComponents != null )
            {
                foreach( Settings settings in pickedComponents )
                {
                    string componentName = settings.GetValue<string>( "componentName" );
                    int index = settings.GetValue<int>( "componentIndex" );
                    string componentPath = settings.GetValue<string>( "componentPath" );

                    Assembly assembly;
                    try
                    {
                        assembly = Assembly.LoadFile( componentPath );
                    }
                    catch
                    {
                        Log.WriteLine( Verbosity.Critical, Feature.General, "CreateInstance: assembly not found or not loadable: {0}", componentPath );
                        continue;
                    }
                    Type type = assembly.GetType( componentName, false );
                    if( type == null )
                    {
                        Log.WriteLine( Verbosity.Critical, Feature.General, "CreateInstance: component not found or not loadable: {0} in {1}", componentName, componentPath );
                        continue;
                    }
                    IComponent component;
                    try
                    {
                        component = ( IComponent )Activator.CreateInstance( type );
                    }
                    catch
                    {
                        Log.WriteLine( Verbosity.Critical, Feature.General, "CreateInstance: component could not be instantiated: {0} in {1}", componentName, componentPath );
                        continue;
                    }

                    switch( component.Type )
                    {
                        case ComponentType.Audio:
                            emulationParams.AudioComponent = component;
                            break;
                        case ComponentType.Bios:
                            emulationParams.BiosComponent = component;
                            break;
                        case ComponentType.Cpu:
                            emulationParams.CpuComponent = component;
                            break;
                        case ComponentType.Input:
                            emulationParams.InputComponent = component;
                            break;
                        case ComponentType.UserMedia:
                            emulationParams.MemoryStickComponent = component;
                            break;
                        case ComponentType.GameMedia:
                            emulationParams.UmdComponent = component;
                            break;
                        case ComponentType.Network:
                            emulationParams.IOComponents.Add( component );
                            break;
                        case ComponentType.Video:
                            emulationParams.VideoComponent = component;
                            break;
                        case ComponentType.Other:
                        default:
                            //Log.WriteLine( Verbosity.Critical, Feature.General, "CreateInstance: unknown component type for {0} in {1}", componentName, componentPath );
                            continue;
                    }

                    ComponentParameters p = null;
                    KeyValuePair<string, int> specifier = new KeyValuePair<string, int>( componentName, index );
                    if( parameters.ContainsKey( specifier ) == true )
                        p = parameters[ specifier ];
                    if( p != null )
                        emulationParams.Parameters[ component ] = p;
                    else
                        emulationParams.Parameters[ component ] = new ComponentParameters();
                }
            }

            _instance = new Instance( this, emulationParams, suppressXmb );

            List<ComponentIssue> issues = _instance.Test();
            bool showReport = false;
            bool allowRun = true;
            if( issues.Count > 0 )
            {
                int errorCount = 0;
                foreach( ComponentIssue issue in issues )
                {
                    if( issue.Level == IssueLevel.Error )
                        errorCount++;
                }
                if( errorCount == 0 )
                {
                    if( Properties.Settings.Default.ShowReportOnWarnings == true )
                        showReport = true;
                }
                else
                {
                    showReport = true;
                    allowRun = false;
                }
            }

            if( showReport == true )
            {
                IssueReport report = new IssueReport( this, issues );
                report.ShowDialog( _player );
            }

            if( allowRun == true )
                return _instance.Create();
            else
                return false;
        }
示例#2
0
        public bool CreateInstance(bool suppressXmb)
        {
            EmulationParameters emulationParams = new EmulationParameters();

            Dictionary <KeyValuePair <string, int>, ComponentParameters> parameters = new Dictionary <KeyValuePair <string, int>, ComponentParameters>();

            Settings[] settingsList = _componentSettings.GetValue <Settings[]>("settingsList");
            if (settingsList != null)
            {
                foreach (Settings settings in settingsList)
                {
                    string componentName  = settings.GetValue <string>("componentName");
                    int    index          = settings.GetValue <int>("componentIndex");
                    ComponentParameters p = settings.GetValue <ComponentParameters>("parameters");
                    parameters.Add(new KeyValuePair <string, int>(componentName, index), p);
                }
            }

            Settings[] pickedComponents = _componentSettings.GetValue <Settings[]>("pickedComponents");
            if (pickedComponents != null)
            {
                foreach (Settings settings in pickedComponents)
                {
                    string componentName = settings.GetValue <string>("componentName");
                    int    index         = settings.GetValue <int>("componentIndex");
                    string componentPath = settings.GetValue <string>("componentPath");

                    Assembly assembly;
                    try
                    {
                        assembly = Assembly.LoadFile(componentPath);
                    }
                    catch
                    {
                        Log.WriteLine(Verbosity.Critical, Feature.General, "CreateInstance: assembly not found or not loadable: {0}", componentPath);
                        continue;
                    }
                    Type type = assembly.GetType(componentName, false);
                    if (type == null)
                    {
                        Log.WriteLine(Verbosity.Critical, Feature.General, "CreateInstance: component not found or not loadable: {0} in {1}", componentName, componentPath);
                        continue;
                    }
                    IComponent component;
                    try
                    {
                        component = ( IComponent )Activator.CreateInstance(type);
                    }
                    catch
                    {
                        Log.WriteLine(Verbosity.Critical, Feature.General, "CreateInstance: component could not be instantiated: {0} in {1}", componentName, componentPath);
                        continue;
                    }

                    switch (component.Type)
                    {
                    case ComponentType.Audio:
                        emulationParams.AudioComponent = component;
                        break;

                    case ComponentType.Bios:
                        emulationParams.BiosComponent = component;
                        break;

                    case ComponentType.Cpu:
                        emulationParams.CpuComponent = component;
                        break;

                    case ComponentType.Input:
                        emulationParams.InputComponent = component;
                        break;

                    case ComponentType.UserMedia:
                        emulationParams.MemoryStickComponent = component;
                        break;

                    case ComponentType.GameMedia:
                        emulationParams.UmdComponent = component;
                        break;

                    case ComponentType.Network:
                        emulationParams.IOComponents.Add(component);
                        break;

                    case ComponentType.Video:
                        emulationParams.VideoComponent = component;
                        break;

                    case ComponentType.Other:
                    default:
                        //Log.WriteLine( Verbosity.Critical, Feature.General, "CreateInstance: unknown component type for {0} in {1}", componentName, componentPath );
                        continue;
                    }

                    ComponentParameters        p         = null;
                    KeyValuePair <string, int> specifier = new KeyValuePair <string, int>(componentName, index);
                    if (parameters.ContainsKey(specifier) == true)
                    {
                        p = parameters[specifier];
                    }
                    if (p != null)
                    {
                        emulationParams.Parameters[component] = p;
                    }
                    else
                    {
                        emulationParams.Parameters[component] = new ComponentParameters();
                    }
                }
            }

            _instance = new Instance(this, emulationParams, suppressXmb);

            List <ComponentIssue> issues = _instance.Test();
            bool showReport = false;
            bool allowRun   = true;

            if (issues.Count > 0)
            {
                int errorCount = 0;
                foreach (ComponentIssue issue in issues)
                {
                    if (issue.Level == IssueLevel.Error)
                    {
                        errorCount++;
                    }
                }
                if (errorCount == 0)
                {
                    if (Properties.Settings.Default.ShowReportOnWarnings == true)
                    {
                        showReport = true;
                    }
                }
                else
                {
                    showReport = true;
                    allowRun   = false;
                }
            }

            if (showReport == true)
            {
                IssueReport report = new IssueReport(this, issues);
                report.ShowDialog(_player);
            }

            if (allowRun == true)
            {
                return(_instance.Create());
            }
            else
            {
                return(false);
            }
        }