Example #1
0
        /// <summary>
        /// Loads the config for the Welding or prepares default values and generates a new config
        /// </summary>
        private void initConfig()
        {
            D.PluginConfiguration oldConfig = D.PluginConfiguration.CreateFor(Constants.settingXmlOldConfigFileName);
            bool oldConfigFound             = oldConfig.exists();

            if (oldConfigFound)
            {
                oldConfig = D.PluginConfiguration.CreateFor();
                oldConfig.load();
                oldConfig.delete();
                Log.dbg("old configfile found and deleted");
            }

            _config = FileManager.loadConfig();
            _config.dataBaseAutoReload = oldConfigFound ? oldConfig.GetValue <bool>(Constants.settingDbAutoReload) : _config.dataBaseAutoReload;
            _config.allowCareerMode    = oldConfigFound ? oldConfig.GetValue <bool>(Constants.settingAllowCareer) : _config.allowCareerMode;

            Welder.includeAllNodes          = oldConfigFound ? oldConfig.GetValue <bool>(Constants.settingAllNodes) : _config.includeAllNodes;
            Welder.dontProcessMasslessParts = oldConfigFound ? oldConfig.GetValue <bool>(Constants.settingDontProcessMasslessParts) : _config.dontProcessMasslessParts;

            Welder.StrengthCalcMethod = oldConfigFound ? StrengthParamsCalcMethod.ArithmeticMean : _config.StrengthCalcMethod;
            Welder.MaxTempCalcMethod  = oldConfigFound ? MaxTempCalcMethod.ArithmeticMean : _config.MaxTempCalcMethod;
            Welder.runInTestMode      = oldConfigFound ? false : _config.runInTestMode;
            Welder.precisionDigits    = oldConfigFound ? 6 : _config.precisionDigits;
            Welder.fileSimplification = oldConfigFound ? false : _config.fileSimplification;
        }
Example #2
0
 /// <summary>
 /// saves the config file and the modulelist file so that it is possible to change them without the need to recompile
 /// </summary>
 /// <param name="configToSave"></param>
 public static void saveConfig(WeldingConfiguration configToSave)
 {
     try {
         saveConfig(configToSave, Constants.settingXmlConfigFileName, Constants.settingXmlListFileName);
     } catch (Exception e) {
         Log.warn(e.Message);
         saveConfig(configToSave, Constants.settingXmlConfigFileName, Constants.settingXmlListFileName);
     }
 }
Example #3
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;

            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);
        }
Example #4
0
 /// <summary>
 /// saves the config file and the modulelist file so that it is possible to change them without the need to recompile
 /// </summary>
 /// <param name="configToSave"></param>
 public static void saveConfig(WeldingConfiguration configToSave)
 {
     try {
         saveConfig(configToSave, CONFIG_FULLPATHNAME, MODULELIST_FULLPATHNAME);
     } catch (Exception e) {
         Log.warn(e.Message);
         checkPathnameAvailability(CONFIG_FULLPATHNAME);
         checkPathnameAvailability(MODULELIST_FULLPATHNAME);
         saveConfig(configToSave, CONFIG_FULLPATHNAME, MODULELIST_FULLPATHNAME);
     }
 }
