UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

2 lines • 4.46 kB
import{i as e}from"./openclaw-state-read-map-size-DJbMcZYM.mjs";import{l as t}from"./openclaw-state-read-home-dir-BQZX1pD2.mjs";import{t as n}from"./openclaw-state-read-path-existence-Bp_sxI9A.mjs";import{n as r}from"./openclaw-state-read-process-env-DgVwfN3Y.mjs";import{t as i}from"./openclaw-state-read-windows-appcontainer-spawn-B9xODvkk.mjs";import a from"node:fs";import o from"node:path";import{execFileSync as s}from"node:child_process";const c=`C:\\Windows`,l=5e3;let u=null;function locateWindowsRegExe(){let e=o.win32.join(c,`System32`,`reg.exe`);return n(e,a.constants.R_OK)?e:null}function trimTrailingSeparators(e){let t=o.win32.parse(e),n=e;for(;n.length>t.root.length&&/[\\/]/.test(n.at(-1)??``);)n=n.slice(0,-1);return n}function normalizeWindowsInstallRoot(e){if(typeof e!=`string`)return null;let t=e.trim();if(!t||t.includes(`\0`)||t.includes(`\r`)||t.includes(` `)||t.includes(`;`))return null;let n=trimTrailingSeparators(o.win32.normalize(t));if(!o.win32.isAbsolute(n)||n.startsWith(`\\\\`))return null;let r=o.win32.parse(n);return!/^[A-Za-z]:\\$/.test(r.root)||n.length<=r.root.length?null:n}function getEnvValueCaseInsensitive(e,t){let n=e[t];if(n!==void 0)return n;let r=t.toUpperCase(),i=Object.keys(e).find(e=>e.toUpperCase()===r);return i?e[i]:void 0}function queryWindowsRegistryValue(t,n,a){let o=locateWindowsRegExe();if(!o)return null;for(let c of[[`/reg:64`],[]]){let u=a===void 0?l:Math.min(l,Math.ceil(a-performance.now()));if(u<=0)return null;i();try{let i=s(o,[`query`,t,`/v`,n,...c],{env:r(),encoding:`utf8`,stdio:[`ignore`,`pipe`,`ignore`],timeout:u,windowsHide:!0}),a=RegExp(`^\\s*${e(n)}\\s+REG_[A-Z0-9_]+\\s+(.+)$`,`im`),l=i.match(a)?.[1]?.trim();if(l)return l}catch{}}return null}function getRegistryProgramFilesRoots(){let readRoot=e=>normalizeWindowsInstallRoot(queryWindowsRegistryValue(`HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion`,e)??void 0)??void 0;return{programFiles:readRoot(`ProgramFilesDir`),programFilesX86:readRoot(`ProgramFilesDir (x86)`),programW6432:readRoot(`ProgramW6432Dir`)}}function buildWindowsInstallRoots(e,t={}){let n=normalizeWindowsInstallRoot(getEnvValueCaseInsensitive(e,`ProgramW6432`)),r=t.programW6432??n??null;return{systemRoot:t.systemRoot??resolveSystemRootFromEnv(e),programFiles:t.programFiles??normalizeWindowsInstallRoot(getEnvValueCaseInsensitive(e,`ProgramFiles`))??r??`C:\\Program Files`,programFilesX86:t.programFilesX86??normalizeWindowsInstallRoot(getEnvValueCaseInsensitive(e,`ProgramFiles(x86)`))??`C:\\Program Files (x86)`,programW6432:r}}function resolveSystemRootFromEnv(e){return normalizeWindowsInstallRoot(getEnvValueCaseInsensitive(e,`SystemRoot`))??normalizeWindowsInstallRoot(getEnvValueCaseInsensitive(e,`WINDIR`))??c}function getProcessRoots(e){if(!u){let t={};for(let e of[`SystemRoot`,`WINDIR`,`ProgramFiles`,`ProgramFiles(x86)`,`ProgramW6432`])t[e]=getEnvValueCaseInsensitive(process.env,e);let n={env:t,systemRoot:normalizeWindowsInstallRoot(queryWindowsRegistryValue(`HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion`,`SystemRoot`,e)??void 0)??resolveSystemRootFromEnv(t)};if(e!==void 0&&performance.now()>=e)return n;u=n}return u}function getWindowsSystemRoot(e,t){if(e!==process.env)return resolveSystemRootFromEnv(e);let n=getProcessRoots(t);return n.installRoots?.systemRoot??n.systemRoot}function getWindowsInstallRoots(e=process.env){if(e===process.env){let e=getProcessRoots();return e.installRoots??=buildWindowsInstallRoots(e.env,{...getRegistryProgramFilesRoots(),systemRoot:e.systemRoot}),e.installRoots}return buildWindowsInstallRoots(e)}function getWindowsProgramFilesRoots(e=process.env){let n=getWindowsInstallRoots(e),r=/* @__PURE__ */ new Set,i=[];for(let e of[n.programW6432,n.programFiles,n.programFilesX86]){if(!e)continue;let n=t(e);r.has(n)||(r.add(n),i.push(e))}return i}function getWindowsCmdExePath(e=process.env){return getWindowsSystem32ExePath(`cmd.exe`,e)}function getWindowsSystem32ExePath(e,t=process.env){if(o.win32.basename(e)!==e||!/^[A-Za-z0-9_.-]+\.exe$/u.test(e))throw Error(`Invalid Windows System32 executable name: ${e}`);return o.win32.join(getWindowsSystemRoot(t),`System32`,e)}function getWindowsPowerShellExePath(e=process.env,t){return o.win32.join(getWindowsSystemRoot(e,t),`System32`,`WindowsPowerShell`,`v1.0`,`powershell.exe`)}export{getWindowsSystem32ExePath as a,getWindowsProgramFilesRoots as i,getWindowsInstallRoots as n,getWindowsPowerShellExePath as r,getWindowsCmdExePath as t};