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); }
public void CreateArchive(IArchiveWriter archiveWriter, Metadata metadata, string pagesPath) { string archiveFilePath; if (PathFormatter.IsEnabled) { archiveFilePath = PathFormatter.GetArchive(metadata, archiveWriter); } else { archiveFilePath = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", PathFormatter.GetCacheDirectory(), metadata.Id, archiveWriter.FileExtension); } if (Directory.Exists(pagesPath)) { archiveWriter.CreateFromDirectory(pagesPath, archiveFilePath); } else { archiveWriter.CreateEmpty(archiveFilePath); } }