示例#1
0
        /// <summary>
        /// Configures and initializes/starts and configures the Pinball object
        /// </summary>
        /// <param name="GlobalConfigFilename">The global config filename.</param>
        /// <param name="TableFilename">The table filename.</param>
        /// <param name="RomName">Name of the rom.</param>
        public void Init(string GlobalConfigFilename = "", string TableFilename = "", string RomName = "")
        {

            bool GlobalConfigLoaded = true;
            //Load the global config


            try
            {
                if (!GlobalConfigFilename.IsNullOrWhiteSpace())
                {
                    FileInfo GlobalConfigFile = new FileInfo(GlobalConfigFilename);


                    GlobalConfig = GlobalConfig.GetGlobalConfigFromConfigXmlFile(GlobalConfigFile.FullName);
                    if (GlobalConfig == null)
                    {
                        GlobalConfigLoaded = false;

                        //set new global config object if it config could not be loaded from the file.
                        GlobalConfig = new GlobalConfig();
                    }
                    GlobalConfig.GlobalConfigFilename = GlobalConfigFile.FullName;
                }
                else
                {
                    GlobalConfig = new GlobalConfig();
                    GlobalConfig.GlobalConfigFilename = GlobalConfigFilename;
                }

            }
            catch (Exception E)
            {

                throw new Exception("DirectOutput framework could initialize global config.\n Inner exception: {0}".Build(E.Message), E);
            }

            if (GlobalConfig.EnableLogging)
            {
                try
                {

                    Log.Filename = GlobalConfig.GetLogFilename((!TableFilename.IsNullOrWhiteSpace() ? new FileInfo(TableFilename).FullName : ""), RomName);
                    Log.Init();

                }
                catch (Exception E)
                {

                    throw new Exception("DirectOutput framework could initialize the log file.\n Inner exception: {0}".Build(E.Message), E);
                }
            }


            try
            {
                if (GlobalConfigLoaded)
                {
                    Log.Write("Global config loaded from: {0}".Build(GlobalConfigFilename));
                }
                else
                {
                    if (!GlobalConfigFilename.IsNullOrWhiteSpace())
                    {
                        Log.Write("Could not find or load theGlobalConfig file {0}".Build(GlobalConfigFilename));
                    }
                    else
                    {
                        Log.Write("No GlobalConfig file loaded. Using newly instanciated GlobalConfig object instead.");
                    }
                }



                Log.Write("Loading Pinball parts");



                //Load global script files
                Log.Write("Loading script files");
                Scripts.LoadAndAddScripts(GlobalConfig.GetGlobalScriptFiles());




                //Load table script files
                if (!TableFilename.IsNullOrWhiteSpace())
                {
                    Scripts.LoadAndAddScripts(GlobalConfig.GetTableScriptFiles(new FileInfo(TableFilename).FullName));
                }
                Log.Write("Script files loaded");


                Log.Write("Loading cabinet");
                //Load cabinet config
                Cabinet = null;
                FileInfo CCF = GlobalConfig.GetCabinetConfigFile();
                if (CCF != null)
                {
                    Log.Write("Will load cabinet config file: {0}".Build(CCF.FullName));
                    try
                    {
                        Cabinet = Cabinet.GetCabinetFromConfigXmlFile(CCF);
                        Cabinet.CabinetConfigurationFilename = CCF.FullName;
                        if (Cabinet.AutoConfigEnabled)
                        {
                            Log.Write("Cabinet config file has AutoConfig feature enable. Calling AutoConfig.");
                            Cabinet.AutoConfig();
                        }
                        Log.Write("Cabinet config loaded successfully from {0}".Build(CCF.FullName));
                    }
                    catch (Exception E)
                    {
                        Log.Exception("A exception occured when load cabinet config file: {0}".Build(CCF.FullName), E);


                    }
                }
                if (Cabinet == null)
                {
                    Log.Write("No cabinet config file loaded. Will use AutoConfig.");
                    //default to a new cabinet object if the config cant be loaded
                    Cabinet = new Cabinet();
                    Cabinet.AutoConfig();
                }

                Log.Write("Cabinet loaded");

                Log.Write("Loading table config");

                //Load table config

                Table = new DirectOutput.Table.Table();
                Table.AddLedControlConfig = true;

                if (!TableFilename.IsNullOrWhiteSpace())
                {
                    FileInfo TableFile = new FileInfo(TableFilename);
                    FileInfo TCF = GlobalConfig.GetTableConfigFile(TableFile.FullName);
                    if (TCF != null)
                    {
                        Log.Write("Will load table config from {0}".Build(TCF.FullName));
                        try
                        {
                            Table = DirectOutput.Table.Table.GetTableFromConfigXmlFile(GlobalConfig.GetTableConfigFile(TableFile.FullName));
                            Table.TableConfigurationFilename = GlobalConfig.GetTableConfigFile(TableFile.FullName).FullName;
                            Log.Write("Table config loaded successfully from {0}".Build(TCF.FullName));
                        }
                        catch (Exception E)
                        {
                            Log.Exception("A exception occured when loading table config: {0}".Build(TCF.FullName), E);
                        }
                        if (Table.AddLedControlConfig)
                        {
                            Log.Write("Table config allows mix with ledcontrol configs.");
                        }
                    }
                    else
                    {
                        Log.Warning("No table config file found. Will try to load config from LedControl file(s).");
                    }
                }
                else
                {
                    Log.Write("No TableFilename specified, will use empty tableconfig");
                }
                if (Table.AddLedControlConfig)
                {
                    if (!RomName.IsNullOrWhiteSpace())
                    {
                        Log.Write("Will try to load configs from DirectOutput.ini or LedControl.ini file(s) for RomName {0}".Build(RomName));
                        //Load ledcontrol
                        LedControlConfigList L = new LedControlConfigList();
                        if (GlobalConfig.LedControlIniFiles.Count > 0)
                        {
                            Log.Write("Will try to load table config from LedControl  file(s) specified in global config.");
                            L.LoadLedControlFiles(GlobalConfig.LedControlIniFiles, false);
                        }
                        else
                        {
                            bool FoundIt = false;
                            List<string> LookupPaths = new List<string>();
                            if (!TableFilename.IsNullOrWhiteSpace())
                            {
                                if (new FileInfo(TableFilename).Directory.Exists)
                                {
                                    LookupPaths.Add(new FileInfo(TableFilename).Directory.FullName);
                                }
                            }
                            LookupPaths.AddRange(new string[] { GlobalConfig.GetGlobalConfigDirectory().FullName, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) });

                            LedControlIniFileList LedControlIniFiles = new LedControlIniFileList();

                            string[] LedControlFilenames = { "directoutputconfig", "ledcontrol" };

                            foreach (string LedControlFilename in LedControlFilenames)
                            {
                                foreach (string P in LookupPaths)
                                {
                                    DirectoryInfo DI = new DirectoryInfo(P);

                                    List<FileInfo> Files = new List<FileInfo>();
                                    foreach (FileInfo FI in DI.EnumerateFiles())
                                    {
                                        if (FI.Name.ToLower().StartsWith(LedControlFilename.ToLower()) && FI.Name.ToLower().EndsWith(".ini"))
                                        {
                                            Files.Add(FI);
                                        }
                                    }


                                    foreach (FileInfo FI in Files)
                                    {
                                        if (string.Equals(FI.Name, "{0}.ini".Build(LedControlFilename), StringComparison.OrdinalIgnoreCase))
                                        {
                                            LedControlIniFiles.Add(FI.FullName, 1);
                                            FoundIt = true;
                                        }
                                        else
                                        {
                                            string F = FI.Name.Substring(LedControlFilename.Length, FI.Name.Length - LedControlFilename.Length - 4);
                                            if (F.IsInteger())
                                            {
                                                int LedWizNr = -1;
                                                if (int.TryParse(F, out LedWizNr))
                                                {
                                                    if (!LedControlIniFiles.Contains(LedWizNr))
                                                    {
                                                        LedControlIniFiles.Add(FI.FullName, LedWizNr);
                                                        FoundIt = true;
                                                    }

                                                }

                                            }

                                        }
                                    };
                                    if (FoundIt) break;
                                }
                                if (FoundIt) break;
                            }

        

                            if (FoundIt)
                            {
                                L.LoadLedControlFiles(LedControlIniFiles, false);
                                Log.Write("{0} directoutput.ini or ledcontrol.ini files loaded.".Build(LedControlIniFiles.Count));
                            }
                            else
                            {
                                Log.Write("No directoutput.ini or ledcontrol.ini files found. No directoutput.ini or ledcontrol.ini configs will be loaded.");
                            }
                        }
                        if (!L.ContainsConfig(RomName))
                        {
                            Log.Write("No config for table found in LedControl data for RomName {0}.".Build(RomName));
                        }
                        else
                        {
                            Log.Write("Config for RomName {0} exists in LedControl data. Updating cabinet and config.".Build(RomName));

                            DirectOutput.LedControl.Setup.Configurator C = new DirectOutput.LedControl.Setup.Configurator();
                            C.EffectMinDurationMs = GlobalConfig.LedControlMinimumEffectDurationMs;
                            C.EffectRGBMinDurationMs = GlobalConfig.LedControlMinimumRGBEffectDurationMs;
                            C.Setup(L, Table, Cabinet, RomName);
                            C = null;
                            //                        L.UpdateTableConfig(Table, RomName, Cabinet);
                        }
                        L = null;
                    }
                    else
                    {

                        Log.Write("Cant load config from directoutput.ini or ledcontrol.ini file(s) since no RomName was supplied. No ledcontrol config will be loaded.");
                    }

                }
                if (Table.TableName.IsNullOrWhiteSpace())
                {
                    if (!TableFilename.IsNullOrWhiteSpace())
                    {
                        Table.TableName = Path.GetFileNameWithoutExtension(new FileInfo(TableFilename).FullName);
                    }
                    else if (!RomName.IsNullOrWhiteSpace())
                    {
                        Table.TableName = RomName;
                    }
                }
                if (!TableFilename.IsNullOrWhiteSpace())
                {
                    Table.TableFilename = new FileInfo(TableFilename).FullName;
                }
                if (!RomName.IsNullOrWhiteSpace())
                {
                    Table.RomName = RomName;
                }
                Log.Write("Table config loading finished");



                Log.Write("Pinball parts loaded");

                Log.Write("Starting processes");
                InitStatistics();
                Cabinet.Init(this);
                Table.Init(this);
                Alarms.Init(this);
                Table.TriggerStaticEffects();
                Cabinet.Update();

                //Add the thread initializing the framework to the threadinfo list
                ThreadInfo TI = new ThreadInfo(Thread.CurrentThread);
                TI.HeartBeatTimeOutMs = 10000;
                TI.HostName = "External caller";
                TI.HeartBeat();
                ThreadInfoList.Add(TI);



                InitMainThread();
                Log.Write("Framework initialized.");
                Log.Write("Have fun! :)");


            }
            catch (Exception E)
            {
                Log.Exception("A eception occured during initialization", E);
                throw new Exception("DirectOutput framework has encountered a exception during initialization.\n Inner exception: {0}".Build(E.Message), E);
            }
        }
