예제 #1
0
        /// <summary>
        /// Analyze replay locally before uploading
        /// </summary>
        /// <param name="file">Replay file</param>
        public Replay Analyze(ReplayFile file)
        {
            try {
                var result      = DataParser.ParseReplay(file.Filename, false, false, false, true);
                var replay      = result.Item2;
                var parseResult = result.Item1;
                var status      = GetPreStatus(replay, parseResult);

                if (status != null)
                {
                    file.UploadStatus = status.Value;
                }

                if (parseResult != DataParser.ReplayParseResult.Success)
                {
                    return(null);
                }

                file.Fingerprint = GetFingerprint(replay);
                return(replay);
            }
            catch (Exception e) {
                _log.Warn(e, $"Error analyzing file {file}");
                return(null);
            }
        }
예제 #2
0
        /// <summary>
        /// Start uploading and watching for new replays
        /// </summary>
        public async void Start()
        {
            if (_initialized)
            {
                return;
            }
            _initialized = true;

            _uploader = new Uploader();
            _analyzer = new Analyzer();
            _monitor  = new Monitor();

            var replays = ScanReplays();

            Files.AddRange(replays);
            replays.Where(x => x.UploadStatus == UploadStatus.None).Reverse().Map(x => processingQueue.Add(x));

            _monitor.ReplayAdded += async(_, e) => {
                await EnsureFileAvailable(e.Data, 3000);

                var replay = new ReplayFile(e.Data);
                Files.Insert(0, replay);
                processingQueue.Add(replay);
            };
            _monitor.Start();

            _analyzer.MinimumBuild = await _uploader.GetMinimumBuild();

            for (int i = 0; i < MaxThreads; i++)
            {
                Task.Run(UploadLoop).Forget();
            }
        }
예제 #3
0
 /// <summary>
 /// Delete replay file
 /// </summary>
 private static void DeleteReplay(ReplayFile file)
 {
     try {
         _log.Info($"Deleting replay {file}");
         file.Deleted = true;
         File.Delete(file.Filename);
     }
     catch (Exception ex) {
         _log.Error(ex, "Error deleting file");
     }
 }
예제 #4
0
 /// <summary>
 /// Upload replay
 /// </summary>
 /// <param name="file"></param>
 public async Task Upload(ReplayFile file)
 {
     file.UploadStatus = UploadStatus.InProgress;
     if (file.Fingerprint != null && await CheckDuplicate(file.Fingerprint))
     {
         _log.Debug($"File {file} marked as duplicate");
         file.UploadStatus = UploadStatus.Duplicate;
     }
     else
     {
         file.UploadStatus = await Upload(file.Filename);
     }
 }
예제 #5
0
 /// <summary>
 /// Decide whether a replay should be deleted according to current settings
 /// </summary>
 /// <param name="file">replay file metadata</param>
 /// <param name="replay">Parsed replay</param>
 private bool ShouldDelete(ReplayFile file, Replay replay)
 {
     return
         (DeleteAfterUpload.HasFlag(DeleteFiles.PTR) && file.UploadStatus == UploadStatus.PtrRegion ||
          DeleteAfterUpload.HasFlag(DeleteFiles.Ai) && file.UploadStatus == UploadStatus.AiDetected ||
          DeleteAfterUpload.HasFlag(DeleteFiles.Custom) && file.UploadStatus == UploadStatus.CustomGame ||
          file.UploadStatus == UploadStatus.Success && (
              DeleteAfterUpload.HasFlag(DeleteFiles.Brawl) && replay.GameMode == GameMode.Brawl ||
              DeleteAfterUpload.HasFlag(DeleteFiles.QuickMatch) && replay.GameMode == GameMode.QuickMatch ||
              DeleteAfterUpload.HasFlag(DeleteFiles.UnrankedDraft) && replay.GameMode == GameMode.UnrankedDraft ||
              DeleteAfterUpload.HasFlag(DeleteFiles.HeroLeague) && replay.GameMode == GameMode.HeroLeague ||
              DeleteAfterUpload.HasFlag(DeleteFiles.TeamLeague) && replay.GameMode == GameMode.TeamLeague
              ));
 }
예제 #6
0
        /// <summary>
        /// Analyze replay locally before uploading
        /// </summary>
        /// <param name="file">Replay file</param>
        public void Analyze(ReplayFile file)
        {
            try {
                var result = DataParser.ParseReplay(file.Filename, false, false, false, true);
                switch (result.Item1)
                {
                case DataParser.ReplayParseResult.ComputerPlayerFound:
                case DataParser.ReplayParseResult.TryMeMode:
                    file.UploadStatus = UploadStatus.AiDetected;
                    return;

                case DataParser.ReplayParseResult.PTRRegion:
                    file.UploadStatus = UploadStatus.PtrRegion;
                    return;

                case DataParser.ReplayParseResult.PreAlphaWipe:
                    file.UploadStatus = UploadStatus.TooOld;
                    return;
                }

                if (result.Item1 != DataParser.ReplayParseResult.Success)
                {
                    return;
                }

                var replay = result.Item2;

                if (replay.ReplayBuild < MinimumBuild)
                {
                    file.UploadStatus = UploadStatus.TooOld;
                    return;
                }

                file.Fingerprint = GetFingerprint(replay);
            }
            catch (Exception e) {
                _log.Warn(e, $"Error analyzing file {file}");
            }
        }