示例#1
0
        private async Task HandleParsedGames()
        {
            foreach (var game in _gameInfo.Where(x => x.DownloadSuccess && x.UnzipSuccess && !x.Skip))
            {
                //Get the json file to be sent to the server
                var jsonDir = Path.GetDirectoryName(game.GetPathLocalJson());

                FileInfo targetFile;
                try
                {
                    targetFile = new FileInfo(
                        Directory.GetFiles(jsonDir).FirstOrDefault(x => x.Contains(game.GetGameUid()) &&
                                                                   !x.Contains("playerpositions", StringComparison.OrdinalIgnoreCase)));

                    game.SetRealJsonLocation(targetFile);
                }
                catch (Exception e)
                {
                    if (_dataService.RSettings.ProgramSettings.Debug)
                    {
                        await _log.LogMessage($"Issue getting file {game.GetGameUid()} It likely failed to parse\n{e}", false,
                                              color : LOG_COLOR);
                    }
                    _matchesFailedParse.Add(game.GetMatchId());

                    game.SetSkip(true);
                    continue;
                }

                if (_dataService.RSettings.ProgramSettings.Debug)
                {
                    await _log.LogMessage("Adding " + game.GetPathLocalJson() + " to the upload list!", false,
                                          color : LOG_COLOR);
                }

                string selectedTag = game.Tag.TagName;

                //Determine paths on the remote server
                var remoteDirectory = $"{selectedTag}_{game.GetMapName()}";
                //Path to local directory containing radars
                var localRadarDir = $"{_dataService.RSettings.ProgramSettings.FaceItDemoPath}\\Radars\\{selectedTag}";

                //Create the directory where we will store the radar files
                Directory.CreateDirectory(localRadarDir);

                //Get the radar file paths
                var radarPng = Directory.GetFiles(localRadarDir, $"*{game.GetMapName()}*.png",
                                                  SearchOption.AllDirectories);
                var radarTxt = Directory.GetFiles(localRadarDir, $"*{game.GetMapName()}*.txt",
                                                  SearchOption.AllDirectories);

                //No radar or text file found. We need to get them and include in the upload.
                if (radarTxt.Length == 0 || radarPng.Length == 0)
                {
                    if (_dataService.RSettings.ProgramSettings.Debug)
                    {
                        await _log.LogMessage($"Getting radar files for {targetFile}", false, color : LOG_COLOR);
                    }

                    var wsId = DemoParser.GetWorkshopIdFromJasonFile(targetFile);

                    if (wsId == null)
                    {
                        await _log.LogMessage($"Failed to get workshop ID for `{game.GetGameUid()}` Skipping radar for this match.");

                        goto addFilesToDict;
                    }

                    var steamApi = new SteamAPI(_dataService, _log);

                    //Handle radar files
                    var radarFiles =
                        await steamApi.GetWorkshopMapRadarFiles(game.GetBaseTempPath().TrimEnd('\\'), wsId);

                    if (radarFiles != null)
                    {
                        foreach (var radarFile in radarFiles)
                        {
                            for (int i = 0; i < 4; i++)
                            {
                                try
                                {
                                    if (File.Exists($"{localRadarDir}\\{radarFile.Name}"))
                                    {
                                        File.Delete($"{localRadarDir}\\{radarFile.Name}");
                                    }

                                    File.Move(radarFile.FullName, $"{localRadarDir}\\{radarFile.Name}");

                                    break;
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e);
                                    await Task.Delay(5000);
                                }
                            }

                            //Add to list of dict to upload
                            _uploadDictionary.Add(new FileInfo($"{localRadarDir}\\{radarFile.Name}"), remoteDirectory);
                        }
                    }
                }
                else
                {
                    if (_dataService.RSettings.ProgramSettings.Debug)
                    {
                        await _log.LogMessage($"Skipping radar files for {targetFile}", false, color : LOG_COLOR);
                    }
                }
addFilesToDict:
                //Add the tag to be called later
                if (!_siteUpdateCalls.Contains(remoteDirectory))
                {
                    _siteUpdateCalls.Add(remoteDirectory);
                }

                //Add to dict of files to upload
                _uploadDictionary.Add(targetFile, remoteDirectory);
            }
        }