You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.cpp 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #include <ctime>
  2. #include <iostream>
  3. #include <sys/stat.h>
  4. #include <string.h>
  5. #include "app/browser/Browser.h"
  6. #include "environment/Environment.h"
  7. #include "interfaces/components/TabbedComponent.h"
  8. #include "interfaces/components/InputComponent.h"
  9. #include "interfaces/graphical/renderers/glfw/opengl.h"
  10. #include "parsers/images/netpbm/pnm.h"
  11. #include "platform/tlsf.h"
  12. #include "tools/CFGFileParser.h"
  13. #include "tools/CommandLineParams.h"
  14. #include "tools/Log.h"
  15. #include "tools/URL.h"
  16. #include "tools/WebResource.h"
  17. #if defined(_WIN32) && !defined(_WIN64)
  18. #define PLATFORM "i686-pc-winnt"
  19. #endif
  20. #ifdef _WIN64
  21. #define PLATFORM "amd64-pc-winnt"
  22. #endif
  23. // global
  24. // to remove this
  25. // window uses this to make windows and get window count (can be just be passed in when creating a window)
  26. // AElement uses it to getActiveDocumentComponent and navTo on that
  27. //
  28. std::unique_ptr<Browser> browser = nullptr;
  29. std::unique_ptr<BaseRenderer> renderer = nullptr;
  30. // forward declaration
  31. bool isAbsolutePath(const std::string s);
  32. bool fileExists(const std::string s);
  33. bool isAbsolutePath(const std::string s) {
  34. return (s.length() > 0 && s[0] == '/');
  35. }
  36. bool fileExists(const std::string s) {
  37. struct stat buf;
  38. return stat(s.c_str(), &buf) != -1;
  39. }
  40. extern TextRasterizerCache *rasterizerCache;
  41. #include <iostream>
  42. #include <fstream>
  43. std::ofstream assignfile;
  44. std::ofstream execfile;
  45. int main(int argc, char *argv[]) {
  46. // show help msg when "--help" appears
  47. if (argc > 1) {
  48. // has to be set up for logging before first logging call
  49. initCLParams(argc, argv);
  50. if (strcmp(argv[1], "--help")==0) {
  51. std::cout << "./netrunner [http://host.tld/|/path/to/file.html] [-log <error|warning|notice|info|debug>]" << std::endl;
  52. return 1;
  53. }
  54. }
  55. std::ofstream myfile;
  56. assignfile.open ("js_assignments.txt");
  57. execfile.open ("js_execution.txt");
  58. std::cout \
  59. << "# # ######" << std::endl \
  60. << "## # ###### ##### # # # # # # # # ###### #####" << std::endl \
  61. << "# # # # # # # # # ## # ## # # # #" << std::endl \
  62. << "# # # ##### # ###### # # # # # # # # ##### # #" << std::endl \
  63. << "# # # # # # # # # # # # # # # # #####" << std::endl \
  64. << "# ## # # # # # # # ## # ## # # #" << std::endl \
  65. << "# # ###### # # # #### # # # # ###### # #" << std::endl;
  66. #if defined(VERSION) && defined(PLATFORM)
  67. std::cout << "/g/ntr - NetRunner build " << __DATE__ << ": rev-" << VERSION << " for " << PLATFORM << std::endl;
  68. #else
  69. std::cout << "/g/ntr - NetRunner build " << __DATE__ << ": internal-dev non-Makefile build" << std::endl;
  70. #endif
  71. Environment::init();
  72. CFGFileParser *parser = new CFGFileParser("res/netrunner.cfg");
  73. BrowserConfiguration *config = new BrowserConfiguration();
  74. if (!parser) {
  75. std::cout << "no parser!" << std::endl;
  76. }
  77. if (parser->ParseText()){
  78. parser->WriteConfig(*config);
  79. }
  80. delete parser;
  81. bool jsConsole = false;
  82. std::cout << "Global Settings contains, in no particular order:\n";
  83. for ( auto it = config->Settings.begin(); it != config->Settings.end(); ++it ){
  84. std::cout << it->first << ":" << it->second << std::endl;
  85. if (it->first == "CONSOLE" && it->second == "TRUE") {
  86. jsConsole = true;
  87. }
  88. }
  89. std::cout << std::endl;
  90. renderer = std::make_unique<OpenGL>();
  91. //Environment::init();
  92. renderer->initialize();
  93. /*
  94. Rect pos;
  95. pos.x=0;
  96. pos.y=0;
  97. pos.w=1024;
  98. pos.h=640;
  99. OpenGLWindowHandle *win = renderer.createWindow("NTR", &pos, 0);
  100. if (!win) {
  101. std::cout << "Couldn't create window" << std::endl;
  102. return 0;
  103. }
  104. OpenGLTexture *blue = win->createSpriteFromColor(0x0000FFFF);
  105. if (!blue) {
  106. std::cout << "Couldn't create blue" << std::endl;
  107. return 0;
  108. }
  109. Rect dPos = { 0, 0, 512, 320 };
  110. */
  111. /*
  112. const std::shared_ptr<TextRasterizer> textRasterizer = rasterizerCache->loadFont(12, false);
  113. rasterizationRequest request;
  114. request.text = "Hello World";
  115. request.startX = 512;
  116. request.availableWidth = 1024;
  117. request.maxTextureSize = 16384;
  118. request.noWrap = true;
  119. //std::cout << "rasterizing [" << text << "] @" << rawX << " availableWidth: " << availableWidth << " sourceStartX: " << rasterStartX << " noWrap: " << noWrap << std::endl;
  120. std::shared_ptr<rasterizationResponse> response = textRasterizer->rasterize(request);
  121. textureMap textureMap;
  122. textureMap.map[0] = response->s0;
  123. textureMap.map[1] = response->t0;
  124. textureMap.map[2] = response->s1;
  125. textureMap.map[3] = response->t1;
  126. OpenGLTexture *text = win->createTextSprite(response->textureData.get(), response->textureWidth, response->textureHeight, textureMap);
  127. Rect dPos3 = { 512, 320, 512, 320};
  128. */
  129. /*
  130. RGBAPNMObject *anime = readPPM("kon32_661.pam");
  131. if (!anime) {
  132. std::cout << "Couldn't load image" << std::endl;
  133. return 0;
  134. }
  135. opengl_texture_handle *red = win->createSprite(anime->m_Ptr, anime->width, anime->height);
  136. Rect dPos2 = { 512, 320, 512, 320};
  137. */
  138. /*
  139. win->clear();
  140. win->drawSpriteBox(blue, &dPos);
  141. win->drawSpriteText(text, 0x000000FF, &dPos3);
  142. //win->drawSpriteBox(red, &dPos2);
  143. win->swapBuffers();
  144. while(1) {
  145. glfwWaitEvents(); // block until something changes
  146. }
  147. return 0;
  148. */
  149. // we need to set up OGL before we can setDOM (because component can't be constructed (currently) without OGL)
  150. // but should be after CommandLineParams incase we need to change some type of window config
  151. browser = std::make_unique<Browser>();
  152. browser->addWindow();
  153. if (!browser->windows.front().get()->window) {
  154. std::cout << "main() - unable to add a window" << std::endl;
  155. return 1;
  156. }
  157. if (jsConsole) {
  158. std::cout << "turning on JS console" << std::endl;
  159. browser->addJSDebuggerWindow();
  160. }
  161. //std::cout << "argc " << argc << std::endl;
  162. if (argc > 1) {
  163. // this isn't going to work
  164. std::string rawUrl = getCLParamByIndex(1);
  165. if (rawUrl != "-log") {
  166. // if we do this here, shouldn't we do this in parseUri too?
  167. if (rawUrl.find("://") == rawUrl.npos) {
  168. // Path should always be absolute for file://
  169. if (isAbsolutePath(rawUrl)) {
  170. rawUrl = "file://" + rawUrl;
  171. } else {
  172. auto absolutePath = std::string(getenv("PWD")) + '/' + rawUrl;
  173. if (fileExists(absolutePath)) {
  174. rawUrl = "file://" + absolutePath;
  175. } else {
  176. // Default to http if the file wasn't found
  177. rawUrl = "http://" + rawUrl;
  178. }
  179. }
  180. }
  181. //logDebug() << "pre URL parse [" << url << "]" << std::endl;
  182. //window->currentURL = URL(rawUrl);
  183. logDebug() << "loading [" << rawUrl << "]" << std::endl;
  184. TabbedComponent *tabComponent = dynamic_cast<TabbedComponent*>(browser->windows.front().get()->tabComponent.get());
  185. if (tabComponent) {
  186. tabComponent->addTab("Start Tab, Loading...");
  187. tabComponent->selectTab(tabComponent->tabs.front());
  188. // render the loading label, before we block for loading
  189. browser->render();
  190. }
  191. /*
  192. if (!setWindowContent(window->currentURL)) {
  193. return 1;
  194. }
  195. */
  196. std::shared_ptr<DocumentComponent> docComponent = browser->getActiveDocumentComponent();
  197. if (docComponent) {
  198. // now tell it to navigate somewhere
  199. docComponent->navTo(rawUrl);
  200. }
  201. } else {
  202. // be nice if we could put http:// in the address bar
  203. }
  204. }
  205. browser->loop();
  206. return 0;
  207. }