Skip to content

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

1.1 KB
Raw Blame
import { existsSync, mkdirSync } from 'graceful-fs'

import { LogPrefix, logError, logInfo } from 'backend/logger'

import { itchioConfigPath } from './constants'

/**
 * Ensure butlerd's writable state directory exists. The daemon stores its
 * SQLite db under `itchioConfigPath`; without the directory, the very first
 * `Profile.LoginWithAPIKey` call fails with an obscure sqlite-open error.
 *
 * The butler binary itself is resolved via `getButlerBin()`, which looks it
 * up under `public/bin/<arch>/<platform>/` (downloaded at build time from
 * broth.itch.zone — see `meta/downloadHelperBinaries.ts`) and falls back to a
 * user-configured `altButlerBin`.
 */
export default function setupItchio(): Promise<void> {
  if (!existsSync(itchioConfigPath)) {
    try {
      mkdirSync(itchioConfigPath, { recursive: true })
      logInfo(
        `Created itch.io config dir at ${itchioConfigPath}`,
        LogPrefix.Itchio
      )
    } catch (err) {
      logError(
        [`Failed to create ${itchioConfigPath}:`, (err as Error).message],
        LogPrefix.Itchio
      )
    }
  }
  return Promise.resolve()
}