diff --git a/wowup-electron/app/file.utils.ts b/wowup-electron/app/file.utils.ts index 085d07d6..704a9b27 100644 --- a/wowup-electron/app/file.utils.ts +++ b/wowup-electron/app/file.utils.ts @@ -1,6 +1,7 @@ import * as fs from "fs-extra"; import * as path from "path"; -import { max } from "lodash"; +import { max, sumBy } from "lodash"; +import { TreeNode } from "../src/common/models/ipc-events"; export async function readDirRecursive(sourcePath: string): Promise { const dirFiles: string[] = []; @@ -19,6 +20,39 @@ export async function readDirRecursive(sourcePath: string): Promise { return dirFiles; } +export async function getDirTree(sourcePath: string): Promise { + const files = await fs.readdir(sourcePath, { withFileTypes: true }); + + const node: TreeNode = { + name: path.basename(sourcePath), + path: sourcePath, + children: [], + isDirectory: true, + size: 0, + }; + + for (const file of files) { + const filePath = path.join(sourcePath, file.name); + if (file.isDirectory()) { + const nestedNode = await getDirTree(filePath); + node.children.push(nestedNode); + node.size = sumBy(node.children, (n) => n.size); + } else { + const stats = await fs.stat(filePath); + node.size += stats.size; + node.children.push({ + name: file.name, + path: filePath, + children: [], + isDirectory: false, + size: stats.size, + }); + } + } + + return node; +} + export async function getLastModifiedFileDate(sourcePath: string): Promise { const dirFiles = await readDirRecursive(sourcePath); const dates: number[] = []; diff --git a/wowup-electron/app/ipc-events.ts b/wowup-electron/app/ipc-events.ts index b296e091..0304f9ea 100644 --- a/wowup-electron/app/ipc-events.ts +++ b/wowup-electron/app/ipc-events.ts @@ -66,6 +66,8 @@ import { IPC_WINDOW_LEAVE_FULLSCREEN, IPC_WOWUP_GET_SCAN_RESULTS, IPC_WRITE_FILE_CHANNEL, + IPC_LIST_DIR_RECURSIVE, + IPC_GET_DIRECTORY_TREE, } from "../src/common/constants"; import { CurseFolderScanResult } from "../src/common/curse/curse-folder-scan-result"; import { Addon } from "../src/common/entities/addon"; @@ -73,13 +75,13 @@ import { CopyFileRequest } from "../src/common/models/copy-file-request"; import { DownloadRequest } from "../src/common/models/download-request"; import { DownloadStatus } from "../src/common/models/download-status"; import { DownloadStatusType } from "../src/common/models/download-status-type"; -import { FsDirent, FsStats } from "../src/common/models/ipc-events"; +import { FsDirent, FsStats, TreeNode } from "../src/common/models/ipc-events"; import { UnzipRequest } from "../src/common/models/unzip-request"; import { RendererChannels } from "../src/common/wowup"; import { MenuConfig, SystemTrayConfig, WowUpScanResult } from "../src/common/wowup/models"; import { createAppMenu } from "./app-menu"; import { CurseFolderScanner } from "./curse-folder-scanner"; -import { getLastModifiedFileDate } from "./file.utils"; +import { getDirTree, getLastModifiedFileDate, readDirRecursive } from "./file.utils"; import { addonStore } from "./stores"; import { createTray, restoreWindow } from "./system-tray"; import { WowUpFolderScanner } from "./wowup-folder-scanner"; @@ -403,6 +405,14 @@ export function initializeIpcHandlers(window: BrowserWindow, userAgent: string): return getLastModifiedFileDate(dirPath); }); + handle(IPC_LIST_DIR_RECURSIVE, (evt, dirPath: string): Promise => { + return readDirRecursive(dirPath); + }); + + handle(IPC_GET_DIRECTORY_TREE, (evt, dirPath: string): Promise => { + return getDirTree(dirPath); + }); + handle(IPC_MINIMIZE_WINDOW, () => { if (window?.minimizable) { window.minimize(); diff --git a/wowup-electron/package-lock.json b/wowup-electron/package-lock.json index f8c98915..9cb7142d 100644 --- a/wowup-electron/package-lock.json +++ b/wowup-electron/package-lock.json @@ -1,6 +1,6 @@ { "name": "wowup", - "version": "2.5.0-beta.2", + "version": "2.5.0-beta.4", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -3820,6 +3820,15 @@ "@bbob/preset": "^2.7.0" } }, + "@circlon/angular-tree-component": { + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/@circlon/angular-tree-component/-/angular-tree-component-11.0.4.tgz", + "integrity": "sha512-Ck86mG6Z9eWG03RiOACDzrCjuzEDXU8rcEDi0aw0+Ku62x6ZY2mx8G0VX3CLEkS1BAXM2ef6luOIcoSKAKtDaA==", + "requires": { + "mobx": "~4.14.1", + "tslib": "^2.0.0" + } + }, "@csstools/convert-colors": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/@csstools/convert-colors/-/convert-colors-1.4.0.tgz", @@ -14357,6 +14366,11 @@ "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", "dev": true }, + "mobx": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/mobx/-/mobx-4.14.1.tgz", + "integrity": "sha512-Oyg7Sr7r78b+QPYLufJyUmxTWcqeQ96S1nmtyur3QL8SeI6e0TqcKKcxbG+sVJLWANhHQkBW/mDmgG5DDC4fdw==" + }, "mocha": { "version": "8.4.0", "resolved": "https://registry.npmjs.org/mocha/-/mocha-8.4.0.tgz", diff --git a/wowup-electron/package.json b/wowup-electron/package.json index dc4cc269..27a76b1a 100644 --- a/wowup-electron/package.json +++ b/wowup-electron/package.json @@ -124,6 +124,7 @@ "@bbob/core": "2.7.0", "@bbob/html": "2.7.0", "@bbob/preset-html5": "2.7.0", + "@circlon/angular-tree-component": "11.0.4", "@fortawesome/fontawesome-svg-core": "1.2.35", "@fortawesome/free-brands-svg-icons": "5.15.3", "@fortawesome/free-regular-svg-icons": "5.15.3", diff --git a/wowup-electron/src/app/components/extra/extra.component.html b/wowup-electron/src/app/components/extra/extra.component.html index 93ae3f78..732901cc 100644 --- a/wowup-electron/src/app/components/extra/extra.component.html +++ b/wowup-electron/src/app/components/extra/extra.component.html @@ -1,7 +1,7 @@
-