Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
Fix list ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirherobrine23 committed Nov 14, 2022
1 parent b371e99 commit 071014d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 19 additions & 7 deletions src/platformPathManeger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,38 @@ export async function changeDefault(platform: bdsPlatform, id: bdsPlatformOption
};
}

export type platformIds = {
[platform in bdsPlatform]?: {
realID?: string,
id: string,
}[]
};

/**
* Get all ids to all platforms installed
* @returns
*/
export async function getIds(): Promise<platformIds>;
/**
* Get all ids to platform
* @param platform
* @param platform - Set platform to get ids
* @returns
*/
export async function getIds(platform?: bdsPlatform) {
export async function getIds(platform: bdsPlatform): Promise<string[]>;
export async function getIds(platform?: bdsPlatform): Promise<platformIds|string[]> {
if (!platform) {
const platformIds: {[platform: string]: {id: string, realID?: string}[]} = {};
const platformIds: platformIds = {};
if (!await extendFs.exists(bdsRoot)) return platformIds;
const Platforms = await fs.readdir(bdsRoot);
if (Platforms.filter(folder => !platformArray.includes(folder as bdsPlatform)).length > 0) throw new Error("Old or invalid Platform path.");
for (const Platform of Platforms) {
const Platforms = (await fs.readdir(bdsRoot)).filter(folder => platformArray.includes(folder as bdsPlatform));
await Promise.all(Platforms.map(async Platform => {
for (const id of await fs.readdir(path.join(bdsRoot, Platform))) {
if (!platformIds[Platform]) platformIds[Platform] = []
const idPlatform = path.join(bdsRoot, Platform, id);
const realPath = await fs.realpath(idPlatform);
if (idPlatform !== realPath) platformIds[Platform].push({id, realID: path.basename(realPath)});
else platformIds[Platform].push({id});
}
}
}));
return platformIds;
}
if (!platformArray.includes(platform)) throw new Error("Invalid platform");
Expand Down

0 comments on commit 071014d

Please sign in to comment.