コード例 #1
0
        /// <summary>
        /// Create the replay file for Replay mod to read
        /// </summary>
        /// <param name="replayFileName">Replay file name</param>
        public void CreateReplayFile(string replayFileName)
        {
            WriteLog("Creating replay file.");

            MetaData.duration = Convert.ToInt32((lastPacketTime - recordStartTime).TotalMilliseconds);
            MetaData.SaveToFile();

            using (Stream recordingFile = new FileStream(Path.Combine(temporaryCache, recordingTmpFileName), FileMode.Open))
            {
                using (Stream metaDataFile = new FileStream(Path.Combine(temporaryCache, MetaData.MetaDataFileName), FileMode.Open))
                {
                    using (ZipOutputStream zs = new ZipOutputStream(Path.Combine(ReplayFileDirectory, replayFileName)))
                    {
                        zs.PutNextEntry(recordingTmpFileName);
                        recordingFile.CopyTo(zs);
                        zs.PutNextEntry(MetaData.MetaDataFileName);
                        metaDataFile.CopyTo(zs);
                        zs.Close();
                    }
                }
            }

            File.Delete(Path.Combine(temporaryCache, recordingTmpFileName));
            File.Delete(Path.Combine(temporaryCache, MetaData.MetaDataFileName));

            WriteLog("Replay file created.");
        }
コード例 #2
0
 /// <summary>
 /// Stop recording and save replay file. Should called once before program exit
 /// </summary>
 public void OnShutDown()
 {
     if (!cleanedUp)
     {
         MetaData.duration = Convert.ToInt32((lastPacketTime - recordStartTime).TotalMilliseconds);
         MetaData.SaveToFile();
         CloseRecordStream();
         CreateReplayFile();
         cleanedUp = true;
     }
 }
コード例 #3
0
        private void Initialize(int protocolVersion)
        {
            this.dataTypes       = new DataTypes(protocolVersion);
            this.packetType      = new PacketTypeHandler().GetTypeHandler(protocolVersion);
            this.protocolVersion = protocolVersion;

            if (!Directory.Exists(ReplayFileDirectory))
            {
                Directory.CreateDirectory(ReplayFileDirectory);
            }
            if (!Directory.Exists(temporaryCache))
            {
                Directory.CreateDirectory(temporaryCache);
            }

            recordStream    = new BinaryWriter(new FileStream(Path.Combine(temporaryCache, recordingTmpFileName), FileMode.Create, FileAccess.ReadWrite));
            recordStartTime = DateTime.Now;

            MetaData           = new MetaDataHandler();
            MetaData.date      = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds;
            MetaData.protocol  = protocolVersion;
            MetaData.mcversion = ProtocolHandler.ProtocolVersion2MCVer(protocolVersion);
            MetaData.SaveToFile();

            playerLastPosition = new Location(0, 0, 0);
            WriteLog("Start recording.");
        }