-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimple_setup.ps1
More file actions
242 lines (216 loc) · 8.36 KB
/
Copy pathsimple_setup.ps1
File metadata and controls
242 lines (216 loc) · 8.36 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# Check if Visual Studio Code is installed
if (-not (Get-Command code -ErrorAction SilentlyContinue)) {
Write-Host "Installing Visual Studio Code..."
$vsCodeInstaller = "https://aka.ms/win32-x64-user-stable"
Invoke-WebRequest -Uri $vsCodeInstaller -OutFile "$env:TEMP\VSCodeSetup.exe"
Start-Process "$env:TEMP\VSCodeSetup.exe" -ArgumentList "/silent" -Wait
Remove-Item "$env:TEMP\VSCodeSetup.exe"
}
else {
Write-Host "Visual Studio Code is already installed."
}
# Check if Git is installed
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
Write-Host "Installing Git..."
$gitInstaller = "https://github.com/git-for-windows/git/releases/download/v2.49.0.windows.1/Git-2.49.0-64-bit.exe"
Invoke-WebRequest -Uri $gitInstaller -OutFile "$env:TEMP\GitSetup.exe"
Start-Process "$env:TEMP\GitSetup.exe" -ArgumentList "/silent" -Wait
Remove-Item "$env:TEMP\GitSetup.exe"
}
else {
Write-Host "Git is already installed."
}
# Check if repository is properly checked out
Write-Host "Checking repository status..."
$isGitRepo = Test-Path -Path ".git"
$hasProjectFiles = Test-Path -Path "pyproject.toml"
if (-not $isGitRepo) {
# No .git folder - not a git repository
Write-Host ""
Write-Host "ERROR: Git repository not found!" -ForegroundColor Red
Write-Host "Current directory: $PWD"
Write-Host ""
Write-Host "This script requires the .git folder to be present."
Write-Host "Please ensure you have extracted the complete zip file including the .git folder."
Write-Host ""
Write-Host "Press any key to exit..."
Read-Host
exit 1
}
if (-not $hasProjectFiles) {
# .git exists but project files missing - need to checkout
Write-Host "Git repository found, but project files are missing."
Write-Host "Checking out project files from repository..."
try {
git reset --hard HEAD
git checkout main
Write-Host "Project files checked out successfully."
}
catch {
Write-Host ""
Write-Host "ERROR: Failed to checkout project files: $_" -ForegroundColor Red
Write-Host ""
Write-Host "Press any key to exit..."
Read-Host
exit 1
}
}
# Verify project files now exist
if (-not (Test-Path -Path "pyproject.toml")) {
Write-Host ""
Write-Host "ERROR: Project files still missing after checkout!" -ForegroundColor Red
Write-Host "The repository may be corrupted or incomplete."
Write-Host ""
Write-Host "Press any key to exit..."
Read-Host
exit 1
}
# Pull latest changes
Write-Host "Updating repository to latest version..."
try {
git fetch origin
git pull origin main
Write-Host "Repository updated successfully."
}
catch {
Write-Host "Warning: Failed to pull latest changes: $_" -ForegroundColor Yellow
Write-Host "Continuing with existing files..."
}
Write-Host "Project files verified successfully."
# Install uv
# Check if uv is installed
if (-not (Get-Command uv -ErrorAction SilentlyContinue)) {
Write-Host "Installing uv..."
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
}
else {
Write-Host "uv is already installed."
}
# Run uv sync
Write-Host "Running uv sync..."
uv sync --dev --extra jupyter
# Install .NET 6 Framework
$dotnetVersion = $null
try {
$dotnetVersion = dotnet --version 2>$null
}
catch {
# dotnet command not found
}
if (-not $dotnetVersion -or -not ($dotnetVersion -match "^6\.")) {
Write-Host "Installing .NET 6 Desktop Runtime..."
$dotnetInstaller = "https://aka.ms/dotnet/6.0/windowsdesktop-runtime-win-x64.exe"
try {
Invoke-WebRequest -Uri $dotnetInstaller -OutFile "$env:TEMP\dotnet-6-desktop-runtime.exe"
Start-Process "$env:TEMP\dotnet-6-desktop-runtime.exe" -ArgumentList "/quiet" -Wait
Remove-Item "$env:TEMP\dotnet-6-desktop-runtime.exe"
Write-Host ".NET 6 Desktop Runtime installed successfully."
}
catch {
Write-Host "Failed to download or install .NET 6 Desktop Runtime automatically."
Write-Host "Please manually install .NET 6 from: https://dotnet.microsoft.com/download/dotnet/6.0"
Write-Host "Press any key to continue..."
Read-Host
}
}
else {
Write-Host ".NET 6 is already installed (version: $dotnetVersion)."
}
# Download and extract RDAConsole
$rdaConsolePath = "./RDAConsole"
if (-not (Test-Path -Path "$rdaConsolePath/RDAConsole.exe")) {
Write-Host "Downloading RDAConsole from GitHub..."
try {
# Get the latest release download URL
$apiUrl = "https://api.github.com/repos/anno-mods/RdaConsole/releases/latest"
$release = Invoke-RestMethod -Uri $apiUrl
$downloadUrl = $release.assets | Where-Object { $_.name -like "*.zip" } | Select-Object -First 1 | ForEach-Object { $_.browser_download_url }
if (-not $downloadUrl) {
throw "No zip asset found in latest release"
}
# Download and extract
$zipPath = "$env:TEMP\RDAConsole.zip"
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath
# Create RDAConsole directory if it doesn't exist
if (-not (Test-Path -Path $rdaConsolePath)) {
New-Item -ItemType Directory -Path $rdaConsolePath -Force
}
# Extract the zip directly to RDAConsole folder (flattening any subdirectories)
$tempExtractPath = "$env:TEMP\RDAConsole_temp"
Expand-Archive -Path $zipPath -DestinationPath $tempExtractPath -Force
# Move all files from any subdirectories to the target directory
Get-ChildItem -Path $tempExtractPath -Recurse -File | ForEach-Object {
Move-Item $_.FullName -Destination $rdaConsolePath -Force
}
# Clean up temporary directories
Remove-Item $zipPath -Force
Remove-Item $tempExtractPath -Recurse -Force
Write-Host "RDAConsole downloaded and extracted successfully."
}
catch {
Write-Host "Failed to download RDAConsole automatically: $_"
Write-Host "Please manually download RDAConsole from: https://github.com/anno-mods/RdaConsole/releases/latest"
Write-Host "Extract it to the 'RDAConsole' folder in the repository root."
Write-Host "Press any key to continue..."
Read-Host
}
}
else {
Write-Host "RDAConsole is already downloaded."
}
# Test RDAConsole execution
Write-Host "Testing RDAConsole.exe..."
try {
$rdaConsoleExe = "$rdaConsolePath/RDAConsole.exe"
if (Test-Path -Path $rdaConsoleExe) {
$result = & $rdaConsoleExe 2>&1
if ($LASTEXITCODE -eq 0 -or $result -match "RDAConsole|Usage|Help") {
Write-Host "RDAConsole.exe is working correctly."
}
else {
throw "RDAConsole.exe execution failed"
}
}
else {
throw "RDAConsole.exe not found at $rdaConsoleExe"
}
}
catch {
Write-Host "RDAConsole.exe test failed: $_"
Write-Host ""
Write-Host "Please ensure:"
Write-Host "1. .NET 6 Framework is installed"
Write-Host "2. RDAConsole is properly downloaded to ./RDAConsole/"
Write-Host "3. RDAConsole.exe exists and is executable"
Write-Host ""
Write-Host "Manual steps:"
Write-Host "1. Download .NET 6 from: https://dotnet.microsoft.com/download/dotnet/6.0"
Write-Host "2. Download RDAConsole from: https://github.com/anno-mods/RdaConsole/releases/latest"
Write-Host "3. Extract RDAConsole.zip to ./RDAConsole/ folder"
Write-Host ""
Write-Host "Press any key to continue..."
Read-Host
}
# Copy config.template.json to config.json if it does not exist
if (-not (Test-Path -Path "./config.json")) {
Write-Host "config.json does not exist. Creating from config.template.json..."
Copy-Item -Path "./config.template.json" -Destination "./config.json"
Write-Host ""
Write-Host "Open config.json and check that the game_path points to the installation directory of your Anno game."
Write-Host "Press any key to continue..."
Read-Host
}
else {
Write-Host "config.json already exists."
}
# Run initial extraction
Write-Host ""
Write-Host "Running initial RDA extraction..."
Write-Host "This will extract required files from your Anno game directory."
Write-Host ""
.\extract.cmd
# Open browsing.ipynb in Visual Studio Code
Write-Host "Opening browsing.ipynb in Visual Studio Code..."
Start-Process -FilePath "code" -ArgumentList "browsing.ipynb"
Write-Host ""
Write-Host "Setup completed! Remember to run extract.cmd whenever there is a game update."