Exemplo 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;
        }
Exemplo n.º 2
0
        public ImageFile(string fileName, string rootPath, string setCode = null, string artist = null, bool isArt = false)
        {
            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);

            if (fileNameWithoutExtension == null)
            {
                throw new ArgumentException(@"fileName is null", nameof(fileName));
            }

            string directoryName = Path.GetDirectoryName(fileName);

            if (directoryName == null)
            {
                throw new ArgumentException(@"directoryName is null", nameof(fileName));
            }

            FullPath = fileName;

            string[] parts        = fileNameWithoutExtension.Split(Array.From('.'), 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].StartsWith("[") && parts[i].EndsWith("]")) && parts[i].Contains(' '));

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

            var imageName = string.Join(".", parts.Take(1 + lastNamePart))
                            .Replace(" - ", string.Empty);

            ImageName = string.Intern(ImageNamePatcher.PatchFileName(imageName));

            var nameParts = ImageName.SplitTailingNumber();

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

            rootPath = rootPath.ToAppRootedPath();

            if (!rootPath.EndsWith("\\"))
            {
                rootPath = rootPath + "\\";
            }

            if (!directoryName.EndsWith("\\"))
            {
                directoryName = directoryName + "\\";
            }

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

            Quality = getQuality();

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

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