mirror of
https://github.com/modernuo/ModernUO
synced 2026-08-11 22:23:06 -04:00
* Adds `BeforeSerialized` for entities to handle cleanup. * Adds `Created` and `LastSerialized` fields to all entities. While this is a big bloat, this will be necessary for identifying dangling references to other invalid entities. * Changes formula for determining a valid reference to be _not null, not deleted, and reference's created date must be at or before the entities last serialized date_. * Adds versioning to idx file and serializes `Created` and `LastSerialized`. * Fixes Save Stats and also disables it by default.
70 lines
2.3 KiB
C#
70 lines
2.3 KiB
C#
/*************************************************************************
|
|
* ModernUO *
|
|
* Copyright 2019-2020 - ModernUO Development Team *
|
|
* Email: hi@modernuo.com *
|
|
* File: BufferedFileWriter.cs *
|
|
* *
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
*************************************************************************/
|
|
|
|
using System;
|
|
using System.IO;
|
|
|
|
namespace Server
|
|
{
|
|
public class BinaryFileWriter : BufferWriter, IDisposable
|
|
{
|
|
private readonly Stream _file;
|
|
private long _position;
|
|
|
|
public BinaryFileWriter(string filename, bool prefixStr) :
|
|
this(new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None), prefixStr)
|
|
{}
|
|
|
|
public BinaryFileWriter(Stream stream, bool prefixStr) : base(prefixStr)
|
|
{
|
|
_file = stream;
|
|
_position = _file.Position;
|
|
}
|
|
|
|
public override long Position => _position + Index;
|
|
|
|
protected override int BufferSize => 81920;
|
|
|
|
public override void Flush()
|
|
{
|
|
if (Index > 0)
|
|
{
|
|
_position += Index;
|
|
|
|
_file.Write(Buffer, 0, (int)Index);
|
|
Index = 0;
|
|
}
|
|
}
|
|
|
|
public override void Close()
|
|
{
|
|
if (Index > 0)
|
|
{
|
|
Flush();
|
|
}
|
|
|
|
_file.Close();
|
|
}
|
|
|
|
public override long Seek(long offset, SeekOrigin origin)
|
|
{
|
|
Flush();
|
|
|
|
return _position = _file.Seek(offset, origin);
|
|
}
|
|
|
|
public void Dispose() => Close();
|
|
}
|
|
}
|