Exemplo n.º 1
0
        public override FArchive CreateFileWriter(string filename, EFileWrite writeFlags = EFileWrite.None, IOutputDevice error = null)
        {
            if (filename == null)
            {
                throw new ArgumentNullException("filename");
            }
            FileStream fs = null;

            var fileInfo = new FileInfo(filename);

            if (fileInfo.Exists)
            {
                if (writeFlags.IsFlagSet(EFileWrite.NoReplaceExisting))
                {
                    throw new FileLoadException("Can't replace existing file: " + filename);
                }

                if (fileInfo.IsReadOnly)
                {
                    if (writeFlags.IsFlagSet(EFileWrite.ReadOnly))
                    {
                        fileInfo.IsReadOnly = false;
                    }
                    else
                    {
                        throw new FileLoadException("Can't write to read only file: " + filename);
                    }
                }

                if (writeFlags.IsFlagSet(EFileWrite.Append))
                {
                    fs = new FileStream(filename, FileMode.Append, FileAccess.Write, FileShare.Read);
                }
                else
                {
                    fs = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Read);
                }
            }
            else
            {
                fs = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Read);
            }
            return(new FBinaryStreamWriter(fs, error));
        }
Exemplo n.º 2
0
 public abstract FArchive CreateFileWriter(string filename, EFileWrite writeFlags = EFileWrite.None, IOutputDevice error = null);