mirror of
https://git.bits.team/Bits/mod-manager.git
synced 2024-11-24 15:08:22 -05:00
Add install by id functionality
This commit is contained in:
parent
8398afcfb4
commit
4e744d11fd
@ -23,16 +23,30 @@ export default class Mods {
|
|||||||
this.MOD_SOURCES.push(source);
|
this.MOD_SOURCES.push(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async isValidModId(id: string, source: ModSource) {
|
||||||
|
const mcVersion = await MinecraftUtils.getCurrentMinecraftVersion();
|
||||||
|
try {
|
||||||
|
await source.getLatestVersion(id, mcVersion);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static async install(mod: string, essential: boolean, confirm: boolean): Promise<void> {
|
public static async install(mod: string, essential: boolean, confirm: boolean): Promise<void> {
|
||||||
// Go through each mod source
|
// Go through each mod source
|
||||||
for (const source of this.MOD_SOURCES) {
|
for (const source of this.MOD_SOURCES) {
|
||||||
const spinner = new PrintUtils.Spinner(`Searching for ${mod}...`);
|
const spinner = new PrintUtils.Spinner(`Searching for ${mod}...`);
|
||||||
spinner.start();
|
spinner.start();
|
||||||
|
|
||||||
// Search for the mod
|
// Determine queried mod id
|
||||||
let id: string | undefined;
|
let id: string | undefined;
|
||||||
try {
|
try {
|
||||||
|
if (await this.isValidModId(mod, source)) {
|
||||||
|
id = mod;
|
||||||
|
} else {
|
||||||
id = await source.search(mod);
|
id = await source.search(mod);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof ModNotFoundError) {
|
if (e instanceof ModNotFoundError) {
|
||||||
spinner.stop(`Mod ${mod} not found on ${source.getSourceName()}`)
|
spinner.stop(`Mod ${mod} not found on ${source.getSourceName()}`)
|
||||||
|
Loading…
Reference in New Issue
Block a user