Example #5
0
        private static void saveConfig(WeldingConfiguration configToSave, String configFullPathName, String moduleFullPathName)
        {
            WeldingConfiguration configuration = (WeldingConfiguration)configToSave.clone();
            ModuleLists          moduleList    = new ModuleLists();
            TextWriter           fileStreamWriter;

            if (configuration == null)
            {
                configuration = new WeldingConfiguration();
            }
            configuration.vector2CurveModules       = null;
            configuration.vector4CurveModules       = null;
            configuration.subModules                = null;
            configuration.modulesToIgnore           = null;
            configuration.modulesToMultiply         = null;
            configuration.maximizedModuleAttributes = null;
            configuration.minimizedModuleAttributes = null;
            configuration.averagedModuleAttributes  = null;
            configuration.unchangedModuleAttributes = null;
            configuration.breakingModuleAttributes  = null;

            XmlSerializer configSerializer = new XmlSerializer(typeof(WeldingConfiguration));

            fileStreamWriter = new StreamWriter(configFullPathName);
            configSerializer.Serialize(fileStreamWriter, configuration);
            fileStreamWriter.Close();

            //ModuleList from the constants or the actual config, depending on length of the array, in case user did add some entries
            moduleList.vector2CurveModules       = WeldingHelpers.convertStringFromToArray(configToSave.vector2CurveModules != null && (configToSave.vector2CurveModules.Length > Constants.basicVector2CurveModules.Length) ? configToSave.vector2CurveModules : Constants.basicVector2CurveModules);
            moduleList.vector4CurveModules       = WeldingHelpers.convertStringFromToArray(configToSave.vector4CurveModules != null && (configToSave.vector4CurveModules.Length > Constants.basicVector4CurveModules.Length) ? configToSave.vector4CurveModules : Constants.basicVector4CurveModules);
            moduleList.subModules                = WeldingHelpers.convertStringFromToArray(configToSave.subModules != null && (configToSave.subModules.Length > Constants.basicSubModules.Length) ? configToSave.subModules : Constants.basicSubModules);
            moduleList.modulesToIgnore           = WeldingHelpers.convertStringFromToArray(configToSave.modulesToIgnore != null && (configToSave.modulesToIgnore.Length > Constants.basicModulesToIgnore.Length) ? configToSave.modulesToIgnore : Constants.basicModulesToIgnore);
            moduleList.modulesToMultiply         = WeldingHelpers.convertStringFromToArray(configToSave.modulesToMultiply != null && (configToSave.modulesToMultiply.Length > Constants.basicModulesToMultiply.Length) ? configToSave.modulesToMultiply : Constants.basicModulesToMultiply);
            moduleList.maximizedModuleAttributes = WeldingHelpers.convertStringFromToArray(configToSave.maximizedModuleAttributes != null && (configToSave.maximizedModuleAttributes.Length > Constants.basicMaximizedModuleAttributes.Length) ? configToSave.maximizedModuleAttributes : Constants.basicMaximizedModuleAttributes);
            moduleList.minimizedModuleAttributes = WeldingHelpers.convertStringFromToArray(configToSave.minimizedModuleAttributes != null && (configToSave.minimizedModuleAttributes.Length > Constants.basicMinimizedModuleAttributes.Length) ? configToSave.minimizedModuleAttributes : Constants.basicMinimizedModuleAttributes);
            moduleList.averagedModuleAttributes  = WeldingHelpers.convertStringFromToArray(configToSave.averagedModuleAttributes != null && (configToSave.averagedModuleAttributes.Length > Constants.basicAveragedModuleAttributes.Length) ? configToSave.averagedModuleAttributes : Constants.basicAveragedModuleAttributes);
            moduleList.unchangedModuleAttributes = WeldingHelpers.convertStringFromToArray(configToSave.unchangedModuleAttributes != null && (configToSave.unchangedModuleAttributes.Length > Constants.basicUnchangedModuleAttributes.Length) ? configToSave.unchangedModuleAttributes : Constants.basicUnchangedModuleAttributes);
            moduleList.breakingModuleAttributes  = WeldingHelpers.convertStringFromToArray(configToSave.breakingModuleAttributes != null && (configToSave.breakingModuleAttributes.Length > Constants.basicBreakingModuleAttributes.Length) ? configToSave.breakingModuleAttributes : Constants.basicBreakingModuleAttributes);

            XmlSerializer moduleListSerializer = new XmlSerializer(typeof(ModuleLists));

            fileStreamWriter = new StreamWriter(moduleFullPathName);
            moduleListSerializer.Serialize(fileStreamWriter, moduleList);

            fileStreamWriter.WriteLine("");
            foreach (string s in comments)
            {
                fileStreamWriter.WriteLine(s);
            }
            fileStreamWriter.Close();
            Log.dbg("Config was saved");
        }
