Exemple #1
0
 void ReleaseMMChunkFile(MMChunkFile mmchunkFile)
 {
     if (mmchunkFile.Release() == 0)
     {
         mmchunkFile.Dispose();
         _mmChunkFiles.ReturnObject(mmchunkFile);
     }
 }
Exemple #2
0
    public Streaming.IMMappedChunkData MMapChunkData(Streaming.IChunk chunk)
    {
        ChunkFile_t chunkFile;

        if (_chunkFiles.TryGetValue(chunk.chunkPos, out chunkFile))
        {
            if ((_chunkRead != null) && (_chunkRead.modifyCount < _modifyCount))
            {
                ReleaseMMChunkFile(_chunkRead);
                _chunkRead = null;
            }

            if (_chunkRead == null)
            {
                _chunkRead = _mmChunkFiles.GetObject();
                try {
                    _chunkRead.Open(_chunkFilePath);
                    _chunkRead.modifyCount = _modifyCount;
                } catch (Exception e) {
                    _chunkRead.Release();
                    _chunkRead.Dispose();
                    _mmChunkFiles.ReturnObject(_chunkRead);
                    _chunkRead = null;
                    throw e;
                }
            }

            if ((chunkFile.ofs + chunkFile.size) > _chunkRead.fileSize)
            {
                _chunkFiles.Remove(chunk.chunkPos);
                return(null);
            }

            var io = _mmChunkIO.GetObject();
            io.worldFile = this;
            io.chunkFile = _chunkRead;
            io.flags     = (EChunkFlags)chunkFile.flags;
            io.len       = (int)chunkFile.size;

            unsafe {
                io.ptr = _chunkRead.ptr + chunkFile.ofs;
            }

            _chunkRead.AddRef();
            return(io);
        }
        return(null);
    }
Exemple #3
0
    void OpenChunkFile(string path)
    {
        _chunkFilePath = path + ".cdf";
        _chunkRead     = _mmChunkFiles.GetObject();
        _chunkRead.Open(_chunkFilePath);

        try {
            var writeFile = File.Open(_chunkFilePath, FileMode.Open, FileAccess.Write, FileShare.ReadWrite);

            _chunkWrite = new BinaryWriter(writeFile);
            _chunkWrite.BaseStream.Position = _chunkWrite.BaseStream.Length;
        } catch (Exception e) {
            _chunkRead.Release();
            _chunkRead.Dispose();
            _mmChunkFiles.ReturnObject(_chunkRead);
            _chunkRead = null;
            throw e;
        }
    }