Upload via GUI (25 Dateien)
This commit is contained in:
+67
-10
@@ -125,8 +125,30 @@ function modsIndexFile(id) {
|
||||
|
||||
// ---------- installierte Mods (Metadaten je Instanz) ----------
|
||||
|
||||
function scanModsDir(id) {
|
||||
const dir = modsDir(id);
|
||||
if (!fs.existsSync(dir)) return [];
|
||||
return fs.readdirSync(dir, { withFileTypes: true })
|
||||
.filter((entry) => entry.isFile() && /\.(jar|zip)$/i.test(entry.name))
|
||||
.sort((a, b) => a.name.localeCompare(b.name))
|
||||
.map((entry) => ({
|
||||
projectId: null,
|
||||
title: entry.name.replace(/\.(jar|zip)$/i, ''),
|
||||
filename: entry.name,
|
||||
versionNumber: 'Importiert',
|
||||
}));
|
||||
}
|
||||
|
||||
function listMods(id) {
|
||||
return readJson(modsIndexFile(id), []);
|
||||
const indexed = readJson(modsIndexFile(id), []);
|
||||
const merged = new Map();
|
||||
for (const entry of indexed) {
|
||||
if (entry && entry.filename) merged.set(entry.filename, entry);
|
||||
}
|
||||
for (const entry of scanModsDir(id)) {
|
||||
if (!merged.has(entry.filename)) merged.set(entry.filename, entry);
|
||||
}
|
||||
return [...merged.values()];
|
||||
}
|
||||
|
||||
function addMod(id, entry) {
|
||||
@@ -230,6 +252,16 @@ function getInstance(id) {
|
||||
return readJson(instanceFile(id), null);
|
||||
}
|
||||
|
||||
function normalizeInstanceName(name) {
|
||||
return String(name || '').trim().toLowerCase();
|
||||
}
|
||||
|
||||
function findInstanceByName(name) {
|
||||
const needle = normalizeInstanceName(name);
|
||||
if (!needle) return null;
|
||||
return listInstances().find((inst) => normalizeInstanceName(inst.name) === needle) || null;
|
||||
}
|
||||
|
||||
// Ordnername aus dem Instanznamen ableiten (wie MultiMC), ungültige Zeichen raus
|
||||
function slugForName(name) {
|
||||
const base = String(name || 'Instanz').trim()
|
||||
@@ -248,20 +280,43 @@ function uniqueFolderId(name) {
|
||||
return id;
|
||||
}
|
||||
|
||||
function createInstance(data) {
|
||||
const inst = defaultInstance(data && data.name);
|
||||
inst.id = uniqueFolderId(inst.name); // Ordner = Instanzname statt Zufalls-ID
|
||||
if (data) {
|
||||
if (data.icon) inst.icon = data.icon;
|
||||
if (data.minecraft) Object.assign(inst.minecraft, data.minecraft);
|
||||
if (data.notes) inst.notes = data.notes;
|
||||
if (data.group !== undefined) inst.group = data.group;
|
||||
}
|
||||
function applyInstanceData(inst, data) {
|
||||
if (!data) return inst;
|
||||
if (data.name) inst.name = data.name;
|
||||
if (data.icon) inst.icon = data.icon;
|
||||
if (data.minecraft) Object.assign(inst.minecraft, data.minecraft);
|
||||
if (data.notes !== undefined) inst.notes = data.notes;
|
||||
if (data.group !== undefined) inst.group = data.group;
|
||||
return inst;
|
||||
}
|
||||
|
||||
function writeInstance(inst) {
|
||||
ensureDir(gameDir(inst.id));
|
||||
writeJson(instanceFile(inst.id), inst);
|
||||
return inst;
|
||||
}
|
||||
|
||||
function createInstance(data) {
|
||||
const inst = applyInstanceData(defaultInstance(data && data.name), data);
|
||||
inst.id = uniqueFolderId(inst.name); // Ordner = Instanzname statt Zufalls-ID
|
||||
return writeInstance(inst);
|
||||
}
|
||||
|
||||
function createOrReplaceImportedInstance(data) {
|
||||
const existing = findInstanceByName(data && data.name);
|
||||
if (!existing) return createInstance(data);
|
||||
|
||||
const inst = applyInstanceData(defaultInstance(data && data.name), data);
|
||||
inst.id = existing.id;
|
||||
inst.created = existing.created || inst.created;
|
||||
inst.lastPlayed = existing.lastPlayed || null;
|
||||
inst.totalPlaySeconds = existing.totalPlaySeconds || 0;
|
||||
|
||||
const p = instancePath(existing.id);
|
||||
if (fs.existsSync(p)) fs.rmSync(p, { recursive: true, force: true });
|
||||
return writeInstance(inst);
|
||||
}
|
||||
|
||||
function updateInstance(id, patch) {
|
||||
const inst = getInstance(id);
|
||||
if (!inst) throw new Error('Instanz nicht gefunden: ' + id);
|
||||
@@ -313,7 +368,9 @@ module.exports = {
|
||||
removeMod,
|
||||
listInstances,
|
||||
getInstance,
|
||||
findInstanceByName,
|
||||
createInstance,
|
||||
createOrReplaceImportedInstance,
|
||||
updateInstance,
|
||||
deleteInstance,
|
||||
duplicateInstance,
|
||||
|
||||
Reference in New Issue
Block a user