Skip to content

Commit 506dd85

Browse files
committed
fixed issue with the same file in two different parts of the manifest (internal and external). Switched concat to union to resolve. disable a lot more now when the download is going, including the mod checkboxes, the folder entry box, and the browse button. adding a network rate so something looks like it is happening instead of freezing at 70% when you're downloading the music mod.
1 parent 3d547f1 commit 506dd85

File tree

4 files changed

+74
-44
lines changed

4 files changed

+74
-44
lines changed

index.html

+8-8
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
background-color: #7b1b1d;
5252
cursor: pointer;
5353
}
54-
button.right.disabled {
54+
button.right:disabled {
5555
background-color: #2f2f2f;
5656
}
5757
#version {
@@ -81,27 +81,27 @@
8181
#play { background:url(./img/playbutton.png) no-repeat; }
8282
#play:hover { background:url(./img/playbuttonhov.png) no-repeat; }
8383
#play:active { background:url(./img/playbuttonclick.png) no-repeat; }
84-
#play.disabled { background:url(./img/playbuttondis.png) no-repeat; }
84+
#play:disabled { background:url(./img/playbuttondis.png) no-repeat; }
8585

8686
#settings { background:url(./img/settingsbutton.png) no-repeat; }
8787
#settings:hover { background:url(./img/settingsbuttonhov.png) no-repeat; }
8888
#settings:active, #settings.active { background:url(./img/settingsbuttonclick.png) no-repeat; }
89-
#settings.disabled { background:url(./img/settingsbuttondis.png) no-repeat; }
89+
#settings:disabled { background:url(./img/settingsbuttondis.png) no-repeat; }
9090

9191
#profcalc { background:url(./img/profcalcbutton.png) no-repeat; }
9292
#profcalc:hover { background:url(./img/profcalcbuttonhov.png) no-repeat; }
9393
#profcalc:active { background:url(./img/profcalcbuttonclick.png) no-repeat; }
94-
#profcalc.disabled { background:url(./img/profcalcbuttondis.png) no-repeat; }
94+
#profcalc:disabled { background:url(./img/profcalcbuttondis.png) no-repeat; }
9595

9696
#web { background:url(./img/webbutton.png) no-repeat; }
9797
#web:hover { background:url(./img/webbuttonhov.png) no-repeat; }
9898
#web:active { background:url(./img/webbuttonclick.png) no-repeat; }
99-
#web.disabled { background:url(./img/webbuttondis.png) no-repeat; }
99+
#web:disabled { background:url(./img/webbuttondis.png) no-repeat; }
100100

101101
#disc { background:url(./img/discbutton.png) no-repeat; }
102102
#disc:hover { background:url(./img/discbuttonhov.png) no-repeat; }
103103
#disc:active { background:url(./img/discbuttonclick.png) no-repeat; }
104-
#disc.disabled { background:url(./img/discbuttondis.png) no-repeat; }
104+
#disc:disabled { background:url(./img/discbuttondis.png) no-repeat; }
105105

106106
#home { background:url(./img/homebutton.png) no-repeat; }
107107
#home:hover { background:url(./img/homebuttonhov.png) no-repeat; }
@@ -140,13 +140,13 @@
140140
</div>
141141

142142
<img class="header-img" src="./img/Relics-of-Corbantis-logo.png" style="position: absolute; left: 2%; top: 2%; width: 334px; -webkit-app-region: drag"/>
143-
<button id="play" class="button disabled" style="top: 23%;"></button>
143+
<button id="play" class="button" disabled style="top: 23%;"></button>
144144
<div id="progressbox" class="button shadow" style="top: 33%;height:24px; color: black; font-size: 16px; border: 3px solid #7b1b1d; border-radius: 8px; box-sizing: border-box; background-color: #627d9f">
145145
<div id="progress" style="width:0%;height:100%;background-color:#cc9966;border-radius:6px"></div>
146146
<div id="progresstext" style="position:absolute;top:0;width:100%;height:100%;text-align:center;"></div>
147147
</div>
148148
<button id="settings" class="button" style="top: 38%;"></button>
149-
<button id="profcalc" class="button disabled" style="top: 53%;"></button>
149+
<button id="profcalc" class="button" disabled style="top: 53%;"></button>
150150
<button id="web" class="button" style="top: 68%;"></button>
151151
<button id="disc" class="button" style="top: 83%;"></button>
152152
<div id="version"></div>

install.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,25 @@ module.exports.getManifest = function(mods, fullScan, emuPath, checkFiles) {
1515
}
1616
request({url:"https://github.com/dpwhittaker/RoC-Launcher/releases/download/Assets/manifest.json", json:true}, function(err, response, body) {
1717
if (err) return console.error(err);
18+
1819
var allmods = [];
1920
for (var mod in body) if (mod != 'required') allmods.push(mod);
2021
if (module.exports.modList) module.exports.modList(allmods);
21-
files = files.concat(body.required);
22-
for (var mod of mods) files = files.concat(body[mod] || []);
22+
files = unionByName(files, body.required);
23+
for (var mod of mods) files = unionByName(files, body[mod] || []);
2324
if (checkFiles) checkFiles(files);
2425
});
2526
}
2627

