Skip to content

Commit f564fea

Browse files
committed
improve app
1 parent 34b8fc8 commit f564fea

2 files changed

Lines changed: 90 additions & 11 deletions

File tree

build.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
import PyInstaller.__main__
22
import os
33
import shutil
4+
import zipfile
5+
6+
# Constants
7+
GAMES_DIR = "All Games Files"
8+
ZIP_NAME = "games_data.zip"
49

510
# Ensure dist/build directories are clean
611
if os.path.exists("dist"):
712
shutil.rmtree("dist")
813
if os.path.exists("build"):
914
shutil.rmtree("build")
1015

16+
# Create Zip archive to speed up startup (unpacking 28k files is slow)
17+
print(f"Creating {ZIP_NAME}...")
18+
with zipfile.ZipFile(ZIP_NAME, 'w', zipfile.ZIP_DEFLATED) as zipf:
19+
for root, dirs, files in os.walk(GAMES_DIR):
20+
for file in files:
21+
file_path = os.path.join(root, file)
22+
# Archive name should be relative to keep structure
23+
# We want them at root of zip so: 3800340.lua
24+
zipf.write(file_path, os.path.basename(file_path))
25+
# Note: The original code expected LUA_FILES_DIR to contain the files.
26+
# We are flattening it here or keeping structure?
27+
# Original structure: All Games Files/3800340.lua
28+
# If we flatten, extraction is simpler. Let's flatten.
29+
1130
print("Starting build process...")
1231

1332
PyInstaller.__main__.run([
@@ -17,7 +36,7 @@
1736
'--noconsole',
1837
'--clean',
1938
'--collect-all=ttkbootstrap', # Important for themes
20-
'--add-data=All Games Files;All Games Files', # Format: "source;dest" (Windows)
39+
'--add-data=games_data.zip;.', # Bundle the zip, not the folder
2140
'--add-data=logo.ico;.', # Bundle icon for runtime use
2241
'--icon=logo.ico' # Set EXE file icon
2342
])

main.py

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from tkinter import messagebox
77
import sys
88
import time
9+
import zipfile
10+
import tempfile
911

1012
try:
1113
import requests
@@ -32,13 +34,7 @@ def get_resource_path(relative_path):
3234
# The user's original path was absolute: r"d:\antigravity\luapatcher\All Games Files"
3335
# We need to switch logic: if bundled, use embedded; if source, use original known path OR relative.
3436

35-
if getattr(sys, 'frozen', False):
36-
# Running as compiled exe (bundled)
37-
LUA_FILES_DIR = get_resource_path("All Games Files")
38-
else:
39-
# Running as script (relative to script)
40-
LUA_FILES_DIR = get_resource_path("All Games Files")
41-
37+
# Constants
4238
STEAM_PLUGIN_DIR = r"C:\Program Files (x86)\Steam\config\stplug-in"
4339
STEAM_EXE_PATH = r"C:\Program Files (x86)\Steam\Steam.exe"
4440

@@ -60,6 +56,60 @@ def __init__(self, root):
6056
self.search_results = []
6157
self.debounce_timer = None
6258
self.current_search_id = 0
59+
self.lua_files_dir = None
60+
61+
# Start initialization
62+
self.start_initialization()
63+
64+
def start_initialization(self):
65+
self.patch_btn.config(state="disabled")
66+
self.search_entry.config(state="disabled")
67+
self.status_var.set("Initializing database... Please wait.")
68+
69+
# Show loading indicator (indeterminate progress)
70+
self.progress = ttk.Progressbar(self.root, mode='indeterminate')
71+
self.progress.pack(fill=X, side=BOTTOM,pady=5)
72+
self.progress.start(10)
73+
74+
threading.Thread(target=self.initialize_data, daemon=True).start()
75+
76+
def initialize_data(self):
77+
try:
78+
if getattr(sys, 'frozen', False):
79+
# Running as bundled exe
80+
zip_path = get_resource_path("games_data.zip")
81+
if os.path.exists(zip_path):
82+
# Extract to temp dir
83+
temp_dir = os.path.join(tempfile.gettempdir(), "SteamLuaPatcher_Cache")
84+
if not os.path.exists(temp_dir):
85+
os.makedirs(temp_dir)
86+
87+
# Check if already extracted (simple check, maybe file count or marker)
88+
# For now, just extract to be safe/update
89+
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
90+
zip_ref.extractall(temp_dir)
91+
92+
self.lua_files_dir = temp_dir
93+
else:
94+
# Fallback or error?
95+
self.lua_files_dir = get_resource_path("All Games Files")
96+
else:
97+
# Running as script
98+
self.lua_files_dir = get_resource_path("All Games Files")
99+
100+
self.root.after(0, self.on_init_complete)
101+
102+
except Exception as e:
103+
self.root.after(0, lambda: messagebox.showerror("Init Error", f"Failed to load data: {e}"))
104+
105+
def on_init_complete(self):
106+
self.progress.stop()
107+
self.progress.destroy()
108+
self.search_entry.config(state="normal")
109+
self.status_var.set("Ready to search")
110+
self.search_entry.focus_set()
111+
self.debounce_timer = None
112+
self.current_search_id = 0
63113

64114
def create_widgets(self):
65115
# Main Container with padding
@@ -113,6 +163,10 @@ def create_widgets(self):
113163
self.tree.pack(fill=BOTH, expand=True, side=LEFT)
114164
self.tree.bind("<<TreeviewSelect>>", self.on_select)
115165

166+
# Configure row colors for status
167+
self.tree.tag_configure("found", foreground="#00bc8c") # Success color (Green-ish)
168+
self.tree.tag_configure("missing", foreground="#e74c3c") # Danger color (Red)
169+
116170
# Actions Section
117171
actions_frame = ttk.Frame(main_container)
118172
actions_frame.pack(fill=X)
@@ -194,8 +248,11 @@ def update_results(self, items):
194248
appid = item.get("id")
195249

196250
# Check if lua file exists
197-
lua_path = os.path.join(LUA_FILES_DIR, f"{appid}.lua")
198-
exists = os.path.exists(lua_path)
251+
if self.lua_files_dir:
252+
lua_path = os.path.join(self.lua_files_dir, f"{appid}.lua")
253+
exists = os.path.exists(lua_path)
254+
else:
255+
exists = False
199256
status = "AVAILABLE" if exists else "Missing"
200257

201258
# Insert with tags for coloring
@@ -231,7 +288,10 @@ def patch_selected(self):
231288
name = item_values[0]
232289
appid = str(item_values[1])
233290

234-
src_file = os.path.join(LUA_FILES_DIR, f"{appid}.lua")
291+
if self.lua_files_dir:
292+
src_file = os.path.join(self.lua_files_dir, f"{appid}.lua")
293+
else:
294+
return # Should not happen if patch button is enabled
235295
dest_file = os.path.join(STEAM_PLUGIN_DIR, f"{appid}.lua")
236296

237297
try:

0 commit comments

Comments
 (0)