Skip to content

Commit 060b3ff

Browse files
committed
fixing lint for stalker 2 pak tab game support
1 parent 79e10f4 commit 060b3ff

1 file changed

Lines changed: 66 additions & 77 deletions

File tree

games/game_stalker2heartofchornobyl.py

Lines changed: 66 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ class Problems(IntEnum):
1515
"""
1616
Enums for IPluginDiagnose.
1717
"""
18-
<<<<<<< HEAD
19-
=======
2018

21-
# PAK files placed in incorrect locations
22-
>>>>>>> ab91432d429d5ec75630e299423146320437832d
2319
MISPLACED_PAK_FILES = auto()
2420
MISSING_MOD_DIRECTORIES = auto()
2521

@@ -56,15 +52,17 @@ def __init__(self):
5652

5753
def resolve_path(self, path: str) -> str:
5854
path = path.replace("%USERPROFILE%", os.environ.get("USERPROFILE", ""))
59-
55+
6056
if "%GAME_DOCUMENTS%" in path:
61-
game_docs = self.GameDocumentsDirectory.replace("%USERPROFILE%", os.environ.get("USERPROFILE", ""))
57+
game_docs = self.GameDocumentsDirectory.replace(
58+
"%USERPROFILE%", os.environ.get("USERPROFILE", "")
59+
)
6260
path = path.replace("%GAME_DOCUMENTS%", game_docs)
63-
61+
6462
if "%GAME_PATH%" in path:
65-
game_path = self._gamePath if hasattr(self, '_gamePath') else ""
63+
game_path = self._gamePath if hasattr(self, "_gamePath") else ""
6664
path = path.replace("%GAME_PATH%", game_path)
67-
65+
6866
return path
6967

7068
def init(self, organizer: mobase.IOrganizer) -> bool:
@@ -73,12 +71,7 @@ def init(self, organizer: mobase.IOrganizer) -> bool:
7371
self._register_feature(
7472
BasicLocalSavegames(QDir(self.resolve_path(self.GameSavesDirectory)))
7573
)
76-
<<<<<<< HEAD
77-
78-
=======
7974

