-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-google-cloudcode.bat
More file actions
110 lines (97 loc) · 3.84 KB
/
Copy pathfix-google-cloudcode.bat
File metadata and controls
110 lines (97 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
@echo off
setlocal
set "SILENT_MODE=0"
if /i "%~1"=="/silent" set "SILENT_MODE=1"
if /i "%~1"=="--silent" set "SILENT_MODE=1"
if /i "%~1"=="/auto" set "SILENT_MODE=1"
if /i "%~1"=="--auto" set "SILENT_MODE=1"
title Google Cloud Code Hosts Fix
color 0B
if "%SILENT_MODE%" neq "1" (
echo.
echo ================================================================
echo ^| ^|
echo ^| GOOGLE CLOUD CODE / ANTIGRAVITY 9ROUTER FIX ^|
echo ^| ^|
echo ================================================================
echo.
)
net session >nul 2>&1
if %errorlevel% neq 0 (
color 0E
echo [!] Administrator permission is required.
echo [*] Requesting Administrator access...
echo.
powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -ArgumentList '%*' -Verb RunAs"
exit /b
)
set "HOSTS_FILE=C:\Windows\System32\drivers\etc\hosts"
set "TARGET_DOMAIN=cloudcode-pa.googleapis.com"
set "DAILY_DOMAIN=daily-cloudcode-pa.googleapis.com"
echo [1/4] Checking local 9Router HTTPS listener...
powershell -NoProfile -Command "$p=Get-NetTCPConnection -State Listen -LocalPort 443 -ErrorAction SilentlyContinue; if ($p) { exit 0 } else { exit 1 }" >nul 2>&1
if %errorlevel% equ 0 (
echo Found listener on port 443.
) else (
color 0E
echo Warning: no local port 443 listener found.
echo Make sure 9Router is running before opening Antigravity.
)
echo.
echo [2/4] Applying 9Router hosts route...
echo Routing Cloud Code domains to localhost 9Router.
echo.
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$hosts='%HOSTS_FILE%';" ^
"$domains=@('%TARGET_DOMAIN%','%DAILY_DOMAIN%');" ^
"$content=Get-Content -Path $hosts -ErrorAction Stop;" ^
"$filtered=$content | Where-Object { $line=$_; -not ($domains | Where-Object { $line -match [regex]::Escape($_) }) };" ^
"$routes=@('', '# 9Router route for Antigravity / Google Cloud Code');" ^
"$routes += $domains | ForEach-Object { '127.0.0.1 ' + $_ };" ^
"$routes += $domains | ForEach-Object { '::1 ' + $_ };" ^
"Set-Content -Path $hosts -Value (@($filtered) + $routes) -Encoding ASCII;" ^
"Write-Host ' Added IPv4 + IPv6 localhost routes.'"
if %errorlevel% neq 0 (
color 0C
echo.
echo [ERROR] Failed to update hosts file.
if "%SILENT_MODE%" neq "1" pause
exit /b 1
)
echo.
echo [3/4] Flushing DNS cache...
ipconfig /flushdns
if %errorlevel% neq 0 (
color 0E
echo [WARN] Failed to flush DNS cache. You may need to run ipconfig /flushdns manually.
)
echo.
echo [4/4] Verifying result...
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$hosts='%HOSTS_FILE%';" ^
"$required=@('127.0.0.1 %TARGET_DOMAIN%','127.0.0.1 %DAILY_DOMAIN%','::1 %TARGET_DOMAIN%','::1 %DAILY_DOMAIN%');" ^
"$content=(Get-Content -Path $hosts -ErrorAction Stop) -join [Environment]::NewLine;" ^
"$missing=@($required | Where-Object { $content -notmatch ('(?m)^\s*' + [regex]::Escape($_) + '\s*$') });" ^
"if ($missing.Count -eq 0) { Write-Host ' All required routes are present.'; exit 0 } else { Write-Host ' Missing routes:'; $missing | ForEach-Object { Write-Host (' - ' + $_) }; exit 1 }"
if %errorlevel% equ 0 (
color 0A
echo.
echo ================================================================
echo 9ROUTER ROUTE IS ENABLED
echo ================================================================
echo.
echo Cloud Code domains now point to local 9Router.
echo Fully close Antigravity, then open it again.
) else (
color 0C
echo.
echo [ERROR] Route verification failed.
if "%SILENT_MODE%" neq "1" pause
exit /b 1
)
if "%SILENT_MODE%" neq "1" (
echo.
echo Press any key to exit...
pause >nul
)
endlocal