Skip to content

Commit 2323118

Browse files
committed
dist: use CMD instead of PS script for potential Win7 compatibility
1 parent 25054bb commit 2323118

5 files changed

Lines changed: 151 additions & 47 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
cp cmake-build-release-visual-studio-x64/src/app/Release/SC4PlopAndPaintCli.exe dist-package/_SC4PlopAndPaintCacheBuilder.exe
7070
7171
cp dist/README.txt dist-package/
72-
cp dist/RUN_CACHE_BUILDER.ps1 dist-package/
72+
cp dist/RUN_CACHE_BUILDER.cmd dist-package/
7373
cp LICENSE.txt dist-package/
7474
cp dist/THIRD_PARTY_NOTICES.txt dist-package/
7575
cp dist/SC4PlopAndPaintInstaller.nsi dist-package/

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ Dependencies:
2424
- SC4RenderServices (required): GitHub project `https://github.com/caspervg/sc4-render-services`
2525
- SC4RenderServices download page: `https://community.simtropolis.com/files/file/37372-sc4-render-services/`
2626
- Visual C++ 2015-2022 Redistributable (x86, required for SimCity 4 / 32-bit): `https://aka.ms/vs/17/release/vc_redist.x86.exe`
27-
- Visual C++ 2015-2022 Redistributable (x64): `https://aka.ms/vs/17/release/vc_redist.x64.exe`
27+
- Visual C++ 2015-2022 Redistributable (x64, required for the cache builder): `https://aka.ms/vs/17/release/vc_redist.x64.exe`
28+
- The bundled cache builder is x64-only and requires 64-bit Windows.
2829

2930
The installer will:
3031

