1- import os
21from functools import cmp_to_key
32from pathlib import Path
4- from typing import List , Tuple , cast
3+ from typing import cast
54
65from PyQt6 .QtCore import QDir , QFileInfo
76from PyQt6 .QtWidgets import QGridLayout , QWidget
@@ -124,26 +123,32 @@ def _parse_pak_files(self):
124123 pak_paths : dict [str , tuple [str , str ]] = {}
125124 pak_source : dict [str , str ] = {}
126125 existing_folders : set [int ] = set ()
127-
126+
128127 print (f"[PAK Debug] Starting scan of { len (mods )} mods" )
129- print (f "[PAK Debug] ONLY scanning ~mods directories, EXCLUDING LogicMods" )
130-
128+ print ("[PAK Debug] ONLY scanning ~mods directories, EXCLUDING LogicMods" )
129+
131130 # First, scan what numbered folders already exist to avoid double-assignment
132131 game = self ._organizer .managedGame ()
133132 if isinstance (game , S2HoCGame ):
134133 pak_mods_dir = QFileInfo (game .paksModsDirectory ().absolutePath ())
135134 if pak_mods_dir .exists () and pak_mods_dir .isDir ():
136- print (f"[PAK Debug] Scanning existing folders in: { pak_mods_dir .absoluteFilePath ()} " )
135+ print (
136+ f"[PAK Debug] Scanning existing folders in: { pak_mods_dir .absoluteFilePath ()} "
137+ )
137138 for entry in QDir (pak_mods_dir .absoluteFilePath ()).entryInfoList (
138139 QDir .Filter .Dirs | QDir .Filter .NoDotAndDotDot
139140 ):
140141 try :
141142 folder_num = int (entry .completeBaseName ())
142143 existing_folders .add (folder_num )
143- print (f"[PAK Debug] Found existing numbered folder: { folder_num } " )
144+ print (
145+ f"[PAK Debug] Found existing numbered folder: { folder_num } "
146+ )
144147 except ValueError :
145- print (f"[PAK Debug] Skipping non-numbered folder: { entry .completeBaseName ()} " )
146-
148+ print (
149+ f"[PAK Debug] Skipping non-numbered folder: { entry .completeBaseName ()} "
150+ )
151+
147152 # Scan mods for PAK files ONLY in Content/Paks/~mods structure (exclude LogicMods)
148153 for mod in mods :
149154 mod_item = self ._organizer .modList ().getMod (mod )
@@ -152,11 +157,13 @@ def _parse_pak_files(self):
152157 filetree = mod_item .fileTree ()
153158
154159 # If this mod contains a LogicMods directory, skip it entirely for the PAK tab
155- has_logicmods = (
156- filetree . find ( "Content/ Paks/LogicMods") or filetree . find ( "Paks/LogicMods" )
160+ has_logicmods = filetree . find ( "Content/Paks/LogicMods" ) or filetree . find (
161+ " Paks/LogicMods"
157162 )
158163 if isinstance (has_logicmods , mobase .IFileTree ):
159- print (f"[PAK Debug] Skipping mod '{ mod_item .name ()} ' because it contains a LogicMods directory." )
164+ print (
165+ f"[PAK Debug] Skipping mod '{ mod_item .name ()} ' because it contains a LogicMods directory."
166+ )
160167 continue
161168
162169 # ONLY look for ~mods directories
@@ -172,16 +179,22 @@ def _parse_pak_files(self):
172179 sub_entry .isFile ()
173180 and sub_entry .suffix ().casefold () == "pak"
174181 ):
175- pak_name = sub_entry .name ()[: - 1 - len (sub_entry .suffix ())]
182+ pak_name = sub_entry .name ()[
183+ : - 1 - len (sub_entry .suffix ())
184+ ]
176185 paks [pak_name ] = entry .name ()
177186 pak_paths [pak_name ] = (
178187 mod_item .absolutePath ()
179188 + "/"
180- + cast (mobase .IFileTree , sub_entry .parent ()).path ("/" ),
181- mod_item .absolutePath () + "/" + pak_mods .path ("/" )
189+ + cast (mobase .IFileTree , sub_entry .parent ()).path (
190+ "/"
191+ ),
192+ mod_item .absolutePath () + "/" + pak_mods .path ("/" ),
182193 )
183194 pak_source [pak_name ] = mod_item .name ()
184- print (f"[PAK Debug] ✅ Added PAK from ~mods numbered folder: { pak_name } in { entry .name ()} " )
195+ print (
196+ f"[PAK Debug] ✅ Added PAK from ~mods numbered folder: { pak_name } in { entry .name ()} "
197+ )
185198 else :
186199 if entry .suffix ().casefold () == "pak" :
187200 pak_name = entry .name ()[: - 1 - len (entry .suffix ())]
@@ -190,36 +203,40 @@ def _parse_pak_files(self):
190203 mod_item .absolutePath ()
191204 + "/"
192205 + cast (mobase .IFileTree , entry .parent ()).path ("/" ),
193- mod_item .absolutePath () + "/" + pak_mods .path ("/" )
206+ mod_item .absolutePath () + "/" + pak_mods .path ("/" ),
194207 )
195208 pak_source [pak_name ] = mod_item .name ()
196- print (f"[PAK Debug] ✅ Added loose PAK from ~mods: { pak_name } " )
209+ print (
210+ f"[PAK Debug] ✅ Added loose PAK from ~mods: { pak_name } "
211+ )
197212 else :
198213 # Check if this mod has LogicMods (for debugging purposes)
199214 logic_mods = filetree .find ("Content/Paks/LogicMods" )
200215 if not logic_mods :
201216 logic_mods = filetree .find ("Paks/LogicMods" )
202217 if isinstance (logic_mods , mobase .IFileTree ):
203- print (f"[PAK Debug] Mod { mod_item .name ()} has LogicMods (not included in PAK tab)" )
218+ print (
219+ f"[PAK Debug] Mod { mod_item .name ()} has LogicMods (not included in PAK tab)"
220+ )
204221
205222 # NOTE: Removed game directory scanning to prevent LogicMods PAKs from appearing
206223 # We only want PAKs from mod files, not from game directory
207- print (f "[PAK Debug] Skipping game directory scan to prevent LogicMods inclusion" )
224+ print ("[PAK Debug] Skipping game directory scan to prevent LogicMods inclusion" )
208225
209226 # Sort PAKs and shake them (preserve order from paks.txt if it exists)
210227 sorted_paks = dict (sorted (paks .items (), key = cmp_to_key (pak_sort )))
211228 shaken_paks : list [str ] = self ._shake_paks (sorted_paks )
212-
229+
213230 # Assign target directories with numbered folders (like Oblivion Remastered)
214231 # Skip numbers that already exist, use next available number starting from 8999
215232 final_paks : dict [str , tuple [str , str , str ]] = {}
216233 pak_index = 8999
217-
234+
218235 for pak in shaken_paks :
219236 # Find next available number (skip existing folders)
220237 while pak_index in existing_folders :
221238 pak_index -= 1
222-
239+
223240 # If PAK is already in a numbered folder, keep its current assignment
224241 current_folder = paks [pak ]
225242 if current_folder .isdigit ():
@@ -232,16 +249,16 @@ def _parse_pak_files(self):
232249 existing_folders .add (pak_index )
233250 print (f"[PAK Debug] Assigning { pak } to new folder { pak_index } " )
234251 pak_index -= 1
235-
252+
236253 final_paks [pak ] = (pak_source [pak ], pak_paths [pak ][0 ], target_dir )
237-
254+
238255 # Convert to model format (4-tuple matching Oblivion Remastered)
239256 new_data_paks : dict [int , tuple [str , str , str , str ]] = {}
240257 i = 0
241258 for pak , data in final_paks .items ():
242259 source , current_path , target_path = data
243260 new_data_paks [i ] = (pak , source , current_path , target_path )
244261 i += 1
245-
262+
246263 print (f"[PAK Debug] Final PAK count: { len (new_data_paks )} " )
247264 self ._model .set_paks (new_data_paks )
0 commit comments