28+
function unionByName(a, b) {
29+
var lookup = {};
30+
for (var i of b) lookup[i.name] = true;
31+
var r = [];
32+
for (var i of a) if (!lookup[i.name]) r.push(i);
33+
for (var i of b) r.push(i);
34+
return r;
35+
}
36+
2737
module.exports.install = function(swgPath, emuPath, mods, fullScan) {
2838
const child_process = require('child_process');
2939

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "roc-launcher",
3-
"version": "0.0.13",
3+
"version": "0.0.14",
44
"description": "Relics of Corbantis Official SWGEMU Launcher",
55
"main": "main.js",
66
"scripts": {

renderer.js

+53-33
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ maxBtn.addEventListener('click', event => {
5151
closeBtn.addEventListener('click', event => remote.getCurrentWindow().close());
5252

5353
playBtn.addEventListener('click', event => {
54-
if (isDisabled(playBtn)) return;
54+
if (playBtn.disabled) return;
5555
fs.writeFileSync(path.join(config.folder, "swgemu_login.cfg"), `[ClientGame]\r\nloginServerAddress0=${server.address}\r\nloginServerPort0=${server.port}`);
5656
var args = ["--",
5757
"-s", "ClientGame", "loginServerAddress0=" + server.address, "loginServerPort0=" + server.port,
@@ -103,37 +103,52 @@ ipc.on('selected-directory', function (event, path) {
103103
});
104104

105105
installBtn.addEventListener('click', function(event) {
106-
if (isDisabled(installBtn)) return;
107-
disable(installBtn);
106+
if (installBtn.disabled = false) return;
107+
installBtn.disabled = true;
108108
ipc.send('open-directory-dialog', 'install-selected');
109109
});
110110

111111
ipc.on('install-selected', function (event, path) {
112-
disable(installBtn);
113-
disable(fullscanBtn);
114-
disable(playBtn);
112+
disableAll();
115113
install.install(path, config.folder, config.mods);
116114
});
117115

118116
ipc.on('downloading-update', function (event, text) {
119117
versionDiv.innerHTML = text;
120-
disable(installBtn);
121-
disable(fullscanBtn);
122-
disable(playBtn);
118+
disableAll();
123119
});
124120

125121
ipc.on('download-progress', function(event, info) {
126122
install.progress(info.transferred, info.total);
127123
})
128124

125+
var lastCompleted = 0;
126+
var lastTime = new Date();
127+
var rate = 0;
128+
var units = " B/s";
129129
install.progress = function(completed, total) {
130+
var time = new Date();
131+
var elapsed = (time - lastTime) / 1000;
132+
if (elapsed >= 1) {
133+
var bytes = completed - lastCompleted;
134+
units = " B/s";
135+
rate = bytes / elapsed;
136+
if (rate > 1024) {
137+
rate = rate / 1024;
138+
units = " KB/s";
139+
}
140+
if (rate > 1024) {
141+
rate = rate / 1024;
142+
units = " MB/s";
143+
}
144+
lastCompleted = completed;
145+
lastTime = time;
146+
}
130147
if (progressBox.style.display == 'none') progressBox.style.display = 'block';
131-
progressText.innerHTML = Math.trunc(completed * 100 / total) + '%';
148+
progressText.innerHTML = Math.trunc(completed * 100 / total) + '% (' + rate.toPrecision(3) + units + ')';
132149
progressBar.style.width = (completed * 100 / total) + '%';
133150
if (completed == total) {
134-
enable(playBtn);
135-
enable(fullscanBtn);
136-
enable(installBtn);
151+
enableAll();
137152
progressBox.style.display = 'none';
138153
}
139154
}
@@ -147,6 +162,7 @@ install.modList = function(mods) {
147162
checkbox.id = mod.replace(/[^a-zA-Z]/g, "");
148163
checkbox.checked = config.mods.includes(mod);
149164
checkbox.onchange = modListChanged;
165+
checkbox.disabled = true;
150166
var label = document.createElement('label');
151167
label.htmlFor = checkbox.id;
152168
label.appendChild(document.createTextNode(mod));
@@ -163,42 +179,46 @@ function modListChanged() {
163179
if (child.children[0].checked) config.mods.push(child.children[0].value);
164180
}
165181
saveConfig();
166-
disable(fullscanBtn);
167-
disable(installBtn);
168-
disable(playBtn);
182+
disableAll();
169183
install.install(config.folder, config.folder, config.mods);
170184
}
171185

172186
fullscanBtn.addEventListener('click', function(event) {
173-
if (isDisabled(fullscanBtn)) return;
174-
disable(fullscanBtn);
175-
disable(installBtn);
176-
disable(playBtn);
187+
if (fullscanBtn.disabled) return;
188+
disableAll();
177189
install.install(config.folder, config.folder, config.mods, true);
178190
});
179191

180192
if (fs.existsSync(path.join(config.folder, 'bottom.tre'))) {
181-
disable(fullscanBtn);
182-
disable(installBtn);
183-
disable(playBtn);
193+
disableAll();
184194
install.install(config.folder, config.folder, config.mods);
185195
} else {
186-
disable(playBtn);
187-
disable(fullscanBtn);
196+
playBtn.disabled = true;
197+
fullscanBtn.disabled = true;
188198
install.getManifest();
189199
settings.click();
190200
}
191201

192-
function isDisabled(btn) {
193-
return /disabled/.test(btn.className);
194-
}
195-
196-
function disable(btn) {
197-
if (!isDisabled(btn)) btn.className += ' disabled';
202+
function disableAll() {
203+
folderBox.disabled = true;
204+
fullscanBtn.disabled = true;
205+
installBtn.disabled = true;
206+
playBtn.disabled = true;
207+
browseBtn.disabled = true;
208+
for (var child of modListBox.children) {
209+
child.children[0].disabled = true;
210+
}
198211
}
199212

200-
function enable(btn) {
201-
btn.className = btn.className.replace(/ ?disabled ?/,'');
213+
function enableAll() {
214+
folderBox.disabled = false;
215+
fullscanBtn.disabled = false;
216+
installBtn.disabled = false;
217+
playBtn.disabled = false;
218+
browseBtn.disabled = false;
219+
for (var child of modListBox.children) {
220+
child.children[0].disabled = false;
221+
}
202222
}
203223

204224
function saveConfig() {

0 commit comments

Comments
 (0)