diff options
Diffstat (limited to 'c/data.cpp')
-rw-r--r-- | c/data.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -11,16 +11,15 @@ #include "util.h" #include "win.h" -static Unique<HINTERNET, InternetCloseHandle> s_hi = - InternetOpenW(L"Episode Browser", INTERNET_OPEN_TYPE_DIRECT, nullptr, nullptr, 0); - -Unique<htmlParserCtxtPtr, xmlFreeParserCtxt> RemoteParserCtxt(const wchar_t* wszUrl, const char* szUrl) +UniqueOk<htmlParserCtxtPtr, xmlFreeParserCtxt> RemoteParserCtxt(const wchar_t* wszUrl, const char* szUrl) { - if (s_hi.Bad(0)) - throw Win32Error(); + static Unique<HINTERNET, InternetCloseHandle> hi = + InternetOpenW(L"Episode Browser", INTERNET_OPEN_TYPE_DIRECT, nullptr, nullptr, 0); + if (hi.Bad(0)) + throw Win32Error(); Unique<HINTERNET, InternetCloseHandle> hiUrl = InternetOpenUrlW( - s_hi.v, wszUrl, nullptr, 0, INTERNET_FLAG_NO_UI, 0); + hi.v, wszUrl, nullptr, 0, INTERNET_FLAG_NO_UI, 0); if (hiUrl.Bad(0)) throw InternetError(); @@ -81,7 +80,7 @@ bool WcharsFromXmlchars(wchar_t (&dst)[N], Unique<xmlChar*, XmlFree> utf8) * shared byte. At any given time, only a single fetch thread may be * performing work. */ -enum Signal +enum Signal : unsigned char { READY = 1<<0, /* Main -> fetch: start working! */ DONE = 1<<1, /* Fetch -> main: work is done. */ @@ -161,7 +160,7 @@ void FetchData(unsigned char* sig) * specific XPath query. This is fragile theoretically, but * unlikely to break practically. */ - Unique<htmlParserCtxtPtr, xmlFreeParserCtxt> ctx = + UniqueOk<htmlParserCtxtPtr, xmlFreeParserCtxt> ctx = RemoteParserCtxt(L"https://www.detectiveconanworld.com/wiki/Anime", "https://www.detectiveconanworld.com/wiki/Anime"); @@ -251,6 +250,9 @@ void FetchScreenwriters(unsigned char* sig) const wchar_t prefix[] = L"https://www.detectiveconanworld.com"; wchar_t url[256]; Wcscpy(url, prefix); + + Unique<xmlXPathContextPtr, xmlXPathFreeContext> xpathCtx; + Unique<xmlXPathObjectPtr, xmlXPathFreeObject> xpathObj; for (iLast++; iLast < iMax; iLast++) { if (*sig & ABORT) return; @@ -265,13 +267,12 @@ void FetchScreenwriters(unsigned char* sig) /* Retrieve screenwriter from HTML. */ - Unique<htmlParserCtxtPtr, xmlFreeParserCtxt> ctx = RemoteParserCtxt(url, nullptr); - Unique<xmlXPathContextPtr, xmlXPathFreeContext> xpathCtx = xmlXPathNewContext(ctx.v->myDoc); + UniqueOk<htmlParserCtxtPtr, xmlFreeParserCtxt> ctx = RemoteParserCtxt(url, nullptr); + xpathCtx = xmlXPathNewContext(ctx.v->myDoc); if (xpathCtx.Bad(0)) throw XmlError(); - Unique<xmlXPathObjectPtr, xmlXPathFreeObject> xpathObj = - xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>( + xpathObj = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>( "//th[contains(text(), 'Screenplay:')]/following-sibling::td"), xpathCtx.v); if (xpathObj.Bad(0)) |