84 lines
2.4 KiB
TypeScript
84 lines
2.4 KiB
TypeScript
import { app } from 'electron'
|
|
import { join } from 'path'
|
|
import { mkdirSync } from 'fs'
|
|
import { readLauncherConfigSync } from './launcher-config'
|
|
|
|
/**
|
|
* Arborescence des données du launcher.
|
|
*
|
|
* La racine est configurable via launcher.json (userData/launcher.json) :
|
|
* { "dataDir": "/chemin/choisi/par/l/utilisateur" }
|
|
* Par défaut : userData d'Electron (%APPDATA%/OFLauncher sur Windows,
|
|
* ~/.config/OFLauncher sur Linux).
|
|
*
|
|
* La config launcher.json elle-même reste toujours dans userData
|
|
* (point d'ancrage fixe, indépendant du dataDir choisi).
|
|
*/
|
|
class LauncherPaths {
|
|
private _root: string | null = null
|
|
|
|
/** Racine des données du jeu (configurable). */
|
|
get root(): string {
|
|
if (!this._root) {
|
|
const { dataDir } = readLauncherConfigSync()
|
|
this._root = dataDir ?? app.getPath('userData')
|
|
}
|
|
return this._root
|
|
}
|
|
|
|
/** Invalide le cache de root (à appeler après écriture d'un nouveau dataDir). */
|
|
invalidate(): void {
|
|
this._root = null
|
|
}
|
|
|
|
/** Dossier "Minecraft" géré par @xmcl : versions/, libraries/, assets/. */
|
|
get gameRoot(): string {
|
|
return this.ensure(join(this.root, 'minecraft'))
|
|
}
|
|
|
|
/** Dossier d'instance du modpack : mods/, config/, saves/ (cible packwiz). */
|
|
get instanceDir(): string {
|
|
return this.ensure(join(this.root, 'instance'))
|
|
}
|
|
|
|
/** Runtimes Java téléchargés (un sous-dossier par composant Mojang). */
|
|
get javaDir(): string {
|
|
return this.ensure(join(this.root, 'java'))
|
|
}
|
|
|
|
/** Cache des tokens d'auth (prismarine-auth). */
|
|
get authCache(): string {
|
|
return this.ensure(join(this.root, 'auth-cache'))
|
|
}
|
|
|
|
/** Fichier de réglages utilisateur. */
|
|
get settingsFile(): string {
|
|
return join(this.root, 'settings.json')
|
|
}
|
|
|
|
/** Dossier des logs du launcher (install/Java/packwiz/jeu). */
|
|
get logsDir(): string {
|
|
return this.ensure(join(this.root, 'logs'))
|
|
}
|
|
|
|
/** Fichier de log courant du launcher. */
|
|
get launcherLogFile(): string {
|
|
return join(this.logsDir, 'launcher.log')
|
|
}
|
|
|
|
/** jar packwiz-installer-bootstrap embarqué dans les resources. */
|
|
get packwizBootstrapJar(): string {
|
|
const base = app.isPackaged
|
|
? join(process.resourcesPath, 'resources')
|
|
: join(app.getAppPath(), 'resources')
|
|
return join(base, 'packwiz-installer-bootstrap.jar')
|
|
}
|
|
|
|
private ensure(dir: string): string {
|
|
mkdirSync(dir, { recursive: true })
|
|
return dir
|
|
}
|
|
}
|
|
|
|
export const paths = new LauncherPaths()
|