// This loads the snapshot from harddisk into memory
        internal void RestoreFromFile()
        {
            lock (this)
            {
                if (isdisposed)
                {
                    return;
                }
                if (!isondisk)
                {
                    return;
                }
                isondisk = false;

                // Read the file data
                MemoryStream instream = new MemoryStream(File.ReadAllBytes(filename));

                // Decompress data
                MemoryStream outstream = SharpCompressHelper.DecompressStream(instream); //mxd
                recstream = new MemoryStream(outstream.ToArray());

                // Clean up
                instream.Dispose();
                File.Delete(filename);
                filename = null;
            }
        }
        // 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();
            }
        }
示例#3
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);
        }
示例#4
0
        // This pastes a prefab. Returns false when paste was cancelled.
        private static void PastePrefab(Stream filedata, PasteOptions options)
        {
            // Create undo
            General.MainWindow.DisplayStatus(StatusType.Action, "Inserted prefab.");
            General.Map.UndoRedo.CreateUndo("Insert prefab");

            // Decompress stream
            MemoryStream memstream;             //mxd

            try
            {
                memstream = SharpCompressHelper.DecompressStream(filedata);                 //mxd
                memstream.Seek(0, SeekOrigin.Begin);
            }
            catch (Exception e)
            {
                General.ErrorLogger.Add(ErrorType.Error, e.GetType().Name + " while reading prefab from file: " + e.Message);
                General.WriteLogLine(e.StackTrace);
                General.ShowErrorMessage("Unable to load prefab. See log file for error details.", MessageBoxButtons.OK);
                return;
            }

            // Mark all current geometry
            General.Map.Map.ClearAllMarks(true);

            // Read data stream
            UniversalStreamReader reader = new UniversalStreamReader(General.Map.FormatInterface.UIFields);             //mxd

            reader.StrictChecking = false;
            General.Map.Map.BeginAddRemove();

            //mxd. UniversalStreamReader can now throw errors
            try
            {
                reader.Read(General.Map.Map, memstream);
            }
            catch (Exception e)
            {
                General.ErrorLogger.Add(ErrorType.Error, "Unable to load prefab. " + e.GetType().Name + ": " + e.Message);
                General.ShowErrorMessage("Unable to load prefab." + Environment.NewLine + Environment.NewLine + e.Message, MessageBoxButtons.OK);
                return;
            }
            finally
            {
                General.Map.Map.EndAddRemove();
            }

            // The new geometry is not marked, so invert the marks to get it marked
            General.Map.Map.InvertAllMarks();

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

            // Modify tags and actions if preferred
            if (options.ChangeTags == PasteOptions.TAGS_REMOVE)
            {
                Tools.RemoveMarkedTags();
            }
            if (options.ChangeTags == PasteOptions.TAGS_RENUMBER)
            {
                Tools.RenumberMarkedTags();
            }
            if (options.RemoveActions)
            {
                Tools.RemoveMarkedActions();
            }

            // Done
            memstream.Dispose();
            General.Map.Map.UpdateConfiguration();
            General.Map.ThingsFilter.Update();
            General.Editing.Mode.OnPasteEnd(options);
            General.Plugins.OnPasteEnd(options);
        }