MCPcopy Create free account
hub / github.com/FSGModding/FSG_Mod_Assistant / addCollection

Method addCollection

lib/modCheckLib.js:570–627  ·  view source on GitHub ↗

* Add a collection * @param {string} folder * @param {boolean} offline collection is currently offline * @returns {Object} newCollection * @returns {modRecord_collectKey} newCollection.collectKey * @returns {number} newCollection.fileCount number of files

(folder, offline = false)

Source from the content-addressed store, hash-verified

568 * @returns {number} newCollection.fileCount number of files
569 */
570 addCollection(folder, offline = false) {
571 const goodFolderContents = []
572 const thisFolderKey = this.#getMD5Hash(folder, 'col_')
573 const thisRealPath = path.normalize(folder)
574 const thisShortName = path.basename(thisRealPath)
575 const thisFullName = this.#populateFullName(thisFolderKey, thisShortName)
576
577 if ( !offline ) {
578 try {
579 const folderContents = fs.readdirSync(thisRealPath, {withFileTypes : true})
580
581 for ( const thisFile of folderContents ) {
582 if ( !this.#junkRegex.test(thisFile.name) ) { goodFolderContents.push(thisFile) }
583 }
584 this.#map_CollectionToStatus[thisFolderKey] = true
585 } catch (err) {
586 this.#log.danger('collection-reader', 'Could not read folder', thisRealPath, err)
587 this.#map_CollectionToStatus[thisFolderKey] = false
588 return null
589 }
590 } else {
591 this.#map_CollectionToStatus[thisFolderKey] = false
592 }
593
594 this.#set_Collections.add(thisFolderKey)
595 this.#list_allMods[thisFolderKey] = {
596 alphaSort : [],
597 dependSet : new Set(),
598 folderSize : 0,
599 fullName : thisFullName,
600 mods : {},
601 modSet : new Set(),
602 name : thisShortName,
603 requireArr : [],
604 requireBy : {},
605 }
606
607 const thisFolderBotIDS = this.#map_CollectionNotes.get(`${thisFolderKey}.notes_fsg_bot`, '')
608
609 const theseIDs = thisFolderBotIDS.split(/\D+/).filter((x) => x.length !== 0)
610
611 for ( const thisID of theseIDs ) { this.#botRequestList.add(thisID) }
612 this.#botRequestMap[thisFolderKey] = theseIDs
613
614 if ( theseIDs.length !== 0 ) { this.startBotInterval() }
615
616 this.#map_FolderContents [thisFolderKey] = goodFolderContents
617 this.#map_CollectionToFolder [thisFolderKey] = thisRealPath
618 this.#map_CollectionToFolderRelative [thisFolderKey] = this.#toHomeDir(thisRealPath)
619 this.#map_FolderToCollection [thisRealPath] = thisFolderKey
620 this.#map_CollectionToName [thisFolderKey] = thisShortName
621 this.#map_CollectionToFullName [thisFolderKey] = thisFullName
622
623 return {
624 collectKey : thisFolderKey,
625 fileCount : goodFolderContents.length,
626 }
627 }

Callers 1

Calls 8

#getMD5HashMethod · 0.95
#populateFullNameMethod · 0.95
startBotIntervalMethod · 0.95
#toHomeDirMethod · 0.95
normalizeMethod · 0.80
dangerMethod · 0.80
addMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected