Add case insensitivity checks for Mac and Linux platforms
This commit is contained in:
@@ -6,24 +6,47 @@ import { DecodedVeh, VehicleRecordInterface } from "./decode-veh.interface";
|
||||
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||
import store from "../store/store";
|
||||
import typeCaster from "../../util/typeCaster";
|
||||
import { platform } from "@electron-toolkit/utils";
|
||||
import { findFileCaseInsensitive } from "./decoder-utils";
|
||||
|
||||
const DecodeVeh = async (
|
||||
extensionlessFilePath: string,
|
||||
): Promise<DecodedVeh> => {
|
||||
let dbf: DBFFile | null = null;
|
||||
try {
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}V.VEH`);
|
||||
} catch (error) {
|
||||
log.error("Error opening VEH File.", errorTypeCheck(error));
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}.VEH`);
|
||||
log.log("Found VEH file using regular CIECA Id.");
|
||||
}
|
||||
if (platform.isWindows) {
|
||||
try {
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}V.VEH`);
|
||||
} catch (error) {
|
||||
log.error("Error opening VEH File.", errorTypeCheck(error));
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}.VEH`);
|
||||
log.log("Found VEH file using regular CIECA Id.");
|
||||
}
|
||||
|
||||
if (!dbf) {
|
||||
log.error(`Could not find any VEH files at ${extensionlessFilePath}`);
|
||||
throw new Error(`Could not find any VEH files at ${extensionlessFilePath}`);
|
||||
if (!dbf) {
|
||||
log.error(`Could not find any VEH files at ${extensionlessFilePath}`);
|
||||
throw new Error(
|
||||
`Could not find any VEH files at ${extensionlessFilePath}`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
const possibleExtensions: string[] = ["v.veh", ".veh"];
|
||||
const filePath = await findFileCaseInsensitive(
|
||||
extensionlessFilePath,
|
||||
possibleExtensions,
|
||||
);
|
||||
try {
|
||||
if (!filePath) {
|
||||
log.error(`Could not find any VEH files at ${extensionlessFilePath}`);
|
||||
throw new Error(
|
||||
`Could not find any VEH files at ${extensionlessFilePath}`,
|
||||
);
|
||||
}
|
||||
dbf = await DBFFile.open(filePath);
|
||||
} catch (error) {
|
||||
log.error("Error opening VEH File.", errorTypeCheck(error));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
const rawDBFRecord = await dbf.readRecords(1);
|
||||
|
||||
//AD2 will always have only 1 row.
|
||||
|
||||
Reference in New Issue
Block a user