| 
									
										
										
										
											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-02 22:18:28 +03:00
										 |  |  | export async function initializeDatabase(customDbBuffer?: Buffer) { | 
					
						
							| 
									
										
										
										
											2025-03-30 21:31:35 +03:00
										 |  |  |     const sqlInit = (await import("./src/services/sql_init.js")).default; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cls.init(() => { | 
					
						
							|  |  |  |         if (!sqlInit.isDbInitialized()) { | 
					
						
							| 
									
										
										
										
											2025-04-02 22:18:28 +03:00
										 |  |  |             sqlInit.createInitialDatabase(true, customDbBuffer); | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | } |