Skip to content

Commit

Permalink
Fixed issue where multiple namespaces in Fallout 4 paths were not han…
Browse files Browse the repository at this point in the history
…dled at all
  • Loading branch information
fireundubh committed Nov 23, 2019
1 parent 8f8b3dd commit 31d95fe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
16 changes: 5 additions & 11 deletions pyro/BuildFacade.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,14 @@ def try_anonymize(self) -> None:
if not scripts and not self.ppj.missing_script_names and not self.ppj.options.no_incremental_build:
BuildFacade.log.error('Cannot anonymize compiled scripts because no source scripts were modified')
else:
# these are absolute paths. there's no reason to manipulate them.
for pex_path in self.ppj.pex_paths:
if self.ppj.options.game_type == 'fo4':
namespace, file_name = PathHelper.nsify(pex_path)
target_path = os.path.join(self.ppj.options.output_path, namespace, file_name)
else:
pex_path = os.path.basename(pex_path)
target_path = os.path.join(self.ppj.options.output_path, pex_path)

if not os.path.exists(target_path):
BuildFacade.log.error('Cannot locate file to anonymize: "%s"' % target_path)
if not os.path.exists(pex_path):
BuildFacade.log.warn('Cannot locate file to anonymize: "%s"' % pex_path)
continue

BuildFacade.log.info('Anonymizing "%s"...' % target_path)
Anonymizer.anonymize_script(target_path)
BuildFacade.log.info('Anonymizing "%s"...' % pex_path)
Anonymizer.anonymize_script(pex_path)

def try_pack(self) -> None:
"""Generates ZIP archive for project"""
Expand Down
6 changes: 3 additions & 3 deletions pyro/PackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def _copy_scripts_to_temp_path(self, psc_paths: list, temp_path: str) -> None:

for pex_path in pex_paths:
if self.ppj.options.game_type == 'fo4':
namespace, file_name = PathHelper.nsify(pex_path)
target_path = os.path.join(self.ppj.options.output_path, namespace, file_name)
temp_file_path = os.path.join(temp_path, namespace, file_name)
rel_object_name = PathHelper.calculate_relative_object_name(pex_path, self.ppj.import_paths)
target_path = os.path.join(self.ppj.options.output_path, rel_object_name)
temp_file_path = os.path.join(temp_path, rel_object_name)
else:
target_path = os.path.abspath(pex_path)
temp_file_path = os.path.join(temp_path, os.path.basename(pex_path))
Expand Down
9 changes: 3 additions & 6 deletions pyro/PapyrusProject.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,9 @@ def _get_pex_paths(self) -> list:
# build paths to compiled scripts
for psc_path in psc_paths:
if self.options.game_type == 'fo4':
namespace, file_name = PathHelper.nsify(psc_path)
target_path = os.path.join(self.options.output_path, namespace, file_name.replace('.psc', '.pex'))
else:
target_path = os.path.join(self.options.output_path, psc_path.replace('.psc', '.pex'))
psc_path = PathHelper.calculate_relative_object_name(psc_path, self.import_paths)

target_path = os.path.join(self.options.output_path, psc_path.replace('.psc', '.pex'))
pex_paths.append(target_path)

return PathHelper.uniqify(pex_paths)
Expand Down Expand Up @@ -384,8 +382,7 @@ def build_commands(self) -> list:
# generate list of commands
for psc_path in psc_paths:
if self.options.game_type == 'fo4':
namespace, file_name = PathHelper.nsify(psc_path)
psc_path = os.path.join(namespace, file_name)
psc_path = PathHelper.calculate_relative_object_name(psc_path, self.import_paths)

arguments.clear()
arguments.append_quoted(compiler_path)
Expand Down
12 changes: 8 additions & 4 deletions pyro/PathHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ def try_append_abspath(a: str, b: list) -> bool:
return False

@staticmethod
def nsify(path: str) -> tuple:
"""Returns tuple(parent folder, file name) from absolute path"""
parent_folder, file_name = map(lambda x: os.path.basename(x), [os.path.dirname(path), path])
return parent_folder, file_name
def calculate_relative_object_name(path: str, import_paths: list) -> str:
"""Returns import-relative path from absolute path (should be used only for Fallout 4 paths)"""
# reverse the list to find the best import path
for import_path in reversed(import_paths):
if len(path) > len(import_path) and import_path in path:
relative_path = os.path.relpath(path, import_path)
return relative_path
raise ValueError('Cannot build import-relative path from absolute path: "%s"' % path)

@staticmethod
def uniqify(items: list) -> list:
Expand Down

0 comments on commit 31d95fe

Please sign in to comment.