public static void Initialize() { Cursor.Current = Cursors.WaitCursor; Books = new List<Book>(); var dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/books"; if(Settings.Default.Path == "") Settings.Default.Path = dir; Console.WriteLine(dir); var bookDirList = Directory.GetDirectories(Settings.Default.Path); foreach (var bookdir in bookDirList) { var book = new Book { Key = bookdir, Title = Path.GetFileName(bookdir) }; if (Settings.Default.BookOrder != null && Settings.Default.BookOrder.Contains(book.Title) && Books.Count > Settings.Default.BookOrder.IndexOf(book.Title)) { Books.Insert(Settings.Default.BookOrder.IndexOf(book.Title), book); } else Books.Add(book); LoadSongs(book.Key, book); Console.WriteLine("Loaded Book"); } Cursor.Current = Cursors.Default; }
private static void LoadSongs(string path, Book book) { book.Songs = new List<SearchSong>(); var songsList = Directory.GetFiles(path); foreach (var s in songsList) { var song = new SearchSong(); song.Key = s; string fileName = Path.GetFileName(s); if (fileName != null && fileName.Length >= 6) { song.Book = fileName.Substring(0, 3); song.Number = fileName.Substring(3, 3); } var stream = File.OpenRead(s); var sr = new StreamReader(stream); song.Title = sr.ReadLine() ?? ""; //Title is always first line sr.ReadLine(); //skip the = sign song.FirstLine = sr.ReadLine() ?? ""; sr.Close(); book.Songs.Add(song); } }
public static void Initialize() { Books = new List<Book>(); var dir = Directory.GetCurrentDirectory() + "/books"; var bookDirList = Directory.GetDirectories(dir); foreach (var bookdir in bookDirList) { var book = new Book { Key = bookdir, Title = Path.GetFileName(bookdir) }; Books.Add(book); LoadSongs(book.Key, book); } }
private static void LoadSongs(string path, Book book) { book.Songs = new List<SearchSong>(); var songsList = Directory.GetFiles(path); foreach (var s in songsList) { if (Path.GetExtension(s).ToLower() == ".txt") { var song = new SearchSong(); song.Key = s; string fileName = Path.GetFileName(s); if (fileName != null && fileName.Length >= 6) { song.Book = fileName.Substring(0, 3); song.Number = fileName.Substring(3, 3).TrimStart(new char[] { '0' }); } var stream = File.OpenRead(s); var sr = new StreamReader(stream); song.Title = GetTitle(sr); sr.ReadLine(); //skip the = sign song.FirstLine = GetFirstLine(sr); sr.Close(); book.Songs.Add(song); } } }