/// <summary>
        /// Analyze replay locally before uploading
        /// </summary>
        /// <param name="file">Replay file</param>
        public Replay Analyze(ReplayFile file)
        {
            try {
                //filename, ignoreerrors, deletefile, allowptrregion, skipeventparsing
                var(parseResult, replay) = DataParser.ParseReplay(file.Filename, false,
                                                                  new ParseOptions {
                    ShouldParseUnits               = false,
                    ShouldParseMouseEvents         = false,
                    ShouldParseDetailedBattleLobby = true,
                    ShouldParseEvents              = false,
                    AllowPTR = false
                });

                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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Start uploading and watching for new replays
        /// </summary>
        public async void Start(IMonitor monitor, PreMatchIMonitor prematch_monitor, IAnalyzer analyzer, IUploader uploader)
        {
            if (_initialized)
            {
                return;
            }
            _initialized = true;

            _uploader         = uploader;
            _analyzer         = analyzer;
            _monitor          = monitor;
            _prematch_monitor = prematch_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);
                if (PreMatchPage)
                {
                    _prematch_monitor.Start();
                }
            };
            _monitor.Start();

            /*
             * _prematch_monitor.TempBattleLobbyCreated += async (_, e) => {
             *  if (PreMatchPage) {
             *      prematch_id = 0;
             *      _prematch_monitor.Stop();
             *      Thread.Sleep(1000);
             *      var tmpPath = Path.GetTempFileName();
             *      await SafeCopy(e.Data, tmpPath, true);
             *      byte[] bytes = System.IO.File.ReadAllBytes(tmpPath);
             *      Replay replay = MpqBattlelobby.Parse(bytes);
             *      await runPreMatch(replay);
             *  }
             * };
             * _prematch_monitor.Start();
             */

            _analyzer.MinimumBuild = await _uploader.GetMinimumBuild();

            for (int i = 0; i < MaxThreads; i++)
            {
                Task.Run(UploadLoop).Forget();
            }
        }
Exemplo n.º 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");
     }
 }
 /// <summary>
 /// Upload replay
 /// </summary>
 /// <param name="file"></param>
 public async Task Upload(Replay replay_results, 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(replay_results, file.Fingerprint, file.Filename);
     }
 }
Exemplo n.º 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 ||
              DeleteAfterUpload.HasFlag(DeleteFiles.StormLeague) && replay.GameMode == GameMode.StormLeague
              ));
 }