Beispiel #1
0
        /// <summary>
        /// Read preferences from the specified file.  If the file
        /// doesn't exist, it creates a default file with factory
        /// defaults.
        /// </summary>
        /// <param name="prefFile">Name of the preferences file</param>
        /// <param name="loadDefaultsOnFail">true: If the file doesn't exist, use defaults, false: return null</param>
        /// <returns>Preferences read or null</returns>
        public static GlobalPreferences Load(String prefFile, bool loadDefaultsOnFail = true)
        {
            GlobalPreferences retVal;

            saveFactoryDefaultSettings();

            retVal = XmlUtils.XmlFileLoad <GlobalPreferences>(prefFile);

            if (retVal == null)
            {
                Log.Debug("Could not load global preferences from " + prefFile + ". Creating a new one");
                if (loadDefaultsOnFail)
                {
                    retVal = new GlobalPreferences();
                }
                else
                {
                    return(retVal);
                }
            }

            if (!XmlUtils.XmlFileSave <GlobalPreferences>(retVal, prefFile))
            {
                Log.Error("Unable to save global preferences!");
                retVal = null;
            }

            return(retVal);
        }
Beispiel #2
0
        /// <summary>
        /// Saves preferenes to the specified file
        /// </summary>
        /// <param name="prefs">preferences to save</param>
        /// <param name="preferencesFile">full path to the file</param>
        /// <returns>true on success</returns>
        public static bool Save(GlobalPreferences prefs, String preferencesFile)
        {
            // save current settings into current file and preset file
            var retVal = XmlUtils.XmlFileSave <GlobalPreferences>(prefs, preferencesFile);

            if (retVal == false)
            {
                Log.Error("Error saving preferences! file=" + preferencesFile);
            }

            return(retVal);
        }
Beispiel #3
0
        /// <summary>
        /// Saves preferenes to the specified file
        /// </summary>
        /// <param name="prefs">preferences to save</param>
        /// <param name="preferencesFile">full path to the file</param>
        /// <returns>true on success</returns>
        public static bool Save(GlobalPreferences prefs, String preferencesFile)
        {
            // save current settings into current file and preset file
            var retVal = XmlUtils.XmlFileSave<GlobalPreferences>(prefs, preferencesFile);

            if (retVal == false)
            {
                Log.Error("Error saving preferences! file=" + preferencesFile);
            }

            return retVal;
        }
Beispiel #4
0
        /// <summary>
        /// Read preferences from the specified file.  If the file
        /// doesn't exist, it creates a default file with factory
        /// defaults.
        /// </summary>
        /// <param name="prefFile">Name of the preferences file</param>
        /// <param name="loadDefaultsOnFail">true: If the file doesn't exist, use defaults, false: return null</param>
        /// <returns>Preferences read or null</returns>
        public static GlobalPreferences Load(String prefFile, bool loadDefaultsOnFail = true)
        {
            saveFactoryDefaultSettings();

            var retVal = XmlUtils.XmlFileLoad<GlobalPreferences>(prefFile);

            if (retVal == null)
            {
                Log.Debug("Could not load global preferences from " + prefFile + ". Creating a new one");
                if (loadDefaultsOnFail)
                {
                    retVal = new GlobalPreferences();
                }
                else
                {
                    return retVal;
                }
            }

            if (!XmlUtils.XmlFileSave<GlobalPreferences>(retVal, prefFile))
            {
                Log.Error("Unable to save global preferences!");
                retVal = null;
            }

            return retVal;
        }