/// <summary> /// Loads a <see cref="Universe"/> from a compressed XML file (map file). /// </summary> /// <param name="path">The file to load from.</param> /// <returns>The loaded <see cref="Universe"/>.</returns> /// <exception cref="IOException">A problem occurred while reading the file.</exception> /// <exception cref="UnauthorizedAccessException">Read access to the file is not permitted.</exception> /// <exception cref="InvalidOperationException">A problem occurred while deserializing the XML data.</exception> public static Universe Load(string path) { // Load the core data but without terrain data yet (that is delay-loaded) var universe = XmlStorage.LoadXmlZip <Universe>(path); universe.SourceFile = path; return(universe); }
public void TestIncorrectPassword() { var tempStream = new MemoryStream(); var testData = new TestData { Data = "Hello" }; testData.SaveXmlZip(tempStream, "Correct password"); tempStream.Seek(0, SeekOrigin.Begin); Assert.Throws <ZipException>(() => XmlStorage.LoadXmlZip <TestData>(tempStream, password: "******")); }
/// <summary> /// Loads a <see cref="Universe"/> from the game content source via the <see cref="ContentManager"/>. /// </summary> /// <param name="id">The ID of the <see cref="Universe"/> to load.</param> /// <returns>The loaded <see cref="Universe"/>.</returns> public static Universe FromContent(string id) { Log.Info("Loading map: " + id); using (var stream = ContentManager.GetFileStream("World/Maps", id)) { var universe = XmlStorage.LoadXmlZip <Universe>(stream); universe.SourceFile = id; return(universe); } }
public void TestZipPassword() { // Write and read file var testData1 = new TestData { Data = "Hello" }; var tempStream = new MemoryStream(); testData1.SaveXmlZip(tempStream, "Test password"); tempStream.Seek(0, SeekOrigin.Begin); var testData2 = XmlStorage.LoadXmlZip <TestData>(tempStream, password: "******"); // Ensure data stayed the same testData2.Data.Should().Be(testData1.Data); }
/// <summary> /// Loads a <see cref="Session"/> from a encrypted XML file (savegame). /// </summary> /// <param name="path">The file to load from.</param> /// <returns>The loaded <see cref="Session"/>.</returns> /// <exception cref="IOException">A problem occurred while reading the file.</exception> /// <exception cref="UnauthorizedAccessException">Read access to the file is not permitted.</exception> /// <exception cref="InvalidOperationException">A problem occurred while deserializing the XML data.</exception> public static Session Load(string path) { // Load the file Session session; try { session = XmlStorage.LoadXmlZip <Session>(path, EncryptionKey); } #region Error handling catch (ZipException ex) { throw new IOException(ex.Message, ex); } #endregion // Restore the orginal map filename session.Universe.SourceFile = session.MapSourceFile; return(session); }
/// <summary> /// Performs the deferred loading of <see cref="Terrain"/> data. /// </summary> private void LoadTerrainData() { // Load the data using (var stream = ContentManager.GetFileStream("World/Maps", SourceFile)) { XmlStorage.LoadXmlZip <Universe>(stream, additionalFiles: new[] { // Callbacks for loading terrain data new EmbeddedFile("height.png", TerrainSerialize.LoadHeightMap), new EmbeddedFile("texture.png", TerrainSerialize.LoadTextureMap), new EmbeddedFile("occlusion.png", TerrainSerialize.LoadOcclusionIntervalMap) }); } if (!TerrainSerialize.DataLoaded) { throw new InvalidOperationException(Resources.TerrainDataNotLoaded); } using (new TimedLogEvent("Initialize pathfinding")) InitializePathfinding(); }