| 106 | } |
| 107 | |
| 108 | export class WindowsSystemScheduler { |
| 109 | constructor(private cronRoot: string) {} |
| 110 | |
| 111 | private runLogPath(jobId: string): string { |
| 112 | return runLogPath(this.cronRoot, jobId) |
| 113 | } |
| 114 | |
| 115 | private taskScriptPath(jobId: string, ext: 'ps1' | 'cmd'): string { |
| 116 | return taskScriptPath(this.cronRoot, jobId, ext) |
| 117 | } |
| 118 | |
| 119 | private winEnvValue(name: string): string { |
| 120 | const env = { ...process.env, ...(EnvSync.AppEnv ?? {}) } |
| 121 | const key = Object.keys(env).find((item) => item.toLowerCase() === name.toLowerCase()) |
| 122 | return key ? `${env[key] || ''}` : '' |
| 123 | } |
| 124 | |
| 125 | private cmdQuote(value: string): string { |
| 126 | return `"${value.replace(/"/g, '""')}"` |
| 127 | } |
| 128 | |
| 129 | private async syncEnv() { |
| 130 | await EnvSync.sync() |
| 131 | } |
| 132 | |
| 133 | private systemRoot(): string { |
| 134 | return this.winEnvValue('SystemRoot') || this.winEnvValue('windir') || 'C:\\Windows' |
| 135 | } |
| 136 | |
| 137 | private async schtasksPath(): Promise<string> { |
| 138 | await this.syncEnv() |
| 139 | const systemRoot = this.systemRoot() |
| 140 | const systemPath = EnvSync.SystemPath || join(systemRoot, 'System32') |
| 141 | const candidates = [ |
| 142 | join(systemPath, 'schtasks.exe'), |
| 143 | join(systemRoot, 'Sysnative', 'schtasks.exe'), |
| 144 | join(systemRoot, 'System32', 'schtasks.exe') |
| 145 | ] |
| 146 | return candidates.find((path) => existsSync(path)) || 'schtasks.exe' |
| 147 | } |
| 148 | |
| 149 | private async cmdPath(): Promise<string> { |
| 150 | await this.syncEnv() |
| 151 | const systemRoot = this.systemRoot() |
| 152 | const candidates = [ |
| 153 | EnvSync.CMDPath, |
| 154 | join(systemRoot, 'Sysnative', 'cmd.exe'), |
| 155 | join(systemRoot, 'System32', 'cmd.exe') |
| 156 | ].filter(Boolean) as string[] |
| 157 | return candidates.find((path) => existsSync(path)) || 'cmd.exe' |
| 158 | } |
| 159 | |
| 160 | private async powerShellPath(): Promise<string> { |
| 161 | await this.syncEnv() |
| 162 | const systemRoot = this.systemRoot() |
| 163 | const candidates = [ |
| 164 | EnvSync.PowerShellPath, |
| 165 | join(systemRoot, 'Sysnative', 'WindowsPowerShell', 'v1.0', 'powershell.exe'), |
nothing calls this directly
no outgoing calls
no test coverage detected