Example #6
0
        /// <summary>
        /// saves the config file and the modulelist file so that it is possible to change them without the need to recompile
        /// </summary>
        /// <param name="configToSave"></param>
        public static void saveConfig(WeldingConfiguration configToSave)
        {
            WeldingConfiguration configuration = (WeldingConfiguration)configToSave.clone();
            ModuleLists          moduleList    = new ModuleLists();
            TextWriter           fileStreamWriter;

            if (configuration == null)
            {
                configuration = new WeldingConfiguration();
            }
            configuration.vector2CurveModules       = null;
            configuration.vector4CurveModules       = null;
            configuration.subModules                = null;
            configuration.modulesToIgnore           = null;
            configuration.averagedModuleAttributes  = null;
            configuration.unchangedModuleAttributes = null;
            configuration.breakingModuleAttributes  = null;

            XmlSerializer configSerializer = new XmlSerializer(typeof(WeldingConfiguration));

            fileStreamWriter = new StreamWriter(_configFile);
            configSerializer.Serialize(fileStreamWriter, configuration);
            fileStreamWriter.Close();


            //ModuleList from the constants or the actual config, depending on length of the array, in case user did add some entries
            moduleList.vector2CurveModules       = WeldingHelpers.convertStringFromToArray(configToSave.vector2CurveModules.Length > Constants.basicVector2CurveModules.Length ? configToSave.vector2CurveModules : Constants.basicVector2CurveModules);
            moduleList.vector4CurveModules       = WeldingHelpers.convertStringFromToArray(configToSave.vector4CurveModules.Length > Constants.basicVector4CurveModules.Length ? configToSave.vector4CurveModules: Constants.basicVector4CurveModules);
            moduleList.subModules                = WeldingHelpers.convertStringFromToArray(configToSave.subModules.Length > Constants.basicSubModules.Length ?configToSave.subModules: Constants.basicSubModules);
            moduleList.modulesToIgnore           = WeldingHelpers.convertStringFromToArray(configToSave.modulesToIgnore.Length > Constants.basicModulesToIgnore.Length ? configToSave.modulesToIgnore : Constants.basicModulesToIgnore);
            moduleList.averagedModuleAttributes  = WeldingHelpers.convertStringFromToArray(configToSave.averagedModuleAttributes.Length > Constants.basicAveragedModuleAttributes.Length ? configToSave.averagedModuleAttributes:Constants.basicAveragedModuleAttributes);
            moduleList.unchangedModuleAttributes = WeldingHelpers.convertStringFromToArray(configToSave.unchangedModuleAttributes.Length > Constants.basicUnchangedModuleAttributes.Length ? configToSave.unchangedModuleAttributes: Constants.basicUnchangedModuleAttributes);
            moduleList.breakingModuleAttributes  = WeldingHelpers.convertStringFromToArray(configToSave.breakingModuleAttributes.Length > Constants.basicBreakingModuleAttributes.Length ? configToSave.breakingModuleAttributes : Constants.basicBreakingModuleAttributes);

            XmlSerializer moduleListSerializer = new XmlSerializer(typeof(ModuleLists));

            fileStreamWriter = new StreamWriter(_moduleListFile);
            moduleListSerializer.Serialize(fileStreamWriter, moduleList);

            fileStreamWriter.WriteLine("");
            foreach (string s in comments)
            {
                fileStreamWriter.WriteLine(s);
            }
            fileStreamWriter.Close();
            Debug.Log(string.Format("{0} Config was saved", Constants.logPrefix));
        }
        /// <summary>
        /// Loads the config for the Welding or prepares default values and generates a new config
        /// </summary>
        private void initConfig()
        {
            string xmlOldConfigFile = FileManager.FULLPATHNAME(Constants.settingXmlFilePath, Constants.settingXmlOldConfigFileName);

            KSP.IO.PluginConfiguration oldConfig = KSP.IO.PluginConfiguration.CreateForType <OldWeldingPluginConfig>();
            bool oldConfigFound = File.Exists(xmlOldConfigFile);

            if (oldConfigFound)
            {
                oldConfig = KSP.IO.PluginConfiguration.CreateForType <OldWeldingPluginConfig>();
                oldConfig.load();
                File.Delete(xmlOldConfigFile);
                Log.dbg("old configfile found and deleted");
            }

            if (!File.Exists(FileManager.CONFIG_FULLPATHNAME))
            {
                _config = new WeldingConfiguration();
                FileManager.saveConfig(_config);
                _config.vector2CurveModules       = Constants.basicVector2CurveModules;
                _config.vector4CurveModules       = Constants.basicVector4CurveModules;
                _config.subModules                = Constants.basicSubModules;
                _config.modulesToIgnore           = Constants.basicModulesToIgnore;
                _config.averagedModuleAttributes  = Constants.basicAveragedModuleAttributes;
                _config.unchangedModuleAttributes = Constants.basicUnchangedModuleAttributes;
                _config.breakingModuleAttributes  = Constants.basicBreakingModuleAttributes;
            }
            else
            {
                _config = FileManager.loadConfig();
            }

            _config.dataBaseAutoReload      = oldConfigFound ? oldConfig.GetValue <bool>(Constants.settingDbAutoReload) : _config.dataBaseAutoReload;
            _config.allowCareerMode         = oldConfigFound ? oldConfig.GetValue <bool>(Constants.settingAllowCareer) : _config.allowCareerMode;
            Welder.includeAllNodes          = oldConfigFound ? oldConfig.GetValue <bool>(Constants.settingAllNodes) : _config.includeAllNodes;
            Welder.dontProcessMasslessParts = oldConfigFound ? oldConfig.GetValue <bool>(Constants.settingDontProcessMasslessParts) : _config.dontProcessMasslessParts;

            Welder.StrengthCalcMethod = oldConfigFound ? StrengthParamsCalcMethod.ArithmeticMean : _config.StrengthCalcMethod;
            Welder.MaxTempCalcMethod  = oldConfigFound ? MaxTempCalcMethod.ArithmeticMean : _config.MaxTempCalcMethod;
            Welder.runInTestMode      = oldConfigFound ? false : _config.runInTestMode;
            Welder.precisionDigits    = oldConfigFound ? 6 : _config.precisionDigits;
            Welder.fileSimplification = oldConfigFound ? false : _config.fileSimplification;
        }
        /// <summary>
        /// Loads the config for the Welding or prepares default values and generates a new config
        /// </summary>
        private void initConfig()
        {
            KSP.IO.PluginConfiguration oldConfig = KSP.IO.PluginConfiguration.CreateForType <OldWeldingPluginConfig>();
            bool oldConfigFound = System.IO.File.Exists(string.Concat(Constants.settingRuntimeDirectory, Constants.settingXmlFilePath, Constants.settingXmlOldConfigFileName));

            if (oldConfigFound)
            {
                oldConfig = KSP.IO.PluginConfiguration.CreateForType <OldWeldingPluginConfig>();
                oldConfig.load();
                System.IO.File.Delete(string.Concat(Constants.settingRuntimeDirectory, Constants.settingXmlFilePath, Constants.settingXmlOldConfigFileName));
                Debug.Log(string.Format("{0}old configfile found and deleted", Constants.logPrefix));
            }

            if (!System.IO.File.Exists(string.Concat(Constants.settingRuntimeDirectory, Constants.settingXmlFilePath, Constants.settingXmlConfigFileName)))
            {
                _config = new WeldingConfiguration();
                FileManager.saveConfig(_config);
                _config.vector2CurveModules       = Constants.basicVector2CurveModules;
                _config.vector4CurveModules       = Constants.basicVector4CurveModules;
                _config.subModules                = Constants.basicSubModules;
                _config.modulesToIgnore           = Constants.basicModulesToIgnore;
                _config.averagedModuleAttributes  = Constants.basicAveragedModuleAttributes;
                _config.unchangedModuleAttributes = Constants.basicUnchangedModuleAttributes;
                _config.breakingModuleAttributes  = Constants.basicBreakingModuleAttributes;
            }
            else
            {
                _config = FileManager.loadConfig();
            }

            _config.dataBaseAutoReload      = oldConfigFound ? oldConfig.GetValue <bool>(Constants.settingDbAutoReload) : _config.dataBaseAutoReload;
            _config.allowCareerMode         = oldConfigFound ? oldConfig.GetValue <bool>(Constants.settingAllowCareer) : _config.allowCareerMode;
            Welder.includeAllNodes          = oldConfigFound ? oldConfig.GetValue <bool>(Constants.settingAllNodes) : _config.includeAllNodes;
            Welder.dontProcessMasslessParts = oldConfigFound ? oldConfig.GetValue <bool>(Constants.settingDontProcessMasslessParts) : _config.dontProcessMasslessParts;

            Welder.StrengthCalcMethod = oldConfigFound ? StrengthParamsCalcMethod.ArithmeticMean : _config.StrengthCalcMethod;
            Welder.MaxTempCalcMethod  = oldConfigFound ? MaxTempCalcMethod.ArithmeticMean : _config.MaxTempCalcMethod;
            Welder.runInTestMode      = oldConfigFound ? false : _config.runInTestMode;
            Welder.precisionDigits    = oldConfigFound ? 6 : _config.precisionDigits;
        }
