2025-03-30 21:31:35 +03:00
|
|
|
import cls from "./src/services/cls.js";
|
2025-03-30 21:37:10 +03:00
|
|
|
import fs from "fs/promises";
|
|
|
|
import fsExtra from "fs-extra";
|
|
|
|
import path from "path";
|
2025-03-30 21:31:35 +03:00
|
|
|
|
2025-04-04 20:01:28 +03:00
|
|
|
export function initializeDatabase(customDbBuffer?: Buffer) {
|
|
|
|
return new Promise<void>(async (resolve) => {
|
|
|
|
const sqlInit = (await import("./src/services/sql_init.js")).default;
|
|
|
|
cls.init(async () => {
|
|
|
|
if (!sqlInit.isDbInitialized()) {
|
|
|
|
await sqlInit.createInitialDatabase(true, customDbBuffer);
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
});
|
2025-03-30 21:31:35 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function startElectron() {
|
|
|
|
await import("./electron-main.js");
|
|
|
|
}
|
|
|
|
|
2025-03-30 21:37:10 +03:00
|
|
|
export async function extractZip(zipFilePath: string, outputPath: string) {
|
|
|
|
const deferred = (await import("./src/services/utils.js")).deferred;
|
|
|
|
|
|
|
|
const promise = deferred<void>()
|
|
|
|
setTimeout(async () => {
|
|
|
|
// Then extract the zip.
|
|
|
|
const { readZipFile, readContent } = (await import("./src/services/import/zip.js"));
|
|
|
|
await readZipFile(await fs.readFile(zipFilePath), async (zip, entry) => {
|
|
|
|
// We ignore directories since they can appear out of order anyway.
|
|
|
|
if (!entry.fileName.endsWith("/")) {
|
|
|
|
const destPath = path.join(outputPath, entry.fileName);
|
|
|
|
const fileContent = await readContent(zip, entry);
|
|
|
|
|
|
|
|
await fsExtra.mkdirs(path.dirname(destPath));
|
|
|
|
await fs.writeFile(destPath, fileContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
zip.readEntry();
|
|
|
|
});
|
|
|
|
promise.resolve();
|
|
|
|
}, 1000);
|
|
|
|
await promise;
|
|
|
|
}
|