예제 #1
0
        public bool WithPagesFolder(int galleryId, Action <string> action)
        {
            string cachedPagesPath;

            if (PathFormatter.IsEnabled)
            {
                string cachedMetadataFilePath = PathFormatter.GetMetadata(galleryId);

                Metadata metadata = SearchResultCache.Find(galleryId) ?? JsonUtility.LoadFromFile <Metadata>(cachedMetadataFilePath);

                if (metadata == null)
                {
                    return(false);
                }

                cachedPagesPath = PathFormatter.GetPages(metadata);
            }
            else
            {
                cachedPagesPath = string.Format(CultureInfo.InvariantCulture, "{0}{1}/", PathFormatter.GetCacheDirectory(), galleryId);
            }

            if (!Directory.Exists(cachedPagesPath))
            {
                return(false);
            }

            if (action != null)
            {
                action.Invoke(cachedPagesPath);
            }

            return(true);
        }
예제 #2
0
        private void GalleryDownloader_GalleryDownloadCompleted(object sender, GalleryDownloadCompletedEventArgs e)
        {
            if (string.IsNullOrEmpty(WebBrowser.DocumentText))
            {
                return;
            }

            DocumentTemplate <Metadata> documentTemplate;

            if (DetailsModel.Target == DetailsTarget.Download)
            {
                documentTemplate = DownloadTemplate;
            }
            else
            {
                documentTemplate = DetailsTemplate;
            }

            WebBrowser.Tag          = e.Metadata.Id;
            WebBrowser.DocumentText = documentTemplate.GetFormattedText(e.Metadata);

            SearchResultCache.CacheRuntimeMetadata(e.Metadata);

            WebBrowser.Document?.InvokeScript("__onGalleryDownloadCompleted", e.ToObjectArray());
        }
예제 #3
0
        private void WebBrowser_GalleryDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            int galleryId = (int)webBrowser.Tag;

            if (!CacheFileSystem.DoesCoverExists(galleryId))
            {
                Metadata cachedMetadata = SearchResultCache.Find(galleryId);
                CoverDownloaderFilters filters;

                if (DetailsBrowserSettings.CoverLoadBlockAction == DetailsCoverLoadBlockAction.None)
                {
                    filters = CoverDownloaderFilters.All;
                }
                else if (DetailsBrowserSettings.CoverLoadBlockAction == DetailsCoverLoadBlockAction.Confirm)
                {
                    bool isInHidelist = MetadataKeywordLists.Hidelist.IsInMetadata(cachedMetadata);

                    if (isInHidelist &&
                        MessageBox.Show("This gallery is currently hidden. Do you want to download the cover?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                    {
                        return;
                    }

                    filters = CoverDownloaderFilters.All & ~CoverDownloaderFilters.Hidelist;
                }
                else
                {
                    filters = CoverDownloaderFilters.None;
                }

                CoverDownloader.Download(cachedMetadata, filters);
            }
        }
예제 #4
0
        public int[] GetCachedPageIndices(int galleryId)
        {
            List <int> indices = new List <int>();

            string cachedMetadataFilePath;

            if (PathFormatter.IsEnabled)
            {
                cachedMetadataFilePath = PathFormatter.GetMetadata(galleryId);
            }
            else
            {
                cachedMetadataFilePath = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", PathFormatter.GetCacheDirectory(), galleryId, ".json");
            }

            Metadata metadata = SearchResultCache.Find(galleryId) ?? JsonUtility.LoadFromFile <Metadata>(cachedMetadataFilePath);

            if (metadata == null)
            {
                return(indices.ToArray());
            }

            string cachedPagesPath;

            if (PathFormatter.IsEnabled)
            {
                cachedPagesPath = PathFormatter.GetPages(metadata);
            }
            else
            {
                cachedPagesPath = string.Format(CultureInfo.InvariantCulture, "{0}{1}/", PathFormatter.GetCacheDirectory(), galleryId);
            }

            if (!Directory.Exists(cachedPagesPath))
            {
                return(indices.ToArray());
            }

            DirectoryInfo dirInfo = new DirectoryInfo(cachedPagesPath);

            foreach (FileInfo fileInfo in dirInfo.EnumerateFiles())
            {
                string fileTitle = Path.GetFileNameWithoutExtension(fileInfo.Name).TrimStart(new char[] { '0' });
                int    num;

                if (int.TryParse(fileTitle, out num))
                {
                    if (num >= 1 && num <= metadata.Images.Pages.Count)
                    {
                        indices.Add(num);
                    }
                }
            }

            return(indices.ToArray());
        }
예제 #5
0
        public bool WithArchive(int galleryId, Action <string> action)
        {
            List <string> cachedArcihveFilePaths = new List <string>();

            if (PathFormatter.IsEnabled)
            {
                string cachedMetadataFilePath = PathFormatter.GetMetadata(galleryId);

                Metadata metadata = SearchResultCache.Find(galleryId) ?? JsonUtility.LoadFromFile <Metadata>(cachedMetadataFilePath);

                if (metadata == null)
                {
                    return(false);
                }

                foreach (IArchiveWriter archiveWriter in ArchiveWriters)
                {
                    string archivePath = PathFormatter.GetArchive(metadata, archiveWriter);

                    cachedArcihveFilePaths.Add(archivePath);
                }
            }
            else
            {
                foreach (IArchiveWriter archiveWriter in ArchiveWriters)
                {
                    string archivePath = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", PathFormatter.GetCacheDirectory(), galleryId, archiveWriter.FileExtension);

                    cachedArcihveFilePaths.Add(archivePath);
                }
            }

            foreach (string archivePath in cachedArcihveFilePaths)
            {
                if (!File.Exists(archivePath))
                {
                    continue;
                }

                if (action != null)
                {
                    action.Invoke(archivePath);
                }

                return(true);
            }

            return(false);
        }
