Пример #1
0
        private void export(
            FsPath directory,
            string setCodesStr,
            ISet <FsPath> exportedSmall,
            ISet <FsPath> exportedZoomed,
            bool small,
            bool zoomed,
            FsPath smallSubdir,
            FsPath zoomedSubdir,
            bool matchingSet,
            bool forceRemoveCorner,
            bool token)
        {
            var setCodes = setCodesStr?.Split(',').ToHashSet(StringComparer.OrdinalIgnoreCase);

            foreach ((string setCode, Set set) in _cardRepo.SetsByCode)
            {
                Console.WriteLine(setCode);

                if (setCodes?.Contains(setCode) == false)
                {
                    continue;
                }

                FsPath smallSetSubdir  = FsPath.None;
                FsPath zoomedSetSubdir = FsPath.None;

                if (small)
                {
                    if (smallSubdir.HasValue())
                    {
                        smallSetSubdir = directory.Join(smallSubdir).Join(setCode);
                    }
                    else
                    {
                        smallSetSubdir = directory.Join(setCode);
                    }

                    smallSetSubdir = ensureSetSubdirectory(smallSetSubdir);
                }

                if (zoomed)
                {
                    if (zoomedSubdir.HasValue())
                    {
                        zoomedSetSubdir = directory.Join(zoomedSubdir).Join(setCode);
                    }
                    else
                    {
                        zoomedSetSubdir = directory.Join(setCode);
                    }

                    zoomedSetSubdir = ensureSetSubdirectory(zoomedSetSubdir);
                }

                foreach (var card in set.Cards)
                {
                    if (card.IsSingleSide() && card.Faces.Main != card)
                    {
                        continue;
                    }

                    if (card.IsToken != token)
                    {
                        continue;
                    }

                    Bitmap     original   = null;
                    ImageModel modelSmall = null;

                    if (small)
                    {
                        modelSmall = _imageRepo.GetSmallImage(card, _cardRepo.GetReleaseDateSimilarity);

                        if (modelSmall != null &&
                            Str.Equals(card.SetCode, modelSmall.ImageFile.SetCode) == matchingSet &&
                            exportedSmall.Add(modelSmall.ImageFile.FullPath))
                        {
                            FsPath smallPath = getTargetPath(modelSmall.ImageFile, smallSetSubdir);

                            if (!smallPath.IsFile() || card.Faces.Count > 1)
                            {
                                original = ImageLoader.Open(modelSmall);
                                addFile(original, modelSmall.ImageFile, smallPath, small: true, forceRemoveCorner);
                            }
                        }
                    }

                    if (zoomed)
                    {
                        var modelZoom = _imageRepo.GetImagePrint(card, _cardRepo.GetReleaseDateSimilarity);

                        if (modelZoom != null &&
                            Str.Equals(card.SetCode, modelZoom.ImageFile.SetCode) == matchingSet &&
                            exportedZoomed.Add(modelZoom.ImageFile.FullPath))
                        {
                            FsPath zoomedPath = getTargetPath(modelZoom.ImageFile, zoomedSetSubdir);

                            if (!zoomedPath.IsFile() || card.Faces.Count > 1)
                            {
                                if (original == null || modelSmall.ImageFile.FullPath != modelZoom.ImageFile.FullPath)
                                {
                                    original?.Dispose();
                                    original = ImageLoader.Open(modelZoom);
                                }

                                addFile(original, modelZoom.ImageFile, zoomedPath, small: false, forceRemoveCorner);
                            }
                        }
                    }

                    original?.Dispose();
                }

                smallSetSubdir.DeleteEmptyDirectory();
                zoomedSetSubdir.DeleteEmptyDirectory();
            }
        }