mirror of
https://github.com/Escartem/AnimeWwise.git
synced 2026-06-05 16:00:27 +08:00
fix subfolders load
This commit is contained in:
@@ -14,15 +14,15 @@ class Allocator:
|
||||
self.files[filename] = mmap_object
|
||||
|
||||
def unload_file(self, name):
|
||||
self.files[name].close()
|
||||
self.files[os.path.basename(name)].close()
|
||||
|
||||
def read_at(self, file, offset, size):
|
||||
mmap_object = self.files[file]
|
||||
mmap_object = self.files[os.path.basename(file)]
|
||||
mmap_object.seek(offset)
|
||||
data = mmap_object.read(size)
|
||||
return data
|
||||
|
||||
def free_mem(self):
|
||||
for file in list(self.files.keys()):
|
||||
self.files[file].close()
|
||||
self.files[os.path.basename(file)].close()
|
||||
self.files.clear()
|
||||
|
||||
5
app.py
5
app.py
@@ -42,6 +42,7 @@ class BackgroundWorker(QObject):
|
||||
self.extract = extract
|
||||
|
||||
if action == "load":
|
||||
self.base = data["base"]
|
||||
self.input = data["input"]
|
||||
self.map = data["map"]
|
||||
self.diff = data["diff"]
|
||||
@@ -54,7 +55,7 @@ class BackgroundWorker(QObject):
|
||||
def run(self):
|
||||
if self.action == "load":
|
||||
print("Loading files and mapping if necessary...")
|
||||
fileStructure = self.extract.load_folder(self.map, self.input, self.diff, progress=self.progress.emit)
|
||||
fileStructure = self.extract.load_folder(self.map, self.input, self.diff, self.base, progress=self.progress.emit)
|
||||
if fileStructure is None:
|
||||
self.finished.emit({"action": "error", "content": {"msg": "Nothing found !", "state": 1}})
|
||||
print("Nothing found !")
|
||||
@@ -270,7 +271,7 @@ class AnimeWwise(QMainWindow):
|
||||
|
||||
# why is all this required for threading damnit
|
||||
self.backgroundThread = QThread()
|
||||
self.backgroundWorker = BackgroundWorker("load", self.extract, {"input": files, "map": _map, "diff": self.folders["diff"]})
|
||||
self.backgroundWorker = BackgroundWorker("load", self.extract, {"base": self.folders["input"], "input": files, "map": _map, "diff": self.folders["diff"]})
|
||||
self.backgroundWorker.moveToThread(self.backgroundThread)
|
||||
self.backgroundThread.started.connect(self.backgroundWorker.run)
|
||||
self.backgroundWorker.finished.connect(self.handleFinished)
|
||||
|
||||
17
extract.py
17
extract.py
@@ -33,7 +33,7 @@ class WwiseExtract:
|
||||
|
||||
return self.maps[map_name]
|
||||
|
||||
def load_folder(self, _map, files, diff_path, progress):
|
||||
def load_folder(self, _map, files, diff_path, base_path, progress):
|
||||
self.progress = progress
|
||||
self.steps = 1
|
||||
|
||||
@@ -67,17 +67,18 @@ class WwiseExtract:
|
||||
hdiff = None
|
||||
if f"{os.path.basename(file)}.hdiff" in hdiff_files:
|
||||
hdiff = path(diff_path, hdiff_files[hdiff_files.index(f"{os.path.basename(file)}.hdiff")])
|
||||
self.load_file(file, hdiff)
|
||||
self.load_file(file, hdiff, base_path)
|
||||
|
||||
return self.file_structure
|
||||
|
||||
def load_file(self, _input, hdiff):
|
||||
def load_file(self, _input, hdiff, diff_path):
|
||||
with open(_input, "rb") as f:
|
||||
data = f.read()
|
||||
f.close()
|
||||
self.get_wems(data, os.path.basename(_input), hdiff)
|
||||
print(diff_path)
|
||||
self.get_wems(data, os.path.basename(_input), hdiff, os.path.relpath(_input, start=diff_path))
|
||||
|
||||
def get_wems(self, data, filename, hdiff):
|
||||
def get_wems(self, data, filename, hdiff, relpath):
|
||||
reader = FileReader(io.BytesIO(data), "little")
|
||||
files = wavescan.get_data(reader, filename)
|
||||
|
||||
@@ -89,7 +90,7 @@ class WwiseExtract:
|
||||
hdiff_files, data = self.get_hdiff_files(data, hdiff_data, filename)
|
||||
files = self.compare_diff(files, hdiff_files)
|
||||
|
||||
self.map_names(files, filename, hdiff is not None, data)
|
||||
self.map_names(files, filename, relpath, hdiff is not None, data)
|
||||
|
||||
def compare_diff(self, old, new):
|
||||
old_dict = {file[0]:file[2] for file in old}
|
||||
@@ -143,7 +144,7 @@ class WwiseExtract:
|
||||
|
||||
return files, data
|
||||
|
||||
def map_names(self, files, filename, hdiff=False, data=None, skip_source=True):
|
||||
def map_names(self, files, filename, relpath, hdiff=False, data=None, skip_source=True):
|
||||
# disable skip source if required
|
||||
mapper = self.mapper
|
||||
base = self.file_structure
|
||||
@@ -160,7 +161,7 @@ class WwiseExtract:
|
||||
key = None
|
||||
|
||||
file_data = {
|
||||
"source": file[3],
|
||||
"source": relpath,
|
||||
"size": file[2],
|
||||
"offset": file[1],
|
||||
"metadata": {}
|
||||
|
||||
Reference in New Issue
Block a user