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