Right, here's another build (are we there yet?). Particular thanks to JSWolf for the latest feedback. This has these additions:
- the cover image and titlepage file will be attempted to be placed in the same directory structure as any detected existing images/html pages
- any inline TOC entries pointing to the old cover will be updated to point to the new cover.
- should handle encoded images/cover page names (like when they have spaces in them)
- handle the opf and ncx files being in different directories internally (not sure if this ever happens, but plugin should now cope with it)
Note the inline TOC behaviour above is different to what a calibre conversion does. During a conversion calibre scans the ebook looking for links to the existing cover from other html pages, and if found it decides to *keep* the existing cover page/image and leave links as they are. It then adds a second cover which is what you see at the front. I don't know the reasoning, it might be legacy logic, or there might be a valid reason.
I've decided for this plugin on the other hand that the presence of other html links to a cover page will not alter the decision on whether that page can be safely removed or not. (Only whether there are other images/text on that identified cover page will decide that).
The upshot being we should get cleaner, smaller epubs with a lower chance of double covers. Well until someone points out a flaw in the logic of course...