From 4b5f061ac6f5332306b761deedf0a93054ff0cce Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 8 Jan 2019 17:55:53 -0500 Subject: [PATCH] Fix Python paks being written into "dat" --- korman/exporter/outfile.py | 49 ++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/korman/exporter/outfile.py b/korman/exporter/outfile.py index 78ff054..4d39cb4 100644 --- a/korman/exporter/outfile.py +++ b/korman/exporter/outfile.py @@ -207,18 +207,27 @@ class OutputFiles: @contextmanager def generate_dat_file(self, filename, **kwargs): - if self._is_zip: + dat_only = self._exporter().dat_only + dirname = kwargs.get("dirname", "dat") + bogus = dat_only and dirname != "dat" + + if self._is_zip or bogus: stream = hsRAMStream(self._version) else: - file_path = str(self._export_file.parent / filename) + if dat_only: + file_path = str(self._export_file.parent / filename) + else: + file_path = str(self._export_path / dirname / filename) stream = hsFileStream(self._version) stream.open(file_path, fmCreate) backing_stream = stream - enc = kwargs.get("enc", None) - if enc is not None: - stream = plEncryptedStream(self._version) - stream.open(backing_stream, fmCreate, enc) + # No sense in wasting time encrypting data that isn't going to be used in the export + if not bogus: + enc = kwargs.get("enc", None) + if enc is not None: + stream = plEncryptedStream(self._version) + stream.open(backing_stream, fmCreate, enc) # The actual export code is run at the "yield" statement. If an error occurs, we # do not want to track this file. Note that the except block is required for the @@ -236,20 +245,20 @@ class OutputFiles: # Not passing enc as a keyword argument to the output file definition. It makes more # sense to yield an encrypted stream from this context manager and encrypt as we go # instead of doing lots of buffer copying to encrypt as a post step. - dirname = kwargs.get("dirname", "dat") - kwargs = { - "file_type": _FileType.generated_dat if dirname == "dat" else - _FileType.generated_ancillary, - "dirname": dirname, - "filename": filename, - "skip_hash": kwargs.get("skip_hash", False), - "internal": kwargs.get("internal", False), - } - if isinstance(backing_stream, hsRAMStream): - kwargs["file_data"] = backing_stream.buffer - else: - kwargs["file_path"] = file_path - self._files.add(_OutputFile(**kwargs)) + if not bogus: + kwargs = { + "file_type": _FileType.generated_dat if dirname == "dat" else + _FileType.generated_ancillary, + "dirname": dirname, + "filename": filename, + "skip_hash": kwargs.get("skip_hash", False), + "internal": kwargs.get("internal", False), + } + if isinstance(backing_stream, hsRAMStream): + kwargs["file_data"] = backing_stream.buffer + else: + kwargs["file_path"] = file_path + self._files.add(_OutputFile(**kwargs)) def _generate_files(self, func=None): dat_only = self._exporter().dat_only