private void DoAfter(ModFileToMerge modFileToMerge)
        {
            var modFile = modFileToMerge.Source;
            var match   = ModNameParse.Parse(modFile);

            if (match?.Filename == null)
            {
                throw new InvalidDataException($"provided file path \"{modFile.Path}\" was not in en expected format - please contact the developer.");
            }

            var surroundings = GetMatchingFiles(match);

            var hasPrefix = match.HasPrefix;

            if (hasPrefix)
            {
                var prefix = match.Prefix;
                if (surroundings.Any(s => s.HasPrefix && s.Prefix == prefix + 1))
                {
                    var toModify  = surroundings.Where(s => s.HasPrefix && s.Prefix <= prefix).OrderByDescending(s => s.Prefix);
                    var modPrefix = prefix;
                    foreach (var item in toModify)
                    {
                        if (modPrefix != item.Prefix)
                        {
                            break;
                        }
                        modPrefix--;
                        item.Prefix    = modPrefix;
                        item.File.Path = item.Path;
                    }
                }
                else
                {
                    match.Prefix = prefix + 1;
                    modFile.Path = match.Path;
                }
            }
            else
            {
                var    dir       = Path.GetDirectoryName(modFile.Path);
                var    filename  = Path.GetFileName(modFile.Path);
                var    extension = Path.GetExtension(modFile.Path);
                var    postfix   = 0;
                string newPath;
                do
                {
                    newPath = Path.Combine(dir, $"{filename}_{postfix++}{extension}");
                } while (modFiles.Any(mf => string.CompareOrdinal(mf.Path, newPath) == 0));

                modFile.Path = newPath;
            }

            Result.Files.Add(modFile);

            CurrentProcess.Remove(modFile);
        }
        private void DoBefore(ModFileToMerge modFileToMerge)
        {
            var modFile = modFileToMerge.Source;
            var match   = ModNameParse.Parse(modFile);

            if (match?.Filename == null)
            {
                throw new InvalidDataException($"provided file path \"{modFile.Path}\" was not in en expected format - please contact the developer.");
            }

            var surroundings = GetMatchingFiles(match);

            var hasPrefix = match.HasPrefix;

            if (hasPrefix)
            {
                var prefix = match.Prefix;
                if (prefix == 0 || surroundings.Any(s => s.HasPrefix && s.Prefix == prefix - 1))
                {
                    var toModify  = surroundings.Where(s => s.HasPrefix && s.Prefix >= prefix).OrderBy(s => s.Prefix);
                    var modPrefix = prefix;
                    foreach (var item in toModify)
                    {
                        if (modPrefix != item.Prefix)
                        {
                            break;
                        }
                        modPrefix++;
                        item.Prefix    = modPrefix;
                        item.File.Path = item.Path;
                    }
                }
                else
                {
                    match.Prefix = prefix - 1;
                    modFile.Path = match.Path;
                }
            }
            else
            {
                int prefix = 0;
                if (surroundings.Any(s => s.HasPrefix))
                {
                    prefix = surroundings.Where(s => s.HasPrefix).Max(s => s.Prefix) + 1;
                }
                match.Prefix = prefix;
                modFile.Path = match.Path;
            }

            Result.Files.Add(modFile);

            CurrentProcess.Remove(modFile);
        }
 private List <ModNameParse> GetMatchingFiles(ModNameParse modFile)
 {
     return(modFiles.Select(ModNameParse.Parse).Where(mft => modFile.Filename == mft?.Filename).OrderBy(r => r.Path).ToList());
 }