-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.bat
More file actions
176 lines (152 loc) · 4.94 KB
/
Copy pathsetup.bat
File metadata and controls
176 lines (152 loc) · 4.94 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
@echo off
REM setup.bat — One-command installer for GeoPolitical Domination on Windows
REM
REM Install from PowerShell:
REM irm https://raw.githubusercontent.com/entity12208/GeoPoliticalDomination/main/setup.bat -OutFile setup.bat; .\setup.bat
REM
REM Or if you already have the repo, just double-click this file.
setlocal enabledelayedexpansion
echo ========================================
echo GeoPolitical Domination — Setup
echo ========================================
echo.
REM --- Detect if we're in an existing install ---
set "INSTALL_DIR=%~dp0"
if exist "%INSTALL_DIR%client.py" (
echo [*] Running from existing install: %INSTALL_DIR%
goto :setup_venv
)
REM --- Fresh install ---
set "INSTALL_DIR=%USERPROFILE%\GeoPoliticalDomination"
echo [*] Fresh install to: %INSTALL_DIR%
REM --- Check for Python ---
where python >nul 2>&1
if %errorlevel% neq 0 (
where python3 >nul 2>&1
if %errorlevel% neq 0 (
echo [!] Python not found.
echo Please install Python 3.8+ from https://www.python.org/downloads/
echo IMPORTANT: Check "Add Python to PATH" during installation.
echo.
pause
exit /b 1
)
set "PY=python3"
) else (
set "PY=python"
)
REM --- Verify Python version ---
%PY% -c "import sys; exit(0 if sys.version_info >= (3,8) else 1)" 2>nul
if %errorlevel% neq 0 (
echo [!] Python 3.8+ required. Please update Python.
pause
exit /b 1
)
for /f "tokens=*" %%i in ('%PY% -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')"') do set PY_VER=%%i
echo [OK] Python %PY_VER%
REM --- Download latest release ---
echo.
echo [*] Downloading latest release...
set "TEMP_ZIP=%TEMP%\gpd_download.zip"
set "TEMP_DIR=%TEMP%\gpd_extract"
set "API_URL=https://api.github.com/repos/entity12208/GeoPoliticalDomination/releases/latest"
REM Try to get release zip URL via Python (more reliable than curl on Windows)
for /f "tokens=*" %%u in ('%PY% -c "import urllib.request,json; d=json.loads(urllib.request.urlopen('%API_URL%').read()); print(d.get('zipball_url',''))" 2^>nul') do set "ZIP_URL=%%u"
if "!ZIP_URL!"=="" (
echo [!] No releases found, downloading main branch...
set "ZIP_URL=https://github.com/entity12208/GeoPoliticalDomination/archive/refs/heads/main.zip"
) else (
echo [OK] Found latest release
)
echo [*] Downloading...
%PY% -c "import urllib.request; urllib.request.urlretrieve('!ZIP_URL!', r'%TEMP_ZIP%'); print('[OK] Downloaded')"
if %errorlevel% neq 0 (
echo [ERROR] Download failed.
pause
exit /b 1
)
echo [*] Extracting...
if exist "%TEMP_DIR%" rmdir /s /q "%TEMP_DIR%"
%PY% -c "import zipfile; zipfile.ZipFile(r'%TEMP_ZIP%').extractall(r'%TEMP_DIR%'); print('[OK] Extracted')"
REM Find the extracted folder
for /d %%d in ("%TEMP_DIR%\*") do set "EXTRACTED=%%d"
if not defined EXTRACTED (
echo [ERROR] Extraction failed.
pause
exit /b 1
)
REM Copy to install dir
if not exist "%INSTALL_DIR%" mkdir "%INSTALL_DIR%"
xcopy /s /e /y /q "%EXTRACTED%\*" "%INSTALL_DIR%\" >nul
del "%TEMP_ZIP%" 2>nul
rmdir /s /q "%TEMP_DIR%" 2>nul
echo [OK] Installed to %INSTALL_DIR%
:setup_venv
cd /d "%INSTALL_DIR%"
REM --- Check Python again (in case we came from existing install) ---
where python >nul 2>&1
if %errorlevel% neq 0 (
set "PY=python3"
) else (
set "PY=python"
)
REM --- Verify client.py exists ---
if not exist "client.py" (
echo [ERROR] client.py not found in %INSTALL_DIR%
pause
exit /b 1
)
REM --- Create venv ---
if not exist ".venv\Scripts\activate.bat" (
echo [*] Creating virtual environment...
%PY% -m venv .venv
if %errorlevel% neq 0 (
echo [ERROR] Failed to create virtual environment.
echo Try: %PY% -m pip install --user virtualenv
pause
exit /b 1
)
)
REM --- Activate venv ---
call .venv\Scripts\activate.bat
echo [OK] Virtual environment active
REM --- Install dependencies ---
echo [*] Installing Python packages...
pip install --upgrade pip -q 2>nul
if exist "requirements.txt" (
pip install -r requirements.txt -q
) else (
pip install pygame-ce requests -q
)
if %errorlevel% neq 0 (
echo [!] pip install failed, retrying...
pip install pygame-ce requests -q
)
echo [OK] Dependencies installed
REM --- Verify pygame ---
python -c "import pygame; print(f'[OK] pygame-ce {pygame.ver}')" 2>nul
if %errorlevel% neq 0 (
echo [!] pygame import failed, reinstalling...
pip install --force-reinstall pygame-ce -q
python -c "import pygame; print(f'[OK] pygame-ce {pygame.ver}')"
)
REM --- Create play.bat ---
(
echo @echo off
echo cd /d "%%~dp0"
echo if exist ".venv\Scripts\activate.bat" call .venv\Scripts\activate.bat
echo python client.py %%*
) > "%INSTALL_DIR%\play.bat"
echo.
echo ========================================
echo Setup complete!
echo ========================================
echo.
echo To play, run:
echo cd %INSTALL_DIR%
echo play.bat
echo.
echo Or double-click play.bat in:
echo %INSTALL_DIR%
echo.
pause