code cleanup

This commit is contained in:
olcxja 2026-09-26 10:13:50 +02:00
commit e8cd664965
8 changed files with 362 additions and 406 deletions

View file

@ -4,6 +4,7 @@ const fs = require('fs')
const fsp = fs.promises
const path = require('path')
const { DIRS, readJson, writeJson } = require('./paths')
const { dedupeDir } = require('./fsutil')
const WINES_DIR = DIRS.WINES
const REGISTRY = path.join(DIRS.DATA, 'wines.json')
@ -119,13 +120,8 @@ async function refreshWines() {
}
const disabled = new Set(prev.filter(w => w.disabled).map(w => w.id))
for (const w of found) if (disabled.has(w.id)) w.disabled = true
const merged = [...found]
for (const p of prev) {
if (p.system) merged.push(p)
else if (!found.some(f => f.id === p.id) && exists(p.path)) merged.push(p)
}
writeJson(REGISTRY, merged)
return merged
writeJson(REGISTRY, found)
return found
}
function getWines() {
@ -169,16 +165,6 @@ function deleteWine(id) {
return { ok: true }
}
function dedupeDir(base, name) {
let candidate = path.join(base, name)
let n = 2
while (fs.existsSync(candidate)) {
candidate = path.join(base, `${name} (${n})`)
n++
}
return candidate
}
// --- symlink healing -------------------------------------------------------
// Wine/Proton builds contain symlinks (e.g. inside the bundled default prefix)
// that point to absolute paths from wherever the build lived before (zip
@ -261,16 +247,13 @@ async function importWineFolder(srcDir) {
const type = detectType(srcDir)
let copySrc = srcDir
if (!type) {
// the user picked a folder one level above the actual build
let subs = []
try {
subs = (await fsp.readdir(srcDir, { withFileTypes: true })).filter(e => e.isDirectory())
} catch {}
for (const s of subs) {
if (detectType(path.join(srcDir, s.name))) {
copySrc = path.join(srcDir, s.name)
break
}
}
const build = subs.find(s => detectType(path.join(srcDir, s.name)))
if (build) copySrc = path.join(srcDir, build.name)
}
const dst = dedupeDir(WINES_DIR, path.basename(copySrc))
await fsp.cp(copySrc, dst, { recursive: true, verbatimSymlinks: true })