Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/services/emulators/extract-disc-sku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
return sku;
};

const extractPs12Sku = async (filePath: string): Promise<string | null> => {

Check failure on line 57 in src/main/services/emulators/extract-disc-sku.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=hydralauncher_hydra&issues=AZ75R7OLyDH9J9fo21be&open=AZ75R7OLyDH9J9fo21be&pullRequest=2403
const lower = filePath.toLowerCase();
if (lower.endsWith(".chd")) {
return extractChdSku(filePath);
Expand All @@ -72,6 +72,18 @@
return null;
}

const targetExists = await fs
.access(target)
.then(() => true)
.catch(() => false);
if (!targetExists) {
logger.warn("[extract-sku] sniff target missing on disk", {
filePath,
target,
});
return null;
}

let fh: import("node:fs/promises").FileHandle | null = null;
try {
fh = await fs.open(target, "r");
Expand Down
23 changes: 22 additions & 1 deletion src/main/services/emulators/sniff-disc-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,35 @@
}
};

const resolveCueRef = async (dir: string, ref: string): Promise<string> => {
const base = path.basename(ref.replace(/\\/g, "/"));

Check warning on line 41 in src/main/services/emulators/sniff-disc-platform.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `String#replaceAll()` over `String#replace()`.

See more on https://sonarcloud.io/project/issues?id=hydralauncher_hydra&issues=AZ75R7HkyDH9J9fo21bd&open=AZ75R7HkyDH9J9fo21bd&pullRequest=2403
const resolved = path.resolve(dir, base);

try {
await fs.access(resolved);
return resolved;
} catch {
try {
const entries = await fs.readdir(dir);
const match = entries.find(
(entry) => entry.toLowerCase() === base.toLowerCase()
);
if (match) return path.resolve(dir, match);
} catch {
return resolved;
}
return resolved;
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.
};

export const parseCueReferencedFiles = async (
cuePath: string
): Promise<string[]> => {
try {
const content = await fs.readFile(cuePath, "utf-8");
const dir = path.dirname(cuePath);
const matches = [...content.matchAll(/FILE\s+"(.+?)"\s+\w+/gi)];
return matches.map((m) => path.resolve(dir, m[1]));
return Promise.all(matches.map((m) => resolveCueRef(dir, m[1])));
} catch {
return [];
}
Expand Down
Loading