private void SetupEpubControlContent()
{
_model.StageEpub(_publishWithoutAudio);
var fileLocator = _model.BookSelection.CurrentSelection.GetFileLocator();
var root = fileLocator.LocateDirectoryWithThrow("Readium");
var tempFolder = Path.GetDirectoryName(_model.StagingDirectory);
// This is kludge. I hope it can be improved. To make a preview we currently need all the Readium
// files in a folder that is a parent of the staging folder containing the book content.
// This allows us to tell Readium about the book by passing the name of the folder using the ?ePUB=
// URL parameter. It doesn't work to use the original Readium file and make the parameter a full path.
// It's possible that there is some variation that would work, e.g., make the param a full file:/// url
// to the book folder. It's also possible we could get away with only copying the HTML file itself,
// if we modified it to have localhost: links to the JS and CSS. Haven't tried this yet. The current
// approach at least works.
DirectoryUtilities.CopyDirectoryContents(root, tempFolder);
var englishTemplatePath = fileLocator.LocateFileWithThrow("ePUB" + Path.DirectorySeparatorChar + "bloomEpubPreview-en.html");
var localizedTemplatePath = BloomFileLocator.GetBestLocalizedFile(englishTemplatePath);
var audioSituationClass = "noAudioAvailable";
if(_publishWithoutAudio)
audioSituationClass = "haveAudioButNotMakingTalkingBook";
else if(_model.BookHasAudio)
audioSituationClass = "isTalkingBook";
var htmlContents = RobustFile.ReadAllText(localizedTemplatePath)
.Replace("{EPUBFOLDER}", Path.GetFileName(_model.StagingDirectory))
.Replace("_AudioSituationClass_", audioSituationClass);
var previewHtmlInstancePath = Path.Combine(tempFolder, "bloomEpubPreview.htm");
RobustFile.WriteAllText(previewHtmlInstancePath, htmlContents);
_epubPreviewBrowser.Navigate(previewHtmlInstancePath.ToLocalhost(), false);
}