Upload via GUI (39 Dateien)
This commit is contained in:
+32
-18
@@ -124,12 +124,25 @@ function gameDir(id) {
|
||||
return path.join(instancePath(id), 'minecraft');
|
||||
}
|
||||
|
||||
function modsDir(id) {
|
||||
return path.join(gameDir(id), 'mods');
|
||||
/*
|
||||
* Inhalte je Art: Mods, Ressourcenpakete und Shader liegen in verschiedenen
|
||||
* Ordnern des Spielverzeichnisses und werden getrennt verzeichnet.
|
||||
* "mod" behält die bisherigen Namen, damit vorhandene Instanzen unverändert
|
||||
* weiterlaufen.
|
||||
*/
|
||||
const INHALT_ORDNER = { mod: 'mods', resourcepack: 'resourcepacks', shader: 'shaderpacks' };
|
||||
const INHALT_INDEX = { mod: 'mods.json', resourcepack: 'resourcepacks.json', shader: 'shaders.json' };
|
||||
|
||||
function inhaltsDir(id, art = 'mod') {
|
||||
return path.join(gameDir(id), INHALT_ORDNER[art] || INHALT_ORDNER.mod);
|
||||
}
|
||||
|
||||
function modsIndexFile(id) {
|
||||
return path.join(instancePath(id), 'mods.json');
|
||||
function modsDir(id, art = 'mod') {
|
||||
return inhaltsDir(id, art);
|
||||
}
|
||||
|
||||
function modsIndexFile(id, art = 'mod') {
|
||||
return path.join(instancePath(id), INHALT_INDEX[art] || INHALT_INDEX.mod);
|
||||
}
|
||||
|
||||
// ---------- installierte Mods (Metadaten je Instanz) ----------
|
||||
@@ -142,8 +155,8 @@ function modsIndexFile(id) {
|
||||
const MOD_ENDUNG = /\.(jar|zip)$/i;
|
||||
const AUS_ENDUNG = /\.(jar|zip)\.disabled$/i;
|
||||
|
||||
function scanModsDir(id) {
|
||||
const dir = modsDir(id);
|
||||
function scanModsDir(id, art = 'mod') {
|
||||
const dir = modsDir(id, art);
|
||||
if (!fs.existsSync(dir)) return [];
|
||||
const gefunden = [];
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
@@ -163,9 +176,9 @@ function scanModsDir(id) {
|
||||
return gefunden;
|
||||
}
|
||||
|
||||
function listMods(id) {
|
||||
const aufDerPlatte = new Map(scanModsDir(id).map((m) => [m.filename, m]));
|
||||
const indexed = readJson(modsIndexFile(id), []);
|
||||
function listMods(id, art = 'mod') {
|
||||
const aufDerPlatte = new Map(scanModsDir(id, art).map((m) => [m.filename, m]));
|
||||
const indexed = readJson(modsIndexFile(id, art), []);
|
||||
const merged = new Map();
|
||||
|
||||
for (const entry of indexed) {
|
||||
@@ -186,8 +199,8 @@ function listMods(id) {
|
||||
* Schaltet eine Mod an oder aus, indem die Datei umbenannt wird.
|
||||
* -> { ok, enabled } oder { ok: false, reason }
|
||||
*/
|
||||
function setModEnabled(id, filename, enabled) {
|
||||
const dir = modsDir(id);
|
||||
function setModEnabled(id, filename, enabled, art = 'mod') {
|
||||
const dir = modsDir(id, art);
|
||||
const anPfad = path.join(dir, filename);
|
||||
const ausPfad = anPfad + '.disabled';
|
||||
// Pfad darf den mods-Ordner nicht verlassen
|
||||
@@ -212,18 +225,18 @@ function setModEnabled(id, filename, enabled) {
|
||||
}
|
||||
}
|
||||
|
||||
function addMod(id, entry) {
|
||||
const list = listMods(id).filter((m) => m.filename !== entry.filename);
|
||||
function addMod(id, entry, art = 'mod') {
|
||||
const list = listMods(id, art).filter((m) => m.filename !== entry.filename);
|
||||
list.push(entry);
|
||||
writeJson(modsIndexFile(id), list);
|
||||
writeJson(modsIndexFile(id, art), list);
|
||||
return list;
|
||||
}
|
||||
|
||||
function removeMod(id, filename) {
|
||||
const list = listMods(id).filter((m) => m.filename !== filename);
|
||||
writeJson(modsIndexFile(id), list);
|
||||
function removeMod(id, filename, art = 'mod') {
|
||||
const list = listMods(id, art).filter((m) => m.filename !== filename);
|
||||
writeJson(modsIndexFile(id, art), list);
|
||||
// zugehörige Datei löschen – auch, wenn sie gerade abgeschaltet ist
|
||||
const jar = path.join(modsDir(id), filename);
|
||||
const jar = path.join(modsDir(id, art), filename);
|
||||
for (const p of [jar, jar + '.disabled']) {
|
||||
try { if (fs.existsSync(p)) fs.unlinkSync(p); } catch { /* egal */ }
|
||||
}
|
||||
@@ -423,6 +436,7 @@ module.exports = {
|
||||
instancePath,
|
||||
gameDir,
|
||||
modsDir,
|
||||
inhaltsDir,
|
||||
iconDataUri,
|
||||
setCustomImage,
|
||||
clearCustomImage,
|
||||
|
||||
Reference in New Issue
Block a user