PixelLauncher 2.1.2 — секции настроек, панель быстрых настроек, сборки Modrinth/CurseForge

This commit is contained in:
kosta committed 2026-10-20 17:36:35 +07:00
1 parent 80dc1826a1
commit 39cf752b7b
13 files changed
+972 -49

No files matched your search

+49 -6
View File
@@ -57,6 +57,29 @@ def read_index(path):
return data, mc, loader, loader_ver
def _primary_download(downloads):
"""Достаёт основной файл из "downloads".
Формат в индексе Modrinth встречается в трёх видах:
["https://..."] — просто список ссылок,
[{"hashes": {...}, "url": "...", ...}] — старый формат с объектами,
{"primary": "https://...", "alternate": [...]} — новый формат.
"""
if isinstance(downloads, dict):
downloads = ([downloads.get("primary")] +
list(downloads.get("alternate") or []))
if not downloads:
return None
first = downloads[0]
if isinstance(first, str):
return {"url": first, "filename": "", "size": 0}
primary = next((d for d in downloads
if isinstance(d, dict) and d.get("primary")), first)
if not isinstance(primary, dict):
return None
return primary
def _files_from_index(index):
"""[(путь_относительно_игры, url, filename, size)] — клиентские файлы."""
out = []
@@ -67,7 +90,9 @@ def _files_from_index(index):
downloads = entry.get("downloads") or []
if not downloads:
continue
primary = next((d for d in downloads if d.get("primary")), downloads[0])
primary = _primary_download(downloads)
if not primary:
continue
url = primary.get("url") or ""
if not url:
continue
@@ -137,9 +162,27 @@ def install(game_dir, pack_path, log=None, progress=None, cancel=None):
ov += 1
if log and ov:
log(f"Пак: распаковано {ov} файлов overrides")
if progress:
progress(1.0)
if log:
log(f"Пак: готово — {got} файл(ов) скачано")
return vid, got
def install_from_url(game_dir, url, log=None, progress=None, cancel=None, filename_hint="pack.mrpack"):
"""Скачивает модпак по прямой ссылке и устанавливает."""
import tempfile
dest = os.path.join(tempfile.gettempdir(), "PixelLauncher",
filename_hint.replace("/", "_"))
os.makedirs(os.path.dirname(dest), exist_ok=True)
def prog(done_b, total_b):
if progress and total_b:
progress(min(0.4, (done_b / total_b) * 0.4))
http.download_file(url, dest, progress=prog, cancel=cancel)
def p2(f):
if progress:
progress(0.4 + f * 0.6)
vid, got = install(game_dir, dest, log=log, progress=p2, cancel=cancel)
try:
os.unlink(dest)
except OSError:
pass
return vid, got