|
|
|
@ -14,11 +14,11 @@
|
|
|
|
|
# along with Korman. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
|
|
|
|
|
import hashlib |
|
|
|
|
import os.path |
|
|
|
|
from pathlib import Path |
|
|
|
|
from PyHSPlasma import * |
|
|
|
|
|
|
|
|
|
def _hashfile(filename, hasher, block=0xFFFF): |
|
|
|
|
with open(filename, "rb") as handle: |
|
|
|
|
with open(str(filename), "rb") as handle: |
|
|
|
|
h = hasher() |
|
|
|
|
data = handle.read(block) |
|
|
|
|
while data: |
|
|
|
@ -36,26 +36,25 @@ class SumFile:
|
|
|
|
|
def _collect_files(self, version): |
|
|
|
|
files = [] |
|
|
|
|
for file in self._files: |
|
|
|
|
filename = os.path.split(file)[1] |
|
|
|
|
extension = os.path.splitext(filename)[1].lower() |
|
|
|
|
filename, extension = file.name, file.suffix.lower() |
|
|
|
|
if extension in {".age", ".csv", ".fni", ".loc", ".node", ".p2f", ".pfp", ".sub"}: |
|
|
|
|
filename = os.path.join("dat", filename) |
|
|
|
|
filename = Path("dat") / filename |
|
|
|
|
elif extension == ".prp" and version > pvPrime: |
|
|
|
|
# ABM and UU don't want the directory for PRPs... Bug? |
|
|
|
|
filename = os.path.join("dat", filename) |
|
|
|
|
filename = Path("dat") / filename |
|
|
|
|
elif extension in {".pak", ".py"}: |
|
|
|
|
filename = os.path.join("Python", filename) |
|
|
|
|
filename = Path("Python") / filename |
|
|
|
|
elif extension in {".avi", ".bik", ".oggv", ".webm"}: |
|
|
|
|
filename = os.path.join("avi", filename) |
|
|
|
|
filename = Path("avi") / filename |
|
|
|
|
elif extension in {".ogg", ".opus", ".wav"}: |
|
|
|
|
filename = os.path.join("sfx", filename) |
|
|
|
|
filename = Path("sfx") / filename |
|
|
|
|
elif extension == ".sdl": |
|
|
|
|
filename = os.path.join("SDL", filename) |
|
|
|
|
filename = Path("SDL") / filename |
|
|
|
|
# else the filename has no directory prefix... oh well |
|
|
|
|
|
|
|
|
|
md5 = _hashfile(file, hashlib.md5) |
|
|
|
|
timestamp = os.path.getmtime(file) |
|
|
|
|
files.append((filename, md5, int(timestamp))) |
|
|
|
|
timestamp = file.stat().st_mtime |
|
|
|
|
files.append((str(filename), md5, int(timestamp))) |
|
|
|
|
return files |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -64,11 +63,11 @@ class SumFile:
|
|
|
|
|
files = self._collect_files(version) |
|
|
|
|
enc = plEncryptedStream.kEncAes if version >= pvEoa else plEncryptedStream.kEncXtea |
|
|
|
|
|
|
|
|
|
with plEncryptedStream(version).open(sumpath, fmWrite, enc) as stream: |
|
|
|
|
with plEncryptedStream(version).open(str(sumpath), fmWrite, enc) as stream: |
|
|
|
|
stream.writeInt(len(files)) |
|
|
|
|
stream.writeInt(0) |
|
|
|
|
for file in files: |
|
|
|
|
stream.writeSafeStr(file[0]) |
|
|
|
|
stream.writeSafeStr(str(file[0])) |
|
|
|
|
stream.write(file[1]) |
|
|
|
|
stream.writeInt(file[2]) |
|
|
|
|
stream.writeInt(0) |
|
|
|
|