MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / downloadAllZip

Function downloadAllZip

Support/SingleFileLibs/javascript/app.js:434–491  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

432 }
433
434 async function downloadAllZip() {
435 downloadAllBtn.disabled = true;
436 try {
437 // Setup cancellation
438 if (state.cancelController) state.cancelController.abort();
439 state.cancelController = new AbortController();
440 const signal = state.cancelController.signal;
441 hudShow('Generating all single-file libraries…');
442
443 // Ensure JSZip is available
444 let JSZipCtor = window.JSZip;
445 if (!JSZipCtor) {
446 // Load dynamically as a fallback
447 await loadExternalScript('https://cdn.jsdelivr.net/npm/jszip@3.10.1/dist/jszip.min.js');
448 JSZipCtor = window.JSZip;
449 }
450 if (!JSZipCtor) throw new Error('JSZip not available');
451 const zip = new JSZipCtor();
452 hudUpdate('Fetching repository tree…', 2);
453 const tree = await getRepoTree(state.currentRef);
454 if (signal.aborted) throw new Error('Cancelled');
455 const total = state.libraryNames.length;
456 let done = 0;
457 for (const name of state.libraryNames) {
458 hudUpdate(`Amalgamating ${name}…`, 5 + Math.floor((done / Math.max(1, total)) * 80));
459 if (signal.aborted) throw new Error('Cancelled');
460 const content = await buildSingleLibraryHeader(name, state.currentRef, tree);
461 zip.file(`SaneCpp${name}.h`, content);
462 // Throttle slightly to be gentle
463 await sleep(50);
464 done++;
465 }
466 // Add README and LICENSE
467 hudUpdate('Adding README and LICENSE…', 90);
468 try {
469 const readme = await fetchText(rawUrl(state.currentRef, 'README.md'));
470 zip.file('README.md', readme);
471 } catch {}
472 try {
473 const license = await fetchText(rawUrl(state.currentRef, 'LICENSE.txt'));
474 zip.file('LICENSE.txt', license);
475 } catch {}
476
477 hudUpdate('Packaging zip…', 96);
478 const blob = await zip.generateAsync({ type: 'blob' });
479 const nameTag = state.currentRefType === 'tag' ? state.currentRef : (state.latestReleaseTag || state.currentRef);
480 triggerDownload(`SaneCppLibraries_SingleFiles_${nameTag}.zip`, blob);
481 hudUpdate('Done!', 100);
482 setTimeout(hudHide, 600);
483 } catch (e) {
484 console.error(e);
485 alert(`Failed to Download All: ${e.message}`);
486 } finally {
487 if (state.cancelController) { state.cancelController.abort(); state.cancelController = null; }
488 hudHide();
489 downloadAllBtn.disabled = false;
490 }
491 }

Callers 1

app.jsFile · 0.85

Calls 10

hudShowFunction · 0.85
loadExternalScriptFunction · 0.85
hudUpdateFunction · 0.85
getRepoTreeFunction · 0.85
buildSingleLibraryHeaderFunction · 0.85
sleepFunction · 0.85
fetchTextFunction · 0.85
rawUrlFunction · 0.85
triggerDownloadFunction · 0.85
hudHideFunction · 0.85

Tested by

no test coverage detected