Skip to content

Commit

Permalink
fix: Warn user during the modloader changed in the instance update
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed May 22, 2024
1 parent e3d815e commit 3d823ca
Show file tree
Hide file tree
Showing 14 changed files with 342 additions and 198 deletions.
5 changes: 5 additions & 0 deletions xmcl-keystone-ui/locales/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,11 @@ instanceTemplate:
instanceUpdate:
basic: Aktualisieren Sie Ihre Einstellungen
files: Dateien aktualisieren
loaderChanged: >-
Der Modloader dieser Instanz wurde geändert.
Der alte Modloader ist {modloader} und der neue Modloader ist
{newModloader}.
title: Aktualisieren Sie Ihre Instanz
update: Aktualisierung beginnen
instances:
Expand Down
1 change: 1 addition & 0 deletions xmcl-keystone-ui/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ instanceUpdate:
files: File Updates
title: Update Instance
update: Start Update
loaderChanged: The modloader of this instance has been changed. The old modloader is {modloader}, and the new modloader is {newModloader}.
instances:
add: Create Game
addDescription: Create a new instance from scratch
Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/locales/es-ES.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ instanceTemplate:
instanceUpdate:
basic: Actualización de Ajustes
files: Actualización de Archivos
loaderChanged: |-
Se ha cambiado el cargador de mods de esta instancia.
El antiguo modloader es {modloader} y el nuevo modloader es {newModloader}.
title: Actualizar Instancia
update: Iniciar Actualización
instances:
Expand Down
5 changes: 5 additions & 0 deletions xmcl-keystone-ui/locales/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,11 @@ instanceTemplate:
instanceUpdate:
basic: Mise à jour des Paramètres
files: Mise à jour des Fichiers
loaderChanged: >-
Le modloader de cette instance a été modifié.
L'ancien modloader est {modloader} et le nouveau modloader est
{newModloader}.
title: Mettre à jour l'Instance
update: Démarrer la Mise à Jour
instances:
Expand Down
4 changes: 4 additions & 0 deletions xmcl-keystone-ui/locales/gl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ disable: Desactivar
downloadUpdate: Descargar actualización
errors:
NotFoundError: 404 non atopado
instanceUpdate:
loaderChanged: |-
Cambiouse o modloader desta instancia.
O modloader antigo é {modloader} e o novo modloader é {newModloader}.
instances:
addServerDescription: Isto creará un xogo que se lanzará directamente ao servidor.
launchBlocked:
Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/locales/hu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ instanceTemplate:
instanceUpdate:
basic: Beállítás frissítése
files: Fájl frissítések
loaderChanged: |-
Ennek a példánynak a modloadere megváltozott.
A régi modloader {modloader}, az új modloader pedig {newModloader}.
title: Példány frissítése
update: Frissítés indítása
instances:
Expand Down
392 changes: 224 additions & 168 deletions xmcl-keystone-ui/locales/pl.yaml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions xmcl-keystone-ui/locales/ru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ instanceTemplate:
instanceUpdate:
basic: Обновление настроек
files: Обновление файлов
loaderChanged: >-
Модлоадер этого экземпляра был изменен.
Старый загрузчик модов — {modloader}, а новый загрузчик модов —
{newModloader}.
title: Обновление экземпляра
update: Начать обновление
instances:
Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/locales/uk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ instanceTemplate:
instanceUpdate:
basic: Оновлення налаштувань
files: Оновлення файлів
loaderChanged: |-
Завантажувач модів цього екземпляра змінено.
Старий завантажувач модів — {modloader}, а новий — {newModloader}.
title: Оновити екземпляр
update: Почати оновлення
instances:
Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ instanceTemplate:
instanceUpdate:
basic: 设置更新
files: 文件更新
loaderChanged: |-
该实例的模组加载器已更改。
旧的 modloader 是 {modloader},新的 modloader 是 {newModloader}。
title: 更新实例
update: 开始更新实例
instances:
Expand Down
4 changes: 4 additions & 0 deletions xmcl-keystone-ui/locales/zh-TW.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ instanceTemplate:
importing: 模板導入
preview: 預覽
title: 模板設置
instanceUpdate:
loaderChanged: |-
該實例的模組載入器已變更。
舊的 modloader 是 {modloader},新的 modloader 是 {newModloader}。
instances:
add: 創建遊戲
addManually: 手動建立
Expand Down
77 changes: 69 additions & 8 deletions xmcl-keystone-ui/src/views/HomeInstanceUpdateDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,38 @@
</v-text-field>
</div>

