Exemple #1
0
        private static void UpdateFileFormat(string originalVoxFile)
        {
            var newFile = Path.ChangeExtension(originalVoxFile, MyVoxelConstants.FILE_EXTENSION);

            if (!File.Exists(originalVoxFile))
            {
                MySandboxGame.Log.WriteLine(string.Format("ERROR: Voxel file '{0}' does not exists!", originalVoxFile));
            }
            if (Path.GetExtension(originalVoxFile) != "vox")
            {
                MySandboxGame.Log.WriteLine(string.Format("ERROR: Unexpected voxel file extensions in path: '{0}'", originalVoxFile));
            }

            using (var decompressFile = new MyCompressionFileLoad(originalVoxFile))
                using (var file = MyFileSystem.OpenWrite(newFile))
                    using (var gzip = new GZipStream(file, CompressionMode.Compress))
                        using (var buffer = new BufferedStream(gzip))
                        {
                            buffer.WriteNoAlloc(m_attributesByType[typeof(MyCellStorage)].SerializedTypeName);

                            // File version. New format will store it in 7bit encoded int right after the name of storage.
                            buffer.Write7BitEncodedInt(decompressFile.GetInt32());

                            // All remaining data is unchanged. Just copy it to new file.
                            byte[] tmp       = new byte[0x4000];
                            int    bytesRead = decompressFile.GetBytes(tmp.Length, tmp);
                            while (bytesRead != 0)
                            {
                                buffer.Write(tmp, 0, bytesRead);
                                bytesRead = decompressFile.GetBytes(tmp.Length, tmp);
                            }
                        }
        }
Exemple #2
0
        private static void UpdateFileFormat(string originalVoxFile)
        {
            var newFile = Path.ChangeExtension(originalVoxFile, MyVoxelConstants.FILE_EXTENSION);

            if (!File.Exists(originalVoxFile))
            {
                MySandboxGame.Log.Error("Voxel file '{0}' does not exist!", originalVoxFile);
                return;
            }

            if (Path.GetExtension(originalVoxFile) != ".vox")
            {
                MySandboxGame.Log.Warning("Unexpected voxel file extensions in path: '{0}'", originalVoxFile);
            }

            try
            {
                using (var decompressFile = new MyCompressionFileLoad(originalVoxFile))
                    using (var file = MyFileSystem.OpenWrite(newFile))
                        using (var gzip = new GZipStream(file, CompressionMode.Compress))
                            using (var buffer = new BufferedStream(gzip))
                            {
                                buffer.WriteNoAlloc(STORAGE_TYPE_NAME_CELL);

                                // File version. New format will store it in 7bit encoded int right after the name of storage.
                                buffer.Write7BitEncodedInt(decompressFile.GetInt32());

                                // All remaining data is unchanged. Just copy it to new file.
                                byte[] tmp       = new byte[0x4000];
                                int    bytesRead = decompressFile.GetBytes(tmp.Length, tmp);
                                while (bytesRead != 0)
                                {
                                    buffer.Write(tmp, 0, bytesRead);
                                    bytesRead = decompressFile.GetBytes(tmp.Length, tmp);
                                }
                            }
            }
            catch (Exception e)
            {
                MySandboxGame.Log.Error("While updating voxel storage '{0}' to new format: {1}", originalVoxFile, e.Message);
            }
        }