public static T Deserialize <T>(Stream stream, ProgressChangedEventHandler callback) { if (stream == null) { throw new ArgumentNullException("stream"); } using (ReadProgressStream cs = new ReadProgressStream(stream)) { cs.ProgressChanged += callback; const int defaultBufferSize = 4096; int onePercentSize = (int)Math.Ceiling(stream.Length / 100.0); using (BufferedStream bs = new BufferedStream(cs, onePercentSize > defaultBufferSize ? defaultBufferSize : onePercentSize)) { XmlSerializer reader = new XmlSerializer(typeof(T)); return((T)reader.Deserialize(bs)); } } }
/// <summary> /// On load /// </summary> protected override void OnCreateControl() { // Call base load base.OnCreateControl(); // If game maker loading, return if (_gameMaker) { return; } // Read the room in var reader = new ReadProgressStream(new FileStream(_path, FileMode.Open)); _gmareProject = ContainerStream.Deserialize <GMareRoom>(reader, reader_ProgressChanged); // Close the form tmrClose.Interval = 500; tmrClose.Start(); }