Skip to content

A games launcher for GOG, Amazon and Epic Games for Linux, Windows and macOS.

6.4 KB
Raw Blame
import {
  mkdirSync,
  mkdtempSync,
  rmSync,
  symlinkSync,
  writeFileSync
} from 'graceful-fs'
import { tmpdir } from 'os'
import { join } from 'path'

import { getSideloadPreset } from 'common/sideload_presets'
import {
  decodeRegistryString,
  parseWineRegistry,
  scanGamesForPreset
} from 'backend/storeManagers/sideload/scan'

describe('sideload registry scanning', () => {
  it('decodes Wine registry escapes', () => {
    expect(decodeRegistryString('Assassin\\x2019s Creed')).toBe(
      'Assassin’s Creed'
    )
    expect(decodeRegistryString('C:\\\\Program Files\\\\Game')).toBe(
      'C:\\Program Files\\Game'
    )
  })

  it('does not corrupt path segments that start with escape letters', () => {
    expect(decodeRegistryString('C:\\\\new\\\\tools\\\\temp\\\\x86_64')).toBe(
      'C:\\new\\tools\\temp\\x86_64'
    )
    expect(decodeRegistryString('C:\\\\x86_64\\\\game.exe')).toBe(
      'C:\\x86_64\\game.exe'
    )
  })

  it('parses sections with timestamps and string values', () => {
    const sections = parseWineRegistry(
      [
        '[Software\\\\Wow6432Node\\\\Ubisoft\\\\Launcher\\\\Installs\\\\1848] 123',
        '#time=1',
        '"InstallDir"="C:/Games/Assassin\\x2019s Creed/"',
        '',
        '[Software\\\\Wow6432Node\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Uninstall\\\\StarCraft] 456',
        '"DisplayName"="StarCraft"',
        '"UninstallString"="\\"C:\\\\ProgramData\\\\Battle.net\\\\Agent\\\\Blizzard Uninstaller.exe\\" --uid=s1"'
      ].join('\n')
    )

    expect(sections[0].name).toBe(
      'Software\\Wow6432Node\\Ubisoft\\Launcher\\Installs\\1848'
    )
    expect(sections[0].values.InstallDir).toBe('C:/Games/Assassin’s Creed/')
    expect(sections[1].values.DisplayName).toBe('StarCraft')
    expect(sections[1].values.UninstallString).toContain('--uid=s1')
  })
})

describe('sideload registry adapters', () => {
  let root: string

  beforeEach(() => {
    root = mkdtempSync(join(tmpdir(), 'heroic-scan-'))
  })

  afterEach(() => {
    rmSync(root, { recursive: true, force: true })
  })

  it('scans Ubisoft installs and builds the uplay URL', async () => {
    const gameDir = join(
      root,
      'drive_c',
      'Program Files (x86)',
      'Ubisoft',
      'Ubisoft Game Launcher',
      'games',
      'Assassin’s Creed Chronicles Russia'
    )
    mkdirSync(gameDir, { recursive: true })
    const sections = parseWineRegistry(
      `[Software\\Wow6432Node\\Ubisoft\\Launcher\\Installs\\1848] 1
"InstallDir"="C:/Program Files (x86)/Ubisoft/Ubisoft Game Launcher/games/Assassin\\x2019s Creed Chronicles Russia/"`
    )

    const games = await scanGamesForPreset(
      getSideloadPreset('ubisoft-connect')!,
      root,
      sections
    )

    expect(games).toHaveLength(1)
    expect(games[0].title).toBe('Assassin’s Creed Chronicles Russia')
    expect(games[0].launchUrl).toBe('uplay://launch/1848/0')
  })

  it('scans EA uninstall entries and finds the game executable', async () => {
    const gameDir = join(
      root,
      'drive_c',
      'Program Files',
      'EA Games',
      'The Sims 3'
    )
    const binDir = join(gameDir, 'Game', 'Bin')
    mkdirSync(binDir, { recursive: true })
    writeFileSync(join(binDir, 'TS3.exe'), '')
    writeFileSync(join(binDir, 'Sims3Launcher.exe'), '')
    const sections = parseWineRegistry(
      `[Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{GUID}] 1
"DisplayName"="The Sims\\x2122 3"
"Publisher"="Electronic Arts Inc."
"InstallLocation"="C:\\Program Files\\EA Games\\The Sims 3\\"`
    )

    const games = await scanGamesForPreset(
      getSideloadPreset('ea-app')!,
      root,
      sections
    )

    expect(games).toHaveLength(1)
    expect(games[0].title).toBe('The Sims 3')
    expect(games[0].executable?.endsWith('TS3.exe')).toBe(true)
  })

  it('scans Battle.net products with a Blizzard uninstaller', async () => {
    const gameDir = join(
      root,
      'drive_c',
      'Program Files (x86)',
      'StarCraft',
      'x86_64'
    )
    mkdirSync(gameDir, { recursive: true })
    writeFileSync(join(gameDir, 'StarCraft.exe'), '')
    const sections = parseWineRegistry(
      `[Software\\Classes\\battlenet] 1
"URL Protocol"=hex(1):
[Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\StarCraft] 1
"DisplayName"="StarCraft"
"InstallLocation"="C:\\Program Files (x86)\\StarCraft"
"UninstallString"="\\"C:\\ProgramData\\Battle.net\\Agent\\Blizzard Uninstaller.exe\\" --lang=enUS --uid=s1 --displayname=\\"StarCraft\\""`
    )

    const games = await scanGamesForPreset(
      getSideloadPreset('battlenet')!,
      root,
      sections
    )

    expect(games).toHaveLength(1)
    expect(games[0].title).toBe('StarCraft')
    expect(games[0].executable?.endsWith('StarCraft.exe')).toBe(true)
    expect(games[0].launchUrl).toBe('battlenet://s1')
  })

  it('maps non-C Wine drives through dosdevices', async () => {
    const gameDir = join(root, 'drive_d', 'EA Games', 'The Sims 3', 'Bin')
    mkdirSync(gameDir, { recursive: true })
    writeFileSync(join(gameDir, 'TS3.exe'), '')
    mkdirSync(join(root, 'dosdevices'), { recursive: true })
    symlinkSync('../drive_d', join(root, 'dosdevices', 'd:'))

    const sections = parseWineRegistry(
      `[Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{GUID}] 1
"DisplayName"="The Sims 3"
"Publisher"="Electronic Arts Inc."
"InstallLocation"="D:\\EA Games\\The Sims 3\\"`
    )

    const games = await scanGamesForPreset(
      getSideloadPreset('ea-app')!,
      root,
      sections
    )

    expect(games).toHaveLength(1)
    expect(games[0].executable?.endsWith('TS3.exe')).toBe(true)
  })

  it('finds executables inside symlinked directories', async () => {
    const installDir = join(root, 'drive_c', 'EA Games', 'The Sims 3')
    const realDir = join(root, 'drive_c', 'shared', 'Bin')
    mkdirSync(realDir, { recursive: true })
    mkdirSync(installDir, { recursive: true })
    writeFileSync(join(realDir, 'TS3.exe'), '')
    symlinkSync(realDir, join(installDir, 'linked'))

    const sections = parseWineRegistry(
      `[Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{GUID}] 1
"DisplayName"="The Sims 3"
"Publisher"="Electronic Arts Inc."
"InstallLocation"="C:\\EA Games\\The Sims 3\\"`
    )

    const games = await scanGamesForPreset(
      getSideloadPreset('ea-app')!,
      root,
      sections
    )

    expect(games).toHaveLength(1)
    expect(games[0].executable?.endsWith('TS3.exe')).toBe(true)
  })
})