Advertisement
willyb321

Untitled

Sep 24th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.51 KB | None | 0 0
  1. 'use strict';
  2. const path = require('path');
  3. const os = require('os');
  4. const fs = require('fs.extra');
  5. const electron = require('electron');
  6. const tableify = require('tableify');
  7. const {dialog} = require('electron');
  8. const LineByLineReader = require('line-by-line');
  9. const tmp = require('tmp');
  10. var html;
  11. const JSONParsed = [];
  12. var HTMLDone = [];
  13. const logPath = path.join(os.homedir(), 'Saved Games', 'Frontier Developments', 'Elite Dangerous');
  14. const app = electron.app;
  15. let loadFile;
  16. let win;
  17. // adds debug features like hotkeys for triggering dev tools and reload
  18. require('electron-debug')();
  19. // prevent window being garbage collected
  20. let mainWindow;
  21. function createMainWindow() {
  22. win = new electron.BrowserWindow({
  23. width: 600,
  24. height: 400
  25. });
  26.  
  27. win.on('closed', onClosed);
  28.  
  29. // menu functions be here
  30. }
  31. function onClosed() {
  32. // dereference the window
  33. // for multiple windows store them in an array
  34. mainWindow = null;
  35. }
  36. function funcLoad() {
  37. loadFile = dialog.showOpenDialog({properties: ['openFile',
  38. {defaultPath: logPath}]});
  39. if (/\.[log]+$/i.test(loadFile) === true) {
  40. fs.writeFile(`${process.resourcesPath}/index2.html`, '', err => {
  41. if (err) {
  42. return console.log(err);
  43. }
  44. });
  45. readLine();
  46. win.loadURL(`file:///${loadFile}`);
  47. } else {
  48. console.log('Please load a .log file.');
  49. }
  50. }
  51. function readLine() {
  52. const loadPls = loadFile;
  53. const lr = new LineByLineReader(loadPls[0]);
  54.  
  55. lr.on('error', err => {
  56. return console.log(err);
  57. });
  58.  
  59. lr.on('line', line => {
  60. const lineParse = JSON.parse(line);
  61. JSONParsed.push(lineParse);
  62. const html = tableify(lineParse) + '<hr>';
  63. fs.appendFile(`${process.resourcesPath}/index2.html`, html, err => {
  64. if (err) {
  65. return console.log(err);
  66. }
  67. });
  68. });
  69. fs.appendFile(`${process.resourcesPath}/index2.html`, '<script src="https://use.fontawesome.com/a39359b6f9.js"></script><style>body {padding: 0; margin: 0; } body {background-color: #313943; color: #bbc8d8; font-family: \'Lato\'; font-size: 22px; font-weight: 500; line-height: 36px; margin-bottom: 36px; text-align: center; } header {position: absolute; width: 500px; height: 250px; top: 50%; left: 50%; margin-top: -125px; margin-left: -250px; text-align: center; } header h1 {font-size: 60px; font-weight: 100; margin: 0; padding: 0; } #grad {background: -webkit-linear-gradient(left, #5A3F37 , #2C7744); /* For Safari 5.1 to 6.0 */ background: -o-linear-gradient(right, #5A3F37 , #2C7744); /* For Opera 11.1 to 12.0 */ background: -moz-linear-gradient(right,#5A3F37 , #2C7744); /* For Firefox 3.6 to 15 */ background: linear-gradient(to right, #5A3F37 , #2C7744); /* Standard syntax */ } hr {color: red; }</style><link href="https://fonts.googleapis.com/css?family=Lato:400,400italic,700" rel="stylesheet" type="text/css">', err => {
  70. if (err) {
  71. return console.log(err);
  72. }
  73. });
  74. lr.on('end', () => {
  75. console.log('done!');
  76. console.log('The file was saved!');
  77. win.loadURL(`file://${process.resourcesPath}/index2.html`);
  78. // win.loadURL(`file://${process.resourcesPath}/index2.html`);
  79. });
  80. return win;
  81. }
  82. function readLineMemory() {
  83. // var html = '';
  84. loadFile = dialog.showOpenDialog({properties: ['openFile']});
  85. console.log(loadFile);
  86. var lr = new LineByLineReader(loadFile[0]);
  87. lr.on('error', err => {
  88. return console.log(err);
  89. });
  90. lr.on('line', function (line) {
  91. // var html = '';
  92. const lineParse = JSON.parse(line);
  93. JSONParsed.push(lineParse);
  94. let htmlTabled = tableify(lineParse) + '<hr>';
  95. html = html + htmlTabled;
  96. });
  97. lr.on('end', function () {
  98. // html = html
  99. html = 'data:text/html,' + html;
  100. });
  101. return html;
  102. }
  103. function readLineMemoryTest() {
  104. return new Promise(function (resolve, reject) {
  105. let html = '';
  106. const loadFile = dialog.showOpenDialog({properties: ['openFile']});
  107. const lr = new LineByLineReader(loadFile[0]);
  108. lr.on('error', err => {
  109. reject(err);
  110. })
  111. .on('line', function (line) { // called every line
  112. const lineParse = JSON.parse(line);
  113. JSONParsed.push(lineParse);
  114. let htmlTabled = tableify(lineParse) + '<hr>';
  115. html = html + htmlTabled;
  116. })
  117. .on('end', function () { // called when file is read fully
  118. html = 'data:text/html,' + html;
  119. resolve(html);
  120. });
  121. });
  122. }
  123.  
  124.  
  125. // cleanupCallback();
  126. // var htmlReturn = html
  127. function test() {
  128. var willy = readLineMemoryTest();
  129. console.log(willy)
  130. win.loadURL(willy);
  131. }
  132. function funcSave() {
  133. dialog.showSaveDialog(fileName => {
  134. if (fileName === undefined) {
  135. console.log('You didn\'t save the file');
  136. return;
  137. }
  138. // fileName is a string that contains the path and filename created in the save file dialog.
  139. fs.copy(`${process.resourcesPath}/index2.html`, fileName, err => {
  140. if (err) {
  141. console.log(err.message);
  142. }
  143. });
  144. }
  145. );
  146. }
  147. function funcSaveJSON() {
  148. dialog.showSaveDialog(fileName => {
  149. if (fileName === undefined) {
  150. console.log('You didn\'t save the file');
  151. return;
  152. }
  153. const JSONParsedSave = JSON.stringify(JSONParsed);
  154. fs.writeFile(fileName, JSONParsedSave, err => {
  155. if (err) {
  156. console.log(err.message);
  157. }
  158. });
  159. });
  160. }
  161. app.on('window-all-closed', () => {
  162. if (process.platform !== 'darwin') {
  163. app.quit();
  164. }
  165. fs.writeFile(`${process.resourcesPath}/index2.html`, '', err => {
  166. if (err) {
  167. return console.log(err);
  168. }
  169. });
  170. });
  171. app.on('activate', () => {
  172. if (!mainWindow) {
  173. mainWindow = createMainWindow();
  174. }
  175. });
  176.  
  177. app.on('ready', () => {
  178. mainWindow = createMainWindow();
  179. });
  180.  
  181. const {Menu} = require('electron');
  182.  
  183. const template = [
  184. {
  185. label: 'File',
  186. submenu: [
  187. {label: 'Save as HTML', click: funcSave},
  188. {label: 'Save as JSON', click: funcSaveJSON},
  189. {label: 'Load', click: funcLoad},
  190. {label: 'test', click: test}
  191.  
  192. ]
  193. },
  194. {
  195. label: 'Edit',
  196. submenu: [
  197. {
  198. role: 'selectall'
  199. }
  200. ]
  201. },
  202. {
  203. label: 'View',
  204. submenu: [
  205. {
  206. label: 'Reload',
  207. accelerator: 'CmdOrCtrl+R',
  208. click(item, focusedWindow) {
  209. if (focusedWindow) {
  210. focusedWindow.reload();
  211. }
  212. }
  213. },
  214. {
  215. role: 'togglefullscreen'
  216. }
  217. ]
  218. },
  219. {
  220. role: 'window',
  221. submenu: [
  222. {
  223. role: 'minimize'
  224. },
  225. {
  226. role: 'close'
  227. }
  228. ]
  229. },
  230. {
  231. role: 'help',
  232. submenu: [
  233. {
  234. label: 'Learn More',
  235. click() {
  236. require('electron').shell.openExternal('http://electron.atom.io');
  237. }
  238. }
  239. ]
  240. }
  241. ];
  242.  
  243. if (process.platform === 'darwin') {
  244. const name = require('electron').remote.app.getName();
  245.  
  246. template.unshift({
  247. label: name,
  248. submenu: [
  249. {
  250. role: 'about'
  251. },
  252. {
  253. type: 'separator'
  254. },
  255. {
  256. role: 'services',
  257. submenu: []
  258. },
  259. {
  260. type: 'separator'
  261. },
  262. {
  263. role: 'hide'
  264. },
  265. {
  266. role: 'hideothers'
  267. },
  268. {
  269. role: 'unhide'
  270. },
  271. {
  272. type: 'separator'
  273. },
  274. {
  275. role: 'quit'
  276. }
  277. ]
  278. });
  279. // Edit menu.
  280. template[1].submenu.push(
  281. {
  282. type: 'separator'
  283. },
  284. {
  285. label: 'Speech',
  286. submenu: [
  287. {
  288. role: 'startspeaking'
  289. },
  290. {
  291. role: 'stopspeaking'
  292. }
  293. ]
  294. }
  295. );
  296. // Window menu.
  297. template[3].submenu = [
  298. {
  299. label: 'Close',
  300. accelerator: 'CmdOrCtrl+W',
  301. role: 'close'
  302. },
  303. {
  304. label: 'Minimize',
  305. accelerator: 'CmdOrCtrl+M',
  306. role: 'minimize'
  307. },
  308. {
  309. label: 'Zoom',
  310. role: 'zoom'
  311. },
  312. {
  313. type: 'separator'
  314. },
  315. {
  316. label: 'Bring All to Front',
  317. role: 'front'
  318. }
  319. ];
  320. }
  321.  
  322. const menu = Menu.buildFromTemplate(template);
  323. Menu.setApplicationMenu(menu);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement