|
1 | | -import re |
2 | 1 | from functools import cmp_to_key |
3 | 2 | from pathlib import Path |
4 | 3 | from typing import cast |
@@ -69,38 +68,31 @@ def write_paks_list(self): |
69 | 68 |
|
70 | 69 | def write_pak_files(self): |
71 | 70 | for index, pak in sorted(self._model.paks.items()): |
72 | | - name, _, current_path, target_path = pak |
| 71 | + _, _, current_path, target_path = pak |
73 | 72 | if current_path and current_path != target_path: |
74 | 73 | path_dir = Path(current_path) |
75 | 74 | target_dir = Path(target_path) |
76 | 75 | if not target_dir.exists(): |
77 | 76 | target_dir.mkdir(parents=True, exist_ok=True) |
78 | 77 | if path_dir.exists(): |
79 | 78 | for pak_file in path_dir.glob("*.pak"): |
80 | | - match = re.match(r"^(\d{4}_)?(.*)", pak_file.stem) |
81 | | - if not match: |
82 | | - continue |
83 | | - match_name = ( |
84 | | - match.group(2) if match.group(2) else match.group(1) |
| 79 | + ucas_file = pak_file.with_suffix(".ucas") |
| 80 | + utoc_file = pak_file.with_suffix(".utoc") |
| 81 | + for file in (pak_file, ucas_file, utoc_file): |
| 82 | + if not file.exists(): |
| 83 | + continue |
| 84 | + try: |
| 85 | + file.rename(target_dir.joinpath(file.name)) |
| 86 | + except FileExistsError: |
| 87 | + pass |
| 88 | + data = self._model.paks[index] |
| 89 | + self._model.paks[index] = ( |
| 90 | + data[0], |
| 91 | + data[1], |
| 92 | + data[3], |
| 93 | + data[3], |
85 | 94 | ) |
86 | | - if match_name == name: |
87 | | - ucas_file = pak_file.with_suffix(".ucas") |
88 | | - utoc_file = pak_file.with_suffix(".utoc") |
89 | | - for file in (pak_file, ucas_file, utoc_file): |
90 | | - if not file.exists(): |
91 | | - continue |
92 | | - try: |
93 | | - file.rename(target_dir.joinpath(file.name)) |
94 | | - except FileExistsError: |
95 | | - pass |
96 | | - data = self._model.paks[index] |
97 | | - self._model.paks[index] = ( |
98 | | - data[0], |
99 | | - data[1], |
100 | | - data[3], |
101 | | - data[3], |
102 | | - ) |
103 | | - break |
| 95 | + break |
104 | 96 | if not list(path_dir.iterdir()): |
105 | 97 | path_dir.rmdir() |
106 | 98 |
|
@@ -140,7 +132,7 @@ def _parse_pak_files(self): |
140 | 132 | if isinstance(pak_mods, mobase.IFileTree): |
141 | 133 | for entry in pak_mods: |
142 | 134 | if is_directory(entry): |
143 | | - if entry.name().casefold() == "magicloader": |
| 135 | + if "magicloader" in entry.name().casefold(): |
144 | 136 | continue |
145 | 137 | for sub_entry in entry: |
146 | 138 | if ( |
@@ -179,7 +171,7 @@ def _parse_pak_files(self): |
179 | 171 | QDir.Filter.Dirs | QDir.Filter.Files | QDir.Filter.NoDotAndDotDot |
180 | 172 | ): |
181 | 173 | if entry.isDir(): |
182 | | - if entry.completeBaseName().casefold() == "magicloader": |
| 174 | + if "magicloader" in entry.completeBaseName().casefold(): |
183 | 175 | continue |
184 | 176 | for sub_entry in QDir(entry.absoluteFilePath()).entryInfoList( |
185 | 177 | QDir.Filter.Files |
@@ -207,7 +199,7 @@ def _parse_pak_files(self): |
207 | 199 | sorted_paks = dict(sorted(paks.items(), key=cmp_to_key(pak_sort))) |
208 | 200 | shaken_paks: list[str] = self._shake_paks(sorted_paks) |
209 | 201 | final_paks: dict[str, tuple[str, str, str]] = {} |
210 | | - pak_index = 9999 |
| 202 | + pak_index = 8999 |
211 | 203 | for pak in shaken_paks: |
212 | 204 | target_dir = pak_paths[pak][1] + "/" + str(pak_index).zfill(4) |
213 | 205 | final_paks[pak] = (pak_source[pak], pak_paths[pak][0], target_dir) |
|
0 commit comments