/// <summary>
        /// loads configfile and prepares it with all needed lists
        /// </summary>
        /// <returns></returns>
        public static WeldingConfiguration loadConfig()
        {
            WeldingConfiguration configuration = new WeldingConfiguration();
            ModuleLists          moduleList    = new ModuleLists();
            FileStream           FileStream;

            if (System.IO.File.Exists(_configFile))
            {
                XmlSerializer configSerializer = new XmlSerializer(typeof(WeldingConfiguration));
                configSerializer.UnknownNode      += new XmlNodeEventHandler(serializer_UnknownNode);
                configSerializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute);
                FileStream    = new FileStream(_configFile, FileMode.Open);
                configuration = (WeldingConfiguration)configSerializer.Deserialize(FileStream);
                FileStream.Close();

                if (configuration.MainWindowXPosition > (Screen.width - Constants.guiScreenEdgeClearance))
                {
                    configuration.MainWindowXPosition = Screen.width - Constants.guiScreenEdgeClearance;
                }
                if (configuration.MainWindowYPosition > (Screen.height - Constants.guiScreenEdgeClearance))
                {
                    configuration.MainWindowYPosition = Screen.height - Constants.guiScreenEdgeClearance;
                }
                FileStream.Close();
            }

            if (System.IO.File.Exists(_moduleListFile))
            {
                XmlSerializer moduleListSerializer = new XmlSerializer(typeof(ModuleLists));
                moduleListSerializer.UnknownNode      += new XmlNodeEventHandler(serializer_UnknownNode);
                moduleListSerializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute);
                FileStream = new FileStream(_moduleListFile, FileMode.Open);
                moduleList = (ModuleLists)moduleListSerializer.Deserialize(FileStream);
                FileStream.Close();

                configuration.vector2CurveModules       = WeldingHelpers.convertFromToStringArray(moduleList.vector2CurveModules);
                configuration.vector4CurveModules       = WeldingHelpers.convertFromToStringArray(moduleList.vector4CurveModules);
                configuration.subModules                = WeldingHelpers.convertFromToStringArray(moduleList.subModules);
                configuration.modulesToIgnore           = WeldingHelpers.convertFromToStringArray(moduleList.modulesToIgnore);
                configuration.averagedModuleAttributes  = WeldingHelpers.convertFromToStringArray(moduleList.averagedModuleAttributes);
                configuration.unchangedModuleAttributes = WeldingHelpers.convertFromToStringArray(moduleList.unchangedModuleAttributes);
                configuration.breakingModuleAttributes  = WeldingHelpers.convertFromToStringArray(moduleList.breakingModuleAttributes);
                FileStream.Close();
            }
            else
            {
                configuration.vector2CurveModules       = Constants.basicVector2CurveModules;
                configuration.vector4CurveModules       = Constants.basicVector4CurveModules;
                configuration.subModules                = Constants.basicSubModules;
                configuration.modulesToIgnore           = Constants.basicModulesToIgnore;
                configuration.averagedModuleAttributes  = Constants.basicAveragedModuleAttributes;
                configuration.unchangedModuleAttributes = Constants.basicUnchangedModuleAttributes;
                configuration.breakingModuleAttributes  = Constants.basicBreakingModuleAttributes;
            }
            Debug.Log(string.Format("{0} Config was loaded", Constants.logPrefix));
            return(configuration);
        }
