66from tkinter import messagebox
77import sys
88import time
9+ import zipfile
10+ import tempfile
911
1012try :
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
4238STEAM_PLUGIN_DIR = r"C:\Program Files (x86)\Steam\config\stplug-in"
4339STEAM_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