// This moves the snapshot from memory to harddisk
        internal void WriteToFile()
        {
            lock (this)
            {
                if (isdisposed)
                {
                    return;
                }
                if (isondisk)
                {
                    return;
                }
                isondisk = true;

                // Compress data
                recstream.Seek(0, SeekOrigin.Begin);
                MemoryStream outstream = SharpCompressHelper.CompressStream(recstream); //mxd

                // Make temporary file
                filename = General.MakeTempFilename(General.Map.TempPath, "snapshot");

                // Write data to file
                File.WriteAllBytes(filename, outstream.ToArray());

                // Remove data from memory
                recstream.Dispose();
                recstream = null;
                outstream.Dispose();
            }
        }
示例#2
0
        // This makes a prefab of the selection. Returns null when cancelled.
        private static MemoryStream MakePrefab()
        {
            // Let the plugins know
            if (General.Plugins.OnCopyBegin())
            {
                // Ask the editing mode to prepare selection for copying.
                // The edit mode should mark all vertices, lines and sectors
                // that need to be copied.
                if (General.Editing.Mode.OnCopyBegin())
                {
                    // Copy the marked geometry
                    // This links sidedefs that are not linked to a marked sector to a virtual sector
                    MapSet copyset = General.Map.Map.CloneMarked();

                    // Convert flags and activations to UDMF fields, if needed
                    if (!(General.Map.FormatInterface is UniversalMapSetIO))
                    {
                        copyset.TranslateToUDMF(General.Map.FormatInterface.GetType());
                    }

                    // Write data to stream
                    MemoryStream          memstream = new MemoryStream();
                    UniversalStreamWriter writer    = new UniversalStreamWriter();
                    writer.RememberCustomTypes = false;
                    writer.Write(copyset, memstream, null);

                    // Compress the stream
                    memstream.Seek(0, SeekOrigin.Begin);
                    MemoryStream compressed = SharpCompressHelper.CompressStream(memstream);                    //mxd

                    // Done
                    memstream.Dispose();
                    General.Editing.Mode.OnCopyEnd();
                    General.Plugins.OnCopyEnd();
                    return(compressed);
                }
            }

            // Aborted
            return(null);
        }