523 lines
22 KiB
Python
523 lines
22 KiB
Python
#!/usr/bin/env python3
|
|
import glob
|
|
import requests
|
|
import shutil
|
|
|
|
from pathlib import Path
|
|
from urllib.parse import quote_plus
|
|
|
|
from openpilot.frogpilot.common.frogpilot_download_utilities import GITLAB_URL, download_file, get_repository_url, handle_error, verify_download
|
|
from openpilot.frogpilot.common.frogpilot_utilities import delete_file, extract_zip, load_json_file, update_json_file
|
|
from openpilot.frogpilot.common.frogpilot_variables import ACTIVE_THEME_PATH, RESOURCES_REPO, THEME_SAVE_PATH
|
|
|
|
CANCEL_DOWNLOAD_PARAM = "CancelThemeDownload"
|
|
DOWNLOAD_PROGRESS_PARAM = "ThemeDownloadProgress"
|
|
|
|
STOCKOP_THEME_PATH = Path(__file__).parent / "stock_theme"
|
|
|
|
THEME_COMPONENT_PARAMS = {
|
|
"colors": "ColorToDownload",
|
|
"distance_icons": "DistanceIconToDownload",
|
|
"icons": "IconToDownload",
|
|
"signals": "SignalToDownload",
|
|
"sounds": "SoundToDownload",
|
|
"steering_wheels": "WheelToDownload"
|
|
}
|
|
|
|
class ThemeManager:
|
|
def __init__(self, params, params_memory, boot_run=False):
|
|
self.params = params
|
|
self.params_memory = params_memory
|
|
|
|
self.downloading_theme = False
|
|
self.theme_updated = False
|
|
|
|
self.previous_asset_mappings = {}
|
|
|
|
self.theme_sizes_path = THEME_SAVE_PATH / "theme_sizes.json"
|
|
|
|
self.theme_sizes = load_json_file(self.theme_sizes_path)
|
|
|
|
self.session = requests.Session()
|
|
self.session.headers.update({
|
|
"Accept": "application/vnd.github.v3+json",
|
|
"Accept-Language": "en",
|
|
"User-Agent": "frogpilot-theme-downloader/1.0 (https://github.com/FrogAi/FrogPilot)"
|
|
})
|
|
|
|
if boot_run:
|
|
self.copy_default_theme()
|
|
|
|
@staticmethod
|
|
def copy_default_theme():
|
|
world_frog_day_theme_path = HOLIDAY_THEME_PATH / "world_frog_day"
|
|
|
|
for theme_subfolder_name, save_subfolder_path in [
|
|
("colors", "theme_packs/frog/colors"),
|
|
("distance_icons", "theme_packs/frog-animated/distance_icons"),
|
|
("icons", "theme_packs/frog-animated/icons"),
|
|
("signals", "theme_packs/frog/signals"),
|
|
("sounds", "theme_packs/frog/sounds"),
|
|
]:
|
|
source_folder_path = world_frog_day_theme_path / theme_subfolder_name
|
|
destination_folder_path = THEME_SAVE_PATH / save_subfolder_path
|
|
destination_folder_path.mkdir(parents=True, exist_ok=True)
|
|
shutil.copytree(source_folder_path, destination_folder_path, dirs_exist_ok=True)
|
|
|
|
steering_wheel_image_path = world_frog_day_theme_path / "steering_wheel/wheel.png"
|
|
steering_wheel_save_path = THEME_SAVE_PATH / "steering_wheels/frog.png"
|
|
steering_wheel_save_path.parent.mkdir(parents=True, exist_ok=True)
|
|
shutil.copy2(steering_wheel_image_path, steering_wheel_save_path)
|
|
|
|
def download_theme(self, theme_component, theme_name, asset_param, frogpilot_toggles):
|
|
self.downloading_theme = True
|
|
|
|
repo_url = get_repository_url(self.session)
|
|
if not repo_url:
|
|
handle_error(None, asset_param, "Repository unavailable", "GitHub and GitLab are offline...", self.params_memory, DOWNLOAD_PROGRESS_PARAM)
|
|
self.downloading_theme = False
|
|
return
|
|
|
|
if theme_component == "distance_icons":
|
|
download_link = f"{repo_url}/Distance-Icons/{theme_name}"
|
|
download_path = THEME_SAVE_PATH / "theme_packs" / theme_name / theme_component
|
|
extension = ".zip"
|
|
elif theme_component == "steering_wheels":
|
|
download_link = f"{repo_url}/Steering-Wheels/{theme_name}"
|
|
download_path = THEME_SAVE_PATH / theme_component / theme_name
|
|
extension = ".gif"
|
|
else:
|
|
download_link = f"{repo_url}/Themes/{theme_name}/{theme_component}"
|
|
download_path = THEME_SAVE_PATH / "theme_packs" / theme_name / theme_component
|
|
extension = ".zip"
|
|
|
|
theme_path = download_path.with_suffix(extension)
|
|
theme_url = download_link + extension
|
|
|
|
delete_file(theme_path)
|
|
|
|
print(f"Downloading theme from GitHub: {theme_name}")
|
|
download_file(CANCEL_DOWNLOAD_PARAM, theme_path, asset_param, self.params_memory, DOWNLOAD_PROGRESS_PARAM, self.session, theme_url)
|
|
|
|
if theme_component == "steering_wheels" and not theme_path.exists() and theme_path.with_suffix(".png").exists():
|
|
theme_path = theme_path.with_suffix(".png")
|
|
extension = ".png"
|
|
theme_url = theme_url.replace(".gif", ".png")
|
|
|
|
if self.params_memory.get_bool(CANCEL_DOWNLOAD_PARAM):
|
|
delete_file(theme_path)
|
|
handle_error(None, asset_param, "Download cancelled...", "Download cancelled...", self.params_memory, DOWNLOAD_PROGRESS_PARAM)
|
|
|
|
self.downloading_theme = False
|
|
return
|
|
|
|
if verify_download(theme_path, self.params_memory, self.session, theme_url):
|
|
print(f"Theme {theme_name} downloaded and verified successfully from GitHub!")
|
|
self.update_theme_size(theme_component, theme_name, theme_path.stat().st_size)
|
|
|
|
if extension == ".zip":
|
|
self.params_memory.put(DOWNLOAD_PROGRESS_PARAM, "Unpacking theme...")
|
|
extract_zip(theme_path, download_path)
|
|
|
|
self.params_memory.put(DOWNLOAD_PROGRESS_PARAM, "Downloaded!")
|
|
self.params_memory.remove(asset_param)
|
|
|
|
self.downloading_theme = False
|
|
|
|
self.update_themes(frogpilot_toggles)
|
|
return
|
|
elif self.handle_verification_failure(extension, theme_component, theme_name, asset_param, theme_path, download_path, frogpilot_toggles):
|
|
return
|
|
|
|
handle_error(download_path, asset_param, "Download failed...", "Download failed...", self.params_memory, DOWNLOAD_PROGRESS_PARAM)
|
|
self.downloading_theme = False
|
|
|
|
def fetch_assets(self, repo_url, frogpilot_toggles):
|
|
is_github = "github" in repo_url
|
|
is_gitlab = "gitlab" in repo_url
|
|
|
|
repo_encoded = quote_plus(RESOURCES_REPO)
|
|
|
|
assets = {"themes": {}, "wheels": []}
|
|
try:
|
|
def list_files(branch):
|
|
if is_github:
|
|
response = self.session.get(f"https://api.github.com/repos/{RESOURCES_REPO}/git/trees/{branch}?recursive=1", timeout=10)
|
|
response.raise_for_status()
|
|
return [
|
|
{
|
|
"path": item.get("path", ""),
|
|
"name": Path(item.get("path", "")).name,
|
|
"type": item.get("type"),
|
|
"size": item.get("size", 0),
|
|
}
|
|
for item in response.json().get("tree", [])
|
|
if item.get("type") == "blob"
|
|
]
|
|
if is_gitlab:
|
|
response = self.session.get(f"https://gitlab.com/api/v4/projects/{repo_encoded}/repository/tree?ref={branch}&recursive=true", timeout=10)
|
|
response.raise_for_status()
|
|
return [
|
|
{
|
|
"path": item.get("path", ""),
|
|
"name": item.get("name", ""),
|
|
"type": item.get("type"),
|
|
"size": 0,
|
|
}
|
|
for item in response.json()
|
|
if item.get("type") in ("blob", "file")
|
|
]
|
|
print(f"Unsupported repository URL: {repo_url}")
|
|
return []
|
|
|
|
def file_size(branch, path, fallback):
|
|
if is_github:
|
|
return int(fallback or 0)
|
|
response = self.session.head(f"https://gitlab.com/api/v4/projects/{repo_encoded}/repository/files/{quote_plus(path)}/raw?ref={branch}", timeout=10)
|
|
return int(response.headers.get("content-length", 0)) if response.ok else 0
|
|
|
|
for branch in ["Distance-Icons", "Steering-Wheels"]:
|
|
for item in list_files(branch):
|
|
if item.get("type") not in ("file", "blob"):
|
|
continue
|
|
|
|
path = item["path"]
|
|
size = file_size(branch, path, item.get("size", 0))
|
|
|
|
if branch == "Steering-Wheels":
|
|
assets["wheels"].append(path)
|
|
theme_name = Path(path).stem
|
|
local_files = list((THEME_SAVE_PATH / "steering_wheels").glob(f"{theme_name}.*"))
|
|
if local_files and size > 0:
|
|
local_size = self.theme_sizes.get("wheels", {}).get(theme_name)
|
|
if local_size != size:
|
|
self.download_theme("steering_wheels", theme_name, THEME_COMPONENT_PARAMS["steering_wheels"], frogpilot_toggles)
|
|
|
|
elif branch == "Distance-Icons":
|
|
component_name = "distance_icons"
|
|
theme_name = Path(path).stem
|
|
assets["themes"].setdefault(theme_name, set()).add(component_name)
|
|
|
|
local_path = THEME_SAVE_PATH / "theme_packs" / theme_name / component_name
|
|
if local_path.exists() and size > 0:
|
|
local_size = self.theme_sizes.get("themes", {}).get(theme_name, {}).get(component_name)
|
|
if local_size != size:
|
|
self.download_theme(component_name, theme_name, THEME_COMPONENT_PARAMS[component_name], frogpilot_toggles)
|
|
|
|
branch = "Themes"
|
|
for item in list_files(branch):
|
|
if item.get("type") not in ("file", "blob") or "/" not in item["path"]:
|
|
continue
|
|
|
|
expected_size = file_size(branch, item["path"], item.get("size", 0))
|
|
|
|
theme_name, sub_path = item["path"].split("/", 1)
|
|
theme_path = sub_path.lower()
|
|
|
|
for key in ("colors", "icons", "signals", "sounds"):
|
|
if key in theme_path:
|
|
assets["themes"].setdefault(theme_name, set()).add(key)
|
|
|
|
local_path = THEME_SAVE_PATH / "theme_packs" / theme_name / key
|
|
if local_path.exists():
|
|
local_size = self.theme_sizes.get("themes", {}).get(theme_name, {}).get(key)
|
|
if local_size != expected_size:
|
|
print(f"{key} {theme_name} is outdated, redownloading...")
|
|
self.download_theme(key, theme_name, THEME_COMPONENT_PARAMS[key], frogpilot_toggles)
|
|
break
|
|
|
|
assets["themes"] = {key: sorted(list(value)) for key, value in assets["themes"].items()}
|
|
assets["wheels"].sort()
|
|
return assets
|
|
|
|
except requests.exceptions.RequestException as error:
|
|
print(f"Failed to fetch theme sizes from {'GitHub' if is_github else 'GitLab'}: {error}")
|
|
return {}
|
|
|
|
@staticmethod
|
|
def format_name(name, component):
|
|
base = Path(name).stem
|
|
creator = ""
|
|
if "~" in base:
|
|
base, creator = base.split("~", 1)
|
|
|
|
parts = base.replace("_", "-").split("-")
|
|
capitalized_parts = [part.capitalize() for part in parts if part]
|
|
|
|
if len(capitalized_parts) > 1 and component != "steering_wheels":
|
|
display = f"{capitalized_parts[0]} ({' '.join(capitalized_parts[1:])})"
|
|
else:
|
|
display = " ".join(capitalized_parts)
|
|
|
|
if creator:
|
|
return f"{display} - by: {creator}"
|
|
return display
|
|
|
|
@staticmethod
|
|
def get_full_themes():
|
|
theme_packs_path = THEME_SAVE_PATH / "theme_packs"
|
|
if not theme_packs_path.exists():
|
|
return []
|
|
|
|
valid_themes = set()
|
|
for theme_directory in theme_packs_path.iterdir():
|
|
if not theme_directory.is_dir():
|
|
continue
|
|
|
|
base_name = theme_directory.name.replace("-animated", "")
|
|
|
|
animated_path = theme_packs_path / f"{base_name}-animated"
|
|
base_path = theme_packs_path / base_name
|
|
|
|
base_valid = all((base_path / asset).is_dir() for asset in {"colors", "sounds"})
|
|
animated_icons_exist = (animated_path / "icons").is_dir()
|
|
base_icons_exist = (base_path / "icons").is_dir()
|
|
|
|
if base_valid and (animated_icons_exist or base_icons_exist):
|
|
if animated_icons_exist:
|
|
valid_themes.add(f"{base_name}-animated")
|
|
else:
|
|
valid_themes.add(base_name)
|
|
|
|
return sorted(valid_themes)
|
|
|
|
def handle_verification_failure(self, extension, theme_component, theme_name, asset_param, theme_path, download_path, frogpilot_toggles):
|
|
if theme_component == "distance_icons":
|
|
download_link = f"{GITLAB_URL}/Distance-Icons/{theme_name}"
|
|
elif theme_component == "steering_wheels":
|
|
download_link = f"{GITLAB_URL}/Steering-Wheels/{theme_name}"
|
|
else:
|
|
download_link = f"{GITLAB_URL}/Themes/{theme_name}/{theme_component}"
|
|
|
|
delete_file(theme_path)
|
|
|
|
theme_url = download_link + extension
|
|
print(f"Downloading theme from GitLab: {theme_name}")
|
|
download_file(CANCEL_DOWNLOAD_PARAM, theme_path, asset_param, self.params_memory, DOWNLOAD_PROGRESS_PARAM, self.session, theme_url)
|
|
|
|
if theme_component == "steering_wheels" and not theme_path.exists() and theme_path.with_suffix(".png").exists():
|
|
theme_path = theme_path.with_suffix(".png")
|
|
extension = ".png"
|
|
theme_url = theme_url.replace(".gif", ".png")
|
|
|
|
if verify_download(theme_path, self.params_memory, self.session, theme_url):
|
|
print(f"Theme {theme_name} downloaded and verified successfully from GitLab!")
|
|
self.update_theme_size(theme_component, theme_name, theme_path.stat().st_size)
|
|
|
|
if extension == ".zip":
|
|
self.params_memory.put(DOWNLOAD_PROGRESS_PARAM, "Unpacking theme...")
|
|
extract_zip(theme_path, download_path)
|
|
|
|
self.params_memory.put(DOWNLOAD_PROGRESS_PARAM, "Downloaded!")
|
|
self.params_memory.remove(asset_param)
|
|
|
|
self.downloading_theme = False
|
|
|
|
self.update_themes(frogpilot_toggles)
|
|
return True
|
|
|
|
handle_error(None, asset_param, "Download failed...", "Download failed...", self.params_memory, DOWNLOAD_PROGRESS_PARAM)
|
|
self.downloading_theme = False
|
|
return False
|
|
|
|
def update_active_theme(self, frogpilot_toggles, boot_run=False):
|
|
asset_mappings = {
|
|
"color_scheme": ("colors", frogpilot_toggles.color_scheme),
|
|
"distance_icons": ("distance_icons", frogpilot_toggles.distance_icons),
|
|
"icon_pack": ("icons", frogpilot_toggles.icon_pack),
|
|
"sound_pack": ("sounds", frogpilot_toggles.sound_pack),
|
|
"turn_signal_pack": ("signals", frogpilot_toggles.signal_icons),
|
|
"wheel_image": ("wheel_image", frogpilot_toggles.wheel_image)
|
|
}
|
|
|
|
if asset_mappings != self.previous_asset_mappings:
|
|
for asset, (asset_type, current_value) in asset_mappings.items():
|
|
print(f"Updating {asset}: {asset_type} with value {current_value}")
|
|
|
|
if asset_type == "wheel_image":
|
|
self.update_wheel_image(current_value, boot_run=boot_run)
|
|
else:
|
|
self.update_theme_asset(asset_type, current_value, boot_run=boot_run)
|
|
|
|
self.previous_asset_mappings = asset_mappings
|
|
|
|
self.theme_updated = True
|
|
|
|
def update_theme_asset(self, asset_type, theme, boot_run=False):
|
|
save_location = ACTIVE_THEME_PATH / asset_type
|
|
asset_location = THEME_SAVE_PATH / "theme_packs" / theme / asset_type
|
|
|
|
if not asset_location.exists() or theme == "stock":
|
|
asset_location = STOCKOP_THEME_PATH / asset_type
|
|
print(f"Using the stock {asset_type[:-1]} instead")
|
|
|
|
delete_file(save_location, print_error=not boot_run)
|
|
|
|
save_location.parent.mkdir(parents=True, exist_ok=True)
|
|
save_location.symlink_to(asset_location, target_is_directory=True)
|
|
print(f"Linked {save_location} to {asset_location}")
|
|
|
|
def update_theme_params(self, downloadable_colors, downloadable_distance_icons, downloadable_icons, downloadable_signals, downloadable_sounds, downloadable_wheels):
|
|
def update_param(key, assets, subfolder):
|
|
if subfolder == "steering_wheels":
|
|
themes_path = THEME_SAVE_PATH / subfolder
|
|
existing_assets = {self.format_name(item.name, "steering_wheels") for item in themes_path.glob("*") if item.is_file()}
|
|
else:
|
|
themes_path = THEME_SAVE_PATH / "theme_packs"
|
|
existing_assets = {self.format_name(item.parent.name, subfolder) for item in themes_path.glob(f"*/{subfolder}") if item.is_dir()}
|
|
|
|
self.params.put(key, ",".join(sorted(set(assets) - existing_assets)))
|
|
print(f"{key} updated successfully")
|
|
|
|
update_param("DownloadableColors", downloadable_colors, "colors")
|
|
update_param("DownloadableDistanceIcons", downloadable_distance_icons, "distance_icons")
|
|
update_param("DownloadableIcons", downloadable_icons, "icons")
|
|
update_param("DownloadableSignals", downloadable_signals, "signals")
|
|
update_param("DownloadableSounds", downloadable_sounds, "sounds")
|
|
update_param("DownloadableWheels", downloadable_wheels, "steering_wheels")
|
|
|
|
downloaded_themes = {}
|
|
for theme_dir in (THEME_SAVE_PATH / "theme_packs").iterdir():
|
|
components = []
|
|
for component in ["colors", "distance_icons", "icons", "signals", "sounds"]:
|
|
if (theme_dir / component).is_dir():
|
|
components.append(component)
|
|
|
|
if components:
|
|
theme_name = self.format_name(theme_dir.name, "theme_packs")
|
|
downloaded_themes[theme_name] = sorted(components)
|
|
|
|
downloaded_wheels = []
|
|
for wheel_file in (THEME_SAVE_PATH / "steering_wheels").iterdir():
|
|
if wheel_file.is_file():
|
|
downloaded_wheels.append(self.format_name(wheel_file.name, "steering_wheels"))
|
|
|
|
self.params.put("ThemesDownloaded", {
|
|
"themes": {key: downloaded_themes[key] for key in sorted(downloaded_themes)},
|
|
"steering_wheels": sorted(downloaded_wheels)
|
|
})
|
|
|
|
print("ThemesDownloaded updated successfully")
|
|
|
|
def update_theme_size(self, theme_component, theme_name, file_size):
|
|
if theme_component == "steering_wheels":
|
|
key = "wheels"
|
|
else:
|
|
key = "themes"
|
|
|
|
if key not in self.theme_sizes:
|
|
self.theme_sizes[key] = {}
|
|
|
|
if key == "wheels":
|
|
self.theme_sizes[key][theme_name] = file_size
|
|
else:
|
|
if theme_name not in self.theme_sizes[key]:
|
|
self.theme_sizes[key][theme_name] = {}
|
|
self.theme_sizes[key][theme_name][theme_component] = file_size
|
|
|
|
update_json_file(self.theme_sizes_path, self.theme_sizes)
|
|
|
|
def update_themes(self, frogpilot_toggles, boot_run=False):
|
|
if self.downloading_theme:
|
|
return
|
|
|
|
repo_url = get_repository_url(self.session)
|
|
if repo_url is None:
|
|
print("GitHub and GitLab are offline...")
|
|
return
|
|
|
|
assets = self.fetch_assets(repo_url, frogpilot_toggles)
|
|
if not assets:
|
|
return
|
|
|
|
downloadable_colors = []
|
|
downloadable_distance_icons = []
|
|
downloadable_icons = []
|
|
downloadable_signals = []
|
|
downloadable_sounds = []
|
|
|
|
for theme, available_assets in assets["themes"].items():
|
|
theme_name = self.format_name(theme, "theme_packs")
|
|
print(f"Theme found: {theme_name}")
|
|
|
|
if "colors" in available_assets:
|
|
downloadable_colors.append(theme_name)
|
|
if "distance_icons" in available_assets:
|
|
downloadable_distance_icons.append(theme_name)
|
|
if "icons" in available_assets:
|
|
downloadable_icons.append(theme_name)
|
|
if "signals" in available_assets:
|
|
downloadable_signals.append(theme_name)
|
|
if "sounds" in available_assets:
|
|
downloadable_sounds.append(theme_name)
|
|
|
|
downloadable_wheels = [self.format_name(wheel, "steering_wheels") for wheel in assets["wheels"]]
|
|
|
|
print(f"Downloadable Colors: {downloadable_colors}")
|
|
print(f"Downloadable Icons: {downloadable_icons}")
|
|
print(f"Downloadable Signals: {downloadable_signals}")
|
|
print(f"Downloadable Sounds: {downloadable_sounds}")
|
|
print(f"Downloadable Distance Icons: {downloadable_distance_icons}")
|
|
print(f"Downloadable Wheels: {downloadable_wheels}")
|
|
|
|
if boot_run:
|
|
self.validate_themes(downloadable_colors, downloadable_distance_icons, downloadable_icons, downloadable_signals, downloadable_sounds, downloadable_wheels, frogpilot_toggles)
|
|
|
|
self.update_theme_params(downloadable_colors, downloadable_distance_icons, downloadable_icons, downloadable_signals, downloadable_sounds, downloadable_wheels)
|
|
|
|
def update_wheel_image(self, image, boot_run=False):
|
|
wheel_save_location = ACTIVE_THEME_PATH / "steering_wheel"
|
|
|
|
if image == "stock":
|
|
wheel_location = STOCKOP_THEME_PATH / "steering_wheel"
|
|
else:
|
|
wheel_location = THEME_SAVE_PATH / "steering_wheels"
|
|
|
|
if not wheel_location.exists():
|
|
wheel_location = STOCKOP_THEME_PATH / "steering_wheel"
|
|
print("Using the stock steering wheel instead")
|
|
|
|
delete_file(wheel_save_location, print_error=not boot_run)
|
|
wheel_save_location.mkdir(parents=True, exist_ok=True)
|
|
|
|
image_name = image.replace(" ", "_").lower()
|
|
matching_files = [images for images in wheel_location.iterdir() if images.stem.lower() in {image_name, "wheel"}]
|
|
if matching_files:
|
|
source_file = matching_files[0]
|
|
destination_file = wheel_save_location / f"wheel{source_file.suffix}"
|
|
destination_file.symlink_to(source_file)
|
|
print(f"Linked {destination_file} to {source_file}")
|
|
|
|
def validate_themes(self, downloadable_colors, downloadable_distance_icons, downloadable_icons, downloadable_signals, downloadable_sounds, downloadable_wheels, frogpilot_toggles):
|
|
downloaded_data = self.params.get("ThemesDownloaded")
|
|
|
|
for display_name, components in downloaded_data.get("themes", {}).items():
|
|
raw_name = display_name.lower().replace(" ", "_").replace("(", "").replace(")", "")
|
|
theme_folder_name = raw_name.replace("_animated", "-animated")
|
|
|
|
for component in components:
|
|
component_path = THEME_SAVE_PATH / "theme_packs" / theme_folder_name / component
|
|
if not component_path.is_dir() or not any(component_path.iterdir()):
|
|
print(f"Missing or empty component '{component}' for theme '{theme_folder_name}'. Downloading...")
|
|
self.download_theme(component, theme_folder_name, THEME_COMPONENT_PARAMS.get(component), frogpilot_toggles)
|
|
self.update_active_theme(frogpilot_toggles)
|
|
|
|
wheels_path = THEME_SAVE_PATH / "steering_wheels"
|
|
for display_name in downloaded_data.get("steering_wheels", []):
|
|
file_stem = display_name.replace(" ", "_").lower()
|
|
matching_files = list(wheels_path.glob(f"{file_stem}.*"))
|
|
if not matching_files:
|
|
print(f"Missing steering wheel '{display_name}'. Downloading...")
|
|
self.download_theme("steering_wheels", file_stem, THEME_COMPONENT_PARAMS["steering_wheels"], frogpilot_toggles)
|
|
self.update_active_theme(frogpilot_toggles)
|
|
|
|
for dir_path in THEME_SAVE_PATH.glob("**/*"):
|
|
if dir_path.is_dir() and not any(dir_path.iterdir()):
|
|
print(f"Deleting empty folder: {dir_path}")
|
|
delete_file(dir_path)
|
|
elif dir_path.is_file() and dir_path.name.startswith("tmp"):
|
|
print(f"Deleting temp file: {dir_path}")
|
|
delete_file(dir_path)
|
|
|
|
print("Theme validation complete.")
|