Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Windows build

on:
workflow_dispatch:
pull_request:
branches:
- main
push:
branches:
- main
Expand Down
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ the official mod page when possible.
Steam auto-detection is unavailable. The selected folder must contain
`Cities2.exe`; mod files still go to the game's AppData folders.
- Offers an advanced **Build trusted source** flow when the official CS2
modding toolchain, the required .NET SDK, and npm are available.
modding toolchain, its required .NET Runtime, the required .NET SDK, and npm
are available.
- Blocks path traversal, archive symlinks, encrypted entries, oversized
packages, and suspicious compression ratios.
- Installs compiled mods transactionally into:
Expand All @@ -47,14 +48,30 @@ the user deliberately chooses **Build trusted source**, SkylineDock:

1. Detects the solution, .NET SDK version, UI projects, build scripts, and CS2
environment requirements.
2. Verifies the Steam game installation, `CSII_TOOLPATH`, `dotnet`, and `npm`.
3. Extracts a validated copy into a temporary build directory.
4. Redirects normal toolchain output through `CSII_USERDATAPATH` so an
unvalidated build does not go directly into the live game folder.
5. Runs a reproducible `npm ci` when a locked UI project is present, followed
2. Verifies the selected game installation, auto-detects its official modding
toolchain, checks `dotnet` and `npm`, and reads the toolchain's own
`runtimeconfig.json` to detect the exact .NET Runtime family it needs.
3. If a component is missing, shows a customer-friendly one-time setup guide
with official download links, including Unity license activation when the
game toolchain pauses for it; no environment-variable setup is required.
4. Extracts a validated copy into a temporary build directory.
5. Redirects both user-data and local-mod output with immutable MSBuild
properties so an unvalidated build does not go directly into the live game
folder.
6. Adds an out-of-tree MSBuild hook that resolves Unity's `mscorlib.dll` and
`System.Memory.dll` from the selected CS2 installation. The mod's source
archive is not modified.
7. Runs a reproducible `npm ci` when a locked UI project is present, followed
by a Release build of the solution.
6. Scans the output again and installs it transactionally only if it looks like
a compiled CS2 mod.
8. Scans the output again and installs it transactionally only if it looks like
a compiled CS2 mod. If a command fails, a complete diagnostic log is saved
under `%LOCALAPPDATA%\SkylineDock\logs`.

Some official CS2 toolchain releases still target .NET Runtime 6.0 even when a
newer .NET SDK is installed. .NET major versions are side-by-side, so a newer
runtime does not automatically satisfy that requirement. SkylineDock reads the
installed toolchain and links the customer directly to the matching x64 Runtime
when it is missing.

This mode executes MSBuild and npm-controlled code with the current Windows
user's permissions. The temporary directory prevents common accidental writes;
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "skylinedock"
version = "0.2.0.dev2"
version = "0.2.0.dev4"
description = "Safe drag-and-drop mod installer for Cities: Skylines II"
readme = "README.md"
requires-python = ">=3.11"
Expand Down
2 changes: 1 addition & 1 deletion skylinedock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

__all__ = ["ArchiveScanner", "PackageKind", "ScanReport", "SourceType"]

__version__ = "0.2.0.dev2"
__version__ = "0.2.0.dev4"
208 changes: 201 additions & 7 deletions skylinedock/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from datetime import datetime, timezone
import threading
import tempfile
import webbrowser
Expand All @@ -20,7 +21,7 @@
from .installer import InstallError, build_install_plan, install
from .models import PackageKind, ScanReport
from .scanner import ArchiveScanner
from .settings import AppSettings, load_settings, save_settings
from .settings import AppSettings, default_settings_path, load_settings, save_settings
from .source_builder import (
SourceBuildError,
build_trusted_source,
Expand All @@ -43,6 +44,11 @@
"danger": "#FF6B7A",
}

UNITY_LICENSE_URL = "https://docs.unity.com/en-us/hub/manage-license"
NODE_DOWNLOAD_URL = "https://nodejs.org/en/download"
DOTNET_DOWNLOAD_URL = "https://dotnet.microsoft.com/en-us/download/dotnet"
DOTNET_RUNTIME_DOWNLOAD_URL = "https://dotnet.microsoft.com/en-us/download/dotnet/{family}"


class SkylineDockApp:
def __init__(self, initial_path: str | None = None) -> None:
Expand Down Expand Up @@ -437,11 +443,7 @@ def _build_source(self) -> None:
return

if not prerequisites.ready:
messagebox.showerror(
"Source build requirements",
"SkylineDock cannot build this source yet:\n\n"
+ "\n".join(f"• {issue}" for issue in prerequisites.issues),
)
self._show_build_requirements(inspection, prerequisites)
return

warnings = "\n".join(f"• {warning}" for warning in inspection.warnings)
Expand Down Expand Up @@ -475,12 +477,189 @@ def worker() -> None:
plan = build_install_plan(result.compiled_report)
destination = install(plan)
self.root.after(0, lambda: self._source_build_succeeded(destination))
except (SourceBuildError, InstallError, OSError) as exc:
except SourceBuildError as exc:
message = str(exc)
log_path = self._save_source_build_log(exc.diagnostic_log)
if log_path is not None:
message += f"\n\nFull diagnostic log:\n{log_path}"
self.root.after(0, lambda message=message: self._source_build_failed(message))
except (InstallError, OSError) as exc:
message = str(exc)
self.root.after(0, lambda message=message: self._source_build_failed(message))

threading.Thread(target=worker, daemon=True).start()

def _show_build_requirements(self, inspection, prerequisites) -> None:
"""Explain missing build tools without exposing environment-variable setup."""

dialog = tk.Toplevel(self.root)
dialog.withdraw()
dialog.title("One-time setup required")
dialog.configure(bg=COLORS["background"])
dialog.resizable(False, False)
dialog.transient(self.root)

content = tk.Frame(dialog, bg=COLORS["background"], padx=28, pady=24)
content.pack(fill=BOTH, expand=True)
tk.Label(
content,
text="A one-time setup is needed to build this source mod",
bg=COLORS["background"],
fg=COLORS["text"],
font=("Segoe UI Semibold", 15),
).pack(anchor="w")
tk.Label(
content,
text=(
"These free components are only needed when building source code. "
"Ready-to-install mods do not need them."
),
bg=COLORS["background"],
fg=COLORS["muted"],
font=("Segoe UI", 9),
justify=LEFT,
wraplength=610,
).pack(anchor="w", pady=(5, 18))

missing_toolchain = prerequisites.tool_path is None
missing_npm = bool(inspection.ui_directories) and prerequisites.npm_executable is None
missing_dotnet = prerequisites.dotnet_executable is None
missing_runtimes = prerequisites.missing_dotnet_runtimes
requirement_number = 1

if missing_toolchain:
self._add_requirement(
content,
f"{requirement_number}. Install the Cities: Skylines II Modding Toolchain",
"Open the game, go to Options → Modding, then install or repair all "
"required tools. If installation waits for a Unity license, open Unity Hub, "
"sign in, then choose Licenses → Add license → Get a free personal license. "
"Return to the game and wait for every item to show a green check.",
"Unity license guide",
UNITY_LICENSE_URL,
)
requirement_number += 1

if missing_npm:
self._add_requirement(
content,
f"{requirement_number}. Install Node.js LTS",
"Download the Windows installer and keep the default options. npm is included "
"with Node.js; it does not need to be installed separately.",
"Download Node.js",
NODE_DOWNLOAD_URL,
)
requirement_number += 1

if missing_dotnet:
version = inspection.dotnet_sdk_version or "a compatible current version"
self._add_requirement(
content,
f"{requirement_number}. Install the .NET SDK",
f"Install .NET SDK {version} or a compatible newer SDK for Windows.",
"Download .NET SDK",
DOTNET_DOWNLOAD_URL,
)
requirement_number += 1

for runtime in missing_runtimes:
self._add_requirement(
content,
f"{requirement_number}. Install .NET Runtime {runtime.family} (x64)",
"The CS2 ModPostProcessor targets "
f"{runtime.framework} {runtime.version}. A newer major runtime does not "
"replace this requirement automatically. Install the latest patch in the "
f"{runtime.family} family; other installed .NET versions can remain.",
f"Download .NET {runtime.family} Runtime",
DOTNET_RUNTIME_DOWNLOAD_URL.format(family=runtime.family),
)
requirement_number += 1

other_issues = []
if not prerequisites.windows_supported:
other_issues.append("Source builds are currently supported on Windows only.")
if prerequisites.steam_game_path is None:
other_issues.append(
"Choose the folder containing Cities2.exe in SkylineDock before building."
)
if other_issues:
tk.Label(
content,
text="\n".join(f"• {issue}" for issue in other_issues),
bg=COLORS["background"],
fg=COLORS["warning"],
font=("Segoe UI", 9),
justify=LEFT,
wraplength=610,
).pack(anchor="w", pady=(0, 14))

tk.Label(
content,
text=(
"When installation is complete, restart SkylineDock, load the package again, "
"and click Build trusted source. SkylineDock will detect the tools automatically."
),
bg=COLORS["panel_alt"],
fg=COLORS["text"],
font=("Segoe UI Semibold", 9),
justify=LEFT,
wraplength=590,
padx=14,
pady=12,
).pack(fill=X, pady=(2, 18))
ttk.Button(
content,
text="Close",
style="Primary.TButton",
command=dialog.destroy,
).pack(anchor="e")

dialog.update_idletasks()
x = self.root.winfo_rootx() + max(
0, (self.root.winfo_width() - dialog.winfo_width()) // 2
)
y = self.root.winfo_rooty() + max(
0, (self.root.winfo_height() - dialog.winfo_height()) // 2
)
dialog.geometry(f"+{x}+{y}")
dialog.deiconify()
dialog.grab_set()

@staticmethod
def _add_requirement(
parent: tk.Widget,
title: str,
explanation: str,
button_text: str,
url: str,
) -> None:
panel = tk.Frame(parent, bg=COLORS["panel_alt"], padx=14, pady=12)
panel.pack(fill=X, pady=(0, 10))
copy = tk.Frame(panel, bg=COLORS["panel_alt"])
copy.pack(side=LEFT, fill=X, expand=True)
tk.Label(
copy,
text=title,
bg=COLORS["panel_alt"],
fg=COLORS["text"],
font=("Segoe UI Semibold", 10),
).pack(anchor="w")
tk.Label(
copy,
text=explanation,
bg=COLORS["panel_alt"],
fg=COLORS["muted"],
font=("Segoe UI", 9),
justify=LEFT,
wraplength=430,
).pack(anchor="w", pady=(3, 0))
ttk.Button(
panel,
text=button_text,
style="Secondary.TButton",
command=lambda: webbrowser.open(url),
).pack(side=RIGHT, padx=(16, 0))

def _source_build_succeeded(self, destination: Path) -> None:
self.status_badge.configure(text="BUILT & INSTALLED", bg=COLORS["good"], fg="#07111A")
self.footer.configure(text=f"Installed: {destination}", fg=COLORS["good"])
Expand All @@ -500,6 +679,21 @@ def _source_build_failed(self, message: str) -> None:
self.open_button.configure(state="normal")
messagebox.showerror("Source build failed", message)

@staticmethod
def _save_source_build_log(log_text: str | None) -> Path | None:
if not log_text:
return None

try:
log_directory = default_settings_path().parent / "logs"
log_directory.mkdir(parents=True, exist_ok=True)
timestamp = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%S-%fZ")
log_path = log_directory / f"source-build-{timestamp}.log"
log_path.write_text(log_text, encoding="utf-8")
except OSError:
return None
return log_path

def _set_details(self, value: str) -> None:
self.details.configure(state="normal")
self.details.delete("1.0", END)
Expand Down
Loading