This commit is contained in:
2026-09-08 15:49:48 +03:00
parent d4db87186a
commit 02435cb5a6
3 changed files with 149 additions and 24 deletions
+69 -12
View File
@@ -9,19 +9,33 @@ import subprocess
import tkinter as tk
from tkinter import ttk, messagebox
try:
from PIL import Image, ImageTk
HAS_PIL = True
except ImportError:
HAS_PIL = False
# ============================================================
# CONFIGURATION - edit these values for your game/project
# ============================================================
GAME_NAME = "My Game" # Shown in the window title
UPDATER_NAME = "Launcher" # Updater, Launcher, etc.
WINDOW_WIDTH = 450
WINDOW_HEIGHT = 280
WINDOW_HEIGHT = 300
# Banner image is scaled to exactly this size (pixels) regardless of the
# source file's actual dimensions, so the layout never shifts if someone
# drops in a differently-sized image. Keep this narrower than WINDOW_WIDTH
# and leave room for the controls below it.
BANNER_WIDTH = 430
BANNER_HEIGHT = 140
# Server address. Use either a domain or an IP - whichever you set SERVER_ADDRESS to.
# Examples: "update.mygame.com" or "123.456.78.90"
SERVER_ADDRESS = "update.mygame.com"
SERVER_PORT = "3232"
USE_HTTPS = False # Set True if your server is behind HTTPS/SSL
SERVER_ADDRESS = "example.com"
SERVER_PORT = "443" # 80/443 for HTTP/HTTPS or servcer port for direct ip
USE_HTTPS = True # Set True if your server is behind HTTPS/SSL
# Available client versions: display name -> access key.
# The access key is a long random hex string (generate with generate_key.py)
@@ -33,8 +47,8 @@ USE_HTTPS = False # Set True if your server is behind HTTPS
# generate a new one, update it here and in the server's config.json, and
# rebuild the exe - no need to rename anything else.
CLIENT_KEYS = {
"Main": "d5af3f9fd06b15fcfcd1e6204b10804edbb9936b094ece123ce38ee7d3382ee0",
"Test": "aa697a8988d49f161c9764c3bb54b9111ad016bca7470243ea3aa2ee4fba37c1",
"Main": "d5af3f9fd06b15fcfcd1e6204b10xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Test": "aa697a8988d49f161c9764c3bb54xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
DEFAULT_CLIENT = "Main"
@@ -78,7 +92,7 @@ def build_server_base_url():
class UpdaterApp:
def __init__(self, root):
self.root = root
self.root.title(f"{GAME_NAME} Updater")
self.root.title(f"{GAME_NAME} {UPDATER_NAME}")
self.root.geometry(f"{WINDOW_WIDTH}x{WINDOW_HEIGHT}")
self.root.resizable(False, False)
@@ -86,11 +100,15 @@ class UpdaterApp:
self.root.iconbitmap(ICON_FILE)
except Exception:
pass
try:
self.bg_image = tk.PhotoImage(file=BANNER_FILE)
self.bg_image = self._load_banner()
if self.bg_image is not None:
tk.Label(root, image=self.bg_image).pack(pady=5)
except Exception:
tk.Label(root, text="[ Banner not found ]", bg="gray", width=60, height=6).pack(pady=5)
else:
tk.Label(
root, text="[ Banner not found ]", bg="gray",
width=60, height=BANNER_HEIGHT // 20
).pack(pady=5)
# Client version selector
mode_frame = tk.Frame(root)
@@ -124,6 +142,45 @@ class UpdaterApp:
self.btn_play = tk.Button(btn_frame, text="Play", command=self.play_game, width=20, state=btn_state)
self.btn_play.pack(side="left", padx=10)
def _load_banner(self):
"""
Loads BANNER_FILE and scales it to exactly (BANNER_WIDTH, BANNER_HEIGHT).
Uses Pillow for proper resizing when available; falls back to
tk.PhotoImage's coarse integer zoom/subsample if Pillow isn't
installed, so the app still runs without the extra dependency.
Returns None if the banner file is missing or fails to load.
"""
if not os.path.exists(BANNER_FILE):
return None
if HAS_PIL:
try:
img = Image.open(BANNER_FILE).convert("RGBA")
img = img.resize((BANNER_WIDTH, BANNER_HEIGHT), Image.LANCZOS)
return ImageTk.PhotoImage(img)
except Exception:
return None
# Pillow not available: best-effort scaling with tk.PhotoImage.
# zoom/subsample only take integer factors, so this can't hit the
# target size exactly - it just gets as close as possible.
try:
image = tk.PhotoImage(file=BANNER_FILE)
src_w, src_h = image.width(), image.height()
if src_w <= 0 or src_h <= 0:
return image
if src_w > BANNER_WIDTH or src_h > BANNER_HEIGHT:
factor = max(1, round(max(src_w / BANNER_WIDTH, src_h / BANNER_HEIGHT)))
image = image.subsample(factor, factor)
elif src_w < BANNER_WIDTH and src_h < BANNER_HEIGHT:
factor = max(1, round(min(BANNER_WIDTH / src_w, BANNER_HEIGHT / src_h)))
image = image.zoom(factor, factor)
return image
except Exception:
return None
def update_ui(self, text=None, prog_val=None, prog_max=None):
if text: self.root.after(0, lambda: self.status_var.set(text))
if prog_max: self.root.after(0, lambda: self.progress.config(maximum=prog_max))
@@ -218,4 +275,4 @@ class UpdaterApp:
if __name__ == "__main__":
root = tk.Tk()
app = UpdaterApp(root)
root.mainloop()
root.mainloop()