Add case insensitivity checks for Mac and Linux platforms
This commit is contained in:
@@ -5,22 +5,46 @@ import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
||||
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||
import YNBoolConverter from "../../util/ynBoolConverter";
|
||||
import { DecodedPfo, DecodedPfoLine } from "./decode-pfo.interface";
|
||||
import { platform } from "@electron-toolkit/utils";
|
||||
import { findFileCaseInsensitive } from "./decoder-utils";
|
||||
|
||||
const DecodePfo = async (
|
||||
extensionlessFilePath: string,
|
||||
): Promise<DecodedPfo> => {
|
||||
let dbf: DBFFile | null = null;
|
||||
try {
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}.PFO`);
|
||||
} catch (error) {
|
||||
log.error("Error opening PFO File.", errorTypeCheck(error));
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}.PFO`);
|
||||
log.log("Trying to find PFO file using regular CIECA Id.");
|
||||
}
|
||||
if (platform.isWindows) {
|
||||
try {
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}.PFO`);
|
||||
} catch (error) {
|
||||
log.error("Error opening PFO File.", errorTypeCheck(error));
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}.PFO`);
|
||||
log.log("Trying to find PFO file using regular CIECA Id.");
|
||||
}
|
||||
|
||||
if (!dbf) {
|
||||
log.error(`Could not find any PFO files at ${extensionlessFilePath}`);
|
||||
throw new Error(`Could not find any PFO files at ${extensionlessFilePath}`);
|
||||
if (!dbf) {
|
||||
log.error(`Could not find any PFO files at ${extensionlessFilePath}`);
|
||||
throw new Error(
|
||||
`Could not find any PFO files at ${extensionlessFilePath}`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
const possibleExtensions: string[] = [".pfo"];
|
||||
const filePath = await findFileCaseInsensitive(
|
||||
extensionlessFilePath,
|
||||
possibleExtensions,
|
||||
);
|
||||
try {
|
||||
if (!filePath) {
|
||||
log.error(`Could not find any PFO files at ${extensionlessFilePath}`);
|
||||
throw new Error(
|
||||
`Could not find any PFO files at ${extensionlessFilePath}`,
|
||||
);
|
||||
}
|
||||
dbf = await DBFFile.open(filePath);
|
||||
} catch (error) {
|
||||
log.error("Error opening PFO File.", errorTypeCheck(error));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
const rawDBFRecord = await dbf.readRecords(1);
|
||||
|
||||
Reference in New Issue
Block a user