-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
146 lines (127 loc) · 4.06 KB
/
index.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
/*
NoSadNile Modpack Installer v0.1.2.0
Created by the NoSadNile Network in 2021
for use with NoSadNile Modpacks.
https://git.nosadnile.net/RedstoneWizard08/nosadnile-modpack-installer/
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
The NoSadNile Network is not associated with Mojang AB.
To create a modpack, see the NoSadNile Modpack Creator (Coming soon).
The libraries used in this program's licenses apply. You can find
them on their respective GitHub pages and/or websites (Not listed here).
*/
const remoteMain = require('@electron/remote/main')
const { app, BrowserWindow, ipcMain } = require("electron");
const path = require("path");
const url = require("url");
const ejse = require("ejs-electron");
const fs = require("fs");
const { exec, execSync } = require("child_process");
const { default: axios } = require("axios");
const uuid = require("uuid");
const express = require("express");
const bp = require("body-parser");
const request = require('request');
const progress = require('request-progress');
const readline = require('readline');
const _cliProgress = require('cli-progress');
const { downloadProgress, downloadOverrides } = require("./download.js");
const yauzl = require("yauzl");
const AdmZip = require("adm-zip");
remoteMain.initialize();
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
app.disableHardwareAcceleration();
var win;
var isInstalling = false;
function createWindow() {
win = new BrowserWindow({
width: 600,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
preload: path.join(__dirname, "preload.js")
},
autoHideMenuBar: true,
title: "NoSadNile Modpack Installer",
icon: getPlatformIcon("icon-256x256"),
resizable: false
});
remoteMain.enable(win.webContents);
if(isInstalling) {
ejse.data("install_modpack", true);
} else {
ejse.data("install_modpack", false);
}
win.loadURL(url.format({
pathname: path.join(__dirname, "index.ejs"),
protocol: "file:",
slashes: true
}));
win.on("close", () => {
win = null;
});
win.on("closed", () => {
win = null;
});
const is = express();
is.use(bp.json());
is.use(bp.urlencoded({ extended: true }));
is.post("/of", (req, res) => {
var cmd = "start cmd /C \"" + req.body.path + "\"";
console.log("Executing: " + cmd);
exec(cmd, (err, stdout, stderr) => {
if(err) {
console.log(err.message);
return;
}
if(stderr) {
console.log(stderr);
return;
}
console.log(stdout);
res.send("Installed");
});
});
is.listen(39999, () => {
console.log("Internal server listening on port 39999.");
});
}
function getPlatformIcon(filename){
let ext
switch(process.platform) {
case 'win32':
ext = 'ico'
break
case 'darwin':
case 'linux':
default:
ext = 'png'
break
}
return path.join(__dirname, 'assets', `${filename}.${ext}`)
}
app.on("ready", () => {
createWindow();
});
app.on("activate", () => {
if(win === null) {
createWindow();
}
});
app.on("window-all-closed", () => {
if(process.platform !== "darwin") {
app.quit();
}
});