Add case insensitivity checks for Mac and Linux platforms

This commit is contained in:
Patrick Fic
2025-04-02 12:57:08 -07:00
parent 20f2963330
commit dbaa88a19b
14 changed files with 469 additions and 124 deletions

View File

@@ -1,25 +1,51 @@
import { platform } from "@electron-toolkit/utils";
import { DBFFile } from "dbffile";
import log from "electron-log/main";
import _ from "lodash";
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
import errorTypeCheck from "../../util/errorTypeCheck";
import store from "../store/store";
import { DecodedAd1, OwnerRecordInterface } from "./decode-ad1.interface";
import { findFileCaseInsensitive } from "./decoder-utils";
const DecodeAD1 = async (
extensionlessFilePath: string,
): Promise<DecodedAd1> => {
let dbf: DBFFile | null = null;
try {
dbf = await DBFFile.open(`${extensionlessFilePath}A.AD1`);
} catch (error) {
// log.debug("Error opening AD1 File.", errorTypeCheck(error));
dbf = await DBFFile.open(`${extensionlessFilePath}.AD1`);
// log.debug("Trying to find AD1 file using regular CIECA Id.");
}
if (!dbf) {
log.error(`Could not find any AD1 files at ${extensionlessFilePath}`);
throw new Error(`Could not find any AD1 files at ${extensionlessFilePath}`);
if (platform.isWindows) {
try {
dbf = await DBFFile.open(`${extensionlessFilePath}A.AD1`);
} catch {
// log.debug("Error opening AD1 File.", errorTypeCheck(error));
dbf = await DBFFile.open(`${extensionlessFilePath}.AD1`);
// log.debug("Trying to find AD1 file using regular CIECA Id.");
}
if (!dbf) {
log.error(`Could not find any AD1 files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any AD1 files at ${extensionlessFilePath}`,
);
}
} else {
const possibleExtensions: string[] = ["a.ad1", ".ad1"];
const filePath = await findFileCaseInsensitive(
extensionlessFilePath,
possibleExtensions,
);
try {
if (!filePath) {
log.error(`Could not find any AD1 files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any AD1 files at ${extensionlessFilePath}`,
);
}
dbf = await DBFFile.open(filePath);
} catch (error) {
log.error("Error opening AD1 File.", errorTypeCheck(error));
throw error;
}
}
const rawDBFRecord = await dbf.readRecords(1);
@@ -205,4 +231,5 @@ const DecodeAD1 = async (
return { ...rawAd1Data, owner: { data: ownerRecord } };
};
export default DecodeAD1;

View File

@@ -3,22 +3,45 @@ import log from "electron-log/main";
import _ from "lodash";
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
import { DecodedAD2 } from "./decode-ad2.interface";
import { platform } from "@electron-toolkit/utils";
import errorTypeCheck from "../../util/errorTypeCheck";
import { findFileCaseInsensitive } from "./decoder-utils";
const DecodeAD2 = async (
extensionlessFilePath: string,
): Promise<DecodedAD2> => {
let dbf: DBFFile | null = null;
try {
dbf = await DBFFile.open(`${extensionlessFilePath}B.AD2`);
} catch (error) {
// log.error("Error opening AD2 File.", errorTypeCheck(error));
dbf = await DBFFile.open(`${extensionlessFilePath}.AD2`);
// log.log("Trying to find AD2 file using regular CIECA Id.");
}
if (platform.isWindows) {
try {
dbf = await DBFFile.open(`${extensionlessFilePath}B.AD2`);
} catch {
dbf = await DBFFile.open(`${extensionlessFilePath}.AD2`);
}
if (!dbf) {
log.error(`Could not find any AD2 files at ${extensionlessFilePath}`);
throw new Error(`Could not find any AD2 files at ${extensionlessFilePath}`);
if (!dbf) {
log.error(`Could not find any AD2 files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any AD2 files at ${extensionlessFilePath}`,
);
}
} else {
const possibleExtensions: string[] = ["b.ad2", ".ad2"];
const filePath = await findFileCaseInsensitive(
extensionlessFilePath,
possibleExtensions,
);
try {
if (!filePath) {
log.error(`Could not find any AD2 files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any AD2 files at ${extensionlessFilePath}`,
);
}
dbf = await DBFFile.open(filePath);
} catch (error) {
log.error("Error opening AD2 File.", errorTypeCheck(error));
throw error;
}
}
const rawDBFRecord = await dbf.readRecords(1);

View File

@@ -4,22 +4,46 @@ import _ from "lodash";
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
import errorTypeCheck from "../../util/errorTypeCheck";
import { DecodedEnv } from "./decode-env.interface";
import { platform } from "@electron-toolkit/utils";
import { findFileCaseInsensitive } from "./decoder-utils";
const DecodeEnv = async (
extensionlessFilePath: string,
): Promise<DecodedEnv> => {
let dbf: DBFFile | null = null;
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.ENV`);
} catch (error) {
log.error("Error opening ENV File.", errorTypeCheck(error));
}
if (!dbf) {
log.error(`Could not find any ENV files at ${extensionlessFilePath}`);
throw new Error(`Could not find any ENV files at ${extensionlessFilePath}`);
}
if (platform.isWindows) {
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.ENV`);
} catch (error) {
log.error("Error opening ENV File.", errorTypeCheck(error));
}
if (!dbf) {
log.error(`Could not find any ENV files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any ENV files at ${extensionlessFilePath}`,
);
}
} else {
const possibleExtensions: string[] = [".env"];
const filePath = await findFileCaseInsensitive(
extensionlessFilePath,
possibleExtensions,
);
try {
if (!filePath) {
log.error(`Could not find any ENV files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any ENV files at ${extensionlessFilePath}`,
);
}
dbf = await DBFFile.open(filePath);
} catch (error) {
log.error("Error opening ENV File.", errorTypeCheck(error));
throw error;
}
}
const rawDBFRecord = await dbf.readRecords(1);
//AD2 will always have only 1 row.

View File

@@ -5,21 +5,45 @@ import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
import errorTypeCheck from "../../util/errorTypeCheck";
import store from "../store/store";
import { DecodedLin, DecodedLinLine } from "./decode-lin.interface";
import { platform } from "@electron-toolkit/utils";
import { findFileCaseInsensitive } from "./decoder-utils";
const DecodeLin = async (
extensionlessFilePath: string,
): Promise<DecodedLin> => {
let dbf: DBFFile | null = null;
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.LIN`);
} catch (error) {
//LIN File only has 1 location.
log.error("Error opening LIN File.", errorTypeCheck(error));
}
if (platform.isWindows) {
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.LIN`);
} catch (error) {
//LIN File only has 1 location.
log.error("Error opening LIN File.", errorTypeCheck(error));
}
if (!dbf) {
log.error(`Could not find any LIN files at ${extensionlessFilePath}`);
throw new Error(`Could not find any LIN files at ${extensionlessFilePath}`);
if (!dbf) {
log.error(`Could not find any LIN files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any LIN files at ${extensionlessFilePath}`,
);
}
} else {
const possibleExtensions: string[] = ["lin"];
const filePath = await findFileCaseInsensitive(
extensionlessFilePath,
possibleExtensions,
);
try {
if (!filePath) {
log.error(`Could not find any LIN files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any LIN files at ${extensionlessFilePath}`,
);
}
dbf = await DBFFile.open(filePath);
} catch (error) {
log.error("Error opening LIN File.", errorTypeCheck(error));
throw error;
}
}
const rawDBFRecord = await dbf.readRecords();

View File

@@ -4,24 +4,47 @@ import _ from "lodash";
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
import errorTypeCheck from "../../util/errorTypeCheck";
import { DecodedPfh } from "./decode-pfh.interface";
import { platform } from "os";
import { findFileCaseInsensitive } from "./decoder-utils";
const DecodePfh = async (
extensionlessFilePath: string,
): Promise<DecodedPfh> => {
let dbf: DBFFile | null = null;
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.PFH`);
} catch (error) {
log.error("Error opening PFH File.", errorTypeCheck(error));
dbf = await DBFFile.open(`${extensionlessFilePath}.PFH`);
log.log("Trying to find PFH file using regular CIECA Id.");
}
if (platform.isWindows) {
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.PFH`);
} catch (error) {
log.error("Error opening PFH File.", errorTypeCheck(error));
dbf = await DBFFile.open(`${extensionlessFilePath}.PFH`);
log.log("Trying to find PFH file using regular CIECA Id.");
}
if (!dbf) {
log.error(`Could not find any PFH files at ${extensionlessFilePath}`);
throw new Error(`Could not find any PFH files at ${extensionlessFilePath}`);
if (!dbf) {
log.error(`Could not find any PFH files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any PFH files at ${extensionlessFilePath}`,
);
}
} else {
const possibleExtensions: string[] = [".pfh"];
const filePath = await findFileCaseInsensitive(
extensionlessFilePath,
possibleExtensions,
);
try {
if (!filePath) {
log.error(`Could not find any PFH files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any PFH files at ${extensionlessFilePath}`,
);
}
dbf = await DBFFile.open(filePath);
} catch (error) {
log.error("Error opening PFH File.", errorTypeCheck(error));
throw error;
}
}
const rawDBFRecord = await dbf.readRecords(1);
//AD2 will always have only 1 row.

