Skip to content

Commit

Permalink
Installer: Patch Steam Library Files (#120, Fixes #113, #119)
Browse files Browse the repository at this point in the history
  • Loading branch information
Foldex authored Mar 19, 2023
1 parent 807aa2e commit 20f2794
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
TARGET_NORMAL = "~/.steam/steam"
TARGET_FLATPAK = "~/.var/app/com.valvesoftware.Steam/.steam/steam"

STEAM_LOOPBACK = "https://steamloopback.host"
STEAM_PATCHED_HEADER = "/*patched*/"

STEAM_FRIENDS_CSS = "clientui/css/friends.css"
STEAM_LIBRARY_CSS = "steamui/css/library.css"
STEAM_CUSTOM_LIBRARY = "steamui/libraryroot.custom.css"
STEAM_CUSTOM_FRIENDS = "clientui/friends.custom.css"

skindir = Path(SKIN_DIR)
patchdir = Path(PATCH_DIR)
webthemedir = Path(WEB_THEME_DIR)
Expand Down Expand Up @@ -208,6 +216,47 @@ def install(source: Path, target: Path, name: str):
shutil.rmtree(target_skin)
shutil.copytree(source, target_skin)

def patch_client_css(source: Path, target: Path, name: str):
if args.no_steam_patch or args.web_theme == "none":
return

print(f"{TEXT_BLUE}{TEXT_ARROW} Patching Steam Client {TEXT_BOLD}{name}{TEXT_RESET}{TEXT_BLUE} Files...{TEXT_RESET}")

if not target.is_dir():
print(f"{TEXT_PURPLE}{TEXT_INFO} Directory {TEXT_BOLD}{target}{TEXT_RESET}{TEXT_PURPLE} does not exist{TEXT_RESET}")
return

if name == "Library":
target_css = target / STEAM_LIBRARY_CSS
custom_css = target / STEAM_CUSTOM_LIBRARY
custom_css_name = custom_css.name
elif name == "Friends":
target_css = target / STEAM_FRIENDS_CSS
custom_css = target / STEAM_CUSTOM_FRIENDS
custom_css_name = custom_css.name
else:
raise SystemExit(f"{TEXT_RED}{TEXT_CROSS} Invalid steam css patch selected: {name}{TEXT_RESET}")

if not target_css.exists():
print(f"{TEXT_PURPLE}{TEXT_INFO} File {TEXT_BOLD}{target_css}{TEXT_RESET}{TEXT_PURPLE} does not exist{TEXT_RESET}")
return

with target_css.open() as css_file:
if css_file.readline().strip() == STEAM_PATCHED_HEADER:
return

orig_css = target_css.rename(target_css.with_suffix(".original.css"))
name = target_css.stem
css_dir = "css"
content = f'{STEAM_PATCHED_HEADER}\n@import url("{STEAM_LOOPBACK}/{css_dir}/{name}.original.css");\n@import url("{STEAM_LOOPBACK}/{custom_css_name}");\n'
target_css.open('w').write(content)

size_diff = orig_css.stat().st_size - target_css.stat().st_size
padding = "\t" * size_diff
target_css.open('a').write(padding)

shutil.copyfile(source / CSS_FILE, custom_css)

if __name__ == "__main__":
if not skindir.exists():
raise SystemExit(f"{TEXT_RED}{TEXT_CROSS} Skin directory {TEXT_BOLD}{SKIN_DIR}{TEXT_RESET}{TEXT_RED} does not exist. Make sure you're running the installer from its root directory{TEXT_RESET}")
Expand All @@ -222,6 +271,7 @@ def install(source: Path, target: Path, name: str):
parser.add_argument("-l", "--list-options", action = "store_true", help = "List available patches, themes, web extras and exit")
parser.add_argument("-p", "--patch", nargs = "+", action = "extend", help = "Apply one or multiple patches")
parser.add_argument("-n", "--name", default = SKIN_DIR, help = "Rename installed skin")
parser.add_argument("-nsp", "--no-steam-patch", action = "store_true", help = "Do not patch steam files")
parser.add_argument("-w", "--web-theme", choices = ["base", "full", "none"], default = "base", help = "Choose web theme variant")
parser.add_argument("-we", "--web-extras", nargs = "+", action = "extend", help = "Enable one or multiple web theme extras")
args = parser.parse_args()
Expand Down Expand Up @@ -302,4 +352,6 @@ def install(source: Path, target: Path, name: str):

for target in targets:
install(sourcedir, target, args.name)
patch_client_css(sourcedir, target, "Library")

print(f"{TEXT_GREEN}{TEXT_CHECK} Done!{TEXT_RESET}")

0 comments on commit 20f2794

Please sign in to comment.