Okay I added s new html file and then changed its name to .xml and and moved it to the top.
Then tried to create a new empty html file and it barfed with this backtrace:
Code:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 com.sigil-ebook.Sigil.app 0x000000010fbf3484 Resource::GetEpubVersion() const + 4
1 com.sigil-ebook.Sigil.app 0x000000010fba0b4c Book::CreateEmptyHTMLFile(HTMLResource*) + 44
2 com.sigil-ebook.Sigil.app 0x000000010fed9072 BookBrowser::AddNewHTML() + 98
3 org.qt-project.QtCore 0x000000011398bb4c QMetaObject::activate(QObject*, int, int, void**) + 3020
...
And the routine in question: CreateEmptyHTMLFile calls CreateNewHTMLFile almost immediately ...
Code:
HTMLResource *Book::CreateNewHTMLFile()
{
TempFolder tempfolder;
QString fullfilepath = tempfolder.GetPath() + "/" + GetFirstUniqueSectionName();
Utility::WriteUnicodeTextFile(PLACEHOLDER_TEXT, fullfilepath);
HTMLResource *html_resource = qobject_cast<HTMLResource *>(m_Mainfolder->AddContentFileToFolder(fullfilepath));
SetModified(true);
return html_resource;
}
The call to GetFirstUniqueSectionName actually defaults to use the same extension of the first file in the list (in this case a .xml file not an xhtml or html file).
The problem is then that raw xml files when added to FolderKeeper are not recognized as an html resource and instead is recognized as a misc xml resource since there is no mimetype passed along.
Code:
QString Book::GetFirstUniqueSectionName(QString extension)
{
// If not files just return the default first name
QList<HTMLResource *> html_resources = m_Mainfolder->GetResourceTypeList<HTMLResource>(true);
if (html_resources.count() < 1) {
return FIRST_SECTION_NAME;
}
// Get the extension of the current file
QString first_html_file = html_resources.first()->Filename();
QString first_html_filename = first_html_file.left(first_html_file.lastIndexOf("."));
if (extension.isEmpty()) {
extension = first_html_file.right(first_html_file.length() - first_html_file.lastIndexOf("."));
// If no extension use the default first name extension
if (extension.isEmpty()) {
extension = FIRST_SECTION_NAME;
extension = extension.right(extension.length() - extension.lastIndexOf("."));
}
}
QString filename = FIRST_SECTION_PREFIX + extension;
return m_Mainfolder->GetUniqueFilenameVersion(filename);
}
And then AddContentToFodler creates an miscellaneous XML resource object and that can not be cast to an HTMLResource *.
So we need to do a number of things in Book.cpp and FolderKeeper.cpp:
1. Teach it to treat files with pure xml extensions to default to xhtml files unless a specific mimetype is passed in that would indicate some other xml file.
2. When creating new html resources/files, we should pass in the correct mimetype so that AddContentToFolder in FolderKeeper actually knows we want a xhtml file regardless of the extension.
This may happen in a lot of places in the code base where empty xhtml files are created (such as the nav, toc.xhtml, etc) so we should search the code to handle that case and not rely on the file extension since it can be flakey.
I am away from my computer almost all day today, so I will try to fix this tomrrow evening in master. I think the same problem happens when splitting files because they start with a new blank xhtml file also.