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