View File

@@ -8,21 +8,45 @@ import {
JobLaborRateFields,
DecodedPflLine,
} from "./decode-pfl.interface";
import { platform } from "@electron-toolkit/utils";
import { findFileCaseInsensitive } from "./decoder-utils";
const DecodePfl = async (
extensionlessFilePath: string,
): Promise<DecodedPfl> => {
let dbf: DBFFile | null = null;
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.PFL`);
} catch (error) {
//PFL File only has 1 location.
log.error("Error opening PFL File.", errorTypeCheck(error));
}
if (platform.isWindows) {
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.PFL`);
} catch (error) {
//PFL File only has 1 location.
log.error("Error opening PFL File.", errorTypeCheck(error));
}
if (!dbf) {
log.error(`Could not find any PFL files at ${extensionlessFilePath}`);
throw new Error(`Could not find any PFL files at ${extensionlessFilePath}`);
if (!dbf) {
log.error(`Could not find any PFL files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any PFL files at ${extensionlessFilePath}`,
);
}
} else {
const possibleExtensions: string[] = [".pfl"];
const filePath = await findFileCaseInsensitive(
extensionlessFilePath,
possibleExtensions,
);
try {
if (!filePath) {
log.error(`Could not find any PFL files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any PFL files at ${extensionlessFilePath}`,
);
}
dbf = await DBFFile.open(filePath);
} catch (error) {
log.error("Error opening PFL File.", errorTypeCheck(error));
throw error;
}
}
const rawDBFRecord = await dbf.readRecords();

