Skip to content
Snippets Groups Projects
Commit 9bb645ec authored by Odilitime's avatar Odilitime
Browse files

don't require an URL on start

parent 514fc965
No related branches found
No related tags found
No related merge requests found
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment