From 002420110de626b6411bc28c1a6ab149f43d9531 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Wed, 24 Sep 2014 13:03:18 +0100 Subject: [PATCH] Fixed loading of missing resources. Fixes #305. --- src/gui/scheme.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/gui/scheme.cpp b/src/gui/scheme.cpp index b37215da..9a72eddd 100644 --- a/src/gui/scheme.cpp +++ b/src/gui/scheme.cpp @@ -47,13 +47,22 @@ namespace loot { // Get the file from the custom URL. string file = (g_path_l10n / string(request->GetURL()).substr(12)).string(); - // Load the file into a CEF stream. - CefRefPtr stream = CefStreamReader::CreateForFile(file); - BOOST_LOG_TRIVIAL(trace) << "Loaded file: " << file; - CefResponse::HeaderMap headers; headers.emplace("Access-Control-Allow-Origin", "*"); - return new CefStreamResourceHandler(200, "OK", "application/octet-stream", headers, stream); + if (boost::filesystem::exists(file)) { + // Load the file into a CEF stream. + CefRefPtr stream = CefStreamReader::CreateForFile(file); + BOOST_LOG_TRIVIAL(trace) << "Loaded file: " << file; + + return new CefStreamResourceHandler(200, "OK", "application/octet-stream", headers, stream); + } + else { + BOOST_LOG_TRIVIAL(trace) << "File " << file << " not found, sending 404."; + + const string error404 = "File not found."; + CefRefPtr stream = CefStreamReader::CreateForData((void*)error404.c_str(), error404.size()); + return new CefStreamResourceHandler(404, "Not Found", "application/octet-stream", headers, stream); + } } } \ No newline at end of file