Exemplo n.º 1
0
        public void ZipImages(string setCodesStr, bool small, bool zoom, bool nonToken, bool token)
        {
            var setCodes = setCodesStr?.Split(',').ToHashSet(StringComparer.OrdinalIgnoreCase);

            foreach (FsPath qualityDir in getQualities(small, zoom))
            {
                foreach ((_, _, FsPath tokenSuffix) in getIsToken(nonToken, token))
                {
                    FsPath compressedRoot = TargetDir.Join(qualityDir).Concat(tokenSuffix).Concat(ZipDirSuffix);
                    compressedRoot.CreateDirectory();

                    FsPath sourceRoot = TargetDir.Join(qualityDir).Concat(tokenSuffix);
                    foreach (var subdir in sourceRoot.EnumerateDirectories())
                    {
                        string subdirRelative = subdir.Basename();
                        if (setCodes?.Contains(subdirRelative) == false)
                        {
                            continue;
                        }

                        var targetFile = compressedRoot.Join(subdirRelative).Concat(SevenZipExtension);
                        if (targetFile.IsFile())
                        {
                            targetFile.DeleteFile();
                        }

                        new SevenZip(false).Compress(subdir, targetFile)
                        .Should().BeTrue();
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void EnsureNoSetSubdirDuplicates(string setCodesStr)
        {
            var setCodes = setCodesStr?.Split(',') ?? Empty <string> .Array;

            foreach (FsPath qualityDir in getQualities(small: true, zoom: true))
            {
                foreach ((_, _, FsPath tokenSuffix) in getIsToken(nonToken: true, token: true))
                {
                    FsPath sourceRoot         = TargetDir.Join(qualityDir).Concat(tokenSuffix);
                    var    caseInsensitiveMap = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase);
                    var    caseSensitiveMap   = new Dictionary <string, bool>(StringComparer.Ordinal);
                    using (new AssertionScope($"Set subdirectory duplicates in {sourceRoot}"))
                        foreach (var subdir in sourceRoot.EnumerateDirectories())
                        {
                            string subdirRelative = subdir.Basename();
                            caseInsensitiveMap.Should().NotContainKey(subdirRelative);
                            caseInsensitiveMap[subdirRelative] = true;
                            caseSensitiveMap[subdirRelative]   = true;
                        }

                    using (new AssertionScope($"Affected set duplicates in {sourceRoot}"))
                        foreach (string setCode in setCodes)
                        {
                            if (caseInsensitiveMap.ContainsKey(setCode))
                            {
                                caseSensitiveMap.Should().ContainKey(setCode);
                            }
                        }
                }
            }
        }
Exemplo n.º 3
0
        public void RemoveObsoleteIndexes()
        {
            if (!_root.IsDirectory())
            {
                return;
            }

            foreach (var subdir in _root.EnumerateDirectories())
            {
                if (subdir != IndexDirectory)
                {
                    subdir.DeleteDirectory(recursive: true);
                }
            }
        }
Exemplo n.º 4
0
        public void PreProcessImages(string setCodesStr, bool nonToken, bool token)
        {
            setupImageConversion();

            FsPath smallDir    = DevPaths.GathererOriginalDir;
            FsPath zoomDir     = DevPaths.GathererPreprocessedDir;
            FsPath smallDirBak = BakDir.Join(smallDir.Basename());
            FsPath zoomDirBak  = BakDir.Join(zoomDir.Basename());

            var setCodes = setCodesStr?.Split(',').ToHashSet(StringComparer.OrdinalIgnoreCase);

            IEnumerable <FsPath> getSetSubdirs(FsPath typeSubdir)
            {
                FsPath typeDir = smallDir.Join(typeSubdir);

                return(typeDir
                       .EnumerateDirectories(_fromPng ? "*.png" : "*", SearchOption.TopDirectoryOnly)
                       .Select(_ => new FsPath(
                                   Regex.Replace(
                                       _.Basename(),
                                       @"\.png$",
                                       string.Empty))));
            }

            foreach ((_, FsPath typeSubdir, _) in getIsToken(nonToken, token))
            {
                foreach (FsPath setSubdir in getSetSubdirs(typeSubdir))
                {
                    if (setCodes?.Contains(setSubdir.Value) == false)
                    {
                        continue;
                    }

                    FsPath smallJpgDir = smallDir.Join(typeSubdir, setSubdir);
                    FsPath zoomJpgDir  = zoomDir.Join(typeSubdir, setSubdir);

                    if (!_fromPng)
                    {
                        if (!_createZoom)
                        {
                            return;
                        }

                        zoomJpgDir.CreateDirectory();
                        foreach (FsPath smallImg in smallJpgDir.EnumerateFiles())
                        {
                            FsPath zoomImg = smallImg.ChangeDirectory(smallDir, zoomDir);
                            if (_keepExisting && zoomImg.IsFile() && isZoomed(zoomImg))
                            {
                                continue;
                            }

                            scale(smallImg, zoomImg);
                        }
                    }
                    else
                    {
                        FsPath setPngSubdir   = setSubdir.Concat(".png");
                        FsPath smallPngDir    = smallDir.Join(typeSubdir, setPngSubdir);
                        FsPath smallPngDirBak = smallDirBak.Join(typeSubdir, setPngSubdir);
                        FsPath zoomPngDir     = zoomDir.Join(typeSubdir, setPngSubdir);
                        FsPath zoomPngDirBak  = zoomDirBak.Join(typeSubdir, setPngSubdir);

                        var dirs = new List <(FsPath pngDir, FsPath pngDirBak, FsPath jpgDir, bool isZoom)>();
                        if (_createZoom)
                        {
                            zoomPngDir.CreateDirectory();
                            foreach (FsPath smallImg in smallPngDir.EnumerateFiles())
                            {
                                FsPath zoomImg      = smallImg.ChangeDirectory(smallDir, zoomDir);
                                FsPath convertedImg = zoomImg.ChangeDirectory(zoomPngDir, zoomJpgDir)
                                                      .WithName(_ => _.Replace(".png", ".jpg"));

                                if (_keepExisting && (
                                        zoomImg.IsFile() && isZoomed(zoomImg) ||
                                        convertedImg.IsFile() && isZoomed(convertedImg)))
                                {
                                    continue;
                                }

                                scale(smallImg, zoomImg);
                            }

                            dirs.Add((pngDir: zoomPngDir, pngDirBak: zoomPngDirBak, jpgDir: zoomJpgDir, isZoom: true));
                        }

                        dirs.Add((pngDir: smallPngDir, pngDirBak: smallPngDirBak, jpgDir: smallJpgDir, isZoom: false));

                        foreach ((FsPath pngDir, FsPath pngDirBak, FsPath jpgDir, bool isZoom) in dirs)
                        {
                            jpgDir.CreateDirectory();

                            var pngImages = pngDir.EnumerateFiles();
                            foreach (FsPath sourceImage in pngImages)
                            {
                                convertToJpg(sourceImage, jpgDir, isZoom);
                            }

                            moveDirectoryToBackup(pngDir, pngDirBak);
                        }
                    }
                }
            }
        }