private void MakeManifest(string coverPageImageFile)
{
// content.opf: contains primarily the manifest, listing all the content files of the ePUB.
var manifestPath = Path.Combine(_contentFolder, "content.opf");
XNamespace opf = "http://www.idpf.org/2007/opf";
var rootElt = new XElement(opf + "package",
new XAttribute("version", "3.0"),
new XAttribute("unique-identifier", "I" + Book.ID));
// add metadata
var dcNamespace = "http://purl.org/dc/elements/1.1/";
XNamespace dc = dcNamespace;
var metadataElt = new XElement(opf + "metadata",
new XAttribute(XNamespace.Xmlns + "dc", dcNamespace),
// attribute makes the namespace have a prefix, not be a default.
new XElement(dc + "title", Book.Title),
new XElement(dc + "language", Book.CollectionSettings.Language1Iso639Code),
new XElement(dc + "identifier",
new XAttribute("id", "I" + Book.ID), "bloomlibrary.org." + Book.ID),
new XElement(opf + "meta",
new XAttribute("property", "dcterms:modified"),
new FileInfo(Storage.FolderPath).LastWriteTimeUtc.ToString("s") + "Z")); // like 2012-03-20T11:37:00Z
rootElt.Add(metadataElt);
var manifestElt = new XElement(opf + "manifest");
rootElt.Add(manifestElt);
TimeSpan bookDuration = new TimeSpan();
foreach (var item in _manifestItems)
{
var mediaType = GetMediaType(item);
var idOfFile = GetIdOfFile(item);
var itemElt = new XElement(opf + "item",
new XAttribute("id", idOfFile),
new XAttribute("href", item),
new XAttribute("media-type", mediaType));
// This isn't very useful but satisfies a validator requirement until we think of
// something better.
if (item == _navFileName)
itemElt.SetAttributeValue("properties", "nav");
if (item == coverPageImageFile)
itemElt.SetAttributeValue("properties", "cover-image");
if (Path.GetExtension(item).ToLowerInvariant() == ".xhtml")
{
var overlay = GetOverlayName(item);
if (_manifestItems.Contains(overlay))
itemElt.SetAttributeValue("media-overlay", GetIdOfFile(overlay));
}
manifestElt.Add(itemElt);
if (mediaType== "application/smil+xml")
{
// need a metadata item giving duration (possibly only to satisfy Pagina validation,
// but that IS an objective).
TimeSpan itemDuration = _pageDurations[idOfFile];
bookDuration += itemDuration;
metadataElt.Add(new XElement(opf + "meta",
new XAttribute("property", "media:duration"),
new XAttribute("refines", "#"+idOfFile),
new XText(itemDuration.ToString())));
}
}
if (bookDuration.TotalMilliseconds > 0)
{
metadataElt.Add(new XElement(opf + "meta",
new XAttribute("property","media:duration"),
new XText(bookDuration.ToString())));
}
MakeSpine(opf, rootElt, manifestPath);
}