Skip to content

Commit

Permalink
chore: temporarily allow only single-target mods
Browse files Browse the repository at this point in the history
  • Loading branch information
mircearoata committed Oct 19, 2023
1 parent 2102898 commit e1c11b0
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/lib/models/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,36 @@ const validateModZip = async (
.loadAsync(file as any)
.then(async (zip) => {
const uPluginFiles = zip.filter((filePath) => basename(filePath) == modReference + '.uplugin');
const targets = uPluginFiles.map((f) => dirname(f.name));

if (uPluginFiles.length === 0) {
return {
message: 'Mod does not contain any ' + modReference + '.uplugin files'
};
}

if (uPluginFiles.length === 1 && uPluginFiles[0].name === modReference + '.uplugin') {
// Single-target mod
const uPluginData = await readUPluginJson(await uPluginFiles[0].async('string'), modReference);

if ('message' in uPluginData) {
return uPluginData;
}

return {
uplugin: uPluginData,
objects: Object.keys(zip.files).filter(
(f) => f.endsWith('.so') || f.endsWith('.dll') || f.endsWith('.pak')
),
targets: ['Windows']
};
}

// Do not allow multi-target mods for now
return {
message: 'multi-target mods are not allowed'
};

// Multi-target mod
if (uPluginFiles.some((f) => f.name === modReference + '.uplugin')) {
return {
message:
Expand All @@ -100,6 +122,8 @@ const validateModZip = async (
};
}

const targets = uPluginFiles.map((f) => dirname(f.name));

const invalidTargets = targets.filter((t) => !ALLOWED_TARGETS.includes(t as TargetName));
if (invalidTargets.length !== 0) {
return {
Expand Down Expand Up @@ -132,6 +156,10 @@ const validateModZip = async (
// Since the .uplugin files are all the same, we only need to parse one
const uPluginData = await readUPluginJson(uPluginFilesData[0], modReference);

if ('message' in uPluginData) {
return uPluginData;
}

return {
uplugin: uPluginData,
objects: Object.keys(zip.files).filter((f) => f.endsWith('.so') || f.endsWith('.dll') || f.endsWith('.pak')),
Expand Down

0 comments on commit e1c11b0

Please sign in to comment.