public Book CreateFromSourceBook(Book sourceBook, string containingDestinationFolder) { string pathToFolderOfNewBook = null; Logger.WriteMinorEvent("Starting CreateFromSourceBook({0})", sourceBook.FolderPath); try { var starter = _bookStarterFactory(); pathToFolderOfNewBook = starter.CreateBookOnDiskFromTemplate(sourceBook.FolderPath, containingDestinationFolder); if (Configurator.IsConfigurable(pathToFolderOfNewBook)) { var c = new Configurator(containingDestinationFolder); if (DialogResult.Cancel == c.ShowConfigurationDialog(pathToFolderOfNewBook)) { return(null); // the template had a configuration page and they clicked "cancel" } c.ConfigureBook(BookStorage.FindBookHtmlInFolder(pathToFolderOfNewBook)); } var newBookInfo = new BookInfo(pathToFolderOfNewBook, true); // _bookInfos.Find(b => b.FolderPath == pathToFolderOfNewBook); if (newBookInfo is ErrorBookInfo) { throw ((ErrorBookInfo)newBookInfo).Exception; } Book newBook = GetBookFromBookInfo(newBookInfo); //Hack: this is a bit of a hack, to handle problems where we make the book with the suggested initial name, but the title is still something else var name = Path.GetFileName(newBookInfo.FolderPath); // this way, we get "my book 1", "my book 2", etc. newBook.SetTitle(name); Logger.WriteMinorEvent("Finished CreateFromnewBook({0})", newBook.FolderPath); Logger.WriteEvent("CreateFromSourceBook({0})", newBook.FolderPath); return(newBook); } catch (Exception) { Logger.WriteEvent("Cleaning up after error CreateFromSourceBook({0})", pathToFolderOfNewBook); //clean up this ill-fated book folder up if (!string.IsNullOrEmpty(pathToFolderOfNewBook) && Directory.Exists(pathToFolderOfNewBook)) { Directory.Delete(pathToFolderOfNewBook, true); } throw; } }