export async function computeLicensePage(packager: WinPackager, options: NsisOptions, scriptGenerator: NsisScriptGenerator, languages: Array<string>): Promise<void> { const license = await getNotLocalizedLicenseFiles(options.license, packager) if (license != null) { let licensePage: Array<string> if (license.endsWith(".html")) { licensePage = [ "!define MUI_PAGE_CUSTOMFUNCTION_SHOW LicenseShow", "Function LicenseShow", " FindWindow $R0 `#32770` `` $HWNDPARENT", " GetDlgItem $R0 $R0 1000", "EmbedHTML::Load /replace $R0 file://$PLUGINSDIR\\license.html", "FunctionEnd", `!insertmacro MUI_PAGE_LICENSE "${path.join(nsisTemplatesDir, "empty-license.txt")}"`, ] } else { licensePage = [`!insertmacro MUI_PAGE_LICENSE "${license}"`] } scriptGenerator.macro("licensePage", licensePage) if (license.endsWith(".html")) { scriptGenerator.macro("addLicenseFiles", [`File /oname=$PLUGINSDIR\\license.html "${license}"`]) } return } const licenseFiles = await getLicenseFiles(packager) if (licenseFiles.length === 0) { return } const licensePage: Array<string> = [] const unspecifiedLangs = new Set(languages) let defaultFile: string | null = null for (const item of licenseFiles) { unspecifiedLangs.delete(item.langWithRegion) if (defaultFile == null) { defaultFile = item.file } licensePage.push(`LicenseLangString MUILicense ${lcid[item.langWithRegion] || item.lang} "${item.file}"`) } for (const l of unspecifiedLangs) { licensePage.push(`LicenseLangString MUILicense ${lcid[l]} "${defaultFile}"`) } licensePage.push('!insertmacro MUI_PAGE_LICENSE "$(MUILicense)"') scriptGenerator.macro("licensePage", licensePage) }
export async function addLicenseToDmg(packager: PackageBuilder, dmgPath: string) { // http://www.owsiak.org/?p=700 const licenseFiles = await getLicenseFiles(packager) if (licenseFiles.length === 0) { return } const licenseButtonFiles = await getLicenseButtonsFile(packager) packager.debugLogger.add("dmg.licenseFiles", licenseFiles) packager.debugLogger.add("dmg.licenseButtons", licenseButtonFiles) const style: Array<string> = [] const rtfs: Array<string> = [] const defaultButtons: Array<string> = [] let counter = 5000 const addedRegionCodes: Array<number> = [] for (const item of licenseFiles) { log("Adding " + item.langName + " license") // value from DropDMG, data the same for any language // noinspection SpellCheckingInspection style.push(`data 'styl' (${counter}, "${item.langName}") { $"0001 0000 0000 000E 0011 0015 0000 000C" $"0000 0000 0000" };`) let data = `data 'RTF ' (${counter}, "${item.langName}") {\n` const fileData = await readFile(item.file, "utf-8") const isRtf = item.file.endsWith(".rtf") || item.file.endsWith(".RTF") data += isRtf ? serializeString((Buffer.from(fileData)).toString("hex")) : wrapInRtf(await readFile(item.file, "utf-8")) data += "\n};" rtfs.push(data) defaultButtons.push(await getLicenseButtons(licenseButtonFiles, item.langWithRegion, counter, item.langName)) addedRegionCodes.push(getRegionCode(item.langWithRegion)) counter++ } const buffer = Buffer.allocUnsafe((2 + (3 * addedRegionCodes.length)) * 2) let offset = 0 buffer.writeUInt16BE(DEFAULT_REGION_CODE, offset) offset += 2 buffer.writeUInt16BE(addedRegionCodes.length, offset) offset += 2 for (let i = 0; i < addedRegionCodes.length; i++) { const regionCode = addedRegionCodes[i] buffer.writeUInt16BE(regionCode, offset) offset += 2 buffer.writeUInt16BE(i, offset) offset += 2 buffer.writeUInt16BE(/* is two byte */ [14, 51, 52, 53].includes(regionCode) ? 1 : 0, offset) offset += 2 } const lPic = `data 'LPic' (5000) {\n${serializeString(buffer.toString("hex"))}\n};` const data = style .concat(rtfs) .concat(lPic) .concat(defaultButtons) .join("\n\n") packager.debugLogger.add("dmg.licenseResource", data) const tempFile = await packager.getTempFile(".r") await outputFile(tempFile, data) await exec("hdiutil", ["unflatten", dmgPath]) await exec("Rez", ["-a", tempFile, "-o", dmgPath]) await exec("hdiutil", ["flatten", dmgPath]) }