public void CreateArchive(Metadata metadata, bool deletePagesDirectoryIfNecessary) { string pagesPath; if (PathFormatter.IsEnabled) { pagesPath = PathFormatter.GetPages(metadata); } else { pagesPath = string.Format(CultureInfo.InvariantCulture, "{0}{1}/", PathFormatter.GetCacheDirectory(), metadata.Id); } foreach (IArchiveWriter archiveWriter in ArchiveWriters) { CreateArchive(archiveWriter, metadata, pagesPath); } if (deletePagesDirectoryIfNecessary) { int[] cachedPageIndices = CacheFileSystem.GetCachedPageIndices(metadata.Id); if (cachedPageIndices.Length == metadata.Images.Pages.Count) { Directory.Delete(pagesPath, true); } } }
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); }
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()); }
public void CreateArchive(IArchiveWriter archiveWriter, Metadata metadata) { string pagesPath; if (PathFormatter.IsEnabled) { pagesPath = PathFormatter.GetPages(metadata); } else { pagesPath = string.Format(CultureInfo.InvariantCulture, "{0}{1}/", PathFormatter.GetCacheDirectory(), metadata.Id); } CreateArchive(archiveWriter, metadata, pagesPath); }
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); }