okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3616148bb
main
1import { execFileSync } from 'node:child_process' ; 2import { readFileSync } from 'node:fs' ; 3import { homedir } from 'node:os' ; 4import { posix , win32 } from 'node:path' ; 5import { utf8Script } from './powershell-utf8.mjs' ; 6 7/** Resolve the user's Documents folder without evaluating shell configuration. */ 8export function defaultModelDirectory ({ platform= process . platform , home= homedir (), env= process . env , read= readFileSync , windowsDocuments= () => execFileSync ( 'powershell.exe' ,[ '-NoProfile' , '-NonInteractive' , '-Command' , utf8Script ( "[Environment]::GetFolderPath('MyDocuments')" )],{ encoding :'utf8' , timeout :5000 , windowsHide :true }). trim ()} = {}) { 9const path = platform === 'win32' ?win32 :posix ; 10if ( env . STRATA_MODELS_DIR ) return path . resolve ( env . STRATA_MODELS_DIR ); 11let documents = env . STRATA_DOCUMENTS_DIR ; 12if ( ! documents && platform === 'win32' ){ try { documents = windowsDocuments ();} catch {} } 13if ( ! documents && platform === 'linux' ){ 14let value = env . XDG_DOCUMENTS_DIR ; 15if ( ! value ){ try { value = read ( path . join ( env . XDG_CONFIG_HOME || path . join ( home , '.config' ), 'user-dirs.dirs' ), 'utf8' ). match ( / ^\s * XDG_DOCUMENTS_DIR=" ([ ^ " \n ] + ) " / m )?.[ 1 ];} catch {} } 16if ( value ){ const expanded = value . replace ( / \$\{HOME\} | \$HOME (? = \/ | $ ) / g , home ); if ( ! expanded . includes ( '$' ) && path . isAbsolute ( expanded )) documents = expanded ;} 17} 18if ( ! documents ||! path . isAbsolute ( documents )) documents = path . join ( home , 'Documents' ); 19return path . join ( documents , 'Strata' , 'Models' ); 20}