public async Task <ActionResult> ReplayGetAuthors(string effectJson)
        {
            var replayHandler = new ReplayHandler(effectJson);
            var result        = await Authors.GetAuthorsEff().Run(replayHandler);

            return(Ok(result));
        }
Example #2
0
        public ReplayBridge(GameCenter gc, SystemControl sys, LogControl log, ReplayManager replay)
        {
            var ses = new SessionIdHandler();

            _gameService   = new GameServiceHandler(gc, sys, log, replay, ses);
            _replayHandler = new ReplayHandler(replay);
        }
Example #3
0
        public IDictionary <string, List <File <IReplay> > > Sort(List <string> replaysThrowingExceptions)
        {
            // Dictionary<directory, dictionary<file, replay>>
            IDictionary <string, List <File <IReplay> > > DirectoryFileReplay = new Dictionary <string, List <File <IReplay> > >();

            // replays grouped by gametype
            var ReplaysByGameTypes = from replay in Sorter.ListReplays
                                     group replay by replay.Content.GameType;

            // make sortdirectory
            string sortDirectory = Sorter.CurrentDirectory;

            if (!(IsNested && !Sorter.GenerateIntermediateFolders))
            {
                if (IsNested)
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + SortCriteria;
                }
                else
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + string.Join(",", Sorter.CriteriaStringOrder);
                }
                sortDirectory = FileHandler.CreateDirectory(sortDirectory);
            }

            // make subdirectory per gametype, and put all associated replays into it

            foreach (var gametype in ReplaysByGameTypes)
            {
                var GameType = gametype.Key.ToString();
                Directory.CreateDirectory(sortDirectory + @"\" + GameType);
                var FileReplays = new List <File <IReplay> >();
                DirectoryFileReplay.Add(new KeyValuePair <string, List <File <IReplay> > >(sortDirectory + @"\" + GameType, FileReplays));

                foreach (var replay in gametype)
                {
                    try
                    {
                        if (IsNested == false)
                        {
                            ReplayHandler.CopyReplay(replay, sortDirectory, GameType, KeepOriginalReplayNames, Sorter.CustomReplayFormat);
                        }
                        else
                        {
                            ReplayHandler.MoveReplay(replay, sortDirectory, GameType, true, null);
                        }

                        FileReplays.Add(replay);
                    }
                    catch (Exception ex)
                    {
                        replaysThrowingExceptions.Add(replay.OriginalFilePath);
                        ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - SortOnGameType exception.", ex: ex);
                    }
                }
            }
            return(DirectoryFileReplay);
        }
Example #4
0
        public override void Initialize()
        {
            SetNetworkPacketEventEnabled(true);
            replay = new ReplayHandler(GetProtocolVersion());
            replay.MetaData.serverName = GetServerHost() + GetServerPort();
            backupCounter = backupInterval;

            RegisterChatBotCommand("replay", "replay command", Command);
        }
        public override void Initialize()
        {
            SetNetworkPacketEventEnabled(true);
            replay = new ReplayHandler(GetProtocolVersion());
            replay.MetaData.serverName = GetServerHost() + GetServerPort();
            backupCounter = backupInterval;

            RegisterChatBotCommand("replay", Translations.Get("bot.replayCapture.cmd"), "replay <save|stop>", Command);
        }
Example #6
0
 public ServerEventHandler(SessionIdHandler sidHandler, TcpClient socket, GameCenter game, SystemControl sys,
                           LogControl log, ReplayManager replay, ICommunicationHandler comm)
 {
     _socket           = socket;
     _gameService      = new GameServiceHandler(game, sys, log, replay, sidHandler);
     _userService      = new UserServiceHandler(game, sys);
     _commHandler      = comm;
     _sessionIdHandler = sidHandler;
     _security         = new SecurityHandler();
     _replayService    = new ReplayHandler(replay);
 }
Example #7
0
    public ReplayHandler Load()
    {
        if (!File.Exists(Application.persistentDataPath + REPLAY_NAME))
        {
            return(null);
        }

        BinaryFormatter binary        = new BinaryFormatter();
        FileStream      fStream       = File.Open(Application.persistentDataPath + REPLAY_NAME, FileMode.Open);
        ReplayHandler   replayHandler = (ReplayHandler)binary.Deserialize(fStream);

        fStream.Close();

        Debug.Log("LOADED : " + replayHandler._serializableTransforms.Count);
        return(replayHandler);
    }
Example #8
0
        public IDictionary <string, List <File <IReplay> > > PreviewSort(List <string> replaysThrowingExceptions, BackgroundWorker worker_ReplaySorter, int currentCriteria, int numberOfCriteria, int currentPositionNested = 0, int numberOfPositions = 0)
        {
            if (SortCriteriaParameters.Durations == null)
            {
                throw new ArgumentException("Duration intervals cannot be null");
            }

            // Dictionary<directory, dictionary<file, replay>>
            IDictionary <string, List <File <IReplay> > > DirectoryFileReplay = new Dictionary <string, List <File <IReplay> > >();
            IDictionary <int, List <File <IReplay> > >    ReplayDurations     = new Dictionary <int, List <File <IReplay> > >();

            foreach (var replay in Sorter.ListReplays)
            {
                TimeSpan replayDuration          = TimeSpan.FromSeconds((replay.Content.FrameCount / ((double)1000 / 42)));
                double   replayDurationInMinutes = replayDuration.TotalMinutes;
                int      durationInterval        = 0;
                while (replayDurationInMinutes > SortCriteriaParameters.Durations[durationInterval])
                {
                    durationInterval++;
                    if (durationInterval == SortCriteriaParameters.Durations.Length)
                    {
                        break;
                    }
                }

                if (durationInterval != SortCriteriaParameters.Durations.Length)
                {
                    if (!ReplayDurations.ContainsKey(SortCriteriaParameters.Durations[durationInterval]))
                    {
                        ReplayDurations.Add(new KeyValuePair <int, List <File <IReplay> > >(SortCriteriaParameters.Durations[durationInterval], new List <File <IReplay> > {
                            replay
                        }));
                    }
                    else
                    {
                        ReplayDurations[SortCriteriaParameters.Durations[durationInterval]].Add(replay);
                    }
                    // => throws error key does not exist !!! => ReplayDurations[durations[durationInterval]].Add(replay);
                }
                else
                {
                    if (!ReplayDurations.ContainsKey(-1))
                    {
                        ReplayDurations.Add(new KeyValuePair <int, List <File <IReplay> > >(-1, new List <File <IReplay> > {
                            replay
                        }));
                    }
                    else
                    {
                        ReplayDurations[-1].Add(replay);
                    }
                }
            }

            string sortDirectory = Sorter.CurrentDirectory;

            if (!(IsNested && !Sorter.GenerateIntermediateFolders))
            {
                if (IsNested)
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + SortCriteria;
                }
                else
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + string.Join(",", Sorter.CriteriaStringOrder);
                }
                sortDirectory = FileHandler.AdjustName(sortDirectory, true);
            }

            int currentPosition    = 0;
            int progressPercentage = 0;

            foreach (var durationInterval in ReplayDurations)
            {
                string DurationName = null;
                if (durationInterval.Key != -1)
                {
                    string previousDuration = null;
                    int    DurationIndex    = GetFirstIndex(SortCriteriaParameters.Durations, durationInterval.Key);
                    if (DurationIndex != 0)
                    {
                        previousDuration = SortCriteriaParameters.Durations[DurationIndex - 1].ToString() + "m";
                    }
                    else
                    {
                        previousDuration = "0m";
                    }
                    DurationName = previousDuration + "-" + durationInterval.Key.ToString() + "m";
                }
                else
                {
                    DurationName = SortCriteriaParameters.Durations[SortCriteriaParameters.Durations.Length - 1].ToString() + "m++";
                }
                try
                {
                    // Directory.CreateDirectory(sortDirectory + @"\" + DurationName);
                    var DurationReplays = ReplayDurations[durationInterval.Key];
                    var FileReplays     = new List <File <IReplay> >();
                    DirectoryFileReplay.Add(new KeyValuePair <string, List <File <IReplay> > >(sortDirectory + @"\" + DurationName, FileReplays));
                    foreach (var replay in DurationReplays)
                    {
                        if (worker_ReplaySorter.CancellationPending == true)
                        {
                            // ??? how am i supposed to do this!! This doesn't feel right at all!! No way i'm supposed to also pass the DoWorkEventArgs!!
                            return(null);
                        }
                        try
                        {
                            if (IsNested == false)
                            {
                                ReplayHandler.CopyReplay(replay, sortDirectory, DurationName, KeepOriginalReplayNames, Sorter.CustomReplayFormat, true);
                            }
                            else
                            {
                                ReplayHandler.MoveReplay(replay, sortDirectory, DurationName, true, null, true);
                            }

                            FileReplays.Add(replay);
                        }
                        catch (Exception ex)
                        {
                            replaysThrowingExceptions.Add(replay.OriginalFilePath);
                            ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - SortOnDuration Exception.", ex: ex);
                        }
                        currentPosition++;
                        if (IsNested == false)
                        {
                            progressPercentage = Convert.ToInt32(((double)currentPosition / Sorter.ListReplays.Count) * 1 / numberOfCriteria * 100);
                        }
                        else
                        {
                            progressPercentage  = Convert.ToInt32((((double)currentPosition / Sorter.ListReplays.Count) * 1 / numberOfPositions * 100 + ((currentPositionNested - 1) * 100 / numberOfPositions)) * ((double)1 / numberOfCriteria));
                            progressPercentage += (currentCriteria - 1) * 100 / numberOfCriteria;
                        }
                        worker_ReplaySorter.ReportProgress(progressPercentage, $"Sorting on duration... {replay.FilePath}");
                    }
                }
                catch (Exception ex)
                {
                    ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - SortOnDuration Exception Outer.", ex: ex);
                }
            }
            return(DirectoryFileReplay);
        }
Example #9
0
        public IDictionary <string, List <File <IReplay> > > Sort(List <string> replaysThrowingExceptions)
        {
            // Dictionary<directory, dictionary<file, replay>>
            IDictionary <string, List <File <IReplay> > > DirectoryFileReplay = new Dictionary <string, List <File <IReplay> > >();

            // get all matchups from the replays
            // allow the ignoring of specific game types

            MatchUpEqualityComparer MatchUpEq = new MatchUpEqualityComparer();
            IDictionary <IDictionary <int, IDictionary <RaceType, int> >, IList <File <IReplay> > > ReplayMatchUps = new Dictionary <IDictionary <int, IDictionary <RaceType, int> >, IList <File <IReplay> > >(MatchUpEq);

            int counter    = 0;
            var maxCounter = Sorter.ListReplays.Count;

            foreach (var replay in Sorter.ListReplays)
            {
                try
                {
                    if (SortCriteriaParameters.ValidGameTypes[replay.Content.GameType] == true)
                    {
                        var wrappedReplay = ReplayDecorator.Create(replay);
                        var matchup       = wrappedReplay.GetReplayItem(Tuple.Create(CustomReplayNameSyntax.Matchup, string.Empty), ++counter, maxCounter);
                        IDictionary <int, IDictionary <RaceType, int> > EncodedMatchUp = new Dictionary <int, IDictionary <RaceType, int> >();
                        int team = 1;
                        foreach (var raceCombination in GetTeamRaces(matchup))
                        {
                            var RaceFrequency = EncodeRacesFrequency(raceCombination);
                            EncodedMatchUp.Add(new KeyValuePair <int, IDictionary <RaceType, int> >(team, RaceFrequency));
                            team++;
                        }

                        // Teams Team = new Teams(replay.Content);
                        // MatchUp MatchUp = new MatchUp(replay.Content, Team);
                        // // int => team
                        // IDictionary<int, IDictionary<RaceType, int>> EncodedMatchUp = new Dictionary<int, IDictionary<RaceType, int>>();
                        // int team = 1;
                        // foreach (var RaceCombination in MatchUp.TeamRaces)
                        // {
                        //     var RaceFrequency = EncodeRacesFrequency(RaceCombination);
                        //     EncodedMatchUp.Add(new KeyValuePair<int, IDictionary<RaceType, int>>(team, RaceFrequency));
                        //     team++;
                        // }
                        if (!ReplayMatchUps.ContainsKey(EncodedMatchUp))
                        {
                            ReplayMatchUps.Add(new KeyValuePair <IDictionary <int, IDictionary <RaceType, int> >, IList <File <IReplay> > >(EncodedMatchUp, new List <File <IReplay> > {
                                replay
                            }));
                        }
                        else
                        {
                            ReplayMatchUps[EncodedMatchUp].Add(replay);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - SortOnMatchUp exception: Encoding matchups, file: {replay.OriginalFilePath}", ex: ex);
                }
            }

            string sortDirectory = Sorter.CurrentDirectory;

            if (!(IsNested && !Sorter.GenerateIntermediateFolders))
            {
                if (IsNested)
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + SortCriteria;
                }
                else
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + string.Join(",", Sorter.CriteriaStringOrder);
                }
                sortDirectory = FileHandler.CreateDirectory(sortDirectory);
            }

            foreach (var matchup in /*MatchUps.Distinct(MatchUpEq)*/ ReplayMatchUps.Keys)
            {
                // make directory per matchup
                var MatchUpName = MatchUpToString(matchup);

                if (string.IsNullOrWhiteSpace(MatchUpName))
                {
                    MatchUpName = "NoPlayers";
                }

                Directory.CreateDirectory(sortDirectory + @"\" + MatchUpName);

                var FileReplays = new List <File <IReplay> >();
                DirectoryFileReplay.Add(new KeyValuePair <string, List <File <IReplay> > >(sortDirectory + @"\" + MatchUpName, FileReplays));

                // write all associated replays to this directory
                var MatchUpReplays = ReplayMatchUps[matchup];
                foreach (var replay in MatchUpReplays)
                {
                    try
                    {
                        if (IsNested == false)
                        {
                            ReplayHandler.CopyReplay(replay, sortDirectory, MatchUpName, KeepOriginalReplayNames, Sorter.CustomReplayFormat);
                        }
                        else
                        {
                            ReplayHandler.MoveReplay(replay, sortDirectory, MatchUpName, true, null);
                        }

                        FileReplays.Add(replay);
                    }
                    catch (Exception ex)
                    {
                        replaysThrowingExceptions.Add(replay.OriginalFilePath);
                        ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - SortOnMatchUp Exception", ex: ex);
                    }
                }
            }
            return(DirectoryFileReplay);
        }
Example #10
0
        private ServiceResult <ServiceResultSummary <IEnumerable <File <IReplay> > > > ComputeNames(BackgroundWorker worker_ReplayRenamer, string outputDirectory, bool restore = false)
        {
            worker_ReplayRenamer.ReportProgress(0, "Computing names...");

            var firstReplay = _listReplays.FirstOrDefault();

            if (firstReplay == null)
            {
                return(new ServiceResult <ServiceResultSummary <IEnumerable <File <IReplay> > > >(ServiceResultSummary <IEnumerable <File <IReplay> > > .Default, false, new List <string> {
                    "You have to parse replays before you can sort. Replay list is empty!"
                }));
            }

            if (!string.IsNullOrWhiteSpace(outputDirectory) && !Directory.Exists(outputDirectory))
            {
                return(new ServiceResult <ServiceResultSummary <IEnumerable <File <IReplay> > > >(ServiceResultSummary <IEnumerable <File <IReplay> > > .Default, false, new List <string> {
                    "Output directory does not exist."
                }));
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();
            int currentPosition           = 0;
            int progressPercentage        = 0;
            int replaysThrowingExceptions = 0;
            var renamedReplays            = new List <File <IReplay> >();

            foreach (var replay in _listReplays)
            {
                if (worker_ReplayRenamer.CancellationPending == true)
                {
                    sw.Stop();
                    return(new ServiceResult <ServiceResultSummary <IEnumerable <File <IReplay> > > >(
                               new ServiceResultSummary <IEnumerable <File <IReplay> > >(
                                   renamedReplays,
                                   $"Renaming cancelled by user... It took {sw.Elapsed} to rename {renamedReplays.Count()} of {_listReplays.Count()} replays. {replaysThrowingExceptions} replays encountered exceptions.",
                                   sw.Elapsed,
                                   currentPosition,
                                   replaysThrowingExceptions
                                   ),
                               true,
                               null
                               ));
                }

                currentPosition++;
                progressPercentage = Convert.ToInt32(((double)currentPosition / (_listReplays.Count() * 2)) * 100);
                worker_ReplayRenamer.ReportProgress(progressPercentage);
                try
                {
                    replay.AddAfterCurrent(
                        (string.IsNullOrWhiteSpace(outputDirectory) ? Directory.GetParent(replay.FilePath).ToString() : outputDirectory) + @"\"
                        +
                        (restore ? FileHandler.GetFileName(replay.OriginalFilePath) : ReplayHandler.GenerateReplayName(replay, CustomReplayFormat) + ".rep")
                        );
                    renamedReplays.Add(replay);
                }
                catch (Exception ex)
                {
                    replaysThrowingExceptions++;
                    //TODO add to serviceresult instead... log later?
                    ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - Error while renaming replay: {replay.OriginalFilePath}", ex: ex);
                }
            }

            sw.Stop();
            return(new ServiceResult <ServiceResultSummary <IEnumerable <File <IReplay> > > >(
                       new ServiceResultSummary <IEnumerable <File <IReplay> > >(
                           renamedReplays,
                           $"Finished renaming replays! It took {sw.Elapsed} to rename {_listReplays.Count()} replays. {replaysThrowingExceptions} replays encountered exceptions.",
                           sw.Elapsed,
                           currentPosition,
                           replaysThrowingExceptions
                           ),
                       true,
                       null
                       ));
        }
Example #11
0
        private ServiceResult <ServiceResultSummary <IEnumerable <File <IReplay> > > > ExecuteRenaming(BackgroundWorker worker_ReplayRenamer, IEnumerable <File <IReplay> > replays, bool shouldCopy, bool forward = true, int steps = 2, bool isPreview = false)
        {
            worker_ReplayRenamer.ReportProgress(50, "Writing replays...");
            // report progress... with "Copying replays with newly generated names..."
            Stopwatch sw = new Stopwatch();

            sw.Start();

            int currentPosition           = 0;
            int progressPercentage        = 0;
            int replaysThrowingExceptions = 0;
            var renamedReplays            = new List <File <IReplay> >();

            foreach (var replay in replays)
            {
                if (worker_ReplayRenamer.CancellationPending == true)
                {
                    sw.Stop();
                    return(new ServiceResult <ServiceResultSummary <IEnumerable <File <IReplay> > > >
                           (
                               new ServiceResultSummary <IEnumerable <File <IReplay> > >
                               (
                                   renamedReplays,
                                   $"Renaming cancelled by user... It took {sw.Elapsed} to write {renamedReplays.Count()} of {replays.Count()} replays. {replaysThrowingExceptions} replays encountered exceptions.",
                                   sw.Elapsed,
                                   currentPosition,
                                   replaysThrowingExceptions
                               ),
                               true,
                               null
                           ));
                }

                currentPosition++;
                progressPercentage = 50 + Convert.ToInt32(((double)currentPosition / (replays.Count() * steps)) * 100);
                worker_ReplayRenamer.ReportProgress(progressPercentage);
                try
                {
                    replay.SaveState();

                    if (isPreview)
                    {
                        replay.Forward();
                    }
                    else
                    {
                        if (shouldCopy)
                        {
                            ReplayHandler.CopyReplay(replay, forward);
                            // don't want this to show up in history
                            //TODO eh this doesn't take into account forward, but i guess copying only occurs when renaming to an output directory which is always forward??

                            // support for listview renaming action result requires history to be recorded...
                            // replay.Rewind();
                            // replay.RemoveAfterCurrent();

                            // File.Copy(replay.OriginalFilePath, replay.FilePath);
                        }
                        else
                        {
                            ReplayHandler.MoveReplay(replay, forward);
                        }
                    }
                    renamedReplays.Add(replay);
                    replay.DiscardSavedState();
                }
                catch (Exception ex)
                {
                    replay.RestoreToSavedState();
                    replaysThrowingExceptions++;
                    //TODO add to serviceresult instead... log later?
                    ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - Error while renaming replay: {replay.OriginalFilePath}", ex: ex);
                }
            }

            sw.Stop();
            return(new ServiceResult <ServiceResultSummary <IEnumerable <File <IReplay> > > >
                   (
                       new ServiceResultSummary <IEnumerable <File <IReplay> > >
                       (
                           renamedReplays,
                           $"Finished writing replays! It took {sw.Elapsed} to write {replays.Count()} replays. {replaysThrowingExceptions} replays encountered exceptions.",
                           sw.Elapsed,
                           currentPosition,
                           replaysThrowingExceptions
                       ),
                       true,
                       null
                   ));
        }
Example #12
0
 private void Awake()
 {
     INSTANCE = this;
     this.currentReplayHandler = new ReplayHandler();
 }
Example #13
0
        public IDictionary <string, List <File <IReplay> > > Sort(List <string> replaysThrowingExceptions)
        {
            // Dictionary<directory, dictionary<file, replay>>
            IDictionary <string, List <File <IReplay> > > DirectoryFileReplay = new Dictionary <string, List <File <IReplay> > >();

            // extract maps from replays, try to group the duplicates
            ReplayMapEqualityComparer MapEq = new ReplayMapEqualityComparer();
            IDictionary <IReplayMap, List <File <IReplay> > > Maps = new Dictionary <IReplayMap, List <File <IReplay> > >(MapEq);


            foreach (var replay in Sorter.ListReplays)
            {
                if (!Maps.Keys.Contains(replay.Content.ReplayMap))
                {
                    Maps.Add(new KeyValuePair <IReplayMap, List <File <IReplay> > >(replay.Content.ReplayMap, new List <File <IReplay> > {
                        replay
                    }));
                }
                else
                {
                    Maps[replay.Content.ReplayMap].Add(replay);
                }
            }

            string sortDirectory = Sorter.CurrentDirectory;

            if (!(IsNested && !Sorter.GenerateIntermediateFolders))
            {
                if (IsNested)
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + SortCriteria;
                }
                else
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + string.Join(",", Sorter.CriteriaStringOrder);
                }
                sortDirectory = FileHandler.CreateDirectory(sortDirectory);
            }

            foreach (var map in Maps)
            {
                var MapName = map.Key.MapName;
                List <File <IReplay> > FileReplays = new List <File <IReplay> >();

                MapName = FileHandler.RemoveInvalidChars(MapName);

                try
                {
                    //TODO use stringbuilder ?
                    string MapFolder = sortDirectory + @"\" + MapName;

                    // key already exists... how/why?? "Untitled Scenario"... different maps, same "internal" name
                    // maps with same name but different dimensions...

                    int count = 1;
                    while (DirectoryFileReplay.ContainsKey(MapFolder) || Directory.Exists(MapFolder))
                    {
                        MapFolder = FileHandler.IncrementName(MapName, string.Empty, sortDirectory, ref count);
                    }

                    DirectoryFileReplay.Add(new KeyValuePair <string, List <File <IReplay> > >(MapFolder, FileReplays));

                    Directory.CreateDirectory(MapFolder);

                    var MapReplays = Maps[map.Key];
                    foreach (var replay in MapReplays)
                    {
                        try
                        {
                            if (IsNested == false)
                            {
                                ReplayHandler.CopyReplay(replay, MapFolder, string.Empty, KeepOriginalReplayNames, Sorter.CustomReplayFormat);
                            }
                            else
                            {
                                ReplayHandler.MoveReplay(replay, MapFolder, string.Empty, true, null);
                            }

                            FileReplays.Add(replay);
                        }
                        catch (Exception ex)
                        {
                            replaysThrowingExceptions.Add(replay.OriginalFilePath);
                            ErrorLogger.GetInstance()?.LogError("SortOnGameType Exception.", ex: ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - SortOnGameType Exception Outer: {DirectoryFileReplay.Count.ToString()}.", ex: ex);
                }
            }
            return(DirectoryFileReplay);
        }
Example #14
0
        public IDictionary <string, List <File <IReplay> > > PreviewSort(List <string> replaysThrowingExceptions, BackgroundWorker worker_ReplaySorter, int currentCriteria, int numberOfCriteria, int currentPositionNested = 0, int numberOfPositions = 0)
        {
            IDictionary <string, List <File <IReplay> > > DirectoryFileReplay = new Dictionary <string, List <File <IReplay> > >();

            ReplayMapEqualityComparer MapEq = new ReplayMapEqualityComparer();
            IDictionary <IReplayMap, List <File <IReplay> > > Maps = new Dictionary <IReplayMap, List <File <IReplay> > >(MapEq);

            foreach (var replay in Sorter.ListReplays)
            {
                if (!Maps.Keys.Contains(replay.Content.ReplayMap))
                {
                    Maps.Add(new KeyValuePair <IReplayMap, List <File <IReplay> > >(replay.Content.ReplayMap, new List <File <IReplay> > {
                        replay
                    }));
                }
                else
                {
                    Maps[replay.Content.ReplayMap].Add(replay);
                }
            }

            string sortDirectory = Sorter.CurrentDirectory;

            if (!(IsNested && !Sorter.GenerateIntermediateFolders))
            {
                if (IsNested)
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + SortCriteria;
                }
                else
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + string.Join(",", Sorter.CriteriaStringOrder);
                }
                sortDirectory = FileHandler.AdjustName(sortDirectory, true);
            }

            int currentPosition    = 0;
            int progressPercentage = 0;

            foreach (var map in Maps)
            {
                var MapName     = map.Key.MapName;
                var FileReplays = new List <File <IReplay> >();

                MapName = FileHandler.RemoveInvalidChars(MapName);

                try
                {
                    //TODO use stringbuilder ?
                    string MapFolder = sortDirectory + @"\" + MapName;

                    // key already exists... how/why?? "Untitled Scenario"... different maps, same "internal" name
                    // maps with same name but different dimensions...

                    int count = 1;
                    while (DirectoryFileReplay.ContainsKey(MapFolder) || Directory.Exists(MapFolder))
                    {
                        MapFolder = FileHandler.IncrementName(MapName, string.Empty, sortDirectory, ref count);
                    }

                    DirectoryFileReplay.Add(new KeyValuePair <string, List <File <IReplay> > >(MapFolder, FileReplays));

                    var MapReplays = Maps[map.Key];
                    foreach (var replay in MapReplays)
                    {
                        if (worker_ReplaySorter.CancellationPending == true)
                        {
                            return(null);
                        }
                        currentPosition++;
                        if (IsNested == false)
                        {
                            progressPercentage = Convert.ToInt32(((double)currentPosition / Sorter.ListReplays.Count) * 1 / numberOfCriteria * 100);
                        }
                        else
                        {
                            progressPercentage  = Convert.ToInt32((((double)currentPosition / Sorter.ListReplays.Count) * 1 / numberOfPositions * 100 + ((currentPositionNested - 1) * 100 / numberOfPositions)) * ((double)1 / numberOfCriteria));
                            progressPercentage += (currentCriteria - 1) * 100 / numberOfCriteria;
                        }
                        worker_ReplaySorter.ReportProgress(progressPercentage, $"sorting on map... {replay.FilePath}");

                        try
                        {
                            if (IsNested == false)
                            {
                                ReplayHandler.CopyReplay(replay, MapFolder, string.Empty, KeepOriginalReplayNames, Sorter.CustomReplayFormat, true);
                            }
                            else
                            {
                                ReplayHandler.MoveReplay(replay, MapFolder, string.Empty, true, null, true);
                            }

                            FileReplays.Add(replay);
                        }
                        catch (Exception ex)
                        {
                            replaysThrowingExceptions.Add(replay.OriginalFilePath);
                            ErrorLogger.GetInstance()?.LogError("SortOnGameType Exception.", ex: ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - SortOnGameType Exception Outer: {DirectoryFileReplay.Count.ToString()}.", ex: ex);
                }
            }
            return(DirectoryFileReplay);
        }
Example #15
0
        public IDictionary <string, List <File <IReplay> > > Sort(List <string> replaysThrowingExceptions)
        {
            if (SortCriteriaParameters.Durations == null)
            {
                throw new ArgumentException("Duration intervals cannot be null");
            }
            // Dictionary<directory, dictionary<file, replay>>
            IDictionary <string, List <File <IReplay> > > DirectoryFileReplay = new Dictionary <string, List <File <IReplay> > >();

            IDictionary <int, List <File <IReplay> > > ReplayDurations = new Dictionary <int, List <File <IReplay> > >();

            foreach (var replay in Sorter.ListReplays)
            {
                TimeSpan replayDuration          = TimeSpan.FromSeconds((replay.Content.FrameCount / ((double)1000 / 42)));
                double   replayDurationInMinutes = replayDuration.TotalMinutes;
                int      durationInterval        = 0;
                while (replayDurationInMinutes > SortCriteriaParameters.Durations[durationInterval])
                {
                    durationInterval++;
                    if (durationInterval == SortCriteriaParameters.Durations.Length)
                    {
                        break;
                    }
                }

                if (durationInterval != SortCriteriaParameters.Durations.Length)
                {
                    if (!ReplayDurations.ContainsKey(SortCriteriaParameters.Durations[durationInterval]))
                    {
                        ReplayDurations.Add(new KeyValuePair <int, List <File <IReplay> > >(SortCriteriaParameters.Durations[durationInterval], new List <File <IReplay> > {
                            replay
                        }));
                    }
                    else
                    {
                        ReplayDurations[SortCriteriaParameters.Durations[durationInterval]].Add(replay);
                    }
                    // => throws error key does not exist !!! => ReplayDurations[durations[durationInterval]].Add(replay);
                }
                else
                {
                    if (!ReplayDurations.ContainsKey(-1))
                    {
                        ReplayDurations.Add(new KeyValuePair <int, List <File <IReplay> > >(-1, new List <File <IReplay> > {
                            replay
                        }));
                    }
                    else
                    {
                        ReplayDurations[-1].Add(replay);
                    }
                }
            }

            string sortDirectory = Sorter.CurrentDirectory;

            if (!(IsNested && !Sorter.GenerateIntermediateFolders))
            {
                if (IsNested)
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + SortCriteria;
                }
                else
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + string.Join(",", Sorter.CriteriaStringOrder);
                }
                sortDirectory = FileHandler.CreateDirectory(sortDirectory);
            }

            foreach (var durationInterval in ReplayDurations)
            {
                string DurationName = null;
                if (durationInterval.Key != -1)
                {
                    string previousDuration = null;
                    int    DurationIndex    = GetFirstIndex(SortCriteriaParameters.Durations, durationInterval.Key);
                    if (DurationIndex != 0)
                    {
                        previousDuration = SortCriteriaParameters.Durations[DurationIndex - 1].ToString() + "m";
                    }
                    else
                    {
                        previousDuration = "0m";
                    }
                    DurationName = previousDuration + "-" + durationInterval.Key.ToString() + "m";
                }
                else
                {
                    DurationName = SortCriteriaParameters.Durations[SortCriteriaParameters.Durations.Length - 1].ToString() + "m++";
                }
                try
                {
                    Directory.CreateDirectory(sortDirectory + @"\" + DurationName);
                    var DurationReplays = ReplayDurations[durationInterval.Key];
                    var FileReplays     = new List <File <IReplay> >();
                    DirectoryFileReplay.Add(new KeyValuePair <string, List <File <IReplay> > >(sortDirectory + @"\" + DurationName, FileReplays));
                    foreach (var replay in DurationReplays)
                    {
                        try
                        {
                            if (IsNested == false)
                            {
                                ReplayHandler.CopyReplay(replay, sortDirectory, DurationName, KeepOriginalReplayNames, Sorter.CustomReplayFormat);
                            }
                            else
                            {
                                ReplayHandler.MoveReplay(replay, sortDirectory, DurationName, true, null);
                            }

                            FileReplays.Add(replay);
                        }
                        catch (Exception ex)
                        {
                            replaysThrowingExceptions.Add(replay.OriginalFilePath);
                            ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - SortOnDuration Exception.", ex: ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - SortOnDuration Exception Outer.", ex: ex);
                }
            }
            return(DirectoryFileReplay);
        }
Example #16
0
        //TODO if you want you could incorporate preview into the regular sort methods, but it's annoying to adjust
        public IDictionary <string, List <File <IReplay> > > PreviewSort(List <string> replaysThrowingExceptions, BackgroundWorker worker_ReplaySorter, int currentCriteria, int numberOfCriteria, int currentPositionNested = 0, int numberOfPositions = 0)
        {
            IDictionary <string, List <File <IReplay> > > DirectoryFileReplay = new Dictionary <string, List <File <IReplay> > >();

            MatchUpEqualityComparer MatchUpEq = new MatchUpEqualityComparer();
            IDictionary <IDictionary <int, IDictionary <RaceType, int> >, IList <File <IReplay> > > ReplayMatchUp = new Dictionary <IDictionary <int, IDictionary <RaceType, int> >, IList <File <IReplay> > >(MatchUpEq);

            var counter    = 0;
            var maxCounter = Sorter.ListReplays.Count;

            foreach (var replay in Sorter.ListReplays)
            {
                try
                {
                    if (SortCriteriaParameters.ValidGameTypes[replay.Content.GameType] == true)
                    {
                        var wrappedReplay = ReplayDecorator.Create(replay);
                        var matchup       = wrappedReplay.GetReplayItem(Tuple.Create(CustomReplayNameSyntax.Matchup, string.Empty), ++counter, maxCounter);
                        IDictionary <int, IDictionary <RaceType, int> > EncodedMatchUp = new Dictionary <int, IDictionary <RaceType, int> >();
                        int team = 1;
                        foreach (var raceCombination in GetTeamRaces(matchup))
                        {
                            var RaceFrequency = EncodeRacesFrequency(raceCombination);
                            EncodedMatchUp.Add(new KeyValuePair <int, IDictionary <RaceType, int> >(team, RaceFrequency));
                            team++;
                        }
                        // Teams Team = new Teams(replay.Content);
                        // MatchUp MatchUp = new MatchUp(replay.Content, Team);
                        // // int => team
                        // IDictionary<int, IDictionary<RaceType, int>> EncodedMatchUp = new Dictionary<int, IDictionary<RaceType, int>>();
                        // int team = 1;
                        // foreach (var RaceCombination in MatchUp.TeamRaces)
                        // {
                        //     var RaceFrequency = EncodeRacesFrequency(RaceCombination);
                        //     EncodedMatchUp.Add(new KeyValuePair<int, IDictionary<RaceType, int>>(team, RaceFrequency));
                        //     team++;
                        // }
                        if (!ReplayMatchUp.ContainsKey(EncodedMatchUp))
                        {
                            ReplayMatchUp.Add(new KeyValuePair <IDictionary <int, IDictionary <RaceType, int> >, IList <File <IReplay> > >(EncodedMatchUp, new List <File <IReplay> > {
                                replay
                            }));
                        }
                        else
                        {
                            ReplayMatchUp[EncodedMatchUp].Add(replay);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - SortOnMatchUp exception: Encoding matchups, file: {replay.OriginalFilePath}", ex: ex);
                }
            }

            string sortDirectory = Sorter.CurrentDirectory;

            if (!(IsNested && !Sorter.GenerateIntermediateFolders))
            {
                if (IsNested)
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + SortCriteria;
                }
                else
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + string.Join(",", Sorter.CriteriaStringOrder);
                }
                sortDirectory = FileHandler.AdjustName(sortDirectory, true);
            }

            int currentPosition    = 0;
            int progressPercentage = 0;

            //TODO if there are no matchups to sort... this will screw with the progress reporting...
            foreach (var matchup in ReplayMatchUp.Keys)
            {
                var MatchUpName = MatchUpToString(matchup);

                if (string.IsNullOrWhiteSpace(MatchUpName))
                {
                    MatchUpName = "NoPlayers";
                }

                var FileReplays = new List <File <IReplay> >();
                DirectoryFileReplay.Add(new KeyValuePair <string, List <File <IReplay> > >(sortDirectory + @"\" + MatchUpName, FileReplays));
                var MatchUpReplays = ReplayMatchUp[matchup];

                foreach (var replay in MatchUpReplays)
                {
                    if (worker_ReplaySorter.CancellationPending == true)
                    {
                        return(null);
                    }
                    currentPosition++;
                    if (IsNested == false)
                    {
                        progressPercentage = Convert.ToInt32(((double)currentPosition / Sorter.ListReplays.Count) * 1 / numberOfCriteria * 100);
                    }
                    else
                    {
                        progressPercentage  = Convert.ToInt32((((double)currentPosition / Sorter.ListReplays.Count) * 1 / numberOfPositions * 100 + ((currentPositionNested - 1) * 100 / numberOfPositions)) * ((double)1 / numberOfCriteria));
                        progressPercentage += (currentCriteria - 1) * 100 / numberOfCriteria;
                    }
                    worker_ReplaySorter.ReportProgress(progressPercentage, $"sorting on matchup... {replay.FilePath}");
                    try
                    {
                        if (IsNested == false)
                        {
                            ReplayHandler.CopyReplay(replay, sortDirectory, MatchUpName, KeepOriginalReplayNames, Sorter.CustomReplayFormat, true);
                        }
                        else
                        {
                            ReplayHandler.MoveReplay(replay, sortDirectory, MatchUpName, true, null, true);
                        }

                        FileReplays.Add(replay);
                    }
                    catch (Exception ex)
                    {
                        replaysThrowingExceptions.Add(replay.OriginalFilePath);
                        ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - SortOnMatchUp Exception", ex: ex);
                    }
                }
            }

            //... This is necessary in case you skip replays because of non-matching matchups
            if (IsNested == false)
            {
                progressPercentage = Convert.ToInt32(1.0 / numberOfCriteria * 100);
            }
            else
            {
                progressPercentage  = Convert.ToInt32((1.0 / numberOfPositions * 100 + ((currentPositionNested - 1) * 100 / numberOfPositions)) * ((double)1 / numberOfCriteria));
                progressPercentage += (currentCriteria - 1) * 100 / numberOfCriteria;
            }
            worker_ReplaySorter.ReportProgress(progressPercentage);
            return(DirectoryFileReplay);
        }
Example #17
0
        public IDictionary <string, List <File <IReplay> > > PreviewSort(List <string> replaysThrowingExceptions, BackgroundWorker worker_ReplaySorter, int currentCriteria, int numberOfCriteria, int currentPositionNested = 0, int numberOfPositions = 0)
        {
            IDictionary <string, List <File <IReplay> > > DirectoryFileReplay = new Dictionary <string, List <File <IReplay> > >();

            var ReplaysByGameTypes = from replay in Sorter.ListReplays
                                     group replay by replay.Content.GameType;

            string sortDirectory = Sorter.CurrentDirectory;

            if (!(IsNested && !Sorter.GenerateIntermediateFolders))
            {
                if (IsNested)
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + SortCriteria;
                }
                else
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + string.Join(",", Sorter.CriteriaStringOrder);
                }
                sortDirectory = FileHandler.AdjustName(sortDirectory, true);
            }

            int currentPosition    = 0;
            int progressPercentage = 0;

            foreach (var gametype in ReplaysByGameTypes)
            {
                var GameType    = gametype.Key.ToString();
                var FileReplays = new List <File <IReplay> >();
                DirectoryFileReplay.Add(new KeyValuePair <string, List <File <IReplay> > >(sortDirectory + @"\" + GameType, FileReplays));

                foreach (var replay in gametype)
                {
                    if (worker_ReplaySorter.CancellationPending == true)
                    {
                        return(null);
                    }

                    try
                    {
                        if (IsNested == false)
                        {
                            ReplayHandler.CopyReplay(replay, sortDirectory, GameType, KeepOriginalReplayNames, Sorter.CustomReplayFormat, true);
                        }
                        else
                        {
                            ReplayHandler.MoveReplay(replay, sortDirectory, GameType, true, null, true);
                        }

                        FileReplays.Add(replay);
                    }
                    catch (Exception ex)
                    {
                        replaysThrowingExceptions.Add(replay.OriginalFilePath);
                        ErrorLogger.GetInstance()?.LogError("SortOnGameType ArgumentException.", ex: ex);
                    }

                    currentPosition++;
                    if (IsNested == false)
                    {
                        progressPercentage = Convert.ToInt32(((double)currentPosition / Sorter.ListReplays.Count) * 1 / numberOfCriteria * 100);
                    }
                    else
                    {
                        progressPercentage  = Convert.ToInt32((((double)currentPosition / Sorter.ListReplays.Count) * 1 / numberOfPositions * 100 + ((currentPositionNested - 1) * 100 / numberOfPositions)) * ((double)1 / numberOfCriteria));
                        progressPercentage += (currentCriteria - 1) * 100 / numberOfCriteria;
                    }
                    worker_ReplaySorter.ReportProgress(progressPercentage, $"sorting on gametype... {replay.FilePath}");
                }
            }
            return(DirectoryFileReplay);
        }
Example #18
0
        public IDictionary <string, List <File <IReplay> > > PreviewSort(List <string> replaysThrowingExceptions, BackgroundWorker worker_ReplaySorter, int currentCriteria, int numberOfCriteria, int currentPositionNested = 0, int numberOfPositions = 0)
        {
            var directoryFileReplay = new Dictionary <string, List <File <IReplay> > >();

            var playerNames         = new List <string>();
            var makeFolderForWinner = (bool)SortCriteriaParameters.MakeFolderForWinner;
            var makeFolderForLoser  = (bool)SortCriteriaParameters.MakeFolderForLoser;
            var currentDirectory    = Sorter.CurrentDirectory;
            var sortCriteria        = Sorter.SortCriteria;
            var playerType          = GetPlayerType(makeFolderForWinner, makeFolderForLoser);

            playerNames.AddRange(ExtractPlayers(Sorter.ListReplays.Select(f => f.Content), playerType).Select(playerName => FileHandler.RemoveInvalidChars(playerName)).Distinct());

            string sortDirectory = Sorter.CurrentDirectory;

            if (!(IsNested && !Sorter.GenerateIntermediateFolders))
            {
                if (IsNested)
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + sortCriteria;
                }
                else
                {
                    sortDirectory = Sorter.CurrentDirectory + @"\" + string.Join(",", Sorter.CriteriaStringOrder);
                }
                sortDirectory = FileHandler.AdjustName(sortDirectory, true);
            }

            foreach (var playerName in playerNames)
            {
                directoryFileReplay.Add(Path.Combine(sortDirectory, playerName), new List <File <IReplay> >());
            }

            if (playerType == PlayerType.None)
            {
                directoryFileReplay.Add(sortDirectory, new List <File <IReplay> >());
            }

            int currentPosition    = 0;
            int progressPercentage = 0;

            foreach (var replay in Sorter.ListReplays)
            {
                if (worker_ReplaySorter.CancellationPending == true)
                {
                    return(null);
                }

                currentPosition++;
                if (IsNested == false)
                {
                    progressPercentage = Convert.ToInt32(((double)currentPosition / Sorter.ListReplays.Count) * 1 / numberOfCriteria * 100);
                }
                else
                {
                    progressPercentage  = Convert.ToInt32((((double)currentPosition / Sorter.ListReplays.Count) * 1 / numberOfPositions * 100 + ((currentPositionNested - 1) * 100 / numberOfPositions)) * ((double)1 / numberOfCriteria));
                    progressPercentage += (currentCriteria - 1) * 100 / numberOfCriteria;
                }
                worker_ReplaySorter.ReportProgress(progressPercentage, $"sorting on playername... {replay.FilePath}");

                var newReplayName = KeepOriginalReplayNames ? FileHandler.GetFileName(replay.FilePath) : ReplayHandler.GenerateReplayName(replay, Sorter.CustomReplayFormat) + ".rep";

                try
                {
                    if (playerType == PlayerType.None)
                    {
                        var newReplayPath = Path.Combine(sortDirectory, newReplayName);

                        if (IsNested)
                        {
                            ReplayHandler.MoveReplay(replay, newReplayPath, true);
                        }
                        else
                        {
                            ReplayHandler.CopyReplay(replay, newReplayPath, true);
                        }
                        directoryFileReplay[sortDirectory].Add(replay);
                    }
                    else
                    {
                        var playersToSortFor = GetPlayers(playerType, replay.Content);

                        foreach (var player in playersToSortFor)
                        {
                            var folderName    = Path.Combine(sortDirectory, FileHandler.RemoveInvalidChars(player.Name));
                            var newReplayPath = Path.Combine(folderName, newReplayName);

                            if (IsNested && player == playersToSortFor.Last())
                            {
                                ReplayHandler.MoveReplay(replay, newReplayPath, true);
                                directoryFileReplay[folderName].Add(replay);
                            }
                            else
                            {
                                ReplayHandler.CopyReplay(replay, newReplayPath, true);
                                var additionalReplayCreated = File <IReplay> .Create(replay.Content, replay.OriginalFilePath, replay.Hash);

                                additionalReplayCreated.AddAfterCurrent(replay.FilePath);
                                additionalReplayCreated.Forward();
                                replay.Rewind();
                                directoryFileReplay[folderName].Add(additionalReplayCreated);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    replaysThrowingExceptions.Add(replay.OriginalFilePath);
                    ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - sort on playername exception: {replay.FilePath}", ex: ex);
                }
            }
            return(directoryFileReplay);
        }
Example #19
0
        public IDictionary <string, List <File <IReplay> > > Sort(List <string> replaysThrowingExceptions)
        {
            var directoryFileReplay = new Dictionary <string, List <File <IReplay> > >();

            var playerNames         = new List <string>();
            var makeFolderForWinner = (bool)SortCriteriaParameters.MakeFolderForWinner;
            var makeFolderForLoser  = (bool)SortCriteriaParameters.MakeFolderForLoser;
            var currentDirectory    = Sorter.CurrentDirectory;
            var sortCriteria        = Sorter.SortCriteria;
            var sortDirectory       = Sorter.CurrentDirectory;

            playerNames.AddRange(ExtractPlayers(Sorter.ListReplays.Select(f => f.Content), GetPlayerType(makeFolderForWinner, makeFolderForLoser)).Select(playerName => FileHandler.RemoveInvalidChars(playerName)).Distinct());

            if (!(IsNested && !Sorter.GenerateIntermediateFolders))
            {
                if (IsNested)
                {
                    sortDirectory = Path.Combine(sortDirectory, sortCriteria.ToString());
                }
                else
                {
                    sortDirectory = Path.Combine(sortDirectory, string.Join(",", Sorter.CriteriaStringOrder));
                }
                sortDirectory = FileHandler.CreateDirectory(sortDirectory);
            }

            var playerType = GetPlayerType(makeFolderForWinner, makeFolderForLoser);

            foreach (var playerName in playerNames)
            {
                try
                {
                    Directory.CreateDirectory(sortDirectory + @"\" + playerName);
                    directoryFileReplay.Add(Path.Combine(sortDirectory, playerName), new List <File <IReplay> >());
                }
                catch (Exception ex)
                {
                    ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - Could not create folder for {playerName}", ex: ex);
                }
            }

            if (playerType == PlayerType.None)
            {
                directoryFileReplay.Add(sortDirectory, new List <File <IReplay> >());
            }

            foreach (var replay in Sorter.ListReplays)
            {
                try
                {
                    var newReplayName = KeepOriginalReplayNames ? FileHandler.GetFileName(replay.FilePath) : ReplayHandler.GenerateReplayName(replay, Sorter.CustomReplayFormat) + ".rep";
                    if (playerType == PlayerType.None)
                    {
                        var newReplayPath = Path.Combine(sortDirectory, newReplayName);

                        if (IsNested)
                        {
                            ReplayHandler.MoveReplay(replay, newReplayPath);
                        }
                        else
                        {
                            ReplayHandler.CopyReplay(replay, newReplayPath);
                        }
                        directoryFileReplay[sortDirectory].Add(replay);
                    }
                    else
                    {
                        var playersToSortFor = GetPlayers(playerType, replay.Content);
                        foreach (var player in playersToSortFor)
                        {
                            var folderName    = Path.Combine(sortDirectory, FileHandler.RemoveInvalidChars(player.Name));
                            var newReplayPath = Path.Combine(folderName, newReplayName);

                            if (IsNested && player == playersToSortFor.Last())
                            {
                                ReplayHandler.MoveReplay(replay, newReplayPath);
                                directoryFileReplay[folderName].Add(replay);
                            }
                            else
                            {
                                ReplayHandler.CopyReplay(replay, newReplayPath);
                                var additionalReplayCreated = File <IReplay> .Create(replay.Content, replay.OriginalFilePath, replay.Hash);

                                additionalReplayCreated.AddAfterCurrent(replay.FilePath);
                                additionalReplayCreated.Forward();
                                replay.Rewind();
                                directoryFileReplay[folderName].Add(additionalReplayCreated);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    replaysThrowingExceptions.Add(replay.OriginalFilePath);
                    ErrorLogger.GetInstance()?.LogError($"{DateTime.Now} - sort on player name exception: {replay.FilePath}", ex: ex);
                }
            }
            return(directoryFileReplay);
        }