Skip to content

Commit a46b9e4

Browse files
committed
Pak fixes
- Revise directory cleaning after refactor - Implement paks.txt load order cache
1 parent 6447d3c commit a46b9e4

File tree

3 files changed

+54
-25
lines changed

3 files changed

+54
-25
lines changed

games/game_oblivion_remaster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class OblivionRemasteredGame(
5959
Name = PLUGIN_NAME
6060
Author = "Silarn"
6161
Version = "0.1.0-b.1"
62-
Description = "TES IV: Oblivion Remastered; an unholy hybrid of Gamebryo and Unreal"
62+
Description = "TES IV: Oblivion Remastered; an unholy hybrid of Bethesda and Unreal"
6363

6464
GameName = "Oblivion Remastered"
6565
GameShortName = "oblivionremastered"

games/oblivion_remaster/paks/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class PaksColumns(IntEnum):
3131
class PaksModel(QAbstractItemModel):
3232
def __init__(self, parent: QWidget | None, organizer: mobase.IOrganizer):
3333
super().__init__(parent)
34-
self.paks: dict[int, tuple[str, str, str, str]] = {}
34+
self.paks: dict[int, _PakInfo] = {}
3535
self._organizer = organizer
3636
self._init_mod_states()
3737

@@ -45,7 +45,7 @@ def _init_mod_states(self):
4545
self.paks[index] = (line, "", "", "")
4646
index += 1
4747

48-
def set_paks(self, paks: dict[int, tuple[str, str, str, str]]):
48+
def set_paks(self, paks: dict[int, _PakInfo]):
4949
self.layoutAboutToBeChanged.emit()
5050
self.paks = paks
5151
self.layoutChanged.emit()

games/oblivion_remaster/paks/widget.py

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import mobase
1010

1111
from ....basic_features.utils import is_directory
12-
from .model import PaksModel
12+
from .model import PaksModel, _PakInfo
1313
from .view import PaksView
1414

1515

@@ -48,6 +48,16 @@ def __init__(self, parent: QWidget | None, organizer: mobase.IOrganizer):
4848
organizer.modList().onModStateChanged(lambda mods: self._parse_pak_files())
4949
self._parse_pak_files()
5050

51+
def load_paks_list(self) -> list[str]:
52+
profile = QDir(self._organizer.profilePath())
53+
paks_txt = QFileInfo(profile.absoluteFilePath("paks.txt"))
54+
paks_list: list[str] = []
55+
if paks_txt.exists():
56+
with open(paks_txt.absoluteFilePath(), "r") as paks_file:
57+
for line in paks_file:
58+
paks_list.append(line.strip())
59+
return paks_list
60+
5161
def write_paks_list(self):
5262
profile = QDir(self._organizer.profilePath())
5363
paks_txt = QFileInfo(profile.absoluteFilePath("paks.txt"))
@@ -91,8 +101,29 @@ def write_pak_files(self):
91101
data[3],
92102
)
93103
break
94-
if not list(path_dir.iterdir()):
95-
path_dir.unlink()
104+
if not list(path_dir.iterdir()):
105+
path_dir.rmdir()
106+
107+
def _shake_paks(self, sorted_paks: dict[str, str]) -> list[str]:
108+
shaken_paks: list[str] = []
109+
shaken_paks_p: list[str] = []
110+
paks_list = self.load_paks_list()
111+
qDebug("Read paks...")
112+
for pak in paks_list:
113+
qDebug(pak)
114+
for pak in paks_list:
115+
if pak in sorted_paks.keys():
116+
if pak.casefold().endswith("_p"):
117+
shaken_paks_p.append(pak)
118+
else:
119+
shaken_paks.append(pak)
120+
sorted_paks.pop(pak)
121+
for pak in sorted_paks.keys():
122+
if pak.casefold().endswith("_p"):
123+
shaken_paks_p.append(pak)
124+
else:
125+
shaken_paks.append(pak)
126+
return shaken_paks + shaken_paks_p
96127

97128
def _parse_pak_files(self):
98129
from ...game_oblivion_remaster import OblivionRemasteredGame
@@ -155,7 +186,7 @@ def _parse_pak_files(self):
155186
QDir.Filter.Dirs | QDir.Filter.Files | QDir.Filter.NoDotAndDotDot
156187
):
157188
if entry.isDir():
158-
if entry.baseName().casefold() == "magicloader":
189+
if entry.completeBaseName().casefold() == "magicloader":
159190
continue
160191
for sub_entry in QDir(entry.absoluteFilePath()).entryInfoList(
161192
QDir.Filter.Files
@@ -164,42 +195,40 @@ def _parse_pak_files(self):
164195
sub_entry.isFile()
165196
and sub_entry.suffix().casefold() == "pak"
166197
):
167-
paks[sub_entry.baseName()] = entry.baseName()
168-
pak_paths[sub_entry.baseName()] = (
198+
paks[sub_entry.completeBaseName()] = (
199+
entry.completeBaseName()
200+
)
201+
pak_paths[sub_entry.completeBaseName()] = (
169202
sub_entry.absolutePath(),
170203
pak_mods.absolutePath(),
171204
)
172-
pak_source[sub_entry.baseName()] = "Game Directory"
205+
pak_source[sub_entry.completeBaseName()] = (
206+
"Game Directory"
207+
)
173208
else:
174209
if entry.suffix().casefold() == "pak":
175210
paks[
176211
entry.completeBaseName()[: -1 - len(entry.suffix())]
177212
] = ""
178-
pak_paths[entry.baseName()] = (
213+
pak_paths[entry.completeBaseName()] = (
179214
entry.absolutePath(),
180215
pak_mods.absolutePath(),
181216
)
182-
pak_source[entry.baseName()] = "Game Directory"
217+
pak_source[entry.completeBaseName()] = "Game Directory"
183218
sorted_paks = dict(sorted(paks.items(), key=cmp_to_key(pak_sort)))
184-
qDebug("Sorted Paks:")
185-
for pak, directory in sorted_paks.items():
186-
item = directory if directory else pak
187-
qDebug(item)
219+
shaken_paks: list[str] = self._shake_paks(sorted_paks)
220+
qDebug("Shaken paks:")
221+
for pak in shaken_paks:
222+
qDebug(pak)
188223
final_paks: dict[str, tuple[str, str, str]] = {}
189224
pak_index = 9999
190-
for pak in sorted_paks.keys():
191-
match = re.match(r"^(\d{4}_)?(.*)$", pak)
192-
if not match:
193-
continue
194-
name = match.group(2) if match.group(2) else match.group(1)
225+
for pak in shaken_paks:
195226
target_dir = pak_paths[pak][1] + "/" + str(pak_index).zfill(4)
196-
final_paks[name] = (pak_source[pak], pak_paths[pak][0], target_dir)
227+
final_paks[pak] = (pak_source[pak], pak_paths[pak][0], target_dir)
197228
pak_index -= 1
198-
new_data_paks: dict[int, tuple[str, str, str, str]] = {}
229+
new_data_paks: dict[int, _PakInfo] = {}
199230
i = 0
200-
qDebug("Final Paks:")
201231
for pak, data in final_paks.items():
202-
qDebug(pak)
203232
source, current_path, target_path = data
204233
new_data_paks[i] = (pak, source, current_path, target_path)
205234
i += 1

0 commit comments

Comments
 (0)