|
6 | 6 |
|
7 | 7 | use Butschster\ContextGenerator\Application\Application;
|
8 | 8 | use Butschster\ContextGenerator\Application\ExceptionHandler;
|
| 9 | +use Butschster\ContextGenerator\Application\FSPath; |
9 | 10 | use Butschster\ContextGenerator\Application\Kernel;
|
10 | 11 | use Spiral\Core\Container;
|
11 | 12 | use Spiral\Core\Options;
|
|
93 | 94 | // -----------------------------------------------------------------------------
|
94 | 95 |
|
95 | 96 | // Determine appropriate location for global state based on OS
|
96 |
| -$globalStateDir = match (PHP_OS_FAMILY) { |
97 |
| - 'Windows' => \getenv('APPDATA') . '/CTX', |
| 97 | +$globalStateDir = (string) FSPath::create(match (PHP_OS_FAMILY) { |
| 98 | + 'Windows' => (function (): string { |
| 99 | + $result = $_SERVER['APPDATA'] ?? null; |
| 100 | + if (\is_string($result)) { |
| 101 | + return $result; |
| 102 | + } |
| 103 | + |
| 104 | + /* |
| 105 | + * In some cases, the APPDATA environment variable may not be set by an MCP client (f.e. Claude) |
| 106 | + * In this case we need to use workaround. |
| 107 | + */ |
| 108 | + /** @psalm-suppress ForbiddenCode */ |
| 109 | + $output = `reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "AppData"`; |
| 110 | + // Check if the command was successful |
| 111 | + $pos = \strpos($output, $_SERVER['USERPROFILE']); |
| 112 | + if ($pos === false) { |
| 113 | + // If the command failed, we can use the default APPDATA path |
| 114 | + return $_SERVER['USERPROFILE'] . '\AppData\Roaming'; |
| 115 | + } |
| 116 | + |
| 117 | + return \trim(\explode("\n", \substr($output, $pos))[0]); |
| 118 | + })() . '/CTX', |
98 | 119 | 'Darwin' => $_SERVER['HOME'] . '/Library/Application Support/CTX',
|
99 | 120 | default => $_SERVER['HOME'] . '/.config/ctx',
|
100 |
| -}; |
| 121 | +}); |
101 | 122 |
|
102 | 123 | $app = Kernel::create(
|
103 | 124 | directories: [
|
|
0 commit comments