/// <summary> Checks if the backing file exists on disc, and if not, creates it. /// Also recreates the backing file if dimensions on disc are less than those in memory. </summary> BlockDBFile ValidateBackingFile() { Vec3U16 fileDims; BlockDBFile format = BlockDBFile.V1; if (!File.Exists(FilePath)) { using (Stream s = OpenWrite()) { fileDims = Dims; BlockDBFile.WriteHeader(s, fileDims); } } else { using (Stream s = OpenRead()) { format = BlockDBFile.ReadHeader(s, out fileDims); } if (fileDims.X < Dims.X || fileDims.Y < Dims.Y || fileDims.Z < Dims.Z) { BlockDBFile.ResizeBackingFile(this); } } return(format); }
/// <summary> Checks if the backing file exists on disc, and if not, creates it. /// Also recreates the backing file if dimensions on disc are less than those in memory. </summary> void ValidateBackingFile() { Vec3U16 fileDims; if (!File.Exists(FilePath)) { using (Stream s = File.OpenWrite(FilePath)) { fileDims = Dims; BlockDBFile.WriteHeader(s, fileDims); } } else { using (Stream s = File.OpenRead(FilePath)) { BlockDBFile.ReadHeader(s, out fileDims); } if (fileDims.X < Dims.X || fileDims.Y < Dims.Y || fileDims.Z < Dims.Z) { BlockDBFile.ResizeBackingFile(this); } } }
object DumpRow(IDataRecord record, object arg) { if (errorOccurred) { return(arg); } try { if (stream == null) { stream = File.Create(BlockDBFile.DumpPath(mapName)); string lvlPath = LevelInfo.MapPath(mapName); dims = IMapImporter.Formats[0].ReadDimensions(lvlPath); BlockDBFile.WriteHeader(stream, dims); } // Only log maps which have a used BlockDB to avoid spam entriesWritten++; if (entriesWritten == 10) { string progress = " (" + DBUpgrader.Progress + ")"; Logger.Log(LogType.SystemActivity, "Dumping BlockDB for " + mapName + progress); } UpdateBlock(record); UpdateCoords(record); UpdatePlayerID(record); UpdateTimestamp(record); buffer.Add(entry); WriteBuffer(false); } catch (Exception ex) { Logger.LogError(ex); errorOccurred = true; } return(arg); }