<v-alert
v-if="loaderDifferences.old.length > 0 || loaderDifferences.new.length > 0"
colored-border
outlined
type="error"
color="error"
>
<i18n-t
tag="p"
keypath="instanceUpdate.loaderChanged"
>
<template #modloader>
<v-chip
label
small
outlined
>
{{ loaderDifferences.old.join(', ') }}
</v-chip>
</template>
<template #newModloader>
<v-chip
label
small
outlined
>
{{ loaderDifferences.new.join(', ') }}
</v-chip>
</template>
</i18n-t>
</v-alert>

<v-subheader>
{{ t('instanceUpdate.files') }}
</v-subheader>
Expand Down Expand Up @@ -140,8 +172,9 @@ import { basename } from '@/util/basename'
import { getFTBTemplateAndFile } from '@/util/ftb'
import { injection } from '@/util/inject'
import { getUpstreamFromResource } from '@/util/upstream'
import { EditInstanceOptions, InstanceData, InstanceFileOperation, InstanceFileUpdate, InstanceInstallServiceKey, InstanceUpdateServiceKey, Resource } from '@xmcl/runtime-api'
import { EditInstanceOptions, InstanceData, InstanceFileOperation, InstanceFileUpdate, InstanceInstallServiceKey, InstanceUpdateServiceKey, Resource, ResourceServiceKey } from '@xmcl/runtime-api'
import { useDialog } from '../composables/dialog'
import { resolveModpackInstanceConfig } from '@/util/modpackFilesResolver'
const selected = ref([] as string[])
Expand Down Expand Up @@ -229,6 +262,7 @@ const { runtime: oldRuntime, path: instancePath } = injection(kInstance)
const { all: javas } = injection(kJavaContext)
const { refresh, refreshing, error } = useRefreshable(async () => {
if (newManifest.value && oldManifest.value) {
// FTB
const [config, newVersionFiles] = getFTBTemplateAndFile(newManifest.value, javas.value)
const [_, oldVersionFiles] = getFTBTemplateAndFile(oldManifest.value, javas.value)
upgrade.value = {
Expand All @@ -246,19 +280,46 @@ const { refresh, refreshing, error } = useRefreshable(async () => {
}
return
}
const path = newResource.value?.path
if (path) {
const res = newResource.value
const path = res?.path
if (res && path) {
const config = resolveModpackInstanceConfig(res) as EditInstanceOptions
const files = await getInstanceUpdateProfile({
instancePath: instancePath.value,
oldModpack: oldResource.value && 'path' in oldResource.value ? oldResource.value.path : undefined,
newModpack: res.path,
})
upgrade.value = {
...await getInstanceUpdateProfile({
instancePath: instancePath.value,
oldModpack: oldResource.value && 'path' in oldResource.value ? oldResource.value.path : undefined,
newModpack: newResource.value.path,
}),
instance: config,
files,
upstream: getUpstreamFromResource(newResource.value),
}
}
})
const loaderDifferences = computed(() => {
const old = oldRuntime.value
const newR = runtime.value
const loaders = ['forge', 'fabricLoader', 'quiltLoader', 'neoForged']
const oldL = [] as string[]
const newL = [] as string[]
for (const l of loaders) {
if (!!old[l] !== !!newR[l]) {
if (old[l]) {
oldL.push(l)
} else {
newL.push(l)
}
}
}
return {
old: oldL,
new: newL,
}
})
const confirm = async () => {
if (upgrade.value) {
const { instance, files, upstream } = upgrade.value
Expand Down
6 changes: 1 addition & 5 deletions xmcl-runtime-api/src/services/InstanceUpdateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ export type UpgradeModpackRawOptions = {
oldVersionFiles: InstanceFile[]
newVersionFiles: InstanceFile[]
}
export interface InstanceUpdateProfile {
instance: EditInstanceOptions
files: InstanceFileUpdate[]
}

export type InstanceFileUpdate = {
file: InstanceFile
Expand All @@ -35,7 +31,7 @@ export type InstanceFileUpdate = {
}

export interface InstanceUpdateService {
getInstanceUpdateProfile(options: UpgradeModpackOptions): Promise<InstanceUpdateProfile>
getInstanceUpdateProfile(options: UpgradeModpackOptions): Promise<InstanceFileUpdate[]>
getInstanceUpdateProfileRaw(options: UpgradeModpackRawOptions): Promise<InstanceFileUpdate[]>
}

Expand Down
29 changes: 12 additions & 17 deletions xmcl-runtime/instanceIO/InstanceUpdateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import { AbstractService, ExposeServiceKey } from '~/service'

type Upstream = Required<Instance>['upstream']

type UpstreamResolver = (upstream: Upstream) => Promise<{
files: InstanceFile[]
} | undefined>
type UpstreamResolver = (upstream: Upstream) => Promise<InstanceFile[] | undefined>

@ExposeServiceKey(InstanceUpdateServiceKey)
export class InstanceUpdateService extends AbstractService implements IInstanceUpdateService {
Expand All @@ -30,13 +28,13 @@ export class InstanceUpdateService extends AbstractService implements IInstanceU
const res = upstream.sha1 ? await resourceService.getResourceByHash(upstream.sha1) : (await resourceService.getResourcesByUris([`modrinth:${upstream.projectId}:${upstream.versionId}`]))[0]
if (res) {
if (res.metadata.instance) {
return res.metadata.instance
return res.metadata.instance.files
}
return await this.modpackService.getModpackInstallProfile(res.path).catch(() => undefined)
return await this.modpackService.getModpackInstallFiles(res.path).catch(() => undefined)
}
const resMetadata = upstream.sha1 ? await resourceService.getResourceMetadataByHash(upstream.sha1) : (await resourceService.getResourceMetadataByUri(`modrinth:${upstream.projectId}:${upstream.versionId}`))[0]
if (resMetadata?.instance) {
return resMetadata.instance
return resMetadata.instance.files
}
}
return undefined
Expand All @@ -47,13 +45,13 @@ export class InstanceUpdateService extends AbstractService implements IInstanceU
const res = upstream.sha1 ? await resourceService.getResourceByHash(upstream.sha1) : (await resourceService.getResourcesByUris([`curseforge:${upstream.modId}:${upstream.fileId}`]))[0]
if (res) {
if (res.metadata.instance) {
return res.metadata.instance
return res.metadata.instance.files
}
return await this.modpackService.getModpackInstallProfile(res.path).catch(() => undefined)
return await this.modpackService.getModpackInstallFiles(res.path).catch(() => undefined)
}
const resMetadata = upstream.sha1 ? await resourceService.getResourceMetadataByHash(upstream.sha1) : (await resourceService.getResourceMetadataByUri(`curseforge:${upstream.modId}:${upstream.fileId}`))[0]
if (resMetadata?.instance) {
return resMetadata.instance
return resMetadata.instance.files
}
}
return undefined
Expand All @@ -67,8 +65,8 @@ export class InstanceUpdateService extends AbstractService implements IInstanceU
private async resolveOldFiles(instancePath: string, instance: InstanceData, oldModpack?: string): Promise<InstanceFile[]> {
if (oldModpack) {
// If old modpack path present, try to get modpack content
const profile = await this.modpackService.getModpackInstallProfile(oldModpack)
return profile.files
const files = await this.modpackService.getModpackInstallFiles(oldModpack)
return files
}

if (instance.upstream) {
Expand All @@ -78,7 +76,7 @@ export class InstanceUpdateService extends AbstractService implements IInstanceU
for (const resolver of this.resolvers) {
const result = await resolver(upstream)
if (result) {
return result.files
return result
}
}
}
Expand Down Expand Up @@ -160,15 +158,12 @@ export class InstanceUpdateService extends AbstractService implements IInstanceU

const oldFiles = await this.resolveOldFiles(instancePath, instance, options.oldModpack)

const { files: newFiles, instance: instanceOptions } = await this.modpackService.getModpackInstallProfile(options.newModpack)
const newFiles = await this.modpackService.getModpackInstallFiles(options.newModpack)

const manifest = await this.instanceManifestService.getInstanceManifest({ path: instancePath, hashes: ['sha1'] })

const result = this.#getInstanceFilesUpdate(oldFiles, manifest.files, newFiles)

return {
instance: instanceOptions,
files: result.filter(r => !r.file.path.endsWith('/')),
}
return result.filter(r => !r.file.path.endsWith('/'))
}
}

0 comments on commit 3d823ca

Please sign in to comment.