Newer
Older
#include "graphics/opengl/Window.h"
#include "html/HTMLParser.h"
#include "Log.h"
#include "URL.h"
#include "WebResource.h"
const std::unique_ptr<Window> window = std::make_unique<Window>();
//URL currentURL;
logDebug() << "main::setWindowContent - " << url << std::endl;
WebResource res = getWebResource(url);
if (res.resourceType == ResourceType::INVALID) {
logError() << "Invalid resource type: " << res.raw << std::endl;
HTMLParser parser;
const std::clock_t begin = clock();
std::shared_ptr<Node> rootNode = parser.parse(res.raw);
const std::clock_t end = clock();
logDebug() << "main::setWindowContent - Parsed document in: " << std::fixed << ((static_cast<double>(end - begin)) / CLOCKS_PER_SEC) << std::scientific << " seconds" << std::endl;
// send NodeTree to window
bool isAbsolutePath(const std::string s);
bool isAbsolutePath(const std::string s) {
return (s.length() > 0 && s[0] == '/');
}
bool fileExists(const std::string s);
bool fileExists(const std::string s) {
struct stat buf;
return stat(s.c_str(), &buf) != -1;
}
std::cout << "./netrunner [http://host.tld/|/path/to/file.html] [-log <error|warning|notice|info|debug>]" << std::endl;
std::cout << "/g/ntr - NetRunner build " << __DATE__ << std::endl;
// we need to set up OGL before we can setDOM (because component can't be constructed (currently) without OGL)
// but should be after CommandLineParams incase we need to change some type of window config
window->windowWidth = 1024;
window->windowHeight = 640;
window->init();
if (!window->window) {
return 1;
}
//std::cout << "argc " << argc << std::endl;
if (argc > 1) {
initCLParams(argc, argv);
// this isn't going to work
std::string rawUrl = getCLParamByIndex(1);
// if we do this here, shouldn't we do this in parseUri too?
if (rawUrl.find("://") == rawUrl.npos) {
// Path should always be absolute for file://
if (isAbsolutePath(rawUrl)) {
rawUrl = "file://" + rawUrl;
} else {
auto absolutePath = std::string(getenv("PWD")) + '/' + rawUrl;
if (fileExists(absolutePath)) {
rawUrl = "file://" + absolutePath;
} else {
// Default to http if the file wasn't found
rawUrl = "http://" + rawUrl;
}
}
}
//logDebug() << "pre URL parse [" << url << "]" << std::endl;
window->currentURL = URL(rawUrl);
logDebug() << "loading [" << window->currentURL << "]" << std::endl;
if (!setWindowContent(window->currentURL)) {
return 1;
}
glfwWaitEvents(); // block until something changes
//const std::clock_t end = clock();
//std::cout << '\r' << std::fixed << (((static_cast<double>(end - begin)) / CLOCKS_PER_SEC) * 1000) << std::scientific << " ms/f " << std::flush;