Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IniWriter"/> class.
 /// </summary>
 /// <param name="fileName">Name of the file to write to.</param>
 /// <param name="properties">Encoding properties.</param>
 public IniWriter(string fileName, IniProperties properties)
 {
     Properties = properties.Valid ? properties : IniProperties.Default;
     FileName   = fileName ?? throw new ArgumentNullException(nameof(fileName));
     if (File.Exists(fileName))
     {
         Load(IniReader.FromFile(fileName));
     }
     else
     {
         using (var f = File.Open(fileName, FileMode.OpenOrCreate))
         {
         }
     }
 }
Ejemplo n.º 2
0
        internal static string Escape(string value, IniProperties properties)
        {
            var box = value.IndexOfAny(new[] { properties.BoxCharacter, '#', ' ' }) > -1;

            if (!properties.DisableEscaping)
            {
                value = value.EscapeUtf8();
            }

            box |= value.IndexOf('\\') > -1 || value.Trim() != value;
            if (box)
            {
                value = value.Box(properties.BoxCharacter);
            }
            return(value);
        }
Ejemplo n.º 3
0
        internal static string Unescape(string value, IniProperties properties)
        {
            if (value.IsBoxed(properties.BoxCharacter, properties.BoxCharacter))
            {
                value = value.Unbox(properties.BoxCharacter);
            }

            if (!properties.DisableEscaping)
            {
                try
                {
                    value = value.Unescape();
                }
                catch
                {
                    // unescape failed, this may be a windows path
                }
            }

            return(value);
        }
Ejemplo n.º 4
0
 /// <summary>Creates an new initialization writer by parsing the specified data.</summary>
 /// <param name="name">The name.</param>
 /// <param name="data">Content to parse.</param>
 /// <param name="properties">The data properties.</param>
 /// <returns>Returns a new <see cref="IniWriter"/> instance.</returns>
 public static IniWriter Parse(string name, byte[] data, IniProperties properties = default) => Parse(name, Encoding.UTF8.GetString(data), properties);
Ejemplo n.º 5
0
 /// <summary>Creates an new initialization writer by parsing the specified data.</summary>
 /// <param name="name">The (file)name.</param>
 /// <param name="data">Content to parse.</param>
 /// <param name="properties">The data properties.</param>
 /// <returns>Returns a new <see cref="IniWriter"/> instance.</returns>
 public static IniWriter Parse(string name, string data, IniProperties properties = default) => new IniWriter(IniReader.Parse(name, data, properties));
Ejemplo n.º 6
0
        /// <summary>Creates an new initialization writer with the specified preexisting content.</summary>
        /// <param name="name">The name.</param>
        /// <param name="stream">The stream to read.</param>
        /// <param name="count">Number of bytes to read.</param>
        /// <param name="properties">The content properties.</param>
        /// <returns>Returns a new <see cref="IniWriter"/> instance.</returns>
        public static IniWriter FromStream(string name, Stream stream, int count, IniProperties properties = default)
        {
            var data = stream.ReadBlock(count);

            return(Parse(name, data, properties));
        }
Ejemplo n.º 7
0
 /// <summary>Creates an new initialization writer with the specified preexisting content.</summary>
 /// <param name="fileName">File name to read.</param>
 /// <param name="properties">The content properties.</param>
 /// <returns>Returns a new <see cref="IniWriter"/> instance.</returns>
 public static IniWriter FromFile(string fileName, IniProperties properties = default) => File.Exists(fileName) ? Parse(fileName, File.ReadAllBytes(fileName), properties) : new IniWriter(fileName, properties);