|
|
|
@ -46,45 +46,52 @@ bool fileExists(const std::string s) {
@@ -46,45 +46,52 @@ bool fileExists(const std::string s) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
|
// no longer require a URL
|
|
|
|
|
/*
|
|
|
|
|
if (argc == 1) { |
|
|
|
|
std::cout << "./netrunner <url|file.html> [-log <error|warning|notice|info|debug>]" << std::endl; |
|
|
|
|
std::cout << "./netrunner [http://host.tld/|/path/to/file.html] [-log <error|warning|notice|info|debug>]" << std::endl; |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
std::cout << "/g/ntr - NetRunner build " << __DATE__ << std::endl; |
|
|
|
|
|
|
|
|
|
initCLParams(argc, argv); |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//logDebug() << "pre URL parse [" << url << "]" << std::endl;
|
|
|
|
|
window->currentURL=URL(rawUrl); |
|
|
|
|
logDebug() << "loading [" << window->currentURL << "]" << std::endl; |
|
|
|
|
|
|
|
|
|
if (!setWindowContent(window->currentURL)) { |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (!glfwWindowShouldClose(window->window)) { |
|
|
|
|
//const std::clock_t begin = clock();
|
|
|
|
|
window->render(); |
|
|
|
|