Skip to content

Commit

Permalink
fix: Should ensure java before forge install
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Oct 8, 2024
1 parent 60acc56 commit c871ee2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
3 changes: 1 addition & 2 deletions xmcl-keystone-ui/src/composables/instanceResourcePack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ function getResourcePackItem(resource: Resource, enabled: Set<string>): Instance
*/
export function useInstanceResourcePacks(path: Ref<string>, gameOptions: Ref<GameOptions | undefined>) {
const { watch } = useService(InstanceResourcePacksServiceKey)
const local = ref([] as Resource[])
const { state, isValidating, revalidate, error } = useState(() => path.value ? watch(path.value) : undefined, ReactiveResourceState)

const { t } = useI18n()
Expand Down Expand Up @@ -108,7 +107,7 @@ export function useInstanceResourcePacks(path: Ref<string>, gameOptions: Ref<Gam
const mapped = [] as InstanceResourcePack[]
const index: Record<string, InstanceResourcePack> = {}
const disabled = [] as InstanceResourcePack[]
for (const r of (state.value?.files || []).concat(local.value)) {
for (const r of (state.value?.files || [])) {
const val = getResourcePackItem(r, enabledSet)
if (val.enabled) {
index[val.id] = val
Expand Down
1 change: 1 addition & 0 deletions xmcl-keystone-ui/src/composables/instanceVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,6 @@ export function useInstanceVersion(instance: Ref<Instance>, local: Ref<VersionHe
error,
isValidating,
resolvedVersion,
refreshResolvedVersion: () => mutate(instance.value),
}
}
19 changes: 14 additions & 5 deletions xmcl-keystone-ui/src/composables/instanceVersionInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface InstanceInstallInstruction {
export const kInstanceVersionInstall = Symbol('InstanceVersionInstall') as InjectionKey<ReturnType<typeof useInstanceVersionInstallInstruction>>
const kAbort = Symbol('Aborted')

function useInstanceVersionInstall(versions: Ref<VersionHeader[]>, servers: Ref<ServerVersionHeader[]>) {
function useInstanceVersionInstall(versions: Ref<VersionHeader[]>, servers: Ref<ServerVersionHeader[]>, javas: Ref<JavaRecord[]>) {
const {
installForge,
installNeoForged,
Expand All @@ -45,7 +45,8 @@ function useInstanceVersionInstall(versions: Ref<VersionHeader[]>, servers: Ref<
installQuilt,
installLabyModVersion,
} = useService(InstallServiceKey)
const { refreshVersion } = useService(VersionServiceKey)
const { refreshVersion, resolveLocalVersion } = useService(VersionServiceKey)
const { installDefaultJava } = useService(JavaServiceKey)

const cfg = inject(kSWRVConfig)

Expand All @@ -68,6 +69,13 @@ function useInstanceVersionInstall(versions: Ref<VersionHeader[]>, servers: Ref<
const forgeVersions = await getSWRV(getForgeVersionsModel(minecraft), cfg)
const found = forgeVersions.find(v => v.version === forge)
const forgeVersionId = found?.version ?? forge

if (javas.value.length === 0 || javas.value.every(java => !java.valid)) {
// no valid java
const mcVersionResolved = await resolveLocalVersion(minecraft)
await installDefaultJava(mcVersionResolved.javaVersion)
}

forgeVersion = await installForge({ mcversion: minecraft, version: forgeVersionId, installer: found?.installer })
} else {
forgeVersion = localForge.id
Expand Down Expand Up @@ -189,15 +197,15 @@ function useInstanceVersionInstall(versions: Ref<VersionHeader[]>, servers: Ref<
}
}

export function useInstanceVersionInstallInstruction(path: Ref<string>, instances: Ref<Instance[]>, resolvedVersion: Ref<InstanceResolveVersion | undefined>, versions: Ref<VersionHeader[]>, servers: Ref<ServerVersionHeader[]>, javas: Ref<JavaRecord[]>) {
export function useInstanceVersionInstallInstruction(path: Ref<string>, instances: Ref<Instance[]>, resolvedVersion: Ref<InstanceResolveVersion | undefined>, refreshResolvedVersion: () => void, versions: Ref<VersionHeader[]>, servers: Ref<ServerVersionHeader[]>, javas: Ref<JavaRecord[]>) {
const { diagnoseAssetIndex, diagnoseAssets, diagnoseJar, diagnoseLibraries, diagnoseProfile } = useService(DiagnoseServiceKey)
const { installAssetsForVersion, installForge, installAssets, installMinecraftJar, installLibraries, installNeoForged, installDependencies, installOptifine, installByProfile } = useService(InstallServiceKey)
const { editInstance } = useService(InstanceServiceKey)
const { resolveLocalVersion } = useService(VersionServiceKey)
const { installDefaultJava } = useService(JavaServiceKey)
const { notify } = useNotifier()

const { install, installServer } = useInstanceVersionInstall(versions, servers)
const { install, installServer } = useInstanceVersionInstall(versions, servers, javas)

let abortController = new AbortController()
const instruction: ShallowRef<InstanceInstallInstruction | undefined> = shallowRef(undefined)
Expand Down Expand Up @@ -442,7 +450,8 @@ export function useInstanceVersionInstallInstruction(path: Ref<string>, instance
}
if (instruction.assetIndex) {
const list = await getSWRV(getMinecraftVersionsModel(), config)
await installAssetsForVersion(instruction.assetIndex.version, list.versions.filter(v => v.id === instruction.runtime.minecraft || v.id === instruction.runtime.assets))
await installAssetsForVersion(instruction.version, list.versions.filter(v => v.id === instruction.runtime.minecraft || v.id === instruction.runtime.assets))
refreshResolvedVersion()
} else if (instruction.assets) {
await installAssets(instruction.assets.map(v => v.asset), instruction.runtime.minecraft, instruction.assets.length > 15)
}
Expand Down
2 changes: 1 addition & 1 deletion xmcl-keystone-ui/src/windows/main/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default defineComponent({
const resourcePackSearch = useResourcePackSearch(instance.runtime, resourcePacks.enabled, resourcePacks.disabled, resourcePacks.enabledSet)
const shaderPackSearch = useShaderPackSearch(instance.runtime, shaderPacks.shaderPacks)

const install = useInstanceVersionInstallInstruction(instance.path, instance.instances, instanceVersion.resolvedVersion, localVersions.versions, localVersions.servers, java.all)
const install = useInstanceVersionInstallInstruction(instance.path, instance.instances, instanceVersion.resolvedVersion, instanceVersion.refreshResolvedVersion, localVersions.versions, localVersions.servers, java.all)

useTelemetryTrack(settings.state)

Expand Down
4 changes: 2 additions & 2 deletions xmcl-runtime/instanceIO/InstanceFileOperationHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DownloadOptions } from '@xmcl/file-transfer'
import { ModrinthV2Client } from '@xmcl/modrinth'
import { InstanceFile, InstanceFileWithOperation, ResourceDomain, ResourceMetadata } from '@xmcl/runtime-api'
import { InstanceFile, InstanceFileOperation, InstanceFileWithOperation, ResourceDomain, ResourceMetadata } from '@xmcl/runtime-api'
import { Task } from '@xmcl/task'
import { existsSync } from 'fs'
import { join, relative } from 'path'
Expand All @@ -21,7 +21,7 @@ export class InstanceFileOperationHandler {
#resourceToUpdate: Array<{ hash: string; metadata: ResourceMetadata; uris: string[]; destination: string }> = []
#copyOrLinkQueue: Array<{ file: InstanceFile; src: string; destination: string }> = []
#unzipQueue: Array<{ file: InstanceFile; zipPath: string; entryName: string; destination: string }> = []
#filesQueue: Array<{ file: InstanceFile; destination: string }> = []
#filesQueue: Array<{ file: InstanceFileWithOperation; destination: string }> = []
#httpsQueue: Array<{ file: InstanceFile; options: DownloadOptions }> = []

/**
Expand Down

0 comments on commit c871ee2

Please sign in to comment.