示例#2
0
        /// <summary>
        /// Configures the Pinball object.<br/>
        /// Loads the global config, table config and cabinet config
        /// </summary>
        /// <param name="GlobalConfigFilename">The global config filename.</param>
        /// <param name="TableFilename">The table filename.</param>
        /// <param name="RomName">Name of the rom.</param>
        public void Setup(string GlobalConfigFilename = "", string TableFilename = "", string RomName = "")
        {
            bool GlobalConfigLoaded = true;

            //Load the global config


            try
            {
                if (!GlobalConfigFilename.IsNullOrWhiteSpace())
                {
                    FileInfo GlobalConfigFile = new FileInfo(GlobalConfigFilename);


                    GlobalConfig = GlobalConfig.GetGlobalConfigFromConfigXmlFile(GlobalConfigFile.FullName);
                    if (GlobalConfig == null)
                    {
                        GlobalConfigLoaded = false;

                        //set new global config object if it config could not be loaded from the file.
                        GlobalConfig = new GlobalConfig();
                    }
                    GlobalConfig.GlobalConfigFilename = GlobalConfigFile.FullName;
                }
                else
                {
                    GlobalConfig = new GlobalConfig();
                    GlobalConfig.GlobalConfigFilename = GlobalConfigFilename;
                }
            }
            catch (Exception E)
            {
                throw new Exception("DirectOutput framework could not initialize global config.\n Inner exception: {0}".Build(E.Message), E);
            }

            if (GlobalConfig.EnableLogging)
            {
                if (GlobalConfig.ClearLogOnSessionStart)
                {
                    try
                    {
                        FileInfo LF = new FileInfo(GlobalConfig.GetLogFilename((!TableFilename.IsNullOrWhiteSpace() ? new FileInfo(TableFilename).FullName : ""), RomName));
                        if (LF.Exists)
                        {
                            LF.Delete();
                        }
                    }
                    catch { }
                }
                try
                {
                    Log.Filename = GlobalConfig.GetLogFilename((!TableFilename.IsNullOrWhiteSpace() ? new FileInfo(TableFilename).FullName : ""), RomName);
                    Log.Init();
                }
                catch (Exception E)
                {
                    throw new Exception("DirectOutput framework could initialize the log file.\n Inner exception: {0}".Build(E.Message), E);
                }
            }


            try
            {
                if (GlobalConfigLoaded)
                {
                    Log.Write("Global config loaded from: {0}".Build(GlobalConfigFilename));
                }
                else
                {
                    if (!GlobalConfigFilename.IsNullOrWhiteSpace())
                    {
                        Log.Write("Could not find or load theGlobalConfig file {0}".Build(GlobalConfigFilename));
                    }
                    else
                    {
                        Log.Write("No GlobalConfig file loaded. Using newly instanciated GlobalConfig object instead.");
                    }
                }



                Log.Write("Loading Pinball parts");



                Log.Write("Loading cabinet");
                //Load cabinet config
                Cabinet = null;
                FileInfo CCF = GlobalConfig.GetCabinetConfigFile();
                if (CCF != null)
                {
                    if (CCF.Exists)
                    {
                        Log.Write("Will load cabinet config file: {0}".Build(CCF.FullName));
                        try
                        {
                            Cabinet = Cabinet.GetCabinetFromConfigXmlFile(CCF);

                            Log.Write("{0} output controller defnitions and {1} toy definitions loaded from cabinet config.".Build(Cabinet.OutputControllers.Count, Cabinet.Toys.Count));


                            Cabinet.CabinetConfigurationFilename = CCF.FullName;
                            if (Cabinet.AutoConfigEnabled)
                            {
                                Log.Write("Cabinet config file has AutoConfig feature enabled. Calling AutoConfig.");
                                try
                                {
                                    Cabinet.AutoConfig();
                                }
                                catch (Exception E)
                                {
                                    Log.Exception("A eception occured during cabinet auto configuration", E);
                                }
                                Log.Write("Autoconfig complete.");
                            }
                            Log.Write("Cabinet config loaded successfully from {0}".Build(CCF.FullName));
                        }
                        catch (Exception E)
                        {
                            Log.Exception("A exception occured when loading cabinet config file: {0}".Build(CCF.FullName), E);
                        }
                    }
                    else
                    {
                        Log.Warning("Cabinet config file {0} does not exist.".Build(CCF.FullName));
                    }
                }
                if (Cabinet == null)
                {
                    Log.Write("No cabinet config file loaded. Will use AutoConfig.");
                    //default to a new cabinet object if the config cant be loaded
                    Cabinet = new Cabinet();
                    Cabinet.AutoConfig();
                }

                Log.Write("Cabinet loaded");

                Log.Write("Loading table config");

                //Load table config

                Table = new DirectOutput.Table.Table();
                Table.AddLedControlConfig = true;

                if (!TableFilename.IsNullOrWhiteSpace())
                {
                    FileInfo TableFile = new FileInfo(TableFilename);
                    FileInfo TCF       = GlobalConfig.GetTableConfigFile(TableFile.FullName);
                    if (TCF != null)
                    {
                        Log.Write("Will load table config from {0}".Build(TCF.FullName));
                        try
                        {
                            Table = DirectOutput.Table.Table.GetTableFromConfigXmlFile(GlobalConfig.GetTableConfigFile(TableFile.FullName));
                            Table.TableConfigurationFilename = GlobalConfig.GetTableConfigFile(TableFile.FullName).FullName;
                            Log.Write("Table config loaded successfully from {0}".Build(TCF.FullName));
                        }
                        catch (Exception E)
                        {
                            Log.Exception("A exception occured when loading table config: {0}".Build(TCF.FullName), E);
                        }
                        if (Table.AddLedControlConfig)
                        {
                            Log.Write("Table config allows mix with ledcontrol configs.");
                        }
                    }
                    else
                    {
                        Log.Warning("No table config file found. Will try to load config from LedControl file(s).");
                    }
                }
                else
                {
                    Log.Write("No TableFilename specified, will use empty tableconfig");
                }
                if (Table.AddLedControlConfig)
                {
                    if (!RomName.IsNullOrWhiteSpace())
                    {
                        Log.Write("Will try to load configs from DirectOutput.ini or LedControl.ini file(s) for RomName {0}".Build(RomName));
                        //Load ledcontrol

                        Dictionary <int, FileInfo> LedControlIniFiles = GlobalConfig.GetIniFilesDictionary(TableFilename);


                        LedControlConfigList L = new LedControlConfigList();
                        if (LedControlIniFiles.Count > 0)
                        {
                            L.LoadLedControlFiles(LedControlIniFiles, false);
                            Log.Write("{0} directoutputconfig.ini or ledcontrol.ini files loaded.".Build(LedControlIniFiles.Count));
                        }
                        else
                        {
                            Log.Write("No directoutputconfig.ini or ledcontrol.ini files found.");
                        }

                        if (!L.ContainsConfig(RomName))
                        {
                            Log.Write("No config for table found in LedControl data for RomName {0}.".Build(RomName));
                        }
                        else
                        {
                            Log.Write("Config for RomName {0} exists in LedControl data. Updating cabinet and config.".Build(RomName));

                            DirectOutput.LedControl.Setup.Configurator C = new DirectOutput.LedControl.Setup.Configurator();
                            C.EffectMinDurationMs    = GlobalConfig.LedControlMinimumEffectDurationMs;
                            C.EffectRGBMinDurationMs = GlobalConfig.LedControlMinimumRGBEffectDurationMs;
                            C.Setup(L, Table, Cabinet, RomName);
                            C = null;
                            //                        L.UpdateTableConfig(Table, RomName, Cabinet);

                            //Check DOF Version
                            Version DOFVersion = typeof(Pinball).Assembly.GetName().Version;

                            if (L.Any(LC => LC.MinDOFVersion != null && LC.MinDOFVersion.CompareTo(DOFVersion) > 0))
                            {
                                Version MaxVersion = null;
                                foreach (LedControlConfig LC in L)
                                {
                                    if (LC.MinDOFVersion != null && (MaxVersion == null || MaxVersion.CompareTo(LC.MinDOFVersion) > 0))
                                    {
                                        MaxVersion = LC.MinDOFVersion;
                                    }
                                }


                                Log.Warning("UPDATE DIRECT OUTPUT FRAMEWORK!");
                                if (MaxVersion != null)
                                {
                                    Log.Warning("Current DOF version is {0}, but DOF version {1} or later is required by one or several config files.".Build(DOFVersion, MaxVersion));
                                }
                                try
                                {
                                    Process.Start(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "UpdateNotification.exe"));
                                }
                                catch (Exception E)
                                {
                                    Log.Exception("A exception occured when displaying the update notification", E);
                                }
                            }
                        }
                        L = null;
                    }
                    else
                    {
                        Log.Write("Cant load config from directoutput.ini or ledcontrol.ini file(s) since no RomName was supplied. No ledcontrol config will be loaded.");
                    }
                }
                if (Table.TableName.IsNullOrWhiteSpace())
                {
                    if (!TableFilename.IsNullOrWhiteSpace())
                    {
                        Table.TableName = Path.GetFileNameWithoutExtension(new FileInfo(TableFilename).FullName);
                    }
                    else if (!RomName.IsNullOrWhiteSpace())
                    {
                        Table.TableName = RomName;
                    }
                }
                if (!TableFilename.IsNullOrWhiteSpace())
                {
                    Table.TableFilename = new FileInfo(TableFilename).FullName;
                }
                if (!RomName.IsNullOrWhiteSpace())
                {
                    Table.RomName = RomName;
                }
                Log.Write("Table config loading finished: romname=" + RomName + ", tablename=" + Table.TableName);


                //update table overrider with romname and tablename references, and activate valid overrides
                TableOverrideSettings.Instance.activeromName   = RomName;
                TableOverrideSettings.Instance.activetableName = Table.TableName;
                TableOverrideSettings.Instance.activateOverrides();

                Log.Write("Pinball parts loaded");
            }
            catch (Exception E)
            {
                Log.Exception("DirectOutput framework has encountered a exception during setup.", E);
                throw new Exception("DirectOutput framework has encountered a exception during setup.\n Inner exception: {0}".Build(E.Message), E);
            }
        }
