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

Method saveFile

lib/modUtilLib.js:665–698  ·  view source on GitHub ↗

* Save current cache

()

Source from the content-addressed store, hash-verified

663 * Save current cache
664 */
665 saveFile() {
666 try {
667 const writeData = fs.createWriteStream(this.#saveFileData)
668 const writeIcon = fs.createWriteStream(this.#saveFileIcon)
669 const writeItem = fs.createWriteStream(this.#saveFileDetail)
670
671 writeData.write('{')
672 writeIcon.write('{')
673 writeItem.write('{')
674
675 let lastData = null
676 let lastIcon = null
677 let lastItem = null
678
679 for ( const [key, value] of this.#cacheMap ) {
680 if ( lastData !== null ) { writeData.write(`${lastData},\n`) }
681 if ( lastIcon !== null ) { writeIcon.write(`${lastIcon},\n`) }
682 if ( lastItem !== null ) { writeItem.write(`${lastItem},\n`) }
683
684 lastIcon = `"${key}" : ${JSON.stringify(value.modDesc.iconImage)}`
685 lastItem = `"${key}" : ${JSON.stringify(value.includeDetail)}`
686 lastData = `"${key}" : ${JSON.stringify(value, (k, v) => k === 'iconImage' || k === 'includeDetail' ? null : v )}`
687 }
688
689 if ( lastData !== null ) { writeData.write(`${lastData}\n`) }
690 if ( lastIcon !== null ) { writeIcon.write(`${lastIcon}\n`) }
691 if ( lastItem !== null ) { writeItem.write(`${lastItem}\n`) }
692 writeData.end('}\n')
693 writeIcon.end('}\n')
694 writeItem.end('}\n')
695 } catch (err) {
696 serveIPC.log.warning('mod-cache-manager', 'Cache Write Error', err)
697 }
698 }
699
700 /**
701 * @property {Array.<string>} keys Array of mod uuid keys

Callers 3

clearAllMethod · 0.95
modAssist_main.jsFile · 0.80
processModsPostMethod · 0.80

Calls 2

endMethod · 0.80
warningMethod · 0.80

Tested by

no test coverage detected