diff options
Diffstat (limited to 'c/data.cpp')
-rw-r--r-- | c/data.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -70,7 +70,7 @@ static inline void XmlFree(void* p) { xmlFree(p); } using XmlCharPtr = XmlPtr<XmlFree, xmlChar*>; template <size_t N> -bool WcharsFromXmlchars(wchar_t (&dst)[N], XmlCharPtr utf8) +bool WcharsFromXmlchars(wchar_t (&dst)[N], XmlCharPtr utf8) noexcept { /* Truncate if source is larger than destination. */ int lenUtf8 = xmlStrlen(utf8); @@ -94,7 +94,7 @@ bool WcharsFromXmlchars(wchar_t (&dst)[N], XmlCharPtr utf8) return MultiByteToWideChar(CP_UTF8, 0, src, cchNarrow, dst, cchWide); } -void FetchData(bool* bDone) +void FetchData() { LIBXML_TEST_VERSION; @@ -123,7 +123,9 @@ void FetchData(bool* bDone) xmlNodeSetPtr nodes = xpathObj->nodesetval; int cNodes = nodes? nodes->nodeNr: 0; - printf("%d nodes\n", cNodes); + if (!cNodes) + throw std::runtime_error("could not find remote episode information"); + for (int i = 0; i < cNodes; i++) { extern FileView<ElvDataA> g_fvElv; extern FileView<DlvDataA> g_fvDlv; @@ -153,8 +155,18 @@ void FetchData(bool* bDone) /* Get wiki URL. */ const xmlNodePtr nodeLink = xmlFirstElementChild(nodeTitle); if (nodeLink) - WcharsFromXmlchars(d.wiki, xmlGetProp(nodeLink, (const xmlChar*)"href")); + WcharsFromXmlchars(d.wiki, + xmlGetProp(nodeLink, reinterpret_cast<const xmlChar*>("href"))); } +} - *bDone = true; +void WaitFetchData(bool* bDone) noexcept +{ + try { + FetchData(); + *bDone = true; + } catch (...) { + *bDone = true; + ShowException(L"Remote data could not be fetched due to %s: %s", L"Error", MB_ICONWARNING); + } } |