add importing from prefix
This commit is contained in:
parent
29a20324a6
commit
b83e530392
11 changed files with 287 additions and 22 deletions
|
|
@ -5,6 +5,7 @@ const path = require('path')
|
|||
const { DIRS, resolvePortablePath } = require('./paths')
|
||||
const { newGame, newGameId, addGame } = require('./library')
|
||||
const { extractIconFromExe } = require('./icons')
|
||||
const { prefixPath } = require('./prefixes')
|
||||
|
||||
// Directories that typically hold installers/redistributables, not the game.
|
||||
const SKIPPED_DIRS = new Set(['redist', 'directx', '_commonredist', 'support', 'dotnet', 'vc'])
|
||||
|
|
@ -62,6 +63,35 @@ async function importGame(srcDir, mode, onProgress) {
|
|||
return addGame(game)
|
||||
}
|
||||
|
||||
// Import from a wine prefix: the folder is picked under the prefix's
|
||||
// drive_c and left in place - the game paths are stored relative to the
|
||||
// prefix, so wine sees the app exactly as if it had been installed
|
||||
// normally into C:\...
|
||||
async function importGameFromPrefix(prefix, srcDir, onProgress) {
|
||||
const prefixes = require('./prefixes')
|
||||
if (!prefixes.listPrefixes().prefixes.some(p => p.name === prefix)) return { ok: false, error: 'prefix-not-found' }
|
||||
// the folder must live inside the prefix's C: drive so the C:\ mapping
|
||||
// holds - drive_c sits at the prefix top for plain wine, under pfx/ for
|
||||
// Proton-managed prefixes
|
||||
const driveRoot = prefixes.prefixDriveRoot(prefix)
|
||||
if (!driveRoot) return { ok: false, error: 'no-drive-c' }
|
||||
const rel = path.relative(driveRoot, srcDir)
|
||||
if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) return { ok: false, error: 'outside-drive-c' }
|
||||
const preExe = await findDefaultExe(srcDir)
|
||||
if (!preExe) return { ok: false, error: 'no-exe-found' }
|
||||
const id = newGameId()
|
||||
const game = newGame({ id, name: path.basename(srcDir), exePath: preExe, workdir: srcDir, mode: 'prefix' })
|
||||
game.importSource = 'prefix'
|
||||
game.prefix = prefix
|
||||
// exe picked automatically -> grab its icon right away; a missing icon is
|
||||
// not an import failure (game can still get one from config)
|
||||
const icon = path.join(DIRS.DATA, 'icons', id, 'icon.ico')
|
||||
if (extractIconFromExe(resolvePortablePath(preExe), icon).ok) {
|
||||
game.iconSource = icon
|
||||
}
|
||||
return addGame(game)
|
||||
}
|
||||
|
||||
// Largest .exe in the tree, skipping redistributable folders. Files are
|
||||
// stat'ed in parallel and folders walked breadth-first so big games don't
|
||||
// turn the picker into a sequential crawl.
|
||||
|
|
@ -103,4 +133,4 @@ async function findDefaultExe(dir) {
|
|||
return best
|
||||
}
|
||||
|
||||
module.exports = { importGame, findDefaultExe, copyRecursive, moveFolder }
|
||||
module.exports = { importGame, importGameFromPrefix, findDefaultExe, copyRecursive, moveFolder }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue