Beispiel #1
0
        public ReplayFilesManager()
        {
            butter = new ButterFile(compressionFormat: SparkSettings.instance.butterCompressionFormat);

            Split();

            Program.NewFrame += AddButterFrame;
            // Program.NewFrame += AddMilkFrame;
            Program.FrameFetched += AddEchoreplayFrame;

            Program.JoinedGame += frame =>
            {
                lock (fileWritingLock)
                {
                    fileName = DateTime.Now.ToString(fileNameFormat);
                }
            };
            Program.LeftGame += frame =>
            {
                Task.Run(async() =>
                {
                    await Task.Delay(100);
                    Split();
                });
            };
            Program.RoundOver    += (_, _) => { Split(); };
            Program.SparkClosing += () =>
            {
                Task.Run(Split);
            };
        }
Beispiel #2
0
        /// <summary>
        /// Part of the process for reading the file
        /// </summary>
        /// <param name="replayFilePath">The full filepath of the replay file</param>
        /// <param name="processFrames"></param>
        public async Task <ReplayFile> LoadFileAsync(string replayFilePath = "", bool processFrames = false)
        {
            if (string.IsNullOrEmpty(replayFilePath))
            {
                return(null);
            }

            Logger.LogRow(Logger.LogType.Info, "Reading file: " + replayFilePath);



            if (replayFilePath.EndsWith(".butter"))
            {
                List <Frame> butterFile = ButterFile.FromBytes(await File.ReadAllBytesAsync(replayFilePath));
                return(new ReplayFile
                {
                    filename = replayFilePath,
                    nframes = butterFile.Count,
                    frames = butterFile
                });
            }
            else
            {
                StreamReader reader = new StreamReader(replayFilePath);

                Thread loadThread = new Thread(() => ReadReplayFile(reader, replayFilePath));
                loadThread.Start();
                while (loadThread.IsAlive)
                {
                    // maybe put a progress bar here
                    await Task.Delay(10);
                }

                //if (processFrames)
                //{
                //	Thread processTemporalDataThread = new Thread(() => ProcessAllTemporalData(loadedDemo));
                //	processTemporalDataThread.Start();
                //}

                return(replayFile);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Generates a new filename from the current time.
        /// </summary>
        public void Split()
        {
            WriteOutEchoreplayFile();

            lock (butterWritingLock)
            {
                WriteOutButterFile();
                butter = new ButterFile(compressionFormat: SparkSettings.instance.butterCompressionFormat);
            }


            lock (fileWritingLock)
            {
                string lastFilename = fileName;
                fileName = DateTime.Now.ToString(fileNameFormat);

                // compress the file
                if (SparkSettings.instance.useCompression)
                {
                    if (File.Exists(Path.Combine(SparkSettings.instance.saveFolder, lastFilename + ".echoreplay")))
                    {
                        zipping = true;
                        string tempDir = Path.Combine(SparkSettings.instance.saveFolder, "temp_zip");
                        Directory.CreateDirectory(tempDir);
                        File.Move(
                            Path.Combine(SparkSettings.instance.saveFolder, lastFilename + ".echoreplay"),
                            Path.Combine(SparkSettings.instance.saveFolder, "temp_zip", lastFilename + ".echoreplay")
                            );
                        ZipFile.CreateFromDirectory(tempDir, Path.Combine(SparkSettings.instance.saveFolder, lastFilename + ".echoreplay"));
                        Directory.Delete(tempDir, true);
                        zipping = false;
                    }
                }
            }


            // reset the replay buffer
            replayBufferTimestamps.Clear();
            replayBufferJSON.Clear();
            replayBufferJSONBones.Clear();
        }