hamster-desktop/electron/ipcMainHandlers.ts
2024-08-05 16:50:11 +08:00

36 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import fs from "fs";
import path from "path";
import * as dicomParser from "dicom-parser"; /* */
import { ipcMain } from "electron";
// 定义一个异步函数来递归地查找.dcm文件
const findDcmFiles = async (
dir: string,
fileList: string[] = []
): Promise<string[]> => {
const files = await fs.promises.readdir(dir, { withFileTypes: true });
await Promise.all(
files.map(async (file) => {
const filePath = path.join(dir, file.name);
if (file.isDirectory()) {
await findDcmFiles(filePath, fileList); // 递归调用以遍历子目录
} else if (file.name.endsWith(".dcm")) {
fileList.push(filePath); // 如果文件是.dcm文件添加到列表中
}
})
);
return fileList;
};
const registerIpcMainHandlers = () => {
ipcMain.on("parseDicom", async (event, file: string) => {
const rootFolder = path.dirname(file);
const fileList = await findDcmFiles(rootFolder);
console.log("rootFolder", rootFolder);
console.log("fileList", fileList);
// event.sender.send("parseDicomResponse", files);
});
};
export default registerIpcMainHandlers;