Пример #1
0
        /*----------Functions----------*/
        //STATIC

        /// <summary>
        /// Save the supplied settings object to the specified path
        /// </summary>
        /// <param name="path">The path that defines where the data should be stored</param>
        /// <param name="settings">The settings values that should be saved to disk</param>
        /// <returns>Returns true if the settings where saved to the supplied path</returns>
        public static bool SaveData(string path, GeneratorSettings settings)
        {
            //Ensure that the directory exists
            Directory.CreateDirectory(Path.GetDirectoryName(path));

            //Try to write the data to disk
            try {
                //Create an output stream for the data
                using (FileStream stream = new FileStream(path, FileMode.Create)) {
                    using (BinaryWriter writer = new BinaryWriter(stream)) {
                        writer.Write(settings.boundarySequence);
                        writer.Write(settings.fillSequence);
                        writer.Write(settings.verticalBoundarySize);
                        writer.Write(settings.horizontalBoundarySize);
                        writer.Write(settings.verticalBufferSize);
                        writer.Write(settings.horizontalBufferSize);
                        writer.Write(settings.sectionBufferSize);
                        writer.Write(settings.useFixedWidth);
                        writer.Write(settings.fixedSize);
                    }
                }
                return(true);
            }

            //If anything goes wrong, assume failure
            catch (Exception exec) {
                Console.WriteLine($"ERROR: Failed to save the settings to the location '{path}'. {exec.Message}");
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Load the settings from the supplied path
        /// </summary>
        /// <param name="path">The path where the data should be loaded from</param>
        /// <param name="settings">Passes out the loaded settings on success <see cref="Generator.GeneratorSettings.Default"/> on failure</param>
        /// <returns>Returns true if the settings where loaded properly from the location</returns>
        public static bool LoadData(string path, out GeneratorSettings settings)
        {
            //try to load the data from the path
            try {
                using (FileStream stream = new FileStream(path, FileMode.Open)) {
                    using (BinaryReader reader = new BinaryReader(stream)) {
                        settings.boundarySequence       = reader.ReadString();
                        settings.fillSequence           = reader.ReadString();
                        settings.verticalBoundarySize   = reader.ReadInt32();
                        settings.horizontalBoundarySize = reader.ReadInt32();
                        settings.verticalBufferSize     = reader.ReadInt32();
                        settings.horizontalBufferSize   = reader.ReadInt32();
                        settings.sectionBufferSize      = reader.ReadInt32();
                        settings.useFixedWidth          = reader.ReadBoolean();
                        settings.fixedSize = reader.ReadInt32();
                    }
                }
                return(true);
            }

            //If the file couldn't be found, silent failure
            catch (FileNotFoundException) {
                settings = Default;
                return(false);
            }

            //If anything goes wrong, assume failure
            catch (Exception exec) {
                Console.WriteLine($"ERROR: Failed to load the settings from the location '{path}'. {exec.Message}");
                settings = Default;
                return(false);
            }
        }
        public bool SaveProfile(string profileName)
        {
            //Attempt to save the current settings under the supplied name
            string path = GetProfilePath(profileName);

            //Try to write the settings to the data path
            return(GeneratorSettings.SaveData(path, GetCurrentSettings()));
        }
 /// <summary>
 /// Apply the supplied settings object to this generator
 /// </summary>
 /// <param name="settings">The collection of settings that should be applied</param>
 public void ApplySettings(GeneratorSettings settings)
 {
     BoundarySequence       = settings.boundarySequence;
     FillSequence           = settings.fillSequence;
     VerticalBoundarySize   = settings.verticalBoundarySize;
     HorizontalBoundarySize = settings.horizontalBoundarySize;
     VerticalBufferSize     = settings.verticalBufferSize;
     HorizontalBufferSize   = settings.horizontalBufferSize;
     SectionBufferSize      = settings.sectionBufferSize;
     UseFixedWidth          = settings.useFixedWidth;
     FixedSize = settings.fixedSize;
 }
        public bool LoadProfile(string profileName)
        {
            //Get the path that would be used for the profile
            string path = GetProfilePath(profileName);

            //Try to load the information from supplied path
            GeneratorSettings settings;

            if (!GeneratorSettings.LoadData(path, out settings))
            {
                Console.WriteLine($"Unable to load the profile '{profileName}'");
                return(false);
            }

            //Apply the loaded settings
            ApplySettings(settings);
            return(true);
        }
 /// <summary>
 /// Initialise this heading generator object with the supplied settings
 /// </summary>
 /// <param name="settings">The starting settings that should be assigned to this generator</param>
 public HeadingGenerator(GeneratorSettings settings)
 {
     ApplySettings(settings);
 }
 /// <summary>
 /// Initialise this object with specified settings
 /// </summary>
 /// <param name="profileStorageLocation">The location on the device where the profile options are stored</param>
 /// <param name="settings">The default settings that this generator should be initialised with</param>
 public ProfiledHeadingGenerator(string profileStorageLocation, GeneratorSettings settings) : base(settings)
 {
     this.profileStorageLocation = profileStorageLocation;
 }