Skip to content

Commit

Permalink
fix: Ensure modpack name is distinct
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Jun 4, 2023
1 parent 12bd622 commit 531e618
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion xmcl-runtime/lib/services/ModpackService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,19 @@ export class ModpackService extends AbstractService implements IModpackService {
if (!manifest || !handler) throw new ModpackException({ type: 'invalidModpack', path })

const config = handler.resolveInstanceOptions(manifest)

const getDistinctName = (names: string[], name: string) => {
let i = 1
while (names.includes(name)) {
name = `${name} (${i++})`
}
return name
}

const instancePath = await this.instanceService.createInstance({
...config,
name: config.name || basename(options.path),
name: getDistinctName(this.instanceService.state.instances.map(i => i.name),
config.name || basename(options.path)),
...options.instanceConfig,
})

Expand Down

0 comments on commit 531e618

Please sign in to comment.