MCPcopy Index your code
hub / github.com/ZToolsCenter/ZTools / getExplorerFolderPathFromWindow

Function getExplorerFolderPathFromWindow

src/main/utils/common.ts:74–105  ·  view source on GitHub ↗
(
  windowInfo: ExplorerFolderWindowInfo,
  logPrefix: string
)

Source from the content-addressed store, hash-verified

72 * 返回 null 表示当前窗口不是可读取目录的 Explorer/桌面窗口。
73 */
74export function getExplorerFolderPathFromWindow(
75 windowInfo: ExplorerFolderWindowInfo,
76 logPrefix: string
77): string | null {
78 if (windowInfo.className === 'Progman' || windowInfo.className === 'WorkerW') {
79 return app.getPath('desktop')
80 }
81
82 if (windowInfo.className !== 'CabinetWClass' && windowInfo.className !== 'ExploreWClass') {
83 return null
84 }
85
86 if (typeof windowInfo.hwnd !== 'number') {
87 console.error(`[${logPrefix}] Explorer 窗口缺少 hwnd,无法读取目录`)
88 return null
89 }
90
91 let folderUrl: string | null = null
92 try {
93 folderUrl = WindowManager.getExplorerFolderPath(windowInfo.hwnd)
94 } catch (error) {
95 console.error(`[${logPrefix}] Explorer 目录读取异常 (hwnd=${windowInfo.hwnd}):`, error)
96 return null
97 }
98
99 if (!folderUrl) {
100 console.error(`[${logPrefix}] Explorer 目录读取失败 (hwnd=${windowInfo.hwnd})`)
101 return null
102 }
103
104 return decodeFileUrlToPath(folderUrl)
105}

Callers 2

getWindowsExplorerPathFunction · 0.90

Calls 2

decodeFileUrlToPathFunction · 0.85
getExplorerFolderPathMethod · 0.80

Tested by

no test coverage detected