Example #9
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);
        }
        /*
         * Main window
         */
        private void HandleMainWindow(int windowID)
        {
            GUIStyle _settingsToggleGroupStyle = new GUIStyle(GUI.skin.toggle);

            _settingsToggleGroupStyle.margin.left += 40;

            //save Window Position
            _config.MainWindowXPosition = (int)_editorMainWindow.xMin;
            _config.MainWindowYPosition = (int)_editorMainWindow.yMin;

            GUILayout.BeginVertical();
            GUILayout.EndVertical();
            GUILayout.BeginVertical();

            if (GUILayout.Button(Constants.guiSettingsGUIContent, GUILayout.MaxWidth(160)))
            {
                _mainWindowsSettingsMode = !_mainWindowsSettingsMode;
            }
            //Settings
            if (_mainWindowsSettingsMode)
            {
                _editorMainWindow.height         = Constants.guiMainWindowHSettingsExpanded;
                _settingsScrollPosition          = GUILayout.BeginScrollView(_settingsScrollPosition);
                _config.includeAllNodes          = GUILayout.Toggle(_config.includeAllNodes, Constants.guiAllNodesGUIContent);
                Welder.includeAllNodes           = _config.includeAllNodes;
                _config.dontProcessMasslessParts = GUILayout.Toggle(_config.dontProcessMasslessParts, Constants.guiDontProcessMasslessPartsGUIContent);
                Welder.dontProcessMasslessParts  = _config.dontProcessMasslessParts;
                _config.dataBaseAutoReload       = GUILayout.Toggle(_config.dataBaseAutoReload, Constants.guiDbAutoReloadGUIContent);
                _config.useNamedCfgFile          = GUILayout.Toggle(_config.useNamedCfgFile, Constants.guiUseNamedCfgFileGUIContent);
                _config.advancedDebug            = GUILayout.Toggle(_config.advancedDebug, Constants.guiAdvancedDebugGUIContent);
                _config.clearEditor        = GUILayout.Toggle(_config.clearEditor, Constants.guiClearEditorGUIContent);
                _config.fileSimplification = GUILayout.Toggle(_config.fileSimplification, Constants.guiFileSimplificationGUIContent);
                Welder.fileSimplification  = _config.fileSimplification;
                GUILayout.Space(10.0f);
                GUILayout.Label(" Vector Precision: " + _config.precisionDigits);
                _config.precisionDigits = (int)GUILayout.HorizontalSlider(_config.precisionDigits, 1, 6);
                Welder.precisionDigits  = _config.precisionDigits;
                GUILayout.Space(10.0f);
                GUILayout.Label("Strength params calculation method");
//				_config.StrengthCalcMethod = (StrengthParamsCalcMethod)GUILayout.SelectionGrid((int)_config.StrengthCalcMethod, Constants.StrengthParamsCalcMethodsGUIContent, 1, GUILayout.MaxWidth(140));
                foreach (StrengthParamsCalcMethod method in Enum.GetValues(typeof(StrengthParamsCalcMethod)))
                {
                    if (GUILayout.Toggle((_config.StrengthCalcMethod == method), Constants.StrengthParamsCalcMethodsGUIContent[(int)method], _settingsToggleGroupStyle))
                    {
                        _config.StrengthCalcMethod = method;
                        Welder.StrengthCalcMethod  = method;
                    }
                }
                GUILayout.Space(10.0f);
                GUILayout.Label("MaxTemp calculation method");
//				_config.MaxTempCalcMethod = (MaxTempCalcMethod)GUILayout.SelectionGrid((int)_config.MaxTempCalcMethod, Constants.MaxTempCalcMethodsGUIContent, 1, GUILayout.MaxWidth(140));
                foreach (MaxTempCalcMethod method in Enum.GetValues(typeof(MaxTempCalcMethod)))
                {
                    if (GUILayout.Toggle((_config.MaxTempCalcMethod == method), Constants.MaxTempCalcMethodsGUIContent[(int)method], _settingsToggleGroupStyle))
                    {
                        _config.MaxTempCalcMethod = method;
                        Welder.MaxTempCalcMethod  = method;
                    }
                }
                GUILayout.EndScrollView();

//				GUILayout.Space(10.0f);
                if (GUILayout.Button(Constants.guiSaveSettingsButtonGUIContent, GUILayout.MaxWidth(160)))
                {
                    FileManager.saveConfig(_config);
                    _config = FileManager.loadConfig();
                }
            }
            else
            {
                _editorMainWindow.height = Constants.guiMainWindowH;
                GUILayout.Space(20.0f);
            }

            //SelectPArtbranch button
            if (GUILayout.RepeatButton(Constants.guiSelectPartGUIContent, GUILayout.MaxWidth(160)))
            {
                this.state = DisplayState.partSelection;
            }

            //Weld button
            if (GUILayout.Button(Constants.guiWeldItButtonGUIContent, GUILayout.MaxWidth(160)))
            {
                FileManager.saveConfig(_config);

                if (EditorLockManager.isEditorLocked())
                {
                    if (_selectedPartbranch == null)
                    {
                        _selectedPartbranch = EditorLogic.RootPart;
                    }
                    repositionPreWeldment(_selectedPartbranch);
                    weldPart(_selectedPartbranch);
                }
            }
            if (GUILayout.Button(Constants.guiCloseGUIContent, GUILayout.MaxWidth(160)))
            {
                closeMainwindow();
            }
            //Hints area
            GUILayout.TextArea(GUI.tooltip, GUILayout.ExpandHeight(true), GUILayout.MaxHeight(100));
            GUIStyle VersionLabelGUIStyle = new GUIStyle(GUI.skin.label);

            VersionLabelGUIStyle.fontSize = 12;
            GUILayout.Label(Constants.logVersion, VersionLabelGUIStyle);
            GUILayout.EndVertical();

            GUI.DragWindow();
        }         //private void OnMainWindow()