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 void SetSong(SearchSong song) { if (song == null) { return; } CurrentSong = BookManager.LoadSong(song.Key); SearchResults = null; SelectedSearchSong = null; SearchString = null; }
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); } } }
public void SetSong(SearchSong song) { if(song == null) { int x; if (IsSearching && SearchString.Length <= 3 && SearchString.All(Char.IsDigit) && int.TryParse(SearchString, out x) && x > 0) { string fmt = "000"; string songNumber = x.ToString(fmt); string bookKey; string bookTitle; if (CurrentBook != null) { bookKey = CurrentBook.Key; bookTitle = CurrentBook.Title; } else { bookKey = BookManager.Books[0].Key; bookTitle = BookManager.Books[0].Title; } CurrentSong = new Song("No Song At This Index" + Environment.NewLine + "=" + Environment.NewLine + "You can press the edit key to create a new song", bookKey + "/" + bookTitle + songNumber + ".TXT"); } return; } CurrentSong = BookManager.LoadSong(song.Key); CurrentSong.BookNumber = song.BookNumber; SearchResults = null; SelectedSearchSong = null; SearchString = null; }
public void SetCurrentBook(int sequence) { if (BookManager.Books.Count >= sequence) { var potentialBook = BookManager.Books[sequence - 1]; if (potentialBook == CurrentBook) CurrentBook = null; else { CurrentBook = potentialBook; SelectedSearchSong = new SearchSong(); SelectedSearchSong.Book = CurrentBook.Title; Console.WriteLine(SelectedSearchSong.BookNumberAndTitle); } } }