public void Run() { var libraryDir = String.IsNullOrWhiteSpace(_libraryDir) ? Directory.GetCurrentDirectory() : _libraryDir; var outputDir = String.IsNullOrWhiteSpace(_outputDir) ? Path.Combine(Directory.GetCurrentDirectory(), "Extracted Photos") : _outputDir; var dbPath = Path.Combine(libraryDir, "iPhotoMain.db"); if (!File.Exists(dbPath)) { Console.WriteLine($"File '{dbPath}' not found."); return; } if (Directory.Exists(outputDir)) { Console.Write($"Warning: directory '{outputDir}' already exists. Continue (y/n)? "); var response = Console.ReadLine().Trim().ToLower(); if (response != "y" && response != "yes") { return; } } Directory.CreateDirectory(outputDir); var photoStore = new PhotoStore(dbPath); List <Photo> photos = photoStore.GetAllPhotos(); Dictionary <string, List <Photo> > albums = photos .GroupBy(p => p.AlbumName) .ToDictionary(g => g.Key, g => g.ToList()); Console.WriteLine($"Found {albums.Keys.Count} albums."); var counter = 1; foreach (string album in albums.Keys) { var albumPhotos = albums[album]; var s = albumPhotos.Count == 1 ? "" : "s"; Console.WriteLine($"[{counter}/{albums.Keys.Count}] Extracting album '{album}' " + $"({albumPhotos.Count} photo{s})..."); ExtractAlbum(libraryDir, outputDir, album, albumPhotos); counter++; } Console.WriteLine("Done."); }
public void Run() { var libraryDir = String.IsNullOrWhiteSpace(_libraryDir) ? Directory.GetCurrentDirectory() : _libraryDir; var outputDir = String.IsNullOrWhiteSpace(_outputDir) ? Directory.GetCurrentDirectory() : _outputDir; var dbPath = Path.Combine(libraryDir, "iPhotoMain.db"); if (!File.Exists(dbPath)) { Console.WriteLine($"File '{dbPath}' not found."); return; } var photoStore = new PhotoStore(dbPath); List <Photo> photos = photoStore.GetAllPhotos(); Dictionary <string, List <Photo> > albums = photos .GroupBy(p => p.AlbumName) .ToDictionary(g => g.Key, g => g.ToList()); Console.WriteLine(_outputDir); string album; for (int i = 0; i < albums.Keys.Count - 1; i++) { album = albums.Keys.ElementAt(i); DrawAlbumTree(album, albums[album], false); } album = albums.Keys.Last(); DrawAlbumTree(album, albums[album], true); }