Add case insensitivity checks for Mac and Linux platforms
This commit is contained in:
@@ -1,25 +1,51 @@
|
|||||||
|
import { platform } from "@electron-toolkit/utils";
|
||||||
import { DBFFile } from "dbffile";
|
import { DBFFile } from "dbffile";
|
||||||
import log from "electron-log/main";
|
import log from "electron-log/main";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
||||||
|
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||||
import store from "../store/store";
|
import store from "../store/store";
|
||||||
import { DecodedAd1, OwnerRecordInterface } from "./decode-ad1.interface";
|
import { DecodedAd1, OwnerRecordInterface } from "./decode-ad1.interface";
|
||||||
|
import { findFileCaseInsensitive } from "./decoder-utils";
|
||||||
|
|
||||||
const DecodeAD1 = async (
|
const DecodeAD1 = async (
|
||||||
extensionlessFilePath: string,
|
extensionlessFilePath: string,
|
||||||
): Promise<DecodedAd1> => {
|
): Promise<DecodedAd1> => {
|
||||||
let dbf: DBFFile | null = null;
|
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) {
|
if (platform.isWindows) {
|
||||||
log.error(`Could not find any AD1 files at ${extensionlessFilePath}`);
|
try {
|
||||||
throw new Error(`Could not find any AD1 files at ${extensionlessFilePath}`);
|
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);
|
const rawDBFRecord = await dbf.readRecords(1);
|
||||||
@@ -205,4 +231,5 @@ const DecodeAD1 = async (
|
|||||||
|
|
||||||
return { ...rawAd1Data, owner: { data: ownerRecord } };
|
return { ...rawAd1Data, owner: { data: ownerRecord } };
|
||||||
};
|
};
|
||||||
|
|
||||||
export default DecodeAD1;
|
export default DecodeAD1;
|
||||||
|
|||||||
@@ -3,22 +3,45 @@ import log from "electron-log/main";
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
||||||
import { DecodedAD2 } from "./decode-ad2.interface";
|
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 (
|
const DecodeAD2 = async (
|
||||||
extensionlessFilePath: string,
|
extensionlessFilePath: string,
|
||||||
): Promise<DecodedAD2> => {
|
): Promise<DecodedAD2> => {
|
||||||
let dbf: DBFFile | null = null;
|
let dbf: DBFFile | null = null;
|
||||||
try {
|
if (platform.isWindows) {
|
||||||
dbf = await DBFFile.open(`${extensionlessFilePath}B.AD2`);
|
try {
|
||||||
} catch (error) {
|
dbf = await DBFFile.open(`${extensionlessFilePath}B.AD2`);
|
||||||
// log.error("Error opening AD2 File.", errorTypeCheck(error));
|
} catch {
|
||||||
dbf = await DBFFile.open(`${extensionlessFilePath}.AD2`);
|
dbf = await DBFFile.open(`${extensionlessFilePath}.AD2`);
|
||||||
// log.log("Trying to find AD2 file using regular CIECA Id.");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!dbf) {
|
if (!dbf) {
|
||||||
log.error(`Could not find any AD2 files at ${extensionlessFilePath}`);
|
log.error(`Could not find any AD2 files at ${extensionlessFilePath}`);
|
||||||
throw new 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);
|
const rawDBFRecord = await dbf.readRecords(1);
|
||||||
|
|||||||
@@ -4,22 +4,46 @@ import _ from "lodash";
|
|||||||
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
||||||
import errorTypeCheck from "../../util/errorTypeCheck";
|
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||||
import { DecodedEnv } from "./decode-env.interface";
|
import { DecodedEnv } from "./decode-env.interface";
|
||||||
|
import { platform } from "@electron-toolkit/utils";
|
||||||
|
import { findFileCaseInsensitive } from "./decoder-utils";
|
||||||
|
|
||||||
const DecodeEnv = async (
|
const DecodeEnv = async (
|
||||||
extensionlessFilePath: string,
|
extensionlessFilePath: string,
|
||||||
): Promise<DecodedEnv> => {
|
): Promise<DecodedEnv> => {
|
||||||
let dbf: DBFFile | null = null;
|
let dbf: DBFFile | null = null;
|
||||||
try {
|
|
||||||
dbf = await DBFFile.open(`${extensionlessFilePath}.ENV`);
|
|
||||||
} catch (error) {
|
|
||||||
log.error("Error opening ENV File.", errorTypeCheck(error));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dbf) {
|
if (platform.isWindows) {
|
||||||
log.error(`Could not find any ENV files at ${extensionlessFilePath}`);
|
try {
|
||||||
throw new Error(`Could not find any ENV files at ${extensionlessFilePath}`);
|
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);
|
const rawDBFRecord = await dbf.readRecords(1);
|
||||||
|
|
||||||
//AD2 will always have only 1 row.
|
//AD2 will always have only 1 row.
|
||||||
|
|||||||
@@ -5,21 +5,45 @@ import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
|||||||
import errorTypeCheck from "../../util/errorTypeCheck";
|
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||||
import store from "../store/store";
|
import store from "../store/store";
|
||||||
import { DecodedLin, DecodedLinLine } from "./decode-lin.interface";
|
import { DecodedLin, DecodedLinLine } from "./decode-lin.interface";
|
||||||
|
import { platform } from "@electron-toolkit/utils";
|
||||||
|
import { findFileCaseInsensitive } from "./decoder-utils";
|
||||||
|
|
||||||
const DecodeLin = async (
|
const DecodeLin = async (
|
||||||
extensionlessFilePath: string,
|
extensionlessFilePath: string,
|
||||||
): Promise<DecodedLin> => {
|
): Promise<DecodedLin> => {
|
||||||
let dbf: DBFFile | null = null;
|
let dbf: DBFFile | null = null;
|
||||||
try {
|
if (platform.isWindows) {
|
||||||
dbf = await DBFFile.open(`${extensionlessFilePath}.LIN`);
|
try {
|
||||||
} catch (error) {
|
dbf = await DBFFile.open(`${extensionlessFilePath}.LIN`);
|
||||||
//LIN File only has 1 location.
|
} catch (error) {
|
||||||
log.error("Error opening LIN File.", errorTypeCheck(error));
|
//LIN File only has 1 location.
|
||||||
}
|
log.error("Error opening LIN File.", errorTypeCheck(error));
|
||||||
|
}
|
||||||
|
|
||||||
if (!dbf) {
|
if (!dbf) {
|
||||||
log.error(`Could not find any LIN files at ${extensionlessFilePath}`);
|
log.error(`Could not find any LIN files at ${extensionlessFilePath}`);
|
||||||
throw new 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();
|
const rawDBFRecord = await dbf.readRecords();
|
||||||
|
|||||||
@@ -4,24 +4,47 @@ import _ from "lodash";
|
|||||||
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
||||||
import errorTypeCheck from "../../util/errorTypeCheck";
|
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||||
import { DecodedPfh } from "./decode-pfh.interface";
|
import { DecodedPfh } from "./decode-pfh.interface";
|
||||||
|
import { platform } from "os";
|
||||||
|
import { findFileCaseInsensitive } from "./decoder-utils";
|
||||||
|
|
||||||
const DecodePfh = async (
|
const DecodePfh = async (
|
||||||
extensionlessFilePath: string,
|
extensionlessFilePath: string,
|
||||||
): Promise<DecodedPfh> => {
|
): Promise<DecodedPfh> => {
|
||||||
let dbf: DBFFile | null = null;
|
let dbf: DBFFile | null = null;
|
||||||
try {
|
if (platform.isWindows) {
|
||||||
dbf = await DBFFile.open(`${extensionlessFilePath}.PFH`);
|
try {
|
||||||
} catch (error) {
|
dbf = await DBFFile.open(`${extensionlessFilePath}.PFH`);
|
||||||
log.error("Error opening PFH File.", errorTypeCheck(error));
|
} catch (error) {
|
||||||
dbf = await DBFFile.open(`${extensionlessFilePath}.PFH`);
|
log.error("Error opening PFH File.", errorTypeCheck(error));
|
||||||
log.log("Trying to find PFH file using regular CIECA Id.");
|
dbf = await DBFFile.open(`${extensionlessFilePath}.PFH`);
|
||||||
}
|
log.log("Trying to find PFH file using regular CIECA Id.");
|
||||||
|
}
|
||||||
|
|
||||||
if (!dbf) {
|
if (!dbf) {
|
||||||
log.error(`Could not find any PFH files at ${extensionlessFilePath}`);
|
log.error(`Could not find any PFH files at ${extensionlessFilePath}`);
|
||||||
throw new 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);
|
const rawDBFRecord = await dbf.readRecords(1);
|
||||||
|
|
||||||
//AD2 will always have only 1 row.
|
//AD2 will always have only 1 row.
|
||||||
|
|||||||
@@ -8,21 +8,45 @@ import {
|
|||||||
JobLaborRateFields,
|
JobLaborRateFields,
|
||||||
DecodedPflLine,
|
DecodedPflLine,
|
||||||
} from "./decode-pfl.interface";
|
} from "./decode-pfl.interface";
|
||||||
|
import { platform } from "@electron-toolkit/utils";
|
||||||
|
import { findFileCaseInsensitive } from "./decoder-utils";
|
||||||
|
|
||||||
const DecodePfl = async (
|
const DecodePfl = async (
|
||||||
extensionlessFilePath: string,
|
extensionlessFilePath: string,
|
||||||
): Promise<DecodedPfl> => {
|
): Promise<DecodedPfl> => {
|
||||||
let dbf: DBFFile | null = null;
|
let dbf: DBFFile | null = null;
|
||||||
try {
|
if (platform.isWindows) {
|
||||||
dbf = await DBFFile.open(`${extensionlessFilePath}.PFL`);
|
try {
|
||||||
} catch (error) {
|
dbf = await DBFFile.open(`${extensionlessFilePath}.PFL`);
|
||||||
//PFL File only has 1 location.
|
} catch (error) {
|
||||||
log.error("Error opening PFL File.", errorTypeCheck(error));
|
//PFL File only has 1 location.
|
||||||
}
|
log.error("Error opening PFL File.", errorTypeCheck(error));
|
||||||
|
}
|
||||||
|
|
||||||
if (!dbf) {
|
if (!dbf) {
|
||||||
log.error(`Could not find any PFL files at ${extensionlessFilePath}`);
|
log.error(`Could not find any PFL files at ${extensionlessFilePath}`);
|
||||||
throw new 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();
|
const rawDBFRecord = await dbf.readRecords();
|
||||||
|
|||||||
@@ -9,23 +9,46 @@ import {
|
|||||||
DecodedPfmLine,
|
DecodedPfmLine,
|
||||||
JobMaterialRateFields,
|
JobMaterialRateFields,
|
||||||
} from "./decode-pfm.interface";
|
} from "./decode-pfm.interface";
|
||||||
|
import { platform } from "@electron-toolkit/utils";
|
||||||
|
import { findFileCaseInsensitive } from "./decoder-utils";
|
||||||
|
|
||||||
const DecodePfm = async (
|
const DecodePfm = async (
|
||||||
extensionlessFilePath: string,
|
extensionlessFilePath: string,
|
||||||
): Promise<DecodedPfm> => {
|
): Promise<DecodedPfm> => {
|
||||||
let dbf: DBFFile | null = null;
|
let dbf: DBFFile | null = null;
|
||||||
try {
|
if (platform.isWindows) {
|
||||||
dbf = await DBFFile.open(`${extensionlessFilePath}.PFM`);
|
try {
|
||||||
} catch (error) {
|
dbf = await DBFFile.open(`${extensionlessFilePath}.PFM`);
|
||||||
//PFM File only has 1 location.
|
} catch (error) {
|
||||||
log.error("Error opening PFM File.", errorTypeCheck(error));
|
//PFM File only has 1 location.
|
||||||
}
|
log.error("Error opening PFM File.", errorTypeCheck(error));
|
||||||
|
}
|
||||||
|
|
||||||
if (!dbf) {
|
if (!dbf) {
|
||||||
log.error(`Could not find any PFM files at ${extensionlessFilePath}`);
|
log.error(`Could not find any PFM files at ${extensionlessFilePath}`);
|
||||||
throw new 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();
|
const rawDBFRecord = await dbf.readRecords();
|
||||||
|
|
||||||
//AD2 will always have only 1 row.
|
//AD2 will always have only 1 row.
|
||||||
|
|||||||
@@ -5,22 +5,46 @@ import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
|||||||
import errorTypeCheck from "../../util/errorTypeCheck";
|
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||||
import YNBoolConverter from "../../util/ynBoolConverter";
|
import YNBoolConverter from "../../util/ynBoolConverter";
|
||||||
import { DecodedPfo, DecodedPfoLine } from "./decode-pfo.interface";
|
import { DecodedPfo, DecodedPfoLine } from "./decode-pfo.interface";
|
||||||
|
import { platform } from "@electron-toolkit/utils";
|
||||||
|
import { findFileCaseInsensitive } from "./decoder-utils";
|
||||||
|
|
||||||
const DecodePfo = async (
|
const DecodePfo = async (
|
||||||
extensionlessFilePath: string,
|
extensionlessFilePath: string,
|
||||||
): Promise<DecodedPfo> => {
|
): Promise<DecodedPfo> => {
|
||||||
let dbf: DBFFile | null = null;
|
let dbf: DBFFile | null = null;
|
||||||
try {
|
if (platform.isWindows) {
|
||||||
dbf = await DBFFile.open(`${extensionlessFilePath}.PFO`);
|
try {
|
||||||
} catch (error) {
|
dbf = await DBFFile.open(`${extensionlessFilePath}.PFO`);
|
||||||
log.error("Error opening PFO File.", errorTypeCheck(error));
|
} catch (error) {
|
||||||
dbf = await DBFFile.open(`${extensionlessFilePath}.PFO`);
|
log.error("Error opening PFO File.", errorTypeCheck(error));
|
||||||
log.log("Trying to find PFO file using regular CIECA Id.");
|
dbf = await DBFFile.open(`${extensionlessFilePath}.PFO`);
|
||||||
}
|
log.log("Trying to find PFO file using regular CIECA Id.");
|
||||||
|
}
|
||||||
|
|
||||||
if (!dbf) {
|
if (!dbf) {
|
||||||
log.error(`Could not find any PFO files at ${extensionlessFilePath}`);
|
log.error(`Could not find any PFO files at ${extensionlessFilePath}`);
|
||||||
throw new 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);
|
const rawDBFRecord = await dbf.readRecords(1);
|
||||||
|
|||||||
@@ -9,23 +9,46 @@ import {
|
|||||||
DecodedPfpLine,
|
DecodedPfpLine,
|
||||||
DecodedPfpLinesByType,
|
DecodedPfpLinesByType,
|
||||||
} from "./decode-pfp.interface";
|
} from "./decode-pfp.interface";
|
||||||
|
import { platform } from "@electron-toolkit/utils";
|
||||||
|
import { findFileCaseInsensitive } from "./decoder-utils";
|
||||||
|
|
||||||
const DecodePfp = async (
|
const DecodePfp = async (
|
||||||
extensionlessFilePath: string,
|
extensionlessFilePath: string,
|
||||||
): Promise<DecodedPfp> => {
|
): Promise<DecodedPfp> => {
|
||||||
let dbf: DBFFile | null = null;
|
let dbf: DBFFile | null = null;
|
||||||
try {
|
if (platform.isWindows) {
|
||||||
dbf = await DBFFile.open(`${extensionlessFilePath}.PFP`);
|
try {
|
||||||
} catch (error) {
|
dbf = await DBFFile.open(`${extensionlessFilePath}.PFP`);
|
||||||
//PFP File only has 1 location.
|
} catch (error) {
|
||||||
log.error("Error opening PFP File.", errorTypeCheck(error));
|
//PFP File only has 1 location.
|
||||||
}
|
log.error("Error opening PFP File.", errorTypeCheck(error));
|
||||||
|
}
|
||||||
|
|
||||||
if (!dbf) {
|
if (!dbf) {
|
||||||
log.error(`Could not find any PFP files at ${extensionlessFilePath}`);
|
log.error(`Could not find any PFP files at ${extensionlessFilePath}`);
|
||||||
throw new 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();
|
const rawDBFRecord = await dbf.readRecords();
|
||||||
|
|
||||||
//AD2 will always have only 1 row.
|
//AD2 will always have only 1 row.
|
||||||
|
|||||||
@@ -1,23 +1,47 @@
|
|||||||
|
import { platform } from "@electron-toolkit/utils";
|
||||||
import { DBFFile } from "dbffile";
|
import { DBFFile } from "dbffile";
|
||||||
import log from "electron-log/main";
|
import log from "electron-log/main";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
||||||
import errorTypeCheck from "../../util/errorTypeCheck";
|
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||||
import { DecodedPft, DecodedPftLine } from "./decode-pft.interface";
|
import { DecodedPft, DecodedPftLine } from "./decode-pft.interface";
|
||||||
|
import { findFileCaseInsensitive } from "./decoder-utils";
|
||||||
|
|
||||||
const DecodePft = async (
|
const DecodePft = async (
|
||||||
extensionlessFilePath: string,
|
extensionlessFilePath: string,
|
||||||
): Promise<DecodedPft> => {
|
): Promise<DecodedPft> => {
|
||||||
let dbf: DBFFile | null = null;
|
let dbf: DBFFile | null = null;
|
||||||
try {
|
if (platform.isWindows) {
|
||||||
dbf = await DBFFile.open(`${extensionlessFilePath}.PFT`);
|
try {
|
||||||
} catch (error) {
|
dbf = await DBFFile.open(`${extensionlessFilePath}.PFT`);
|
||||||
log.error("Error opening PFH File.", errorTypeCheck(error));
|
} catch (error) {
|
||||||
}
|
log.error("Error opening PFH File.", errorTypeCheck(error));
|
||||||
|
}
|
||||||
|
|
||||||
if (!dbf) {
|
if (!dbf) {
|
||||||
log.error(`Could not find any PFT files at ${extensionlessFilePath}`);
|
log.error(`Could not find any PFT files at ${extensionlessFilePath}`);
|
||||||
throw new 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);
|
const rawDBFRecord = await dbf.readRecords(1);
|
||||||
|
|||||||
@@ -4,22 +4,45 @@ import _ from "lodash";
|
|||||||
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
||||||
import errorTypeCheck from "../../util/errorTypeCheck";
|
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||||
import { DecodedStl, DecodedStlLine } from "./decode-stl.interface";
|
import { DecodedStl, DecodedStlLine } from "./decode-stl.interface";
|
||||||
|
import { platform } from "@electron-toolkit/utils";
|
||||||
|
import { findFileCaseInsensitive } from "./decoder-utils";
|
||||||
|
|
||||||
const DecodeStl = async (
|
const DecodeStl = async (
|
||||||
extensionlessFilePath: string,
|
extensionlessFilePath: string,
|
||||||
): Promise<DecodedStl> => {
|
): Promise<DecodedStl> => {
|
||||||
let dbf: DBFFile | null = null;
|
let dbf: DBFFile | null = null;
|
||||||
try {
|
if (platform.isWindows) {
|
||||||
dbf = await DBFFile.open(`${extensionlessFilePath}.STL`);
|
try {
|
||||||
} catch (error) {
|
dbf = await DBFFile.open(`${extensionlessFilePath}.STL`);
|
||||||
log.error("Error opening STL File.", errorTypeCheck(error));
|
} catch (error) {
|
||||||
}
|
log.error("Error opening STL File.", errorTypeCheck(error));
|
||||||
|
}
|
||||||
|
|
||||||
if (!dbf) {
|
if (!dbf) {
|
||||||
log.error(`Could not find any STL files at ${extensionlessFilePath}`);
|
log.error(`Could not find any STL files at ${extensionlessFilePath}`);
|
||||||
throw new 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();
|
const rawDBFRecord = await dbf.readRecords();
|
||||||
|
|
||||||
//AD2 will always have only 1 row.
|
//AD2 will always have only 1 row.
|
||||||
|
|||||||
@@ -4,20 +4,44 @@ import _ from "lodash";
|
|||||||
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
||||||
import errorTypeCheck from "../../util/errorTypeCheck";
|
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||||
import { DecodedTtl, DecodedTtlLine } from "./decode-ttl.interface";
|
import { DecodedTtl, DecodedTtlLine } from "./decode-ttl.interface";
|
||||||
|
import { platform } from "@electron-toolkit/utils";
|
||||||
|
import { findFileCaseInsensitive } from "./decoder-utils";
|
||||||
|
|
||||||
const DecodeTtl = async (
|
const DecodeTtl = async (
|
||||||
extensionlessFilePath: string,
|
extensionlessFilePath: string,
|
||||||
): Promise<DecodedTtl> => {
|
): Promise<DecodedTtl> => {
|
||||||
let dbf: DBFFile | null = null;
|
let dbf: DBFFile | null = null;
|
||||||
try {
|
if (platform.isWindows) {
|
||||||
dbf = await DBFFile.open(`${extensionlessFilePath}.TTL`);
|
try {
|
||||||
} catch (error) {
|
dbf = await DBFFile.open(`${extensionlessFilePath}.TTL`);
|
||||||
log.error("Error opening TTL File.", errorTypeCheck(error));
|
} catch (error) {
|
||||||
}
|
log.error("Error opening TTL File.", errorTypeCheck(error));
|
||||||
|
}
|
||||||
|
|
||||||
if (!dbf) {
|
if (!dbf) {
|
||||||
log.error(`Could not find any TTL files at ${extensionlessFilePath}`);
|
log.error(`Could not find any TTL files at ${extensionlessFilePath}`);
|
||||||
throw new 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);
|
const rawDBFRecord = await dbf.readRecords(1);
|
||||||
|
|||||||
@@ -6,24 +6,47 @@ import { DecodedVeh, VehicleRecordInterface } from "./decode-veh.interface";
|
|||||||
import errorTypeCheck from "../../util/errorTypeCheck";
|
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||||
import store from "../store/store";
|
import store from "../store/store";
|
||||||
import typeCaster from "../../util/typeCaster";
|
import typeCaster from "../../util/typeCaster";
|
||||||
|
import { platform } from "@electron-toolkit/utils";
|
||||||
|
import { findFileCaseInsensitive } from "./decoder-utils";
|
||||||
|
|
||||||
const DecodeVeh = async (
|
const DecodeVeh = async (
|
||||||
extensionlessFilePath: string,
|
extensionlessFilePath: string,
|
||||||
): Promise<DecodedVeh> => {
|
): Promise<DecodedVeh> => {
|
||||||
let dbf: DBFFile | null = null;
|
let dbf: DBFFile | null = null;
|
||||||
try {
|
if (platform.isWindows) {
|
||||||
dbf = await DBFFile.open(`${extensionlessFilePath}V.VEH`);
|
try {
|
||||||
} catch (error) {
|
dbf = await DBFFile.open(`${extensionlessFilePath}V.VEH`);
|
||||||
log.error("Error opening VEH File.", errorTypeCheck(error));
|
} catch (error) {
|
||||||
dbf = await DBFFile.open(`${extensionlessFilePath}.VEH`);
|
log.error("Error opening VEH File.", errorTypeCheck(error));
|
||||||
log.log("Found VEH file using regular CIECA Id.");
|
dbf = await DBFFile.open(`${extensionlessFilePath}.VEH`);
|
||||||
}
|
log.log("Found VEH file using regular CIECA Id.");
|
||||||
|
}
|
||||||
|
|
||||||
if (!dbf) {
|
if (!dbf) {
|
||||||
log.error(`Could not find any VEH files at ${extensionlessFilePath}`);
|
log.error(`Could not find any VEH files at ${extensionlessFilePath}`);
|
||||||
throw new 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);
|
const rawDBFRecord = await dbf.readRecords(1);
|
||||||
|
|
||||||
//AD2 will always have only 1 row.
|
//AD2 will always have only 1 row.
|
||||||
|
|||||||
36
src/main/decoder/decoder-utils.ts
Normal file
36
src/main/decoder/decoder-utils.ts
Normal 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 };
|
||||||
Reference in New Issue
Block a user