MCPcopy Index your code
hub / github.com/GooseMod/OpenAsar / installModule

Function installModule

src/updater/moduleUpdater.js:172–221  ·  view source on GitHub ↗
(name, ver, path)

Source from the content-addressed store, hash-verified

170};
171
172const installModule = async (name, ver, path) => {
173 installing.total++;
174
175 // log('Modules', 'Installing', `${name}@${ver}`);
176
177 let err;
178 const onErr = e => {
179 if (err) return;
180 err = true;
181
182 log('Modules', 'Failed install', name, e);
183
184 finishInstall(name, ver, false);
185 };
186
187
188 // Extract zip via unzip cmd line - replaces yauzl dep (speed++, size--, jank++)
189 let total = 0, cur = 0;
190 execFile('unzip', ['-l', path], (e, o) => total = parseInt(o.toString().match(/([0-9]+) files/)?.[1] ?? 0)); // Get total count and extract in parallel
191
192 const ePath = join(basePath, name);
193 mkdir(ePath);
194
195 const proc = execFile('unzip', ['-o', path, '-d', ePath]);
196
197 proc.on('error', (e) => {
198 if (e.code === 'ENOENT') {
199 require('electron').dialog.showErrorBox('Failed Dependency', 'Please install "unzip"');
200 process.exit(1); // Close now
201 }
202
203 onErr(e);
204 });
205 proc.stderr.on('data', onErr);
206
207 proc.stdout.on('data', x => {
208 cur += x.toString().split('\n').length;
209
210 events.emit('installing-module', { name, cur, total });
211 });
212
213 proc.on('close', () => {
214 if (err) return;
215
216 installed[name] = { installedVersion: ver };
217 commitManifest();
218
219 finishInstall(name, ver, true);
220 });
221};
222
223const finishInstall = (name, ver, success) => {
224 if (!success) installing.fail++;

Callers 1

downloadModuleFunction · 0.85

Calls 4

mkdirFunction · 0.85
onErrFunction · 0.85
commitManifestFunction · 0.85
finishInstallFunction · 0.85

Tested by

no test coverage detected