80-
# Create the directory more reliably
81-
>>>>>>> ab91432d429d5ec75630e299423146320437832d
8275
if (
8376
self._organizer.managedGame()
8477
and self._organizer.managedGame().gameName() == self.gameName()
@@ -87,21 +80,21 @@ def init(self, organizer: mobase.IOrganizer) -> bool:
8780
try:
8881
os.makedirs(mod_path, exist_ok=True)
8982
if not os.path.exists(mod_path):
90-
self._organizer.log(mobase.LogLevel.WARNING, f"Failed to create directory: {mod_path}")
83+
self._organizer.log(
84+
mobase.LogLevel.WARNING,
85+
f"Failed to create directory: {mod_path}",
86+
)
9187
except OSError as e:
92-
self._organizer.log(mobase.LogLevel.ERROR, f"OS error creating mod directory: {e}")
88+
self._organizer.log(
89+
mobase.LogLevel.ERROR, f"OS error creating mod directory: {e}"
90+
)
9391
except Exception as e:
94-
<<<<<<< HEAD
95-
self._organizer.log(mobase.LogLevel.ERROR, f"Unexpected error creating mod directory: {e}")
96-
97-
organizer.onUserInterfaceInitialized(self.init_tab)
98-
=======
99-
print(f"Error creating mod directory: {e}")
92+
self._organizer.log(
93+
mobase.LogLevel.ERROR,
94+
f"Unexpected error creating mod directory: {e}",
95+
)
10096

101-
# Initialize PAK tab when UI is ready
10297
organizer.onUserInterfaceInitialized(self.init_tab)
103-
104-
>>>>>>> ab91432d429d5ec75630e299423146320437832d
10598
return True
10699

107100
def init_tab(self, main_window: QMainWindow):
@@ -115,7 +108,9 @@ def init_tab(self, main_window: QMainWindow):
115108
self._main_window = main_window
116109
tab_widget: QTabWidget = main_window.findChild(QTabWidget, "tabWidget")
117110
if not tab_widget:
118-
self._organizer.log(mobase.LogLevel.WARNING, "No main tab widget found!")
111+
self._organizer.log(
112+
mobase.LogLevel.WARNING, "No main tab widget found!"
113+
)
119114
return
120115

121116
from .stalker2heartofchornobyl.paks import S2HoCPaksTabWidget
@@ -125,71 +120,75 @@ def init_tab(self, main_window: QMainWindow):
125120
tab_widget.addTab(self._paks_tab, "PAK Files")
126121
self._organizer.log(mobase.LogLevel.INFO, "PAK Files tab added!")
127122
except ImportError as e:
128-
self._organizer.log(mobase.LogLevel.ERROR, f"Failed to import PAK tab widget: {e}")
123+
self._organizer.log(
124+
mobase.LogLevel.ERROR, f"Failed to import PAK tab widget: {e}"
125+
)
129126
except Exception as e:
130-
self._organizer.log(mobase.LogLevel.ERROR, f"Error initializing PAK tab: {e}")
127+
self._organizer.log(
128+
mobase.LogLevel.ERROR, f"Error initializing PAK tab: {e}"
129+
)
131130
import traceback
132131

133132
traceback.print_exc()
134133

135134
def mappings(self) -> List[mobase.Mapping]:
136135
pak_extensions = ["*.pak", "*.utoc", "*.ucas"]
137136
target_dir = "Content/Paks/~mods/"
138-
137+
139138
mappings = []
140-
139+
141140
for ext in pak_extensions:
142141
mappings.append(mobase.Mapping(ext, target_dir, False))
143-
142+
144143
source_dirs = ["Paks/", "~mods/", "Content/Paks/~mods/"]
145144
for source_dir in source_dirs:
146145
for ext in pak_extensions:
147146
mappings.append(mobase.Mapping(f"{source_dir}{ext}", target_dir, False))
148-
147+
149148
return mappings
150149

151150
def gameDirectory(self) -> QDir:
152151
return QDir(self._gamePath)
153152

154153
def paksDirectory(self) -> QDir:
155-
<<<<<<< HEAD
156-
path = os.path.join(self.gameDirectory().absolutePath(), self.GameDataPath, "Content", "Paks")
154+
path = os.path.join(
155+
self.gameDirectory().absolutePath(), self.GameDataPath, "Content", "Paks"
156+
)
157157
return QDir(path)
158-
158+
159159
def paksModsDirectory(self) -> QDir:
160160
try:
161161
path = os.path.join(self.paksDirectory().absolutePath(), "~mods")
162162
return QDir(path)
163-
except Exception as e:
164-
fallback = os.path.join(self.gameDirectory().absolutePath(), self.GameDataPath, "Content", "Paks", "~mods")
163+
except Exception:
164+
fallback = os.path.join(
165+
self.gameDirectory().absolutePath(),
166+
self.GameDataPath,
167+
"Content",
168+
"Paks",
169+
"~mods",
170+
)
165171
return QDir(fallback)
166-
167-
def logicModsDirectory(self) -> QDir:
168-
path = os.path.join(self.gameDirectory().absolutePath(), self.GameDataPath, "Content", "Paks", "LogicMods")
169-
return QDir(path)
170-
171-
def binariesDirectory(self) -> QDir:
172-
path = os.path.join(self.gameDirectory().absolutePath(), self.GameDataPath, "Binaries", "Win64")
173-
return QDir(path)
174-
175-
=======
176-
return QDir(self.gameDirectory().absolutePath() + "/Stalker2/Content/Paks")
177-
178-
def paksModsDirectory(self) -> QDir:
179-
# Use os.path.join for more reliable path construction
180-
path = os.path.join(self.paksDirectory().absolutePath(), "~mods")
181-
return QDir(path)
182172

183173
def logicModsDirectory(self) -> QDir:
184-
# Update path to place LogicMods under Paks
185-
return QDir(
186-
self.gameDirectory().absolutePath() + "/Stalker2/Content/Paks/LogicMods"
174+
path = os.path.join(
175+
self.gameDirectory().absolutePath(),
176+
self.GameDataPath,
177+
"Content",
178+
"Paks",
179+
"LogicMods",
187180
)
181+
return QDir(path)
188182

189183
def binariesDirectory(self) -> QDir:
190-
return QDir(self.gameDirectory().absolutePath() + "/Stalker2/Binaries/Win64")
184+
path = os.path.join(
185+
self.gameDirectory().absolutePath(),
186+
self.GameDataPath,
187+
"Binaries",
188+
"Win64",
189+
)
190+
return QDir(path)
191191

192-
>>>>>>> ab91432d429d5ec75630e299423146320437832d
193192
def getModMappings(self) -> dict[str, list[str]]:
194193
return {
195194
"Content/Paks/~mods": [self.paksModsDirectory().absolutePath()],
@@ -198,31 +197,17 @@ def getModMappings(self) -> dict[str, list[str]]:
198197
def activeProblems(self) -> list[int]:
199198
problems = set()
200199
if self._organizer.managedGame() == self:
201-
<<<<<<< HEAD
202-
203-
mod_path = self.paksModsDirectory().absolutePath()
204-
if not os.path.isdir(mod_path):
205-
problems.add(Problems.MISSING_MOD_DIRECTORIES)
206-
self._organizer.log(mobase.LogLevel.DEBUG, f"Missing mod directory: {mod_path}")
207-
208-
for mod in self._organizer.modList().allMods():
209-
mod_info = self._organizer.modList().getMod(mod)
210-
filetree = mod_info.fileTree()
211-
212-
=======
213-
# More reliable directory check using os.path
214200
mod_path = self.paksModsDirectory().absolutePath()
215201
if not os.path.isdir(mod_path):
216202
problems.add(Problems.MISSING_MOD_DIRECTORIES)
217-
print(f"Missing mod directory: {mod_path}")
203+
self._organizer.log(
204+
mobase.LogLevel.DEBUG, f"Missing mod directory: {mod_path}"
205+
)
218206

219-
# Check for misplaced PAK files
220207
for mod in self._organizer.modList().allMods():
221208
mod_info = self._organizer.modList().getMod(mod)
222209
filetree = mod_info.fileTree()
223210

224-
# Check for PAK files at the root level (remove LogicMods paths)
225-
>>>>>>> ab91432d429d5ec75630e299423146320437832d
226211
for entry in filetree:
227212
if entry.name().endswith((".pak", ".utoc", ".ucas")) and not any(
228213
entry.path().startswith(p)
@@ -275,9 +260,13 @@ def startGuidedFix(self, key: int) -> None:
275260
case Problems.MISSING_MOD_DIRECTORIES:
276261
try:
277262
os.makedirs(self.paksModsDirectory().absolutePath(), exist_ok=True)
278-
self._organizer.log(mobase.LogLevel.INFO, "Created missing mod directories")
263+
self._organizer.log(
264+
mobase.LogLevel.INFO, "Created missing mod directories"
265+
)
279266
except Exception as e:
280-
self._organizer.log(mobase.LogLevel.ERROR, f"Failed to create mod directories: {e}")
267+
self._organizer.log(
268+
mobase.LogLevel.ERROR, f"Failed to create mod directories: {e}"
269+
)
281270
case _:
282271
pass
283272

0 commit comments

Comments
 (0)