EtherDuels.Config.Configuration.Save C# (CSharp) Method

Save() public method

Saves the current Configuration to a file.
public Save ( ) : void
return void
        public void Save()
        {
            if (this.path == null)
            {
                throw new Exception("0010 Path not set for saving configuration.");
            }

            try
            {
                if (File.Exists(this.path))
                {
                    stream = File.Open(this.path, FileMode.Truncate);
                }
                else
                {
                    stream = File.Open(this.path, FileMode.Create);
                }
            }
            catch (FileNotFoundException e)
            {
                throw new Exception("0020 File couldn't be found / opened while saving configuration.\n" + e.ToString());
            }
            catch (UnauthorizedAccessException e)
            {
                throw new Exception("0030 Lacking permission to create / write " + this.path.ToString() + " file.\n" + e.ToString());
            }

            if (binaryFormatter == null)
            {
                binaryFormatter = new BinaryFormatter();
            }

            binaryFormatter.Serialize(stream, this);
            stream.Close();
        }