<commit_before>import { asArray, isEmptyOrSpaces, log } from "builder-util"
import { outputFile } from "fs-extra"
import { Lazy } from "lazy-val"
import { LinuxTargetSpecificOptions } from ".."
import { LinuxPackager } from "../linuxPackager"
import { IconInfo } from "../platformPackager"

export const installPrefix = "/opt"

export class LinuxTargetHelper {
  private readonly iconPromise = new Lazy(() => this.computeDesktopIcons())

  private readonly mimeTypeFilesPromise = new Lazy(() => this.computeMimeTypeFiles())

  maxIconPath: string | null = null

  constructor(private packager: LinuxPackager) {
  }

  get icons(): Promise<Array<IconInfo>> {
    return this.iconPromise.value
  }

  get mimeTypeFiles(): Promise<string | null> {
    return this.mimeTypeFilesPromise.value
  }

  private async computeMimeTypeFiles(): Promise<string | null> {
    const items: Array<string> = []
    for (const fileAssociation of this.packager.fileAssociations) {
      if (!fileAssociation.mimeType) {
        continue
      }

      const data = `<mime-type type="${fileAssociation.mimeType}">
  <glob pattern="*.${fileAssociation.ext}"/>
    ${fileAssociation.description ? `<comment>${fileAssociation.description}</comment>` : ""}
  <icon name="x-office-document" />
  </mime-type>
</mime-info>`
      items.push(data)
    }

    if (items.length === 0) {
      return null
    }

    const file = await this.packager.getTempFile(".xml")
    await outputFile(file, '<?xml version="1.0" encoding="utf-8"?>\n<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">\n' + items.join("\n") + "\n</mime-info>")
    return file
  }

  // must be name without spaces and other special characters, but not product name used
  private async computeDesktopIcons(): Promise<Array<IconInfo>> {
    const packager = this.packager
    const iconDir = packager.platformSpecificBuildOptions.icon
    const sources = iconDir == null ? [] : [iconDir]

    const commonConfiguration = packager.config
    const icnsPath = (commonConfiguration.mac || {}).icon || commonConfiguration.icon<commit_msg>fix: Remove additional xml closing tag (#4078)<commit_after>import { asArray, isEmptyOrSpaces, log } from "builder-util"
import { outputFile } from "fs-extra"
import { Lazy } from "lazy-val"
import { LinuxTargetSpecificOptions } from ".."
import { LinuxPackager } from "../linuxPackager"
import { IconInfo } from "../platformPackager"

export const installPrefix = "/opt"

export class LinuxTargetHelper {
  private readonly iconPromise = new Lazy(() => this.computeDesktopIcons())

  private readonly mimeTypeFilesPromise = new Lazy(() => this.computeMimeTypeFiles())

  maxIconPath: string | null = null

  constructor(private packager: LinuxPackager) {
  }

  get icons(): Promise<Array<IconInfo>> {
    return this.iconPromise.value
  }

  get mimeTypeFiles(): Promise<string | null> {
    return this.mimeTypeFilesPromise.value
  }

  private async computeMimeTypeFiles(): Promise<string | null> {
    const items: Array<string> = []
    for (const fileAssociation of this.packager.fileAssociations) {
      if (!fileAssociation.mimeType) {
        continue
      }

      const data = `<mime-type type="${fileAssociation.mimeType}">
  <glob pattern="*.${fileAssociation.ext}"/>
    ${fileAssociation.description ? `<comment>${fileAssociation.description}</comment>` : ""}
  <icon name="x-office-document" />
  </mime-type>`
      items.push(data)
    }

    if (items.length === 0) {
      return null
    }

    const file = await this.packager.getTempFile(".xml")
    await outputFile(file, '<?xml version="1.0" encoding="utf-8"?>\n<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">\n' + items.join("\n") + "\n</mime-info>")
    return file
  }

  // must be name without spaces and other special characters, but not product name used
  private async computeDesktopIcons(): Promise<Array<IconInfo>> {
    const packager = this.packager
    const iconDir = packager.platformSpecificBuildOptions.icon
    const sources = iconDir == null ? [] : [iconDir]

    const commonConfiguration = packager.config
    const icnsPath = (commonConfiguration.mac || {}).icon || commonConfiguration.icon
{'fraction_non_alphanumeric': 0.1362126245847176, 'fraction_numerical': 0.0028476506881822496, 'mean_word_length': 3.9705188679245285, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 2, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 7}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '933862', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1211, 'n_words': 298}