Exemple #2
0
        /// <summary>
        /// loads configfile and prepares it with all needed lists
        /// </summary>
        /// <returns></returns>
        public static WeldingConfiguration loadConfig()
        {
            WeldingConfiguration configuration = new WeldingConfiguration();
            ModuleLists          moduleList    = new ModuleLists();
            FileStream           FileStream    = null;

            try {
                XmlSerializer configSerializer = new XmlSerializer(typeof(WeldingConfiguration));
                configSerializer.UnknownNode      += new XmlNodeEventHandler(serializer_UnknownNode);
                configSerializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute);
                FileStream    = new FileStream(CONFIG_FULLPATHNAME, FileMode.Open);
                configuration = (WeldingConfiguration)configSerializer.Deserialize(FileStream);

                if (configuration.MainWindowXPosition > (Screen.width - Constants.guiScreenEdgeClearance))
                {
                    configuration.MainWindowXPosition = Screen.width - Constants.guiScreenEdgeClearance;
                }
                if (configuration.MainWindowYPosition > (Screen.height - Constants.guiScreenEdgeClearance))
                {
                    configuration.MainWindowYPosition = Screen.height - Constants.guiScreenEdgeClearance;
                }
            } catch (Exception e) {
                configuration = new WeldingConfiguration();
                Log.warn(String.Format("{0} : {1}", CONFIG_FULLPATHNAME, e.Message));
            } finally {
                if (null != FileStream)
                {
                    FileStream.Close();
                }
                FileStream = null;
            }

            try {
                XmlSerializer moduleListSerializer = new XmlSerializer(typeof(ModuleLists));
                moduleListSerializer.UnknownNode      += new XmlNodeEventHandler(serializer_UnknownNode);
                moduleListSerializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute);
                FileStream = new FileStream(MODULELIST_FULLPATHNAME, FileMode.Open);
                moduleList = (ModuleLists)moduleListSerializer.Deserialize(FileStream);

                configuration.vector2CurveModules = moduleList.vector2CurveModules != null?WeldingHelpers.convertFromToStringArray(moduleList.vector2CurveModules) : new string[0];

                configuration.vector4CurveModules = moduleList.vector4CurveModules != null?WeldingHelpers.convertFromToStringArray(moduleList.vector4CurveModules) : new string[0];

                configuration.subModules = moduleList.subModules != null?WeldingHelpers.convertFromToStringArray(moduleList.subModules) : new string[0];

                configuration.modulesToIgnore = moduleList.modulesToIgnore != null?WeldingHelpers.convertFromToStringArray(moduleList.modulesToIgnore) : new string[0];

                configuration.modulesToMultiply = moduleList.modulesToMultiply != null?WeldingHelpers.convertFromToStringArray(moduleList.modulesToMultiply) : new string[0];

                configuration.maximizedModuleAttributes = moduleList.maximizedModuleAttributes != null?WeldingHelpers.convertFromToStringArray(moduleList.maximizedModuleAttributes) : new string[0];

                configuration.minimizedModuleAttributes = moduleList.minimizedModuleAttributes != null?WeldingHelpers.convertFromToStringArray(moduleList.minimizedModuleAttributes) : new string[0];

                configuration.averagedModuleAttributes = moduleList.averagedModuleAttributes != null?WeldingHelpers.convertFromToStringArray(moduleList.averagedModuleAttributes) : new string[0];

                configuration.unchangedModuleAttributes = moduleList.unchangedModuleAttributes != null?WeldingHelpers.convertFromToStringArray(moduleList.unchangedModuleAttributes) : new string[0];

                configuration.breakingModuleAttributes = moduleList.breakingModuleAttributes != null?WeldingHelpers.convertFromToStringArray(moduleList.breakingModuleAttributes) : new string[0];
            } catch (Exception e) {
                configuration.vector2CurveModules       = Constants.basicVector2CurveModules;
                configuration.vector4CurveModules       = Constants.basicVector4CurveModules;
                configuration.subModules                = Constants.basicSubModules;
                configuration.modulesToIgnore           = Constants.basicModulesToIgnore;
                configuration.modulesToMultiply         = Constants.basicModulesToMultiply;
                configuration.maximizedModuleAttributes = Constants.basicMaximizedModuleAttributes;
                configuration.minimizedModuleAttributes = Constants.basicMinimizedModuleAttributes;
                configuration.averagedModuleAttributes  = Constants.basicAveragedModuleAttributes;
                configuration.unchangedModuleAttributes = Constants.basicUnchangedModuleAttributes;
                configuration.breakingModuleAttributes  = Constants.basicBreakingModuleAttributes;
                Log.warn(String.Format("{0} : {1}", CONFIG_FULLPATHNAME, e.Message));
            } finally {
                if (null != FileStream)
                {
                    FileStream.Close();
                }
                FileStream = null;
            }

            Log.dbg("Config was loaded");
            return(configuration);
        }