forked from nmrugg/UE4Launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
1071 lines (919 loc) · 26.7 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"use strict";
// Modules to control application life and create native browser window
var electron = require("electron");
var p = require("path");
var fs = require("fs");
var request = require("./libs/request-helper.js");
var loadJsonFile = require("./libs/loadJsonFile.js");
var projectsManager = require("./libs/projects.js");
var app = electron.app;
var BrowserWindow = electron.BrowserWindow;
var Menu = electron.Menu;
var ipc = electron.ipcMain;
var loginWindow;
var isLoggedIn = false;
var cookies;
var offline = false;
var assetAPI;
var cacheDir = p.join(__dirname, "cache");
var vaultPath = p.join(cacheDir, "vault.json");
var configPath = p.join(__dirname, "config.json");
var assetJsonPath = p.join(cacheDir, "assets.json");
var localAssetsPath = p.join(__dirname, "localAssets.json");
var vaultData;
var configData;
var assetsData;
var localAssetsData;
function mkdirSync(dir)
{
try {
fs.mkdirSync(dir);
} catch (e) {}
}
function loadConfig()
{
configData = loadJsonFile.sync(configPath, {});
verifyConfigData();
}
function verifyConfigData()
{
var os;
if (!configData.engines) {
configData.engines = [];
}
if (!configData.projectDirPaths || configData.projectDirPaths.length === 0) {
os = require("os");
configData.projectDirPaths = [
p.join(os.homedir(), "Unreal Projects"),
p.join(os.homedir(), "Documents", "Unreal Projects"),
];
}
}
function saveConfig(data)
{
configData = data || configData;
fs.writeFileSync(configPath, JSON.stringify(configData, "", " "));
}
function loadLocalAssets(cb)
{
loadJsonFile(localAssetsPath, [], function onload(json)
{
localAssetsData = json;
if (cb) {
cb();
}
});
}
function saveLocalAssets(cb)
{
if (!localAssetsData || !localAssetsData.length) {
fs.unlink(localAssetsPath, function ()
{
if (cb) {
cb();
}
});
} else {
fs.writeFile(localAssetsPath, JSON.stringify(localAssetsData, "", " "), function onwrite()
{
if (cb) {
cb();
}
});
}
}
/*
var menuTemplate = [
{
label: "Window Manager",
submenu: [
{ label: "create New" }
]
},
{
label : "View",
submenu : [
{ role : "reload" },
{ label : "custom reload" }
]
}
];
*/
mkdirSync(cacheDir);
loadConfig();
loadLocalAssets();
app.on("browser-window-created",function(e,window) {
window.setMenu(null);
});
// Keep a global reference of the window object, if you don"t, the window will
// be closed automatically when the JavaScript object is garbage collected.
var mainWindow;
/// Removes the top menu.
Menu.setApplicationMenu(null);
function getJson(url, options, cb)
{
/// Make requireLogin optional.
if (typeof options === "function") {
cb = options;
options = {};
}
if (typeof options.login === "undefined") {
options.login = true;
}
downloadURL(url, options, function ondownload(err, data)
{
if (!err) {
try {
data = JSON.parse(data);
} catch (e) {
return cb(e);
}
}
cb(err, data);
});
}
function downloadURL(url, options, cb)
{
var urlOpts;
var retries = 0;
var sendRequest;
/// Make requireLogin optional.
if (typeof requireLogin === "function") {
cb = options;
options = {};
}
if (options.login && !cookies) {
return loginIfNecessary(function (err)
{
if (err) {
cb(err);
} else {
downloadURL(url, options, cb);
}
});
}
urlOpts = options.urlOpts || {
url: url,
};
if (options.login) {
if (!urlOpts.headers) {
urlOpts.headers = {};
}
urlOpts.headers = {
Cookie: request._getWebCookieString(),
};
}
if (typeof urlOpts.timeout === "undefined") {
urlOpts.timeout = 30000;
}
sendRequest = function ()
{
request.get(urlOpts, function(err, res, body)
{
///TODO: Retry
if (err || !res) {
++retries;
console.error(err);
if (retries < 4) {
console.log("Retrying download (" + retries + ")");
return setTimeout(sendRequest, 1000);
}
} else if (res.statusCode >= 300) {
err = {code: res.statusCode};
}
cb(err, body);
});
};
sendRequest();
}
function login(cb)
{
var contents;
var needsToRedirect;
var redirectTimer;
var atLeastOnePageLoaded = false;
var loginURL = "https://www.epicgames.com/id/login";
var currentURL = loginURL;
/// Another url
console.log("logging in")
if (loginWindow) {
try {
loginWindow.close();
} catch (e) {}
}
isLoggedIn = false;
// Create the browser window.
loginWindow = new BrowserWindow({
width: 800,
height: 800,
/*
webPreferences: {
preload: p.join(__dirname, "preload.js")
},
*/
icon: p.join(__dirname, "ue-logo.png"),
show: true, /// Use FALSE for graceful loading
title: "Unreal Engine Launcher"
});
contents = loginWindow.webContents;
// and load the index.html of the app.
//loginWindow.loadFile("index.html")
loginWindow.loadURL(loginURL);
/*
loginWindow.removeMenu();
loginWindow.setMenuBarVisibility(false);
loginWindow.setMenu(null);
*/
//let menu = Menu.buildFromTemplate([]);
// Open the DevTools.
// loginWindow.webContents.openDevTools()
// Emitted when the window is closed.
/*
loginWindow.on("closed", function ()
{
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
*/
loginWindow.on("closed", function ()
{
if (!isLoggedIn && cb) {
console.error("Login window closed unexpectedly");
setImmediate(cb, new Error("Login window closed unexpectedly"));
cb = null;
}
});
/// Set the show to FALSE to use.
/**
loginWindow.once("ready-to-show", function ()
{
loginWindow.show()
});
*/
/*
contents.on("will-navigate", function (e, url)
{
console.log("will-navigate");
console.log(url);
///event.preventDefault();
});
contents.on("did-navigate", function (e, url, code, status)
{
console.log("did-navigate");
console.log(url, code, status);
///event.preventDefault();
});
*/
function onLogin()
{
console.log("Logged in");
isLoggedIn = true;
loginWindow.close();
//cb(null, loginWindow);
if (cb) {
setImmediate(cb, null);
cb = null;
}
}
function redirectOnLogOut()
{
if (needsToRedirect) {
needsToRedirect = false;
loginWindow.loadURL("https://www.unrealengine.com/login");
console.log("Redirecting to login.");
}
}
function getCookiesFromSession(cb)
{
electron.session.defaultSession.cookies.get({}).then(function onget(sessionCookies)
{
cb(null, sessionCookies);
}).catch(function onerror(err)
{
cb(err);
});
}
function hasLoginCookie(sessionCookies)
{
var i;
for (i = sessionCookies.length - 1; i >= 0; --i) {
if (sessionCookies[i] && sessionCookies[i].name && sessionCookies[i].name.toUpperCase() === "EPIC_SSO") {
return true;
}
}
return false;
}
function checkIfLoggedIn()
{
if (atLeastOnePageLoaded && currentURL.indexOf("id/login") === -1) {
getCookiesFromSession(function onget(err, sessionCookies)
{
if (!isLoggedIn) {
if (err) {
console.error("Error getting cookies");
console.error(err);
} else {
//console.log(sessionCookies);
if (hasLoginCookie(sessionCookies)) {
cookies = sessionCookies;
request._setCookiesFromBrowser(cookies);
onLogin();
}
}
}
});
}
}
contents.on("did-frame-navigate", function (e, url, code, status, isMainFrame, frameProcessId, frameRoutingId)
{
console.log("did-frame-navigate", url)
currentURL = url;
if (needsToRedirect) {
redirectOnLogOut();
//} else if (url === "https://www.unrealengine.com/" || /^https\:\/\/www\.unrealengine\.com\/.*\/feed$/.test(url)) {
// onLogin();
} else if (!isLoggedIn) {
checkIfLoggedIn();
}
//console.log("did-frame-navigate");
//console.log(url, code, status, isMainFrame, frameProcessId, frameRoutingId);
/// Went here after logging out.
/// did-frame-navigate https://www.unrealengine.com/id/login?redirectUrl=https%3A%2F%2Fwww.unrealengine.com%2F&client_id=932e595bedb643d9ba56d3e1089a5c4b&noHostRedirect=true
});
contents.on("did-frame-finish-load", function (e, isMainFrame, frameProcessId, frameRoutingId)
{
atLeastOnePageLoaded = true;
console.log()
console.log("did-frame-finish-load");
if (!isLoggedIn) {
checkIfLoggedIn();
}
});
/*
contents.on("did-navigate-in-page", function (e, url, isMainFrame, frameProcessId, frameRoutingId)
{
console.log("did-frame-navigate");
console.log(url, isMainFrame, frameProcessId, frameRoutingId);
///event.preventDefault();
});
contents.on("page-title-updated", function (e, title, explicitSet)
{
console.log("page-title-updated");
console.log(title, explicitSet)
});
*/
/// Quixel login
/// https://www.epicgames.com/id/login?client_id=b9101103b8814baa9bb4e79e5eb107d0&response_type=code
/// Ends here https://quixel.com/?code=812d81d1f1ad4f699091b03f0b1083d7
contents.on("page-title-updated", function (e, title, explicitSet)
{
console.log("page-title-updated", title, explicitSet)
///TODO: Make sure it goes to the right page when logging out
///page-title-updated Logging out... | Epic Games true
if (typeof title === "string" && title.indexOf("Logging out") > -1) {
console.log("Detected logout. Will redirect to log in.");
atLeastOnePageLoaded = false;
/// Redirect to the login page.
needsToRedirect = true;
/// Sometimes it does not redirect.
redirectTimer = setTimeout(redirectOnLogOut, 5000);
}
});
}
function loginIfNecessary(cb)
{
if (!cookies) {
login(function (err)
{
cb(err);
});
} else {
setImmediate(cb, cookies);
}
}
function logout(cb)
{
///TODO: Make a way to logout so that if a login expires (like because a computer was put into standby), we can log back in again.
console.error("NOT IMPLEMENTED");
setImmediate(cb, new Error("NOT IMPLEMENTED"));
}
function sanitizeConfigWindowData()
{
if (typeof configData.isMaximized !== "boolean") {
configData.isMaximized = true;
}
if (typeof configData.width !== "number" || configData.width < 100) {
configData.width = 1200;
}
if (typeof configData.height !== "number" || configData.height < 100) {
configData.height = 1000;
}
if (typeof configData.x !== "number" || typeof configData.y !== "number") {
configData.x = undefined;
configData.y = undefined;
}
}
function createMainWindow()
{
sanitizeConfigWindowData();
console.log(configData)
// Create the browser window.
mainWindow = new BrowserWindow({
width: configData.width, /// 1200
height: configData.height, /// 1000
x: configData.x,
y: configData.y,
fullscreenable: true,
webPreferences: {
//preload: p.join(__dirname, "preload.js")
nodeIntegration: true,
devTools: configData.devTools,
},
icon: p.join(__dirname, "ue-logo.png"),
show: true, /// Use FALSE for graceful loading
title: "Unreal Engine Launcher"
});
var contents = mainWindow.webContents;
// and load the index.html of the app.
mainWindow.loadFile("pages/unreal_engine.html");
if (configData.devTools) {
mainWindow.webContents.openDevTools()
} else {
/// Make it show up in the json file for easy editing.
configData.devTools = false;
}
if (configData.isMaximized) {
mainWindow.maximize();
}
function saveSizeAndPos()
{
var size = mainWindow.getSize();
var pos = mainWindow.getPosition();
configData.width = size[0];
configData.height = size[1];
configData.x = pos[0];
configData.y = pos[1];
saveConfig();
}
mainWindow.on("close", function ()
{
if (!configData.isMaximized) {
saveSizeAndPos();
}
/// Make sure everything is closed.
if (loginWindow) {
try {
loginWindow.close();
} catch (e) {}
}
});
mainWindow.on("maximize", function ()
{
configData.isMaximized = true;
saveConfig();
});
mainWindow.on("unmaximize", function ()
{
configData.isMaximized = false;
saveSizeAndPos();
});
}
function isInVault(vault, el)
{
var i;
for (i = vault.length - 1; i >= 0; --i) {
if (vault[i].catalogItemId === el.catalogItemId) {
return true;
}
}
return false;
}
function downloadVaultData(cb)
{
var vault;
var dlCount = 25;
var dlTotal;
var dlIndex;
function done()
{
console.log("Done downloading vault");
cb(vault);
}
if (vaultData && vaultData.length) {
vault = vaultData;
dlIndex = vaultData.length;
} else {
vault = [];
dlIndex = 0
}
//debugger;
(function loop()
{
var url;
console.log(dlIndex);
//debugger;
if (dlTotal !== undefined && dlIndex >= dlTotal - 1) {
return done();
}
url = "https://www.unrealengine.com/marketplace/api/assets/vault?start=" + dlIndex + "&count=" + dlCount;
getJson(url, function (err, data)
{
var addedCount = 0;
//debugger;
console.log(data);
if (err || !data || data.status !== "OK") {
/// Did the user not cancle the update?
if (!err || err.message !== "Login window closed unexpectedly") {
console.error("Cannot download vault page: " + url)
console.error(err);
if (data) {
console.log("DATA:");
console.error(data);
}
///TODO: Try again?
}
cb(vault);
} else {
dlTotal = data.data.paging.total;
if (data.data && data.data.elements && data.data.elements.length) {
data.data.elements.forEach(function addIfNew(element)
{
///NOTE: If you request beyond the total number in the vault, you will get back some of the last elements.
if (!isInVault(vault, element)) {
vault.push(element);
++addedCount;
}
});
if (addedCount) {
dlIndex += addedCount;
} else {
return done();
}
} else {
return done();
}
loop();
}
//console.log(data);
//fs.writeFileSync(p.join(__dirname, "test.json"), JSON.stringify(data));
});
}());
}
function getVault()
{
if (typeof vaultData === "undefined") {
vaultData = loadJsonFile.sync(vaultPath, []);
}
return vaultData;
}
function updateVault(ignoreCache, cb)
{
var shouldDownload;
if (offline) {
console.log("Not updating vault: offline")
if (cb) {
setImmediate(cb);
}
} else {
shouldDownload = true;
try {
/// Only update the vault every 18 hours by default.
if (!ignoreCache && fs.existsSync(vaultPath) && Date.now() - fs.statSync(vaultPath).mtime.valueOf() < 1000 * 60 * 60 * 18) {
shouldDownload = false;
}
} catch (e) {}
if (shouldDownload) {
downloadVaultData(function (data)
{
if (data) {
vaultData = data;
} else {
vaultData = [];
}
fs.writeFileSync(vaultPath, JSON.stringify(vaultData));
if (cb) {
cb(vaultData);
}
});
} else {
console.log("Not updating vault: already up to date")
setImmediate(cb);
}
}
}
function startup()
{
loadAssetCache(function ()
{
createMainWindow();
});
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on("ready", startup);
/// Delete?
// Quit when all windows are closed.
app.on("window-all-closed", function ()
{
app.quit();
setTimeout(function ()
{
/// Make sure everything stops, even downloads.
process.exit();
}, 200).unref();
})
// In this file you can include the rest of your app"s specific main process
// code. You can also put them in separate files and require them here.
/*
ipc.on("asynchronous-message", function (event, arg)
{
console.log(arg) // prints "ping"
event.reply("asynchronous-reply", "pong")
})
ipc.on("synchronous-message", function (event, arg)
{
console.log(arg) // prints "ping"
event.returnValue = "pong"
})
*/
function getEngineVersion(path)
{
var data;
var match
try {
//Engine/Build/Build.version ;
data = JSON.parse(fs.readFileSync(p.join(path, "Engine", "Build", "Build.version"), "utf8"));
if (data.MajorVersion && data.MinorVersion) {
return data.MajorVersion + "." + data.MinorVersion;
}
} catch (e) {}
try {
/// Check the last tag for the engine number.
data = require("child_process").execSync("git describe --abbrev=0", {stdio: "pipe", cwd: path, encoding: "utf8"}).trim();
match = data.match(/^(\d+\.\d+).*release$/);
if (match) {
return match[1];
}
} catch (e) {}
try {
/// Check BRANCH_NAME in UE4Defines.pri for the engine number.
data = fs.readFileSync(p.join(path, "UE4Defines.pri"), "utf8");
match = data.match(/BRANCH_NAME=".*?(\d+\.\d+)"/);
if (match) {
return match[1];
}
} catch (e) {}
}
function addEngine(path)
{
var engineBasePath;
var engineVersion;
var execPath;
/// Is this a link to the file?
try {
if (!fs.lstatSync(path).isDirectory()) {
engineBasePath = p.join(path, "..", "..", "..", "..");
}
execPath = path;
} catch (e) {}
if (!engineBasePath) {
/// Is it a link to the folder with the binary?
try {
if (fs.existsSync(p.join(path, "UE4Editor"))) {
engineBasePath = p.join(path, "..", "..", "..");
execPath = p.join(path, "UE4Editor");
}
} catch (e) {}
}
if (!engineBasePath) {
/// Assume that it's the path to the root of the engine.
engineBasePath = path;
///TODO: Support other platforms
execPath = p.join(engineBasePath, "Engine", "Binaries", "Linux", "UE4Editor");
}
engineVersion = getEngineVersion(engineBasePath);
if (engineVersion) {
configData.engines.push({
baseDir: engineBasePath,
version: engineVersion,
execPath: execPath,
});
saveConfig();
return true;
}
throw new Error("Cannot add engine");
}
function findImageInDir(dir, cb)
{
fs.readdir(dir, function onread(err, paths)
{
var i;
var len;
var ext;
if (paths) {
len = paths.length;
for (i = 0; i < len; ++i) {
ext = p.extname(paths[i]).toLowerCase();
if (ext === ".png" || ext === ".jpg" || ext === ".jpeg" || ext === ".webp") {
return cb(p.join(dir, paths[i]));
}
}
}
cb();
});
}
function findImage(path, cb)
{
/// Check a couple of common directories.
findImageInDir(p.join(path, "Resources"), function onsearch(imgPath)
{
if (imgPath) {
return cb(imgPath);
}
findImageInDir(path, cb);
});
}
function addLocalAssetDir(path, cb)
{
findImage(path, function onfind(imagePath)
{
localAssetsData.push({
title: p.basename(path),
path: path,
thumbnail: imagePath,
});
saveLocalAssets(function ()
{
cb();
});
});
}
function hasLocalAsset(path)
{
return localAssetsData.some(function (asset)
{
return asset.path === path;
})
}
function addLocalAsset(path, cb)
{
/// Check if path is directory or compressed file.
/// If directory, add path
///TODO: Be able to copy
/// If file, extract
/// Find icon
/// Add to JSON
/// Reply
if (hasLocalAsset(path)) {
return cb("This asset has already been added.");
}
fs.stat(path, function onstat(err, stat)
{
if (err) {
console.error(err);
return cb("Path cannot be read.");
}
if (stat.isDirectory()) {
addLocalAssetDir(path, cb);
}
});
}
function delLocalAsset(path, cb)
{
var i;
for (i = localAssetsData.length - 1; i >= 0; --i) {
if (localAssetsData[i].path === path) {
localAssetsData.splice(i, 1);
}
}
saveLocalAssets(function ()
{
cb();
});
}
function loadAssetCache(cb)
{
loadJsonFile(assetJsonPath, {}, function onload(json)
{
assetsData = json;
cb();
});
}
ipc.on("getVault", function (e/*, arg*/)
{
console.log("getting vault");
e.returnValue = JSON.stringify(getVault());
});
ipc.on("updateVault", function (e, ignoreCache)
{
console.log("updating vault");
updateVault(ignoreCache === "1", function (data)
{
e.reply("updateVault", data ? JSON.stringify(data) : "");
});
});
ipc.on("getConfig", function (e, arg)
{
e.returnValue = JSON.stringify(configData);
});
/*
ipc.on("saveConfig", function (e, arg)
{
e.returnValue = JSON.stringify(getVault());
});
*/
ipc.on("getAssetsData", function (e, arg)
{
e.returnValue = JSON.stringify(assetsData);
});
ipc.on("addEngine", function (e, path)
{
///TODO: Make it async.
/// Make sure it does not freeze.
try {
addEngine(path);
/// If you do not set this, it will hang.
e.returnValue = "";
} catch (err) {
console.error(err);
e.returnValue = err.message;
}
});
ipc.on("addLocalAsset", function (e, path)
{
addLocalAsset(path, function (err)
{
e.reply("localAssetsModified", err);
});
});
ipc.on("delLocalAsset", function (e, path)
{
delLocalAsset(path, function ()
{
e.reply("localAssetsModified", null);
});
});
ipc.on("addAssetToProject", function (e, data)