public void PopulateDoujins() { if (!Directory.Exists(SettingsUtil.DoujinDirectory)) { return; } List <string> potentialDoujinDirectories = GetPotentialDoujinDirectories(); if (potentialDoujinDirectories == null) { return; } cache = new Cache(); if (cache.CachedDoujins != null) { List <string> doujinsFoundInCache = GetDoujinsFoundInCache(potentialDoujinDirectories); potentialDoujinDirectories = potentialDoujinDirectories.Except(doujinsFoundInCache).ToList <string>(); Invoke_AddCachedDoujinsToViewModel(doujinsFoundInCache); } TagScrubber tagScrubber = new TagScrubber(); // Search for the first image in the directory // and set it as cover image + add it to the panel foreach (string directory in potentialDoujinDirectories) { string coverImagePath = GetDefaultCoverPath(directory); string dirName = Path.GetFileName(Path.GetDirectoryName(coverImagePath)); coverImagePath = ImageCompressor.CompressImage(coverImagePath, 40); tagScrubber.GatherDoujinDetails(dirName, TagScrubber.SearchMode.Title); try { Invoke_AddDoujinToViewModel(coverImagePath, DateTime.Now, dirName, directory, tagScrubber); } catch (NotSupportedException) { Debug.WriteLine("Image corrupted or not supported: " + coverImagePath); } catch { Debug.WriteLine("Failed to add doujin at: " + coverImagePath); } tagScrubber.Clear(); // Add delay to prevent sending too many requests to nHentai // currently still results in a ban (403 Forbidden) System.Threading.Thread.Sleep(1000); } Invoke_SaveToCache(DoujinsModel.Doujins.ToList <Doujin>()); }
private void Invoke_AddDoujinToViewModel(string coverImagePath, DateTime dateAdded, string title, string directory, TagScrubber tagScrubber) { Invoke_AddDoujinToViewModel(coverImagePath, dateAdded, title, tagScrubber.Author, directory, tagScrubber.Parodies, tagScrubber.Characters, tagScrubber.Tags, tagScrubber.ID); }