Skip to content

Commit 19b1ee1

Browse files
committed
Cleanup and fixes.
1 parent b8c6e50 commit 19b1ee1

3 files changed

Lines changed: 196 additions & 230 deletions

File tree

games/game_payday1.py

Lines changed: 71 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def getContentsFor(self, filetree: mobase.IFileTree) -> list[int]:
8686

8787

8888
class ModDetectionCandidate(TypedDict):
89-
tree: mobase.IFileTree
89+
tree: mobase.IFileTree | mobase.FileTreeEntry
9090
name: str
9191
display: str
9292
destination: str
@@ -216,24 +216,17 @@ def addModDetectionCandidate(
216216
category: str,
217217
destination: str,
218218
) -> None:
219-
debug_name = name or tree.name()
220-
debug_path = ""
221-
if hasattr(tree, "path"):
222-
try:
223-
debug_path = tree.path()
224-
except Exception:
225-
debug_path = ""
226-
if not debug_path and hasattr(tree, "name"):
227-
debug_path = tree.name()
219+
tree_name = tree.name()
220+
tree_path = tree.path()
228221

229222
print(
230-
f"[Payday1ModDataChecker] Detected mod candidate: {debug_name} | "
231-
f"path={debug_path} | category={category} | destination={destination}"
223+
f"Detected mod candidate: {tree_name} | "
224+
f"path={tree_path} | category={category} | destination={destination}"
232225
)
233226
self.modDetectionCandidates.append(
234227
{
235228
"tree": tree,
236-
"name": name,
229+
"name": tree_name,
237230
"display": f"{name} ({category})",
238231
"destination": destination,
239232
}
@@ -283,72 +276,73 @@ def showModDetectionDialog(self) -> set[int] | None:
283276
def collectModCandidates(
284277
self, tree: mobase.IFileTree | mobase.FileTreeEntry
285278
) -> bool:
286-
hasDisallowedPath = False
287-
disallowedFolders = {"assets", "levels", "lua"}
288-
tree_path = tree.path()
289-
tree_path_lower = (
290-
tree_path.replace("\\", "/").casefold()
291-
if isinstance(tree_path, str)
292-
else ""
293-
)
294-
if disallowedFolders & set(tree_path_lower.split("/")):
295-
hasDisallowedPath = True
296-
hasFolderListSubfolder = any(
297-
tree.exists(validFolder, mobase.IFileTree.DIRECTORY)
298-
for validFolder in self.folderList
299-
)
300-
if tree.exists("mod.txt", mobase.IFileTree.FILE) and not hasFolderListSubfolder:
301-
self.addModDetectionCandidate(
302-
tree,
303-
sanitize_folder_name(tree.name()),
304-
"Mods Folder with mod.txt",
305-
"mods/FOLDERNAME/",
306-
)
307-
return True
308-
elif (
309-
tree.exists("main.xml", mobase.IFileTree.FILE)
310-
and tree.exists("levels", mobase.IFileTree.DIRECTORY)
311-
and not hasDisallowedPath
312-
):
313-
self.addModDetectionCandidate(
314-
tree,
315-
sanitize_folder_name(tree.name()),
316-
"Maps Folder with main.xml and levels folder",
317-
"maps/FOLDERNAME/",
279+
if isinstance(tree, mobase.IFileTree):
280+
hasDisallowedPath = False
281+
disallowedFolders = {"assets", "levels", "lua", "map_replacements"}
282+
tree_path = tree.path()
283+
tree_path_lower = tree_path.replace("\\", "/").casefold()
284+
if disallowedFolders & set(tree_path_lower.split("/")):
285+
hasDisallowedPath = True
286+
hasFolderListSubfolder = any(
287+
tree.exists(validFolder, mobase.IFileTree.DIRECTORY)
288+
for validFolder in self.folderList
318289
)
319-
return True
320-
elif (
321-
tree.exists("main.xml", mobase.IFileTree.FILE)
322-
or tree.exists("add.xml", mobase.IFileTree.FILE)
323-
and not hasDisallowedPath
324-
):
325-
self.addModDetectionCandidate(
326-
tree,
327-
sanitize_folder_name(tree.name()),
328-
"Mod Override Folder with main.xml/add.xml",
329-
"assets/mod_overrides/FOLDERNAME/",
330-
)
331-
return True
332-
elif tree.exists("mod_overrides", mobase.IFileTree.DIRECTORY):
333-
sourcetree = tree.find("mod_overrides", mobase.IFileTree.DIRECTORY)
334-
if isinstance(sourcetree, mobase.IFileTree):
290+
if (
291+
tree.exists("mod.txt", mobase.IFileTree.FILE)
292+
and not hasFolderListSubfolder
293+
):
294+
self.addModDetectionCandidate(
295+
tree,
296+
sanitize_folder_name(tree.name()),
297+
"Mods Folder with mod.txt",
298+
"mods/FOLDERNAME/",
299+
)
300+
return True
301+
elif (
302+
tree.exists("main.xml", mobase.IFileTree.FILE)
303+
and tree.exists("levels", mobase.IFileTree.DIRECTORY)
304+
and not hasDisallowedPath
305+
):
335306
self.addModDetectionCandidate(
336-
sourcetree,
337-
sanitize_folder_name(sourcetree.name()),
338-
"Mod Override Folder",
339-
"assets/mod_overrides/FOLDERNAME/",
307+
tree,
308+
sanitize_folder_name(tree.name()),
309+
"Maps Folder with main.xml and levels folder",
310+
"maps/FOLDERNAME/",
340311
)
341312
return True
342-
elif not hasDisallowedPath:
343-
for validFolder in self.folderList:
344-
if tree.exists(validFolder, mobase.IFileTree.DIRECTORY):
313+
elif (
314+
tree.exists("main.xml", mobase.IFileTree.FILE)
315+
or tree.exists("add.xml", mobase.IFileTree.FILE)
316+
or tree.exists("supermod.xml", mobase.IFileTree.FILE)
317+
):
318+
if not hasDisallowedPath:
345319
self.addModDetectionCandidate(
346320
tree,
347321
sanitize_folder_name(tree.name()),
348-
"Fallback Mod Override Folder",
322+
"Mod Override Folder with main.xml/add.xml",
349323
"assets/mod_overrides/FOLDERNAME/",
350324
)
351325
return True
326+
elif tree.exists("mod_overrides", mobase.IFileTree.DIRECTORY):
327+
sourcetree = tree.find("mod_overrides", mobase.IFileTree.DIRECTORY)
328+
if isinstance(sourcetree, mobase.IFileTree):
329+
self.addModDetectionCandidate(
330+
sourcetree,
331+
sanitize_folder_name(sourcetree.name()),
332+
"Mod Override Folder",
333+
"assets/mod_overrides/FOLDERNAME/",
334+
)
335+
return True
336+
elif not hasDisallowedPath:
337+
for validFolder in self.folderList:
338+
if tree.exists(validFolder, mobase.IFileTree.DIRECTORY):
339+
self.addModDetectionCandidate(
340+
tree,
341+
sanitize_folder_name(tree.name()),
342+
"Fallback Mod Override Folder",
343+
"assets/mod_overrides/FOLDERNAME/",
344+
)
345+
return True
352346
return False
353347

354348
def walk_entry(self, path: str, entry: mobase.FileTreeEntry):
@@ -376,11 +370,14 @@ def fix(self, filetree: mobase.IFileTree) -> mobase.IFileTree | None:
376370
"FOLDERNAME",
377371
candidate["name"],
378372
)
379-
print(f"Installing Mod: {candidate['name']} to {candidate['destination']}")
380-
if self.moveTreeContent(
381-
candidate["tree"], newtree, candidate["destination"]
382-
):
383-
self.needsNameFix = True
373+
if isinstance(candidate["tree"], mobase.IFileTree):
374+
print(
375+
f"Installing Mod: {candidate['name']} to {candidate['destination']}"
376+
)
377+
if self.moveTreeContent(
378+
candidate["tree"], newtree, candidate["destination"]
379+
):
380+
self.needsNameFix = True
384381

385382
return newtree if len(newtree) > 0 else filetree
386383

games/game_payday2.py

Lines changed: 71 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def getContentsFor(self, filetree: mobase.IFileTree) -> list[int]:
8686

8787

8888
class ModDetectionCandidate(TypedDict):
89-
tree: mobase.IFileTree
89+
tree: mobase.IFileTree | mobase.FileTreeEntry
9090
name: str
9191
display: str
9292
destination: str
@@ -216,24 +216,17 @@ def addModDetectionCandidate(
216216
category: str,
217217
destination: str,
218218
) -> None:
219-
debug_name = name or tree.name()
220-
debug_path = ""
221-
if hasattr(tree, "path"):
222-
try:
223-
debug_path = tree.path()
224-
except Exception:
225-
debug_path = ""
226-
if not debug_path and hasattr(tree, "name"):
227-
debug_path = tree.name()
219+
tree_name = tree.name()
220+
tree_path = tree.path()
228221

229222
print(
230-
f"[Payday2ModDataChecker] Detected mod candidate: {debug_name} | "
231-
f"path={debug_path} | category={category} | destination={destination}"
223+
f"Detected mod candidate: {tree_name} | "
224+
f"path={tree_path} | category={category} | destination={destination}"
232225
)
233226
self.modDetectionCandidates.append(
234227
{
235228
"tree": tree,
236-
"name": name,
229+
"name": tree_name,
237230
"display": f"{name} ({category})",
238231
"destination": destination,
239232
}
@@ -283,72 +276,73 @@ def showModDetectionDialog(self) -> set[int] | None:
283276
def collectModCandidates(
284277
self, tree: mobase.IFileTree | mobase.FileTreeEntry
285278
) -> bool:
286-
hasDisallowedPath = False
287-
disallowedFolders = {"assets", "levels", "lua"}
288-
tree_path = tree.path()
289-
tree_path_lower = (
290-
tree_path.replace("\\", "/").casefold()
291-
if isinstance(tree_path, str)
292-
else ""
293-
)
294-
if disallowedFolders & set(tree_path_lower.split("/")):
295-
hasDisallowedPath = True
296-
hasFolderListSubfolder = any(
297-
tree.exists(validFolder, mobase.IFileTree.DIRECTORY)
298-
for validFolder in self.folderList
299-
)
300-
if tree.exists("mod.txt", mobase.IFileTree.FILE) and not hasFolderListSubfolder:
301-
self.addModDetectionCandidate(
302-
tree,
303-
sanitize_folder_name(tree.name()),
304-
"Mods Folder with mod.txt",
305-
"mods/FOLDERNAME/",
306-
)
307-
return True
308-
elif (
309-
tree.exists("main.xml", mobase.IFileTree.FILE)
310-
and tree.exists("levels", mobase.IFileTree.DIRECTORY)
311-
and not hasDisallowedPath
312-
):
313-
self.addModDetectionCandidate(
314-
tree,
315-
sanitize_folder_name(tree.name()),
316-
"Maps Folder with main.xml and levels folder",
317-
"maps/FOLDERNAME/",
279+
if isinstance(tree, mobase.IFileTree):
280+
hasDisallowedPath = False
281+
disallowedFolders = {"assets", "levels", "lua", "map_replacements"}
282+
tree_path = tree.path()
283+
tree_path_lower = tree_path.replace("\\", "/").casefold()
284+
if disallowedFolders & set(tree_path_lower.split("/")):
285+
hasDisallowedPath = True
286+
hasFolderListSubfolder = any(
287+
tree.exists(validFolder, mobase.IFileTree.DIRECTORY)
288+
for validFolder in self.folderList
318289
)
319-
return True
320-
elif (
321-
tree.exists("main.xml", mobase.IFileTree.FILE)
322-
or tree.exists("add.xml", mobase.IFileTree.FILE)
323-
and not hasDisallowedPath
324-
):
325-
self.addModDetectionCandidate(
326-
tree,
327-
sanitize_folder_name(tree.name()),
328-
"Mod Override Folder with main.xml/add.xml",
329-
"assets/mod_overrides/FOLDERNAME/",
330-
)
331-
return True
332-
elif tree.exists("mod_overrides", mobase.IFileTree.DIRECTORY):
333-
sourcetree = tree.find("mod_overrides", mobase.IFileTree.DIRECTORY)
334-
if isinstance(sourcetree, mobase.IFileTree):
290+
if (
291+
tree.exists("mod.txt", mobase.IFileTree.FILE)
292+
and not hasFolderListSubfolder
293+
):
335294
self.addModDetectionCandidate(
336-
sourcetree,
337-
sanitize_folder_name(sourcetree.name()),
338-
"Mod Override Folder",
339-
"assets/mod_overrides/FOLDERNAME/",
295+
tree,
296+
sanitize_folder_name(tree.name()),
297+
"Mods Folder with mod.txt",
298+
"mods/FOLDERNAME/",
340299
)
341300
return True
342-
elif not hasDisallowedPath:
343-
for validFolder in self.folderList:
344-
if tree.exists(validFolder, mobase.IFileTree.DIRECTORY):
301+
elif (
302+
tree.exists("main.xml", mobase.IFileTree.FILE)
303+
and tree.exists("levels", mobase.IFileTree.DIRECTORY)
304+
and not hasDisallowedPath
305+
):
306+
self.addModDetectionCandidate(
307+
tree,
308+
sanitize_folder_name(tree.name()),
309+
"Maps Folder with main.xml and levels folder",
310+
"maps/FOLDERNAME/",
311+
)
312+
return True
313+
elif (
314+
tree.exists("main.xml", mobase.IFileTree.FILE)
315+
or tree.exists("add.xml", mobase.IFileTree.FILE)
316+
or tree.exists("supermod.xml", mobase.IFileTree.FILE)
317+
):
318+
if not hasDisallowedPath:
345319
self.addModDetectionCandidate(
346320
tree,
347321
sanitize_folder_name(tree.name()),
348-
"Fallback Mod Override Folder",
322+
"Mod Override Folder with main.xml/add.xml",
349323
"assets/mod_overrides/FOLDERNAME/",
350324
)
351325
return True
326+
elif tree.exists("mod_overrides", mobase.IFileTree.DIRECTORY):
327+
sourcetree = tree.find("mod_overrides", mobase.IFileTree.DIRECTORY)
328+
if isinstance(sourcetree, mobase.IFileTree):
329+
self.addModDetectionCandidate(
330+
sourcetree,
331+
sanitize_folder_name(sourcetree.name()),
332+
"Mod Override Folder",
333+
"assets/mod_overrides/FOLDERNAME/",
334+
)
335+
return True
336+
elif not hasDisallowedPath:
337+
for validFolder in self.folderList:
338+
if tree.exists(validFolder, mobase.IFileTree.DIRECTORY):
339+
self.addModDetectionCandidate(
340+
tree,
341+
sanitize_folder_name(tree.name()),
342+
"Fallback Mod Override Folder",
343+
"assets/mod_overrides/FOLDERNAME/",
344+
)
345+
return True
352346
return False
353347

354348
def walk_entry(self, path: str, entry: mobase.FileTreeEntry):
@@ -376,14 +370,14 @@ def fix(self, filetree: mobase.IFileTree) -> mobase.IFileTree | None:
376370
"FOLDERNAME",
377371
candidate["name"],
378372
)
379-
print(
380-
f"[Payday2ModDataChecker] Installing candidate: {candidate['name']} "
381-
f"to {candidate['destination']}"
382-
)
383-
if self.moveTreeContent(
384-
candidate["tree"], newtree, candidate["destination"]
385-
):
386-
self.needsNameFix = True
373+
if isinstance(candidate["tree"], mobase.IFileTree):
374+
print(
375+
f"Installing Mod: {candidate['name']} to {candidate['destination']}"
376+
)
377+
if self.moveTreeContent(
378+
candidate["tree"], newtree, candidate["destination"]
379+
):
380+
self.needsNameFix = True
387381

388382
return newtree if len(newtree) > 0 else filetree
389383

0 commit comments

Comments
 (0)