Browse Source

Improve behavior on url without scheme

pull/2/head
tomleb 5 years ago
parent
commit
11d626d99a
  1. 25
      src/main.cpp

25
src/main.cpp

@ -1,11 +1,13 @@ @@ -1,11 +1,13 @@
#include "CommandLineParams.h"
#include "graphics/opengl/Window.h"
#include "html/HTMLParser.h"
#include "Log.h"
#include "URL.h"
#include "WebResource.h"
#include <ctime>
#include <iostream>
#include "WebResource.h"
#include "CommandLineParams.h"
#include "URL.h"
#include "Log.h"
#include <sys/stat.h>
const std::unique_ptr<Window> window = std::make_unique<Window>();
//URL currentURL;
@ -32,6 +34,12 @@ bool isAbsolutePath(const std::string s) { @@ -32,6 +34,12 @@ 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;
}
int main(int argc, char *argv[]) {
if (argc == 1) {
std::cout << "./netrunner <url|file.html> [-log <error|warning|notice|info|debug>]" << std::endl;
@ -47,8 +55,13 @@ int main(int argc, char *argv[]) { @@ -47,8 +55,13 @@ int main(int argc, char *argv[]) {
if (isAbsolutePath(rawUrl)) {
rawUrl = "file://" + rawUrl;
} else {
rawUrl = "file://" + std::string(getenv("PWD")) + '/' + rawUrl;
std::cout << rawUrl << std::endl;
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;
}
}
}

Loading…
Cancel
Save