3132
1. Ask for your game root and Plugins directory.
3233
2. Verify that `SC4RenderServices.dll` is already present in your Plugins folder. If it is missing, the installer will stop and direct you to the SC4RenderServices download page.
3334
3. Place `SC4PlopAndPaint.dll` and `SC4PlopAndPaint.dat` in your Plugins folder.
3435
4. Let you choose the thumbnail size used for cache generation and apply the same size to `ThumbnailDisplaySize` in `SC4PlopAndPaint.ini`.
35-
5. Place `_SC4PlopAndPaintCacheBuilder.exe` and a generated `Rebuild-Cache.ps1` in `Documents\SimCity 4\SC4PlopAndPaint\`.
36+
5. Place `_SC4PlopAndPaintCacheBuilder.exe` and a generated `Rebuild-Cache.cmd` in `Documents\SimCity 4\SC4PlopAndPaint\`.
3637
6. Optionally run the cache builder immediately.
3738

38-
To rebuild the cache later, for example after adding or removing plugins, run `Rebuild-Cache.ps1`.
39+
To rebuild the cache later, for example after adding or removing plugins, run `Rebuild-Cache.cmd`.
3940

4041
If something looks wrong in game, check the separate services plugin's log output in `Documents\SimCity 4\`.
4142

dist/README.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ Installation instructions:
1111
- SC4RenderServices download page: https://community.simtropolis.com/files/file/37372-sc4-render-services/
1212
- Install the Microsoft Visual C++ 2015-2022 Redistributables:
1313
- x86 (required for SimCity 4 / 32-bit): https://aka.ms/vs/17/release/vc_redist.x86.exe
14-
- x64 (also installed): https://aka.ms/vs/17/release/vc_redist.x64.exe
14+
- x64 (required for the cache builder): https://aka.ms/vs/17/release/vc_redist.x64.exe
15+
- The bundled cache builder is x64-only and requires 64-bit Windows.
1516
- Run the included SC4 Plop and Paint installer.
1617
- The installer will ask for your SimCity 4 game root and Plugins folder, verify the SC4RenderServices dependency, and install the plugin files. If SC4RenderServices is missing, the installer will stop and tell you where to download it.
1718
- The installer also lets you choose the thumbnail size used for cache generation and sets the same size in SC4PlopAndPaint.ini for the in-game UI.
18-
- The installer can also run the cache builder for you. If you skip that step, run Rebuild-Cache.ps1 later from Documents\SimCity 4\SC4PlopAndPaint\.
19+
- The installer can also run the cache builder for you. If you skip that step, run Rebuild-Cache.cmd later from Documents\SimCity 4\SC4PlopAndPaint\.
1920
- The cache builder scans your game and Plugins folders and writes lots.cbor, props.cbor and flora.cbor into your Plugins folder.
2021
- If thumbnail rendering is enabled, it also writes lot_thumbnails.bin, prop_thumbnails.bin and flora_thumbnails.bin into your Plugins folder.
2122

dist/RUN_CACHE_BUILDER.cmd

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
@echo off
2+
setlocal EnableExtensions
3+
4+
set "SCRIPT_DIR=%~dp0"
5+
set "EXE=%SCRIPT_DIR%_SC4PlopAndPaintCacheBuilder.exe"
6+
7+
if not exist "%EXE%" (
8+
echo Could not find "%EXE%"
9+
echo Build the CLI first or update this path in RUN_CACHE_BUILDER.cmd.
10+
pause
11+
exit /b 1
12+
)
13+
14+
if /I "%PROCESSOR_ARCHITECTURE%"=="x86" if not defined PROCESSOR_ARCHITEW6432 (
15+
echo This cache builder requires 64-bit Windows.
16+
pause
17+
exit /b 1
18+
)
19+
20+
echo === SC4 Plop and Paint Cache Builder ===
21+
echo.
22+
23+
set "DO_SCAN="
24+
set /p "DO_SCAN=Run cache building scan now? (y/N): "
25+
if /I not "%DO_SCAN%"=="Y" (
26+
echo.
27+
echo Skipping scan.
28+
pause
29+
exit /b 0
30+
)
31+
32+
echo.
33+
set "DEFAULT_GAME_ROOT=%ProgramFiles(x86)%\SimCity 4 Deluxe Edition"
34+
if not defined ProgramFiles(x86) set "DEFAULT_GAME_ROOT=%ProgramFiles%\SimCity 4 Deluxe Edition"
35+
set "DEFAULT_PLUGINS=%USERPROFILE%\Documents\SimCity 4\Plugins"
36+
set "DEFAULT_LOCALE=English"
37+
set "DEFAULT_THUMBNAIL_SIZE=44"
38+
39+
set "GAME_ROOT="
40+
set "PLUGINS_DIR="
41+
set "LOCALE_DIR="
42+
set "RENDER_THUMBS="
43+
set "THUMBNAIL_SIZE="
44+
45+
set /p "GAME_ROOT=Game root directory [default: %DEFAULT_GAME_ROOT%]: "
46+
if not defined GAME_ROOT set "GAME_ROOT=%DEFAULT_GAME_ROOT%"
47+
48+
set /p "PLUGINS_DIR=User Plugins directory [default: %DEFAULT_PLUGINS%]: "
49+
if not defined PLUGINS_DIR set "PLUGINS_DIR=%DEFAULT_PLUGINS%"
50+
51+
set /p "LOCALE_DIR=Locale under game root [default: %DEFAULT_LOCALE%]: "
52+
if not defined LOCALE_DIR set "LOCALE_DIR=%DEFAULT_LOCALE%"
53+
54+
set /p "RENDER_THUMBS=Render 3D thumbnails? (y/N): "
55+
56+
set /p "THUMBNAIL_SIZE=Thumbnail size in pixels (22-176) [default: %DEFAULT_THUMBNAIL_SIZE%]: "
57+
if not defined THUMBNAIL_SIZE set "THUMBNAIL_SIZE=%DEFAULT_THUMBNAIL_SIZE%"
58+
59+
echo.
60+
echo Running:
61+
echo "%EXE%" --scan --game "%GAME_ROOT%" --plugins "%PLUGINS_DIR%" --locale "%LOCALE_DIR%" --thumbnail-size "%THUMBNAIL_SIZE%"
62+
if /I "%RENDER_THUMBS%"=="Y" echo --render-thumbnails
63+
64+
if /I "%RENDER_THUMBS%"=="Y" (
65+
"%EXE%" --scan --game "%GAME_ROOT%" --plugins "%PLUGINS_DIR%" --locale "%LOCALE_DIR%" --thumbnail-size "%THUMBNAIL_SIZE%" --render-thumbnails
66+
) else (
67+
"%EXE%" --scan --game "%GAME_ROOT%" --plugins "%PLUGINS_DIR%" --locale "%LOCALE_DIR%" --thumbnail-size "%THUMBNAIL_SIZE%"
68+
)
69+
70+
echo.
71+
pause

dist/SC4PlopAndPaintInstaller.nsi

Lines changed: 72 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,12 @@ Function ConfigureCachePage
388388
${NSD_Check} $HCacheBuildNow
389389
${EndIf}
390390

391+
${IfNot} ${RunningX64}
392+
StrCpy $CacheBuildNow "0"
393+
${NSD_Uncheck} $HCacheBuildNow
394+
${NSD_CreateLabel} 0u 140u 100% 18u "Cache building is unavailable on this machine. The bundled cache builder requires 64-bit Windows."
395+
${EndIf}
396+
391397
nsDialogs::Show
392398
FunctionEnd
393399

@@ -428,6 +434,13 @@ Function ConfigureCachePageLeave
428434
${Else}
429435
StrCpy $CacheBuildNow "0"
430436
${EndIf}
437+
438+
${If} $CacheBuildNow == "1"
439+
${IfNot} ${RunningX64}
440+
MessageBox MB_OK|MB_ICONEXCLAMATION "Cache building is unavailable on this machine.$\r$\n$\r$\nThe bundled cache builder is 64-bit and requires a 64-bit version of Windows."
441+
StrCpy $CacheBuildNow "0"
442+
${EndIf}
443+
${EndIf}
431444
FunctionEnd
432445

433446
Function PopulateLocaleDropDown
@@ -526,52 +539,69 @@ Section "Install"
526539
WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoRepair" 1
527540

528541
; Generate a reusable cache rebuild script with the exact installation settings.
529-
StrCpy $2 "$SC4ToolsDir\Rebuild-Cache.ps1"
542+
Delete "$SC4ToolsDir\Rebuild-Cache.ps1"
543+
StrCpy $2 "$SC4ToolsDir\Rebuild-Cache.cmd"
530544
FileOpen $3 $2 w
531-
FileWrite $3 "# Auto-generated by ${APP_NAME} installer.$\r$\n"
532-
FileWrite $3 "$$ErrorActionPreference = 'Stop'$\r$\n"
533-
FileWrite $3 "$$exe = Join-Path $$PSScriptRoot '_SC4PlopAndPaintCacheBuilder.exe'$\r$\n"
534-
FileWrite $3 "$$game = '$GameRoot'.TrimEnd('\')$\r$\n"
535-
FileWrite $3 "$$plugins = '$SC4PluginsDir'.TrimEnd('\')$\r$\n"
536-
FileWrite $3 "$$locale = '$CacheLocale'.TrimEnd('\')$\r$\n"
537-
FileWrite $3 "$$thumbnailSize = '$CacheThumbnailSize'$\r$\n"
538-
FileWrite $3 "$$cacheArgs = @('--scan', '--game', $$game, '--plugins', $$plugins, '--locale', $$locale, '--thumbnail-size', $$thumbnailSize)$\r$\n"
545+
FileWrite $3 '@echo off$\r$\n'
546+
FileWrite $3 'setlocal EnableExtensions$\r$\n'
547+
FileWrite $3 'set "SCRIPT_DIR=%~dp0"$\r$\n'
548+
FileWrite $3 'set "EXE=%SCRIPT_DIR%_SC4PlopAndPaintCacheBuilder.exe"$\r$\n'
549+
FileWrite $3 'set "LOG_FILE=%SCRIPT_DIR%cache_build.log"$\r$\n'
550+
FileWrite $3 'if not exist "%EXE%" ($\r$\n'
551+
FileWrite $3 ' echo Could not find "%EXE%".$\r$\n'
552+
FileWrite $3 ' exit /b 1$\r$\n'
553+
FileWrite $3 ')$\r$\n'
554+
FileWrite $3 'if /I "%PROCESSOR_ARCHITECTURE%"=="x86" if not defined PROCESSOR_ARCHITEW6432 ($\r$\n'
555+
FileWrite $3 ' echo The bundled cache builder requires 64-bit Windows.$\r$\n'
556+
FileWrite $3 ' echo This installation includes an x64-only cache builder executable.$\r$\n'
557+
FileWrite $3 ' exit /b 1$\r$\n'
558+
FileWrite $3 ')$\r$\n'
559+
FileWrite $3 'echo Writing cache build log to "%LOG_FILE%".$\r$\n'
560+
FileWrite $3 '> "%LOG_FILE%" echo SC4 Plop and Paint Cache Build Log$\r$\n'
561+
FileWrite $3 '>> "%LOG_FILE%" echo Installer version: ${APP_VERSION}$\r$\n'
562+
FileWrite $3 '>> "%LOG_FILE%" echo Game root: "$GameRoot"$\r$\n'
563+
FileWrite $3 '>> "%LOG_FILE%" echo Plugins dir: "$SC4PluginsDir"$\r$\n'
564+
FileWrite $3 '>> "%LOG_FILE%" echo Locale: "$CacheLocale"$\r$\n'
565+
FileWrite $3 '>> "%LOG_FILE%" echo Render thumbnails: $CacheRenderThumbs$\r$\n'
566+
FileWrite $3 '>> "%LOG_FILE%" echo Thumbnail size: $CacheThumbnailSize px$\r$\n'
567+
FileWrite $3 '>> "%LOG_FILE%" echo Command: "%EXE%" --scan --game "$GameRoot" --plugins "$SC4PluginsDir" --locale "$CacheLocale" --thumbnail-size "$CacheThumbnailSize"'
568+
${If} $CacheRenderThumbs == "1"
569+
FileWrite $3 ' --render-thumbnails'
570+
${EndIf}
571+
FileWrite $3 '$\r$\n'
572+
FileWrite $3 '>> "%LOG_FILE%" echo.$\r$\n'
573+
FileWrite $3 '"%EXE%" --scan --game "$GameRoot" --plugins "$SC4PluginsDir" --locale "$CacheLocale" --thumbnail-size "$CacheThumbnailSize"'
539574
${If} $CacheRenderThumbs == "1"
540-
FileWrite $3 "$$cacheArgs += '--render-thumbnails'$\r$\n"
541-
${EndIf}
542-
FileWrite $3 "$$logFile = Join-Path $$PSScriptRoot 'cache_build.log'$\r$\n"
543-
FileWrite $3 "$$renderThumbs = '$CacheRenderThumbs'$\r$\n"
544-
FileWrite $3 "$$header = @($\r$\n"
545-
FileWrite $3 " 'SC4 Plop and Paint Cache Build Log',$\r$\n"
546-
FileWrite $3 " 'Installer version: ${APP_VERSION}',$\r$\n"
547-
FileWrite $3 " ('Timestamp (local): ' + (Get-Date -Format 'yyyy-MM-dd HH:mm:ss zzz')),$\r$\n"
548-
FileWrite $3 " ('Game root: ' + $$game),$\r$\n"
549-
FileWrite $3 " ('Plugins dir: ' + $$plugins),$\r$\n"
550-
FileWrite $3 " ('Locale: ' + $$locale),$\r$\n"
551-
FileWrite $3 " ('Render thumbnails: ' + $$renderThumbs),$\r$\n"
552-
FileWrite $3 " ('Thumbnail size: ' + $$thumbnailSize + ' px'),$\r$\n"
553-
FileWrite $3 " ('Command: ' + $$exe + ' ' + ($$cacheArgs -join ' ')),$\r$\n"
554-
FileWrite $3 " ''$\r$\n"
555-
FileWrite $3 ")$\r$\n"
556-
FileWrite $3 "$$header | Set-Content -Path $$logFile -Encoding UTF8$\r$\n"
557-
FileWrite $3 "$$header | ForEach-Object { Write-Host $$_ }$\r$\n"
558-
FileWrite $3 "& $$exe @cacheArgs 2>&1 | ForEach-Object { $$line = [string]$$_; Write-Host $$line; Add-Content -Path $$logFile -Value $$line -Encoding UTF8 }$\r$\n"
559-
FileWrite $3 "$$exitCode = $$LASTEXITCODE$\r$\n"
560-
FileWrite $3 "$$exitLine = 'Exit code: ' + $$exitCode$\r$\n"
561-
FileWrite $3 "Write-Host $$exitLine$\r$\n"
562-
FileWrite $3 "Add-Content -Path $$logFile -Value $$exitLine -Encoding UTF8$\r$\n"
563-
FileWrite $3 "exit $$exitCode$\r$\n"
575+
FileWrite $3 ' --render-thumbnails'
576+
${EndIf}
577+
FileWrite $3 ' >> "%LOG_FILE%" 2>&1$\r$\n'
578+
FileWrite $3 'set "EXITCODE=%ERRORLEVEL%"$\r$\n'
579+
FileWrite $3 '>> "%LOG_FILE%" echo Exit code: %EXITCODE%$\r$\n'
580+
FileWrite $3 'if "%EXITCODE%"=="0" ($\r$\n'
581+
FileWrite $3 ' echo Cache build completed successfully.$\r$\n'
582+
FileWrite $3 ') else ($\r$\n'
583+
FileWrite $3 ' echo Cache build failed with exit code %EXITCODE%.$\r$\n'
584+
FileWrite $3 ')$\r$\n'
585+
FileWrite $3 'echo See "%LOG_FILE%" for details.$\r$\n'
586+
FileWrite $3 'exit /b %EXITCODE%$\r$\n'
564587
FileClose $3
565588

566589
${If} $CacheBuildNow == "1"
567-
DetailPrint "Building SC4 Plop and Paint cache..."
568-
DetailPrint "Using script: $SC4ToolsDir\Rebuild-Cache.ps1"
569-
StrCpy $0 'powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$SC4ToolsDir\Rebuild-Cache.ps1"'
570-
nsExec::ExecToLog $0
571-
Pop $1
572-
${If} $1 != "0"
573-
MessageBox MB_ICONEXCLAMATION|MB_YESNO "Cache build failed (exit code: $1). Continue installation anyway?" IDYES +2
574-
Abort
590+
${IfNot} ${RunningX64}
591+
MessageBox MB_OK|MB_ICONEXCLAMATION "Cache build was skipped because the bundled cache builder requires 64-bit Windows.$\r$\n$\r$\nYou can still finish installing ${APP_NAME}, but you'll need to build the cache on a 64-bit machine and copy the generated files into your Plugins folder."
592+
${Else}
593+
DetailPrint "Building SC4 Plop and Paint cache..."
594+
DetailPrint "Manual rebuild script: $SC4ToolsDir\Rebuild-Cache.cmd"
595+
StrCpy $0 '"$SC4ToolsDir\_SC4PlopAndPaintCacheBuilder.exe" --scan --game "$GameRoot" --plugins "$SC4PluginsDir" --locale "$CacheLocale" --thumbnail-size "$CacheThumbnailSize"'
596+
${If} $CacheRenderThumbs == "1"
597+
StrCpy $0 '$0 --render-thumbnails'
598+
${EndIf}
599+
nsExec::ExecToLog $0
600+
Pop $1
601+
${If} $1 != "0"
602+
MessageBox MB_ICONEXCLAMATION|MB_YESNO "Cache build failed (exit code: $1). Continue installation anyway?$\r$\n$\r$\nYou can retry later with Rebuild-Cache.cmd in $SC4ToolsDir." IDYES +2
603+
Abort
604+
${EndIf}
575605
${EndIf}
576606
${EndIf}
577607
SectionEnd
@@ -615,6 +645,7 @@ Section "Uninstall"
615645
Delete "$SC4ToolsDir\_SC4PlopAndPaintCacheBuilder.exe"
616646
Delete "$SC4ToolsDir\LICENSE.txt"
617647
Delete "$SC4ToolsDir\THIRD_PARTY_NOTICES.txt"
648+
Delete "$SC4ToolsDir\Rebuild-Cache.cmd"
618649
Delete "$SC4ToolsDir\Rebuild-Cache.ps1"
619650
Delete "$SC4ToolsDir\cache_build.log"
620651
Delete "$SC4ToolsDir\Uninstall-SC4PlopAndPaint.exe"

0 commit comments

Comments
 (0)