예제 #1
0
        protected override void Save(UndoCache buffer, string path)
        {
            using (FileStream fs = File.Create(path)) {
                BinaryWriter  w          = new BinaryWriter(fs);
                long          entriesPos = 0;
                ChunkHeader   last       = default(ChunkHeader);
                UndoCacheNode node       = buffer.Head;

                while (node != null)
                {
                    List <UndoCacheItem> items = node.Items;
                    for (int i = 0; i < items.Count; i++)
                    {
                        UndoCacheItem uP       = items[i];
                        DateTime      time     = node.BaseTime.AddSeconds(uP.TimeDelta);
                        int           timeDiff = (int)(time - last.BaseTime).TotalSeconds;
                        if (last.LevelName != node.MapName || timeDiff > (65535 >> 2) || last.Entries == ushort.MaxValue)
                        {
                            WriteChunkEntries(w, last.Entries, entriesPos);
                            last = WriteEmptyChunk(w, node, time, ref entriesPos);
                        }

                        int flags = (uP.Flags & 0xC000) | timeDiff;
                        w.Write((ushort)flags); w.Write(uP.Index);
                        w.Write(uP.Type); w.Write(uP.NewType);
                        last.Entries++;
                    }
                    if (last.Entries > 0)
                    {
                        WriteChunkEntries(w, last.Entries, entriesPos);
                    }
                    node = node.Next;
                }
            }
        }
예제 #2
0
        /// <summary> Saves the undo data for the given player to disc. </summary>
        /// <remarks> Clears the player's in-memory undo buffer on success. </remarks>
        public static void SaveUndo(Player p)
        {
            if (p == null || p.UndoBuffer.Count < 1)
            {
                return;
            }

            CreateDefaultDirectories();
            if (Directory.GetDirectories(undoDir).Length >= Server.totalUndo)
            {
                Directory.Delete(prevUndoDir, true);
                Directory.Move(undoDir, prevUndoDir);
                Directory.CreateDirectory(undoDir);
            }

            string playerDir = Path.Combine(undoDir, p.name.ToLower());

            if (!Directory.Exists(playerDir))
            {
                Directory.CreateDirectory(playerDir);
            }

            int    numFiles = Directory.GetFiles(playerDir).Length;
            string path     = Path.Combine(playerDir, numFiles + NewFormat.Ext);

            UndoCache cache = p.UndoBuffer;

            using (IDisposable locker = cache.ClearLock.AccquireReadLock()) {
                NewFormat.Save(cache, path);
            }

            using (IDisposable locker = cache.ClearLock.AccquireWriteLock()) {
                lock (cache.AddLock)
                    cache.Clear();
            }
        }
예제 #3
0
 protected override void Save(UndoCache buffer, string path)
 {
     throw new NotSupportedException("UndoFileOnline is read only.");
 }
예제 #4
0
 public UndoFormatOnline(UndoCache cache)
 {
     this.cache = cache;
 }
예제 #5
0
 protected override void Save(UndoCache buffer, string path)
 {
     throw new NotSupportedException("Non-optimised binary undo files have been deprecated");
 }
예제 #6
0
 protected abstract void Save(UndoCache buffer, string path);