import { existsSync, renameSync } from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' export const WINDOWS_LAUNCHER_EXE = 'FarmControl.exe' const SOURCE_LAUNCHER_NAMES = ['launcher.exe', 'Farm Control.exe'] export function patchWindowsBinaries(appDir) { const binDir = path.join(appDir, 'bin') if (!existsSync(binDir)) { throw new Error(`patch-windows-binaries: bin directory not found at ${binDir}`) } const destPath = path.join(binDir, WINDOWS_LAUNCHER_EXE) const sourcePath = SOURCE_LAUNCHER_NAMES.map((name) => path.join(binDir, name) ).find((candidate) => existsSync(candidate)) if (existsSync(destPath) && !sourcePath) { console.log(`patch-windows-binaries: ${WINDOWS_LAUNCHER_EXE} already present`) return } if (!sourcePath) { console.warn( `patch-windows-binaries: skipping; no launcher.exe or Farm Control.exe in ${binDir}` ) return } if (existsSync(destPath) && destPath !== sourcePath) { renameSync(destPath, `${destPath}.old`) } if (sourcePath !== destPath) { renameSync(sourcePath, destPath) console.log( `patch-windows-binaries: renamed ${path.basename(sourcePath)} -> ${WINDOWS_LAUNCHER_EXE}` ) } } if (process.argv[1] === fileURLToPath(import.meta.url)) { const appDirArg = process.argv[2] if (!appDirArg) { console.error('Usage: bun scripts/patch-windows-binaries.mjs ') process.exit(1) } patchWindowsBinaries(path.resolve(appDirArg)) }