public static MyStorageBase LoadFromFile(string absoluteFilePath, Dictionary<byte, byte> modifiers = null) { //get hash code MyVoxelObjectDefinition definition = new MyVoxelObjectDefinition(absoluteFilePath, modifiers); int sh = definition.GetHashCode(); MyStorageBase result = null; if (UseStorageCache) { result = m_storageCache.Read(sh); if (result != null) { result.Shared = true; return result; } } const string loadingMessage = "Loading voxel storage from file '{0}'"; if (!MyFileSystem.FileExists(absoluteFilePath)) { var oldPath = Path.ChangeExtension(absoluteFilePath, "vox"); MySandboxGame.Log.WriteLine(string.Format(loadingMessage, oldPath)); if (!MyFileSystem.FileExists(oldPath)) { //Debug.Fail("Voxel map could not be loaded! " + absoluteFilePath); return null; } UpdateFileFormat(oldPath); } else { MySandboxGame.Log.WriteLine(string.Format(loadingMessage, absoluteFilePath)); } Debug.Assert(absoluteFilePath.EndsWith(MyVoxelConstants.FILE_EXTENSION)); byte[] compressedData = null; using (var file = MyFileSystem.OpenRead(absoluteFilePath)) { compressedData = new byte[file.Length]; file.Read(compressedData, 0, compressedData.Length); } result = Load(compressedData); //change materials if (definition.Changes != null) result.ChangeMaterials(definition.Changes); if (UseStorageCache) { m_storageCache.Write(sh, result); result.Shared = true; } else m_storageCache.Reset(); return result; }
public static MyStorageBase LoadFromFile(string absoluteFilePath, Dictionary <byte, byte> modifiers = null) { //get hash code MyVoxelObjectDefinition definition = new MyVoxelObjectDefinition(absoluteFilePath, modifiers); int sh = definition.GetHashCode(); MyStorageBase result = null; if (UseStorageCache) { result = m_storageCache.Read(sh); if (result != null) { result.Shared = true; return(result); } } const string loadingMessage = "Loading voxel storage from file '{0}'"; if (!MyFileSystem.FileExists(absoluteFilePath)) { var oldPath = Path.ChangeExtension(absoluteFilePath, "vox"); MySandboxGame.Log.WriteLine(string.Format(loadingMessage, oldPath)); if (!MyFileSystem.FileExists(oldPath)) { //Debug.Fail("Voxel map could not be loaded! " + absoluteFilePath); return(null); } UpdateFileFormat(oldPath); } else { MySandboxGame.Log.WriteLine(string.Format(loadingMessage, absoluteFilePath)); } Debug.Assert(absoluteFilePath.EndsWith(MyVoxelConstants.FILE_EXTENSION)); byte[] compressedData = null; using (var file = MyFileSystem.OpenRead(absoluteFilePath)) { compressedData = new byte[file.Length]; file.Read(compressedData, 0, compressedData.Length); } result = Load(compressedData); //change materials if (definition.Changes != null) { result.ChangeMaterials(definition.Changes); } if (UseStorageCache) { m_storageCache.Write(sh, result); result.Shared = true; } else { m_storageCache.Reset(); } return(result); }