static void Main(string[] args) { HtmlReader htmlReader = new HtmlReader(); if (args.Count() < 2) { Usage(); } else { string option = args[0]; string masterFilename = args[1]; if (option.Equals("page", StringComparison.CurrentCultureIgnoreCase)) { string diagnostic = null; SlideShow slideShow = htmlReader.ReadSlideShow(masterFilename, out diagnostic); if (slideShow == null) { Console.WriteLine("Converter: failed to read slide show in " + masterFilename); Console.WriteLine(diagnostic); Usage(); } // Determine the name of the XML output file from the name of the HTML input file string directory = GetDirectory(masterFilename); string baseFilename = GetBaseFilename(masterFilename); string xmlFilename = directory + "\\" + baseFilename + ".xml"; slideShow.Save(xmlFilename); } else if (option.Equals("album", StringComparison.CurrentCultureIgnoreCase)) { string diagnostic = null; if (htmlReader.ReadAlbum(masterFilename, out diagnostic) == null) { Console.WriteLine("Converter: failed to read album in " + masterFilename); Console.WriteLine(diagnostic); Usage(); } } else { Usage(); } } }
void convertMenuItem_Click(object sender, EventArgs e) { // It should only be possible to invoke the Convert menu item for an HTML // file, but we will check to make sure ListView.SelectedListViewItemCollection selectedItems = this.listView.SelectedItems; if (selectedItems.Count == 1) { string filename = selectedItems[0].Text; if (IsHtml(new FileInfo(filename))) { // Parse HTML file string currentDirectory = TreePath(treeView.SelectedNode); string htmlPath = currentDirectory + "\\" + filename; HtmlReader htmlReader = new HtmlReader(); string diagnostic = null; string baseFilename = Path.GetFileNameWithoutExtension(filename); string xmlFilename = Path.Combine(currentDirectory, baseFilename + ".xml"); if (baseFilename.Equals("yearframe", StringComparison.CurrentCultureIgnoreCase)) { // Create album from parsing Album album = htmlReader.ReadAlbum(htmlPath, out diagnostic); if (album == null) { MessageBox.Show("Failed to read HTML file\n" + diagnostic, "PhotoStudio"); } else { // Save album to XML file xmlFilename = currentDirectory + "\\album.xml"; album.Save(xmlFilename); MessageBox.Show("Album converted", "PhotoStudio"); } } else if (baseFilename.Equals("events", StringComparison.CurrentCultureIgnoreCase)) { // Create event list from parsing EventList events = htmlReader.ReadEvents(htmlPath, out diagnostic); if (events == null) { MessageBox.Show("Failed to read HTML file\n" + diagnostic, "PhotoStudio"); } else { // Save event list to XML file events.Save(true); MessageBox.Show("Events converted", "PhotoStudio"); } } else { // Create slide show from parsing SlideShow slideShow = htmlReader.ReadSlideShow(htmlPath, out diagnostic); if (slideShow == null) { MessageBox.Show("Failed to read HTML file\n" + diagnostic, "PhotoStudio"); } else { // Save slide show to XML file slideShow.Save(xmlFilename); MessageBox.Show("SlideShow converted", "PhotoStudio"); } } // Refresh display (should be a new XML file) ListFolderContents(new DirectoryInfo(currentDirectory)); } } }