Skip to content

Commit

Permalink
refactor: Clean up the resource urn & unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Jul 4, 2022
1 parent 2551d0a commit eddb370
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ export function useCurseforgeProjectFiles(projectId: number) {
try {
const f = await fetchProjectFiles({ modId: projectId })
data.files = Object.freeze(f.data)
console.log(data.files)
data.index = f.pagination.index
data.pageSize = f.pagination.pageSize
data.totalCount = f.pagination.totalCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function useInstanceResourcePacks() {
return ({
path: resource.path,
name: resource.name,
id: `file/${basename(resource.fileName)}`,
id: `file/${resource.fileName.endsWith('.zip') ? resource.fileName : resource.fileName + '.zip'}`,
url: resource.uri,
pack_format: resource.metadata.pack_format,
description: resource.metadata.description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

{{
selected.path
? $t("curseforge.installTo", { path: selected.name })
? t("curseforge.installTo", { path: selected.name })
: selected.name
}}
</span>
Expand All @@ -36,7 +36,7 @@
</v-list-item-avatar>
<v-list-item-title>
{{
$t("curseforge.installTo", { path: item.name })
t("curseforge.installTo", { path: item.name })
}}
</v-list-item-title>
</v-list-item>
Expand All @@ -63,8 +63,8 @@ const props = defineProps<{
const emit = defineEmits(['input'])
const { instances } = useInstances()
const { $t } = useI18n()
const defaultItem = computed(() => ({ name: $t('curseforge.installToStorage'), path: '' }))
const { t } = useI18n()
const defaultItem = computed(() => ({ name: t('curseforge.installToStorage'), path: '' }))
const items = computed(() => instances.value.map(i => ({ path: i.path, name: i.name ?? basename(i.path) })))
const selected = computed({
get() {
Expand Down
1 change: 1 addition & 0 deletions xmcl-runtime-api/src/services/ResourceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export interface ResourceService extends StatefulService<ResourceState>, Generic
* @returns The resource resolved. If the resource cannot be resolved, it will goes to unknown domain.
*/
importResource(options: ImportResourceOptions): Promise<AnyPersistedResource>
importResource(options: ImportResourceOptions & { optional: true }): Promise<AnyPersistedResource | undefined>
/**
* Import the resource from the same disk. This will parse the file and import it into our db by hard link.
* If the file already existed, it will not re-import it again
Expand Down
1 change: 0 additions & 1 deletion xmcl-runtime/.eslintignore
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
lib/database/client.gen/**/*
3 changes: 0 additions & 3 deletions xmcl-runtime/lib/app/LauncherApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import NetworkManager from '../managers/NetworkManager'
import SemaphoreManager from '../managers/SemaphoreManager'
import ServiceManager from '../managers/ServiceManager'
import ServiceStateManager from '../managers/ServiceStateManager'
import DatabaseManager from '../managers/DatabaseManager'
import TaskManager from '../managers/TaskManager'
import TelemetryManager from '../managers/TelemetryManager'
import WorkerManager from '../managers/WorkerManager'
Expand Down Expand Up @@ -98,8 +97,6 @@ export abstract class LauncherApp extends EventEmitter {

readonly telemetryManager = new TelemetryManager(this)

readonly databaseManager = new DatabaseManager(this)

readonly credentialManager = new CredentialManager(this)

readonly workerManager = new WorkerManager(this)
Expand Down
4 changes: 2 additions & 2 deletions xmcl-runtime/lib/entities/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ export class ResourceDomainIndexer<T> {
batch.del(uri)
}

for (const tag of res.tags) {
// for (const tag of res.tags) {

}
// }

this.hashSet.del(key)
}
Expand Down
23 changes: 0 additions & 23 deletions xmcl-runtime/lib/managers/DatabaseManager.ts

This file was deleted.

5 changes: 4 additions & 1 deletion xmcl-runtime/lib/managers/ServiceManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ServiceKey } from '@xmcl/runtime-api'
import { Exception, ServiceKey } from '@xmcl/runtime-api'
import { Task } from '@xmcl/task'
import { Manager } from '.'
import LauncherApp from '../app/LauncherApp'
Expand Down Expand Up @@ -91,6 +91,9 @@ export default class ServiceManager extends Manager {
} else {
this.error(JSON.stringify(e))
}
if (e instanceof Exception) {
this.error(JSON.stringify(e.exception, null, 4))
}
const error = serializeError(e)
error.serviceName = serviceName
error.serviceMethod = serviceMethod
Expand Down
2 changes: 1 addition & 1 deletion xmcl-runtime/lib/services/CurseForgeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class CurseForgeService extends StatefulService<CurseforgeState> implemen
worlds: 'save',
modpacks: 'curseforge-modpack',
}
const urls = [file.downloadUrl, `curseforge://${projectId}/${file.id}`]
const urls = [file.downloadUrl, `curseforge:${projectId}:${file.id}`]
this.log(`Try install file ${file.displayName}(${file.downloadUrl}) in type ${type}`)
const resource = this.resourceService.getResource({ url: urls })
if (resource) {
Expand Down
2 changes: 1 addition & 1 deletion xmcl-runtime/lib/services/InstanceIOService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export class InstanceIOService extends AbstractService implements IInstanceIOSer
try {
const start = Date.now()
const allHeaders = headers ? { ...headers } : {}
if (!allHeaders.Authorization && this.userService.state.user.msAccessToken) {
if (!allHeaders.Authorization && this.userService.state.user?.msAccessToken) {
allHeaders.Authorization = `Bearer ${this.userService.state.user.msAccessToken}`
}

Expand Down
7 changes: 5 additions & 2 deletions xmcl-runtime/lib/services/InstanceVersionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ export class InstanceVersionService extends StatefulService<InstanceVersionState
id: VersionIssueKey,
fix: async (issue) => {
const { minecraft, forge, fabricLoader, optifine, quiltLoader } = issue
await this.installRuntime({ minecraft, forge, fabricLoader, optifine, quiltLoader })
const version = await this.installRuntime({ minecraft, forge, fabricLoader, optifine, quiltLoader })
if (version) {
await this.versionService.refreshVersion(version)
}
},
validator: async (builder, issue) => {
const runtime = this.instanceService.state.instance.runtime
const valid = runtime.minecraft === issue.minecraft && runtime.forge === issue.forge && runtime.fabricLoader === issue.fabricLoader
const valid = runtime.minecraft === issue.minecraft && runtime.forge === issue.forge && runtime.fabricLoader === issue.fabricLoader && runtime.quiltLoader === issue.quiltLoader
if (valid) {
await this.diagnoseAll(builder, this.state.version)
}
Expand Down
2 changes: 1 addition & 1 deletion xmcl-runtime/lib/services/ModrinthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class ModrinthService extends StatefulService<ModrinthState> implements I
const hashes = Object.entries(file.hashes)
const urls = [file.url]
if (version) {
urls.push(`modrinth://${version.project_id}/${version.id}`)
urls.push(`modrinth:${version.project_id}:${version.id}`)
}
const resource = this.resourceService.getResource({ url: urls })
if (resource) {
Expand Down
2 changes: 0 additions & 2 deletions xmcl-runtime/lib/services/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,6 @@ export abstract class AbstractService extends EventEmitter {

get credentialManager() { return this.app.credentialManager }

get databaseManager() { return this.app.databaseManager }

get workerManager() { return this.app.workerManager }

get semaphoreManager() { return this.app.semaphoreManager }
Expand Down
4 changes: 3 additions & 1 deletion xmcl-runtime/lib/services/VersionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { basename, dirname, join, relative, sep } from 'path'
import { LauncherApp } from '../app/LauncherApp'
import { isDirectory, missing, readdirEnsured } from '../util/fs'
import { isNonnull } from '../util/object'
import { StatefulService } from './Service'
import { Singleton, StatefulService } from './Service'

/**
* The local version service maintains the installed versions on disk
Expand Down Expand Up @@ -104,6 +104,7 @@ export class VersionService extends StatefulService<VersionState> implements IVe
* Refresh a version in the version folder.
* @param versionFolder The version folder name. It must existed under the `versions` folder.
*/
@Singleton(v => v)
async refreshVersion(versionFolder: string) {
try {
const version = await this.resolveLocalVersion(versionFolder)
Expand All @@ -116,6 +117,7 @@ export class VersionService extends StatefulService<VersionState> implements IVe
}
}

@Singleton()
async refreshVersions() {
const dir = this.getPath('versions')
let files = await readdirEnsured(dir)
Expand Down

0 comments on commit eddb370

Please sign in to comment.