feat: publish HoloLake model-native living system source
This commit is contained in:
parent
6ad10edde1
commit
c395dd3a99
2467 changed files with 615073 additions and 0 deletions
|
|
@ -0,0 +1,42 @@
|
|||
function normalizeVaultContainmentPath(path: string): string {
|
||||
return path.replace(/\\/g, '/').replace(/\/+$/, '')
|
||||
}
|
||||
|
||||
function tildeRootSuffix(path: string): string | null {
|
||||
if (path === '~') return ''
|
||||
return path.startsWith('~/') ? path.slice(1) : null
|
||||
}
|
||||
|
||||
function expandTildeRootFromTarget(targetPath: string, rootPath: string): string {
|
||||
const suffix = tildeRootSuffix(rootPath)
|
||||
if (suffix === null || suffix === '') return rootPath
|
||||
const suffixIndex = targetPath.indexOf(suffix)
|
||||
return suffixIndex > 0 ? `${targetPath.slice(0, suffixIndex)}${suffix}` : rootPath
|
||||
}
|
||||
|
||||
function compareVaultContainmentPath(path: string, vaultPath: string): [string, string] {
|
||||
const normalizedPath = normalizeVaultContainmentPath(path)
|
||||
const normalizedVaultPath = expandTildeRootFromTarget(
|
||||
normalizedPath,
|
||||
normalizeVaultContainmentPath(vaultPath),
|
||||
)
|
||||
const hasWindowsDrive = /^[a-z]:/i.test(normalizedPath) || /^[a-z]:/i.test(normalizedVaultPath)
|
||||
return hasWindowsDrive
|
||||
? [normalizedPath.toLowerCase(), normalizedVaultPath.toLowerCase()]
|
||||
: [normalizedPath, normalizedVaultPath]
|
||||
}
|
||||
|
||||
export function isPathInsideVaultRoot(path: string, vaultPath: string): boolean {
|
||||
const trimmedVaultPath = vaultPath.trim()
|
||||
if (!trimmedVaultPath) return true
|
||||
const [targetPath, rootPath] = compareVaultContainmentPath(path, trimmedVaultPath)
|
||||
if (!rootPath || !targetPath) return false
|
||||
return targetPath === rootPath || targetPath.startsWith(`${rootPath}/`)
|
||||
}
|
||||
|
||||
export function canWritePathToVault(path: string, vaultPath: string | readonly string[]): boolean {
|
||||
if (typeof vaultPath !== 'string') {
|
||||
return vaultPath.some((candidate) => canWritePathToVault(path, candidate))
|
||||
}
|
||||
return isPathInsideVaultRoot(path, vaultPath)
|
||||
}
|
||||
Loading…
Reference in a new issue