aboutsummaryrefslogtreecommitdiff
path: root/c/data.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c/data.cpp')
-rw-r--r--c/data.cpp69
1 files changed, 34 insertions, 35 deletions
diff --git a/c/data.cpp b/c/data.cpp
index 771e6fb..e260209 100644
--- a/c/data.cpp
+++ b/c/data.cpp
@@ -6,46 +6,45 @@
#include <libxml/xpath.h>
#include "data.h"
+#include "win.h"
struct InternetFile
{
- InternetFile(const wchar_t* url);
- ~InternetFile();
- DWORD Read(void* buf, DWORD cb);
- HINTERNET hi;
- HINTERNET hiUrl;
-};
+ InternetFile(const wchar_t* url)
+ {
+ hi = InternetOpen(L"Episode Browser",
+ INTERNET_OPEN_TYPE_DIRECT, nullptr, nullptr,
+ /*INTERNET_FLAG_ASYNC*/0);
+ if (!hi)
+ throw Win32Error{};
+
+ hiUrl = InternetOpenUrl(hi, url,
+ nullptr, 0, INTERNET_FLAG_NO_UI, 0);
+ if (!hiUrl) {
+ DWORD e = GetLastError();
+ InternetCloseHandle(hi);
+ throw InternetError(e);
+ }
+ }
-InternetFile::InternetFile(const wchar_t* url)
-{
- hi = InternetOpen(L"Episode Browser",
- INTERNET_OPEN_TYPE_DIRECT, nullptr, nullptr,
- /*INTERNET_FLAG_ASYNC*/0);
- if (!hi)
- throw Win32Error{};
-
- hiUrl = InternetOpenUrl(hi, url,
- nullptr, 0, INTERNET_FLAG_NO_UI, 0);
- if (!hiUrl) {
+ ~InternetFile()
+ {
+ InternetCloseHandle(hiUrl);
InternetCloseHandle(hi);
- throw Win32Error{};
}
-}
-InternetFile::~InternetFile()
-{
- InternetCloseHandle(hiUrl);
- InternetCloseHandle(hi);
-}
+ DWORD Read(void* buf, DWORD cb)
+ {
+ DWORD cbRead;
+ if (InternetReadFile(hiUrl, buf, cb, &cbRead))
+ return cbRead;
+ else
+ throw InternetError{};
+ }
-DWORD InternetFile::Read(void* buf, DWORD cb)
-{
- DWORD cbRead;
- if (InternetReadFile(hiUrl, buf, cb, &cbRead))
- return cbRead;
- else
- throw Win32Error{};
-}
+ HINTERNET hi;
+ HINTERNET hiUrl;
+};
template <auto F, typename T>
struct XmlPtr
@@ -98,8 +97,8 @@ void FetchData()
{
LIBXML_TEST_VERSION;
- InternetFile inf{L"https://www.detectiveconanworld.com/wiki/Anime"};
- //InternetFile inf{L"file://C:/Users/John/Desktop/dcw.html"};
+ InternetFile inf(L"https://www.detectiveconanworld.com/wiki/Anime");
+ //InternetFile inf(L"file://C:/Users/John/Desktop/dcw.html");
char buf[1024];
HtmlParserCtxtPtr ctxt = htmlCreatePushParserCtxt(nullptr, nullptr,
@@ -167,6 +166,6 @@ void WaitFetchData(bool* bDone) noexcept
*bDone = true;
} catch (...) {
*bDone = true;
- ShowException(L"Remote data could not be fetched due to %s: %s", L"Error", MB_ICONWARNING);
+ ShowException(L"Remote data could not be fetched due to an error: %s", L"Error", MB_ICONWARNING);
}
}