// 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 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); }