mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-16 01:31:19 +10:00
feat: import of custom platforms & file extensions
This commit is contained in:
@ -20,7 +20,7 @@ class DownloadContextManager {
|
||||
where: {
|
||||
gameId: game,
|
||||
versionPath,
|
||||
gameVersion: {
|
||||
game: {
|
||||
isNot: null,
|
||||
},
|
||||
},
|
||||
|
||||
@ -55,47 +55,64 @@ class ManifestGenerator {
|
||||
async generateManifest(versionId: string) {
|
||||
const versions = [];
|
||||
|
||||
const baseVersion = await prisma.version.findUnique({
|
||||
const baseVersion = await prisma.gameVersion.findUnique({
|
||||
where: {
|
||||
versionId,
|
||||
version: {
|
||||
gameId: {
|
||||
not: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
gameVersion: true,
|
||||
platform: true,
|
||||
version: {
|
||||
select: {
|
||||
gameId: true,
|
||||
dropletManifest: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!baseVersion) return undefined;
|
||||
versions.push(baseVersion);
|
||||
|
||||
// Collect other versions if this is a delta
|
||||
if (baseVersion.gameVersion?.delta) {
|
||||
if (baseVersion.delta) {
|
||||
// Start at the same index minus one, and keep grabbing them
|
||||
// until we run out or we hit something that isn't a delta
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
for (let i = baseVersion.gameVersion.versionIndex - 1; true; i--) {
|
||||
const currentVersion = await prisma.version.findFirst({
|
||||
for (let i = baseVersion.versionIndex - 1; true; i--) {
|
||||
const currentVersion = await prisma.gameVersion.findFirst({
|
||||
where: {
|
||||
gameId: baseVersion.gameId,
|
||||
platform: baseVersion.platform,
|
||||
gameVersion: {
|
||||
versionIndex: i,
|
||||
version: {
|
||||
gameId: baseVersion.version.gameId!,
|
||||
},
|
||||
platform: {
|
||||
id: baseVersion.platform.id,
|
||||
},
|
||||
versionIndex: i,
|
||||
},
|
||||
include: {
|
||||
gameVersion: true,
|
||||
version: {
|
||||
select: {
|
||||
dropletManifest: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!currentVersion) return undefined;
|
||||
versions.push(currentVersion);
|
||||
if (!currentVersion.gameVersion?.delta) break;
|
||||
if (!currentVersion?.delta) break;
|
||||
}
|
||||
}
|
||||
versions.reverse();
|
||||
const metadata: DropManifestMetadata[] = versions.map((version) => {
|
||||
const metadata: DropManifestMetadata[] = versions.map((gameVersion) => {
|
||||
return {
|
||||
manifest: JSON.parse(
|
||||
version.dropletManifest?.toString() ?? "{}",
|
||||
gameVersion.version.dropletManifest?.toString() ?? "{}",
|
||||
) as DropManifest,
|
||||
versionId: version.versionId,
|
||||
versionId: gameVersion.versionId,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@ -9,13 +9,12 @@ import path from "path";
|
||||
import prisma from "../db/database";
|
||||
import { fuzzy } from "fast-fuzzy";
|
||||
import taskHandler from "../tasks";
|
||||
import { parsePlatform } from "../utils/parseplatform";
|
||||
import notificationSystem from "../notifications";
|
||||
import { GameNotFoundError, type LibraryProvider } from "./provider";
|
||||
import { logger } from "../logging";
|
||||
import { createHash } from "node:crypto";
|
||||
import type { ImportVersion } from "~/server/api/v1/admin/import/version/index.post";
|
||||
import type { LaunchOptionCreateManyGameVersionInput } from "~/prisma/client/models";
|
||||
import type { LaunchOptionCreateManyInput } from "~/prisma/client/models";
|
||||
|
||||
export function createGameImportTaskId(libraryId: string, libraryPath: string) {
|
||||
return createHash("md5")
|
||||
@ -221,6 +220,8 @@ class LibraryManager {
|
||||
const library = this.libraries.get(game.libraryId);
|
||||
if (!library) return undefined;
|
||||
|
||||
const userPlatforms = await prisma.userPlatform.findMany({});
|
||||
|
||||
const fileExts: { [key: string]: string[] } = {
|
||||
Linux: [
|
||||
// Ext for Unity games
|
||||
@ -239,6 +240,12 @@ class LibraryManager {
|
||||
],
|
||||
};
|
||||
|
||||
for (const platform of userPlatforms) {
|
||||
fileExts[platform.id] = platform.fileExtensions;
|
||||
}
|
||||
|
||||
console.log(fileExts);
|
||||
|
||||
const options: Array<{
|
||||
filename: string;
|
||||
platform: string;
|
||||
@ -299,9 +306,6 @@ class LibraryManager {
|
||||
) {
|
||||
const taskId = createVersionImportTaskId(gameId, versionPath);
|
||||
|
||||
const platform = parsePlatform(metadata.platform);
|
||||
if (!platform) return undefined;
|
||||
|
||||
const game = await prisma.game.findUnique({
|
||||
where: { id: gameId },
|
||||
select: { mName: true, libraryId: true, libraryPath: true },
|
||||
@ -345,17 +349,14 @@ class LibraryManager {
|
||||
versionPath: versionPath,
|
||||
versionName: metadata.name ?? versionPath,
|
||||
dropletManifest: manifest,
|
||||
platform: platform,
|
||||
|
||||
gameVersion: {
|
||||
gameVersions: {
|
||||
create: {
|
||||
versionIndex: currentIndex,
|
||||
delta: metadata.delta,
|
||||
umuIdOverride: metadata.umuId,
|
||||
|
||||
onlySetup: metadata.onlySetup,
|
||||
setupCommand: metadata.setup,
|
||||
setupArgs: metadata.setupArgs,
|
||||
|
||||
launches: {
|
||||
createMany: {
|
||||
@ -364,12 +365,27 @@ class LibraryManager {
|
||||
({
|
||||
name: v.name,
|
||||
description: v.description,
|
||||
launchCommand: v.launchCommand,
|
||||
launchArgs: v.launchArgs,
|
||||
}) satisfies LaunchOptionCreateManyGameVersionInput,
|
||||
command: v.launchCommand,
|
||||
args: v.launchArgs,
|
||||
}) satisfies LaunchOptionCreateManyInput,
|
||||
),
|
||||
},
|
||||
},
|
||||
|
||||
install: {
|
||||
create: {
|
||||
name: "",
|
||||
description: "",
|
||||
command: metadata.setup,
|
||||
args: metadata.setupArgs,
|
||||
},
|
||||
},
|
||||
|
||||
platform: {
|
||||
connect: {
|
||||
id: metadata.platform,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
47
server/internal/platform/link.ts
Normal file
47
server/internal/platform/link.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import { Platform, type HardwarePlatform } from "~/prisma/client/enums";
|
||||
import prisma from "../db/database";
|
||||
import type { PlatformLink } from "~/prisma/client/client";
|
||||
|
||||
export async function convertIDsToPlatforms(platformIDs: string[]) {
|
||||
const userPlatforms = await prisma.userPlatform.findMany({
|
||||
where: {
|
||||
id: {
|
||||
in: platformIDs,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const platforms = platformIDs.map(
|
||||
(e) => userPlatforms.find((v) => v.id === e) ?? (e as HardwarePlatform),
|
||||
);
|
||||
|
||||
return platforms;
|
||||
}
|
||||
|
||||
export async function convertIDToLink(
|
||||
id: string,
|
||||
): Promise<PlatformLink | undefined> {
|
||||
const link = await prisma.platformLink.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
if (link) return link;
|
||||
|
||||
if (Platform[id as Platform]) {
|
||||
return await prisma.platformLink.create({
|
||||
data: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const userPlatform = await prisma.userPlatform.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
if (!userPlatform) return undefined;
|
||||
return await prisma.platformLink.create({
|
||||
data: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user