示例#3
0
        /// <summary>
        /// Configures and initializes/starts and configures the Pinball object
        /// </summary>
        /// <param name="GlobalConfigFilename">The global config filename.</param>
        /// <param name="TableFilename">The table filename.</param>
        /// <param name="RomName">Name of the rom.</param>
        public void Init(string GlobalConfigFilename = "", string TableFilename = "", string RomName = "")
        {
            bool GlobalConfigLoaded = true;

            //Load the global config


            try
            {
                if (!GlobalConfigFilename.IsNullOrWhiteSpace())
                {
                    FileInfo GlobalConfigFile = new FileInfo(GlobalConfigFilename);


                    GlobalConfig = GlobalConfig.GetGlobalConfigFromConfigXmlFile(GlobalConfigFile.FullName);
                    if (GlobalConfig == null)
                    {
                        GlobalConfigLoaded = false;

                        //set new global config object if it config could not be loaded from the file.
                        GlobalConfig = new GlobalConfig();
                    }
                    GlobalConfig.GlobalConfigFilename = GlobalConfigFile.FullName;
                }
                else
                {
                    GlobalConfig = new GlobalConfig();
                    GlobalConfig.GlobalConfigFilename = GlobalConfigFilename;
                }
            }
            catch (Exception E)
            {
                throw new Exception("DirectOutput framework could initialize global config.\n Inner exception: {0}".Build(E.Message), E);
            }

            if (GlobalConfig.EnableLogging)
            {
                try
                {
                    Log.Filename = GlobalConfig.GetLogFilename((!TableFilename.IsNullOrWhiteSpace() ? new FileInfo(TableFilename).FullName : ""), RomName);
                    Log.Init();
                }
                catch (Exception E)
                {
                    throw new Exception("DirectOutput framework could initialize the log file.\n Inner exception: {0}".Build(E.Message), E);
                }
            }


            try
            {
                if (GlobalConfigLoaded)
                {
                    Log.Write("Global config loaded from: {0}".Build(GlobalConfigFilename));
                }
                else
                {
                    if (!GlobalConfigFilename.IsNullOrWhiteSpace())
                    {
                        Log.Write("Could not find or load theGlobalConfig file {0}".Build(GlobalConfigFilename));
                    }
                    else
                    {
                        Log.Write("No GlobalConfig file loaded. Using newly instanciated GlobalConfig object instead.");
                    }
                }



                Log.Write("Loading Pinball parts");



                //Load global script files
                Log.Write("Loading script files");
                Scripts.LoadAndAddScripts(GlobalConfig.GetGlobalScriptFiles());



                //Load table script files
                if (!TableFilename.IsNullOrWhiteSpace())
                {
                    Scripts.LoadAndAddScripts(GlobalConfig.GetTableScriptFiles(new FileInfo(TableFilename).FullName));
                }
                Log.Write("Script files loaded");


                Log.Write("Loading cabinet");
                //Load cabinet config
                Cabinet = null;
                FileInfo CCF = GlobalConfig.GetCabinetConfigFile();
                if (CCF != null)
                {
                    Log.Write("Will load cabinet config file: {0}".Build(CCF.FullName));
                    try
                    {
                        Cabinet = Cabinet.GetCabinetFromConfigXmlFile(CCF);
                        Cabinet.CabinetConfigurationFilename = CCF.FullName;
                        if (Cabinet.AutoConfigEnabled)
                        {
                            Log.Write("Cabinet config file has AutoConfig feature enable. Calling AutoConfig.");
                            Cabinet.AutoConfig();
                        }
                        Log.Write("Cabinet config loaded successfully from {0}".Build(CCF.FullName));
                    }
                    catch (Exception E)
                    {
                        Log.Exception("A exception occured when load cabinet config file: {0}".Build(CCF.FullName), E);
                    }
                }
                if (Cabinet == null)
                {
                    Log.Write("No cabinet config file loaded. Will use AutoConfig.");
                    //default to a new cabinet object if the config cant be loaded
                    Cabinet = new Cabinet();
                    Cabinet.AutoConfig();
                }

                Log.Write("Cabinet loaded");

                Log.Write("Loading table config");

                //Load table config

                Table = new DirectOutput.Table.Table();
                Table.AddLedControlConfig = true;

                if (!TableFilename.IsNullOrWhiteSpace())
                {
                    FileInfo TableFile = new FileInfo(TableFilename);
                    FileInfo TCF       = GlobalConfig.GetTableConfigFile(TableFile.FullName);
                    if (TCF != null)
                    {
                        Log.Write("Will load table config from {0}".Build(TCF.FullName));
                        try
                        {
                            Table = DirectOutput.Table.Table.GetTableFromConfigXmlFile(GlobalConfig.GetTableConfigFile(TableFile.FullName));
                            Table.TableConfigurationFilename = GlobalConfig.GetTableConfigFile(TableFile.FullName).FullName;
                            Log.Write("Table config loaded successfully from {0}".Build(TCF.FullName));
                        }
                        catch (Exception E)
                        {
                            Log.Exception("A exception occured when loading table config: {0}".Build(TCF.FullName), E);
                        }
                        if (Table.AddLedControlConfig)
                        {
                            Log.Write("Table config allows mix with ledcontrol configs.");
                        }
                    }
                    else
                    {
                        Log.Warning("No table config file found. Will try to load config from LedControl file(s).");
                    }
                }
                else
                {
                    Log.Write("No TableFilename specified, will use empty tableconfig");
                }
                if (Table.AddLedControlConfig)
                {
                    if (!RomName.IsNullOrWhiteSpace())
                    {
                        Log.Write("Will try to load configs from DirectOutput.ini or LedControl.ini file(s) for RomName {0}".Build(RomName));
                        //Load ledcontrol
                        LedControlConfigList L = new LedControlConfigList();
                        if (GlobalConfig.LedControlIniFiles.Count > 0)
                        {
                            Log.Write("Will try to load table config from LedControl  file(s) specified in global config.");
                            L.LoadLedControlFiles(GlobalConfig.LedControlIniFiles, false);
                        }
                        else
                        {
                            bool          FoundIt     = false;
                            List <string> LookupPaths = new List <string>();
                            if (!TableFilename.IsNullOrWhiteSpace())
                            {
                                if (new FileInfo(TableFilename).Directory.Exists)
                                {
                                    LookupPaths.Add(new FileInfo(TableFilename).Directory.FullName);
                                }
                            }
                            LookupPaths.AddRange(new string[] { GlobalConfig.GetGlobalConfigDirectory().FullName, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) });

                            LedControlIniFileList LedControlIniFiles = new LedControlIniFileList();

                            string[] LedControlFilenames = { "directoutputconfig", "ledcontrol" };

                            foreach (string LedControlFilename in LedControlFilenames)
                            {
                                foreach (string P in LookupPaths)
                                {
                                    DirectoryInfo DI = new DirectoryInfo(P);

                                    List <FileInfo> Files = new List <FileInfo>();
                                    foreach (FileInfo FI in DI.EnumerateFiles())
                                    {
                                        if (FI.Name.ToLower().StartsWith(LedControlFilename.ToLower()) && FI.Name.ToLower().EndsWith(".ini"))
                                        {
                                            Files.Add(FI);
                                        }
                                    }


                                    foreach (FileInfo FI in Files)
                                    {
                                        if (string.Equals(FI.Name, "{0}.ini".Build(LedControlFilename), StringComparison.OrdinalIgnoreCase))
                                        {
                                            LedControlIniFiles.Add(FI.FullName, 1);
                                            FoundIt = true;
                                        }
                                        else
                                        {
                                            string F = FI.Name.Substring(LedControlFilename.Length, FI.Name.Length - LedControlFilename.Length - 4);
                                            if (F.IsInteger())
                                            {
                                                int LedWizNr = -1;
                                                if (int.TryParse(F, out LedWizNr))
                                                {
                                                    if (!LedControlIniFiles.Contains(LedWizNr))
                                                    {
                                                        LedControlIniFiles.Add(FI.FullName, LedWizNr);
                                                        FoundIt = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    ;
                                    if (FoundIt)
                                    {
                                        break;
                                    }
                                }
                                if (FoundIt)
                                {
                                    break;
                                }
                            }



                            if (FoundIt)
                            {
                                L.LoadLedControlFiles(LedControlIniFiles, false);
                                Log.Write("{0} directoutput.ini or ledcontrol.ini files loaded.".Build(LedControlIniFiles.Count));
                            }
                            else
                            {
                                Log.Write("No directoutput.ini or ledcontrol.ini files found. No directoutput.ini or ledcontrol.ini configs will be loaded.");
                            }
                        }
                        if (!L.ContainsConfig(RomName))
                        {
                            Log.Write("No config for table found in LedControl data for RomName {0}.".Build(RomName));
                        }
                        else
                        {
                            Log.Write("Config for RomName {0} exists in LedControl data. Updating cabinet and config.".Build(RomName));

                            DirectOutput.LedControl.Setup.Configurator C = new DirectOutput.LedControl.Setup.Configurator();
                            C.EffectMinDurationMs    = GlobalConfig.LedControlMinimumEffectDurationMs;
                            C.EffectRGBMinDurationMs = GlobalConfig.LedControlMinimumRGBEffectDurationMs;
                            C.Setup(L, Table, Cabinet, RomName);
                            C = null;
                            //                        L.UpdateTableConfig(Table, RomName, Cabinet);
                        }
                        L = null;
                    }
                    else
                    {
                        Log.Write("Cant load config from directoutput.ini or ledcontrol.ini file(s) since no RomName was supplied. No ledcontrol config will be loaded.");
                    }
                }
                if (Table.TableName.IsNullOrWhiteSpace())
                {
                    if (!TableFilename.IsNullOrWhiteSpace())
                    {
                        Table.TableName = Path.GetFileNameWithoutExtension(new FileInfo(TableFilename).FullName);
                    }
                    else if (!RomName.IsNullOrWhiteSpace())
                    {
                        Table.TableName = RomName;
                    }
                }
                if (!TableFilename.IsNullOrWhiteSpace())
                {
                    Table.TableFilename = new FileInfo(TableFilename).FullName;
                }
                if (!RomName.IsNullOrWhiteSpace())
                {
                    Table.RomName = RomName;
                }
                Log.Write("Table config loading finished");



                Log.Write("Pinball parts loaded");

                Log.Write("Starting processes");
                InitStatistics();
                Cabinet.Init(this);
                Table.Init(this);
                Alarms.Init(this);
                Table.TriggerStaticEffects();
                Cabinet.Update();

                //Add the thread initializing the framework to the threadinfo list
                ThreadInfo TI = new ThreadInfo(Thread.CurrentThread);
                TI.HeartBeatTimeOutMs = 10000;
                TI.HostName           = "External caller";
                TI.HeartBeat();
                ThreadInfoList.Add(TI);



                InitMainThread();
                Log.Write("Framework initialized.");
                Log.Write("Have fun! :)");
            }
            catch (Exception E)
            {
                Log.Exception("A eception occured during initialization", E);
                throw new Exception("DirectOutput framework has encountered a exception during initialization.\n Inner exception: {0}".Build(E.Message), E);
            }
        }