forked from tkashkin/Adwaita-for-Steam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.py
executable file
·160 lines (136 loc) · 5.45 KB
/
install.py
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
#!/usr/bin/env python3
from argparse import ArgumentParser
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import NoReturn
import subprocess
import shutil
import os
TEXT_BOLD = "\033[1m"
TEXT_RESET = "\033[0m"
SKIN_DIR = "Adwaita"
PATCH_DIR = "patches"
WEB_THEME_DIR = "web_themes"
CSS_FILE = "resource/webkit.css"
TARGET_NORMAL = "~/.steam/steam"
TARGET_FLATPAK = "~/.var/app/com.valvesoftware.Steam/.steam/steam"
skindir = Path(SKIN_DIR)
patchdir = Path(PATCH_DIR)
webthemedir = Path(WEB_THEME_DIR)
WEB_BASE_FILES = [
webthemedir / "base/1_root.css",
webthemedir / "base/3_library.css",
webthemedir / "base/4_collections.css",
webthemedir / "base/5_game_details.css",
webthemedir / "base/6_downloads.css",
webthemedir / "base/9_scrollbars.css",
]
WEB_FULL_FILES = [
webthemedir / "base/1_root.css",
webthemedir / "full/2_global.css",
webthemedir / "base/3_library.css",
webthemedir / "full/3_library.css",
webthemedir / "base/4_collections.css",
webthemedir / "base/5_game_details.css",
webthemedir / "full/5_game_details.css",
webthemedir / "base/6_downloads.css",
webthemedir / "full/6_downloads.css",
webthemedir / "full/7_uninstall_dialog.css",
webthemedir / "full/8_chat.css",
webthemedir / "base/9_scrollbars.css",
]
def find_patches() -> list[Path]:
return list(patchdir.glob("**/*.patch"))
def patch_name(patch: Path) -> str:
return os.path.relpath(patch, patchdir).removesuffix(".patch")
def list_patches(patches: list[Path]) -> NoReturn:
if patches:
print(f"{len(patches)} patches available:\n")
for patch in patches:
patch_name = os.path.relpath(patch, patchdir).removesuffix(".patch")
patch_description = ""
with patch.open() as patch_file:
patch_description = " - {}".format(patch_file.readline().removeprefix("#").strip())
print(f"{TEXT_BOLD}{patch_name}{TEXT_RESET}{patch_description}")
print(f"\nApply patches using {TEXT_BOLD}'./install.py --patch PATCH_NAME'{TEXT_RESET}")
else:
print("No patches available")
exit(0)
def apply_patch(parentdir: Path, patch: Path):
with patch.open() as patch_file:
print(f"\nApplying patch {TEXT_BOLD}{patch_name(patch)}{TEXT_RESET}...")
try:
subprocess.run(["patch", "-l", "-p0"], cwd = parentdir, stdin = patch_file)
except Exception as e:
print(f"\nError applying patch: {e}")
def gen_webkit_theme(target: Path, name: str, selected_extras: list[Path]):
if name == "none":
return
elif name == "base":
selected_files = WEB_BASE_FILES
elif name == "full":
selected_files = WEB_FULL_FILES
else:
raise SystemExit(f"Invalid web theme selected: {name}")
with open(target,'wb') as wfd:
for f in selected_files:
with open(f,'rb') as fd:
shutil.copyfileobj(fd, wfd)
if selected_extras:
for f in selected_extras:
f = webthemedir / "extras/{}{}".format(f.removesuffix(".css"), ".css")
if f.exists():
with open(f,'rb') as fd:
shutil.copyfileobj(fd, wfd)
else:
print(f"Web Extra: {TEXT_BOLD}{f}{TEXT_RESET} not found!")
def install(source: Path, target: Path, name: str):
if target.is_dir():
if target.stem != "skins":
target = target / "skins"
target.mkdir(exist_ok = True)
else:
print(f"Directory {TEXT_BOLD}{target}{TEXT_RESET} does not exist")
return
print(f"Installing skin {TEXT_BOLD}{name}{TEXT_RESET} into {TEXT_BOLD}{target}{TEXT_RESET}...")
target_skin = target / name
if target_skin.exists():
shutil.rmtree(target_skin)
shutil.copytree(source, target_skin)
if __name__ == "__main__":
if not skindir.exists():
raise SystemExit(f"Skin directory {TEXT_BOLD}{SKIN_DIR}{TEXT_RESET} does not exist. Make sure you're running the installer from its root directory")
if not webthemedir.exists():
raise SystemExit(f"Web Theme directory {TEXT_BOLD}{WEB_THEME_DIR}{TEXT_RESET} does not exist. Make sure you're running the installer from its root directory")
parser = ArgumentParser(description = "Adwaita-for-Steam installer")
parser.add_argument("-t", "--target", nargs = "+", action = "extend", default = ["normal", "flatpak"], help = "Install targets: 'normal', 'flatpak', custom paths")
parser.add_argument("-l", "--list-patches", action = "store_true", help = "List available patches 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("-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()
if args.list_patches:
list_patches(find_patches())
with TemporaryDirectory() as tmpdir:
tmp = Path(tmpdir)
sourcedir = tmp / SKIN_DIR
print(f"Copying to the stage directory {TEXT_BOLD}{sourcedir}{TEXT_RESET}")
shutil.copytree(skindir, sourcedir)
if args.patch:
for patch_file in args.patch:
patch = patchdir / "{}{}".format(patch_file.removesuffix(".patch"), ".patch")
if patch.exists():
apply_patch(tmp, patch)
gen_webkit_theme(sourcedir / CSS_FILE, args.web_theme, args.web_extras)
targets = set()
for t in args.target:
match t:
case "normal":
targets.add(Path(TARGET_NORMAL).expanduser().resolve())
case "flatpak":
targets.add(Path(TARGET_FLATPAK).expanduser().resolve())
case _:
targets.add(Path(t).expanduser().resolve())
for target in targets:
install(sourcedir, target, args.name)