예제 #6
0
파일: Taskbar.cs 프로젝트: NHxD/NHxD
        private void PageDownloader_PagesDownloadEnqueued(object sender, PagesDownloadStartedEventArgs e)
        {
            if (e.PageIndices == null)
            {
                Metadata metadata = SearchResultCache.Find(e.GalleryId);

                if (metadata != null)
                {
                    AddTasks(metadata.Images.Pages.Count());
                }
            }
            else
            {
                AddTasks(e.PageIndices.Length);
            }
        }
예제 #7
0
        // NOTE: at the moment both details and download share the same webbrowser.
        private bool ShowDetailsOrDownload(int galleryId, Action <Metadata> action)
        {
            DetailsModel.AddSearch(galleryId);

            string cachedMetadataFilePath;

            if (PathFormatter.IsEnabled)
            {
                cachedMetadataFilePath = PathFormatter.GetMetadata(galleryId);
            }
            else
            {
                cachedMetadataFilePath = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", PathFormatter.GetCacheDirectory(), galleryId, ".json");
            }

            Metadata metadata = SearchResultCache.Find(galleryId) ?? JsonUtility.LoadFromFile <Metadata>(cachedMetadataFilePath);

            if (metadata == null)
            {
                // let it download in the background, DetailsBrowserView will respond to its completion event.
                GalleryDownloader.Download(galleryId);

                return(false);
            }

            if (metadata == null)
            {
                MessageBox.Show("can't find metadata");

                return(false);
            }

            if (action != null)
            {
                action.Invoke(metadata);
            }

            return(true);
        }
예제 #8
0
        public bool DoesCoverExists(int galleryId)
        {
            string cachedMetadataFilePath;

            if (PathFormatter.IsEnabled)
            {
                cachedMetadataFilePath = PathFormatter.GetMetadata(galleryId);
            }
            else
            {
                cachedMetadataFilePath = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", PathFormatter.GetCacheDirectory(), galleryId, ".json");
            }

            Metadata metadata = SearchResultCache.Find(galleryId) ?? JsonUtility.LoadFromFile <Metadata>(cachedMetadataFilePath);

            if (metadata == null)
            {
                return(false);
            }

            return(WithCover(metadata, null));
        }
예제 #9
0
        public bool DoesPageExists(int galleryId, int pageIndex)
        {
            string cachedMetadataFilePath;

            if (PathFormatter.IsEnabled)
            {
                cachedMetadataFilePath = PathFormatter.GetMetadata(galleryId);
            }
            else
            {
                cachedMetadataFilePath = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", PathFormatter.GetCacheDirectory(), galleryId, ".json");
            }

            Metadata metadata = SearchResultCache.Find(galleryId) ?? JsonUtility.LoadFromFile <Metadata>(cachedMetadataFilePath);

            if (metadata == null ||
                pageIndex < 0 ||
                pageIndex > metadata.Images.Pages.Count - 1)
            {
                return(false);
            }

            return(WithPage(metadata, pageIndex, null));
        }
예제 #10
0
        public bool WithCachedPage(int galleryId, Func <int, int, int, bool> predicate, Action <string> action)
        {
            string cachedMetadataFilePath;

            if (PathFormatter.IsEnabled)
            {
                cachedMetadataFilePath = PathFormatter.GetMetadata(galleryId);
            }
            else
            {
                cachedMetadataFilePath = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", PathFormatter.GetCacheDirectory(), galleryId, ".json");
            }

            Metadata metadata = SearchResultCache.Find(galleryId) ?? JsonUtility.LoadFromFile <Metadata>(cachedMetadataFilePath);

            if (metadata == null)
            {
                return(false);
            }

            string cachedPagesPath;

            if (PathFormatter.IsEnabled)
            {
                cachedPagesPath = PathFormatter.GetPages(metadata);
            }
            else
            {
                cachedPagesPath = string.Format(CultureInfo.InvariantCulture, "{0}{1}/", PathFormatter.GetCacheDirectory(), galleryId);
            }

            if (!Directory.Exists(cachedPagesPath))
            {
                return(false);
            }

            DirectoryInfo dirInfo           = new DirectoryInfo(cachedPagesPath);
            string        firstPageFileName = null;
            int           numPages          = metadata.Images.Pages.Count;

            foreach (FileInfo fileInfo in dirInfo.EnumerateFiles())
            {
                string fileTitle = Path.GetFileNameWithoutExtension(fileInfo.Name).TrimStart(new char[] { '0' });
                int    num;

                if (int.TryParse(fileTitle, out num))
                {
                    if (predicate.Invoke(num, 1, numPages))
                    //if (num >= 1 && num <= metadata.Images.Pages.Count)
                    {
                        firstPageFileName = fileInfo.FullName;
                        break;
                    }
                }
            }

            if (string.IsNullOrEmpty(firstPageFileName))
            {
                return(false);
            }

            if (action != null)
            {
                action.Invoke(firstPageFileName);
            }

            return(true);
        }