View File

@@ -9,23 +9,46 @@ import {
DecodedPfmLine,
JobMaterialRateFields,
} from "./decode-pfm.interface";
import { platform } from "@electron-toolkit/utils";
import { findFileCaseInsensitive } from "./decoder-utils";
const DecodePfm = async (
extensionlessFilePath: string,
): Promise<DecodedPfm> => {
let dbf: DBFFile | null = null;
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.PFM`);
} catch (error) {
//PFM File only has 1 location.
log.error("Error opening PFM File.", errorTypeCheck(error));
}
if (platform.isWindows) {
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.PFM`);
} catch (error) {
//PFM File only has 1 location.
log.error("Error opening PFM File.", errorTypeCheck(error));
}
if (!dbf) {
log.error(`Could not find any PFM files at ${extensionlessFilePath}`);
throw new Error(`Could not find any PFM files at ${extensionlessFilePath}`);
if (!dbf) {
log.error(`Could not find any PFM files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any PFM files at ${extensionlessFilePath}`,
);
}
} else {
const possibleExtensions: string[] = [".pfm"];
const filePath = await findFileCaseInsensitive(
extensionlessFilePath,
possibleExtensions,
);
try {
if (!filePath) {
log.error(`Could not find any PFM files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any PFM files at ${extensionlessFilePath}`,
);
}
dbf = await DBFFile.open(filePath);
} catch (error) {
log.error("Error opening PFM File.", errorTypeCheck(error));
throw error;
}
}
const rawDBFRecord = await dbf.readRecords();
//AD2 will always have only 1 row.

View File

@@ -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);

View File

@@ -9,23 +9,46 @@ import {
DecodedPfpLine,
DecodedPfpLinesByType,
} from "./decode-pfp.interface";
import { platform } from "@electron-toolkit/utils";
import { findFileCaseInsensitive } from "./decoder-utils";
const DecodePfp = async (
extensionlessFilePath: string,
): Promise<DecodedPfp> => {
let dbf: DBFFile | null = null;
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.PFP`);
} catch (error) {
//PFP File only has 1 location.
log.error("Error opening PFP File.", errorTypeCheck(error));
}
if (platform.isWindows) {
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.PFP`);
} catch (error) {
//PFP File only has 1 location.
log.error("Error opening PFP File.", errorTypeCheck(error));
}
if (!dbf) {
log.error(`Could not find any PFP files at ${extensionlessFilePath}`);
throw new Error(`Could not find any PFP files at ${extensionlessFilePath}`);
if (!dbf) {
log.error(`Could not find any PFP files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any PFP files at ${extensionlessFilePath}`,
);
}
} else {
const possibleExtensions: string[] = [".pfp"];
const filePath = await findFileCaseInsensitive(
extensionlessFilePath,
possibleExtensions,
);
try {
if (!filePath) {
log.error(`Could not find any PFP files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any PFP files at ${extensionlessFilePath}`,
);
}
dbf = await DBFFile.open(filePath);
} catch (error) {
log.error("Error opening PFP File.", errorTypeCheck(error));
throw error;
}
}
const rawDBFRecord = await dbf.readRecords();
//AD2 will always have only 1 row.

View File

@@ -1,23 +1,47 @@
import { platform } from "@electron-toolkit/utils";
import { DBFFile } from "dbffile";
import log from "electron-log/main";
import _ from "lodash";
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
import errorTypeCheck from "../../util/errorTypeCheck";
import { DecodedPft, DecodedPftLine } from "./decode-pft.interface";
import { findFileCaseInsensitive } from "./decoder-utils";
const DecodePft = async (
extensionlessFilePath: string,
): Promise<DecodedPft> => {
let dbf: DBFFile | null = null;
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.PFT`);
} catch (error) {
log.error("Error opening PFH File.", errorTypeCheck(error));
}
if (platform.isWindows) {
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.PFT`);
} catch (error) {
log.error("Error opening PFH File.", errorTypeCheck(error));
}
if (!dbf) {
log.error(`Could not find any PFT files at ${extensionlessFilePath}`);
throw new Error(`Could not find any PFT files at ${extensionlessFilePath}`);
if (!dbf) {
log.error(`Could not find any PFT files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any PFT files at ${extensionlessFilePath}`,
);
}
} else {
const possibleExtensions: string[] = ["pft"];
const filePath = await findFileCaseInsensitive(
extensionlessFilePath,
possibleExtensions,
);
try {
if (!filePath) {
log.error(`Could not find any PFT files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any PFT files at ${extensionlessFilePath}`,
);
}
dbf = await DBFFile.open(filePath);
} catch (error) {
log.error("Error opening PFT File.", errorTypeCheck(error));
throw error;
}
}
const rawDBFRecord = await dbf.readRecords(1);

View File

@@ -4,22 +4,45 @@ import _ from "lodash";
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
import errorTypeCheck from "../../util/errorTypeCheck";
import { DecodedStl, DecodedStlLine } from "./decode-stl.interface";
import { platform } from "@electron-toolkit/utils";
import { findFileCaseInsensitive } from "./decoder-utils";
const DecodeStl = async (
extensionlessFilePath: string,
): Promise<DecodedStl> => {
let dbf: DBFFile | null = null;
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.STL`);
} catch (error) {
log.error("Error opening STL File.", errorTypeCheck(error));
}
if (platform.isWindows) {
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.STL`);
} catch (error) {
log.error("Error opening STL File.", errorTypeCheck(error));
}
if (!dbf) {
log.error(`Could not find any STL files at ${extensionlessFilePath}`);
throw new Error(`Could not find any STL files at ${extensionlessFilePath}`);
if (!dbf) {
log.error(`Could not find any STL files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any STL files at ${extensionlessFilePath}`,
);
}
} else {
const possibleExtensions: string[] = ["stl"];
const filePath = await findFileCaseInsensitive(
extensionlessFilePath,
possibleExtensions,
);
try {
if (!filePath) {
log.error(`Could not find any STL files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any STL files at ${extensionlessFilePath}`,
);
}
dbf = await DBFFile.open(filePath);
} catch (error) {
log.error("Error opening STL File.", errorTypeCheck(error));
throw error;
}
}
const rawDBFRecord = await dbf.readRecords();
//AD2 will always have only 1 row.

View File

@@ -4,20 +4,44 @@ import _ from "lodash";
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
import errorTypeCheck from "../../util/errorTypeCheck";
import { DecodedTtl, DecodedTtlLine } from "./decode-ttl.interface";
import { platform } from "@electron-toolkit/utils";
import { findFileCaseInsensitive } from "./decoder-utils";
const DecodeTtl = async (
extensionlessFilePath: string,
): Promise<DecodedTtl> => {
let dbf: DBFFile | null = null;
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.TTL`);
} catch (error) {
log.error("Error opening TTL File.", errorTypeCheck(error));
}
if (platform.isWindows) {
try {
dbf = await DBFFile.open(`${extensionlessFilePath}.TTL`);
} catch (error) {
log.error("Error opening TTL File.", errorTypeCheck(error));
}
if (!dbf) {
log.error(`Could not find any TTL files at ${extensionlessFilePath}`);
throw new Error(`Could not find any TTL files at ${extensionlessFilePath}`);
if (!dbf) {
log.error(`Could not find any TTL files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any TTL files at ${extensionlessFilePath}`,
);
}
} else {
const possibleExtensions: string[] = ["ttl"];
const filePath = await findFileCaseInsensitive(
extensionlessFilePath,
possibleExtensions,
);
try {
if (!filePath) {
log.error(`Could not find any TTL files at ${extensionlessFilePath}`);
throw new Error(
`Could not find any TTL files at ${extensionlessFilePath}`,
);
}
dbf = await DBFFile.open(filePath);
} catch (error) {
log.error("Error opening TTL File.", errorTypeCheck(error));
throw error;
}
}
const rawDBFRecord = await dbf.readRecords(1);

View File

@@ -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.

View File

@@ -0,0 +1,36 @@
import log from "electron-log/main";
import fs from "fs";
import path from "path";
const findFileCaseInsensitive = async (
extensionlessFilePath: string,
extensions: string[],
): Promise<string | null> => {
const directory: string = path.dirname(extensionlessFilePath);
try {
const matchingFiles = fs
.readdirSync(directory)
.filter((file: string) =>
extensions.some((ext) =>
file.toLowerCase().endsWith(ext.toLowerCase()),
),
);
const files: string[] = [];
matchingFiles.forEach((file) => {
const fullPath = path.join(directory, file);
files.push(fullPath);
});
// Return the first matching file if needed
if (files.length > 0) {
return files[0];
}
} catch (error) {
log.error(`Failed to read directory ${directory}:`, error);
throw error;
}
return null;
};
export { findFileCaseInsensitive };