First build

This commit is contained in:
olcxja 2026-09-25 17:09:38 +02:00
commit fd773f5832
954 changed files with 305115 additions and 2 deletions

87
src/library.js Normal file
View file

@ -0,0 +1,87 @@
'use strict'
const path = require('path')
const { DIRS, readJson, writeJson } = require('./paths')
const { prefixPath } = require('./prefixes')
const REGISTRY = path.join(DIRS.DATA, 'games.json')
const SETTINGS = path.join(DIRS.DATA, 'settings.json')
function loadGames() {
return readJson(REGISTRY, [])
}
function saveGames(games) {
writeJson(REGISTRY, games)
}
function getGame(id) {
return loadGames().find(g => g.id === id) || null
}
function addGame(game) {
const games = loadGames()
games.push(game)
saveGames(games)
return game
}
function updateGame(id, patch) {
const games = loadGames()
const g = games.find(x => x.id === id)
if (!g) return null
Object.assign(g, patch)
saveGames(games)
return g
}
function removeGame(id) {
const games = loadGames()
const idx = games.findIndex(g => g.id === id)
if (idx === -1) return false
const g = games[idx]
if (g.imported && g.path && g.path.startsWith(DIRS.GAMES)) {
try {
require('fs').rmSync(g.path, { recursive: true, force: true })
} catch {}
}
games.splice(idx, 1)
saveGames(games)
return true
}
function loadSettings() {
return readJson(SETTINGS, { language: 'en-us', defaultWine: 'system', theme: 'dark' })
}
function saveSettings(patch) {
const s = { ...loadSettings(), ...patch }
writeJson(SETTINGS, s)
return s
}
function newGame({ name, exePath, workdir, mode }) {
return {
id: 'g' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6),
name,
mode,
path: workdir,
exePath,
workdir,
wine: 'system',
prefix: '',
args: '',
dllOverrides: [],
env: {},
created: Date.now(),
lastPlayed: 0
}
}
function resolvePrefixDir(game) {
if (game.prefix) return prefixPath(game.prefix)
const defs = readJson(path.join(DIRS.DATA, 'prefixes.json'), { default: 'default', prefixes: [] })
return prefixPath(defs.default || 'default')
}
module.exports = { loadGames, saveGames, getGame, addGame, updateGame, removeGame, loadSettings, saveSettings, newGame, resolvePrefixDir }