Ejemplo n.º 1
0
        public ImageFile(
            FsPath fileName, FsPath rootPath, string setCode = null, string artist = null,
            bool isArt = false, int?customPriority = null)
        {
            var    fileNameWithoutExtension = fileName.Basename(extension: false);
            FsPath directoryName            = fileName.Parent();

            FullPath = fileName;

            string[] parts        = fileNameWithoutExtension.Split(Sequence.Array('.'), StringSplitOptions.None);
            var      lastNamePart = Enumerable.Range(0, parts.Length)
                                    .Last(i =>
                                          i == 0 ||
                                          // Richard Garfield, Ph.D..xlhq.jpg
                                          // S.N.O.T..xlhq.jpg
                                          // Our Market Research....xlhq.jpg
                                          parts[i].Length <= 1 ||
                                          // Sarpadian Empires, Vol. VII.xlhq.jpg
                                          // Но Thoughtseize.[Size 16x20].jpg
                                          parts[i].Contains(' ') && !(parts[i].StartsWith("[") && parts[i].EndsWith("]")));

            Type = string.Join(".", parts.Skip(1 + lastNamePart));

            string imageNameRaw = string.Join(".", parts.Take(1 + lastNamePart));
            var    imageName    = _patternToRemove.Replace(imageNameRaw, string.Empty);
            var    replacedName = _nameReplacements.TryGet(imageName) ?? imageName;

            ImageName = string.Intern(replacedName);

            var nameParts = ImageName.SplitTailingNumber();

            Name          = string.Intern(nameParts.Item1);
            VariantNumber = nameParts.Item2;

            rootPath = rootPath.ToAppRootedPath();

            if (setCode != null)
            {
                SetCode = string.Intern(setCode);
                SetCodeIsFromAttribute = true;
            }
            else
            {
                var setCodeMatch = _setCodeRegex.Match(directoryName.RelativeTo(rootPath).Value);
                if (setCodeMatch.Success)
                {
                    SetCode = string.Intern(setCodeMatch.Value.ToUpperInvariant());
                }
                else
                {
                    SetCode = string.Empty;
                }
            }

            Priority = customPriority ?? getPriority();

            if (artist != null)
            {
                Artist = string.Intern(artist);
            }

            IsArt   = isArt;
            IsToken = directoryName.Value.IndexOf("Token", Str.Comparison) >= 0;
        }