1
0
mirror of https://github.com/Escartem/AnimeWwise.git synced 2026-06-04 23:40:25 +08:00

can extract files again

This commit is contained in:
Escartem
2024-07-23 15:26:53 +02:00
parent d96771c60d
commit 9498fabeac
3 changed files with 99 additions and 46 deletions

67
app.py
View File

@@ -44,15 +44,27 @@ class BackgroundWorker(QObject):
self.map = data["map"]
if action == "extract":
self.input = data["input"]
self.files = data["files"]
self.format = data["format"]
self.output = data["output"]
def run(self):
if self.action == "load":
print("Loading files and mapping if necessary...")
fileStructure = self.extract.load_folder(self.map, self.input)
if fileStructure is None:
self.finished.emit({"action": "error", "content": {"msg": "Nothing found !", "state": 1}})
print("Nothing found !")
return
print("Done !")
self.finished.emit({"action": "load", "content": fileStructure})
if self.action == "extract":
self.extract.extract_files(self.input)
if len(self.files) == 0:
self.finished.emit({"action": "error", "content": {"msg": "Nothing selected !", "state": 2}})
return
print(f"Extracting {len(self.files)} files...")
self.extract.extract_files(self.input, self.files, self.output, self.format, progress=self.progress.emit)
self.finished.emit({"action": "extract"})
class AnimeWwise(QMainWindow):
def __init__(self):
@@ -99,16 +111,16 @@ class AnimeWwise(QMainWindow):
self.actionReset.triggered.connect(lambda: self.resetApp())
self.actionExit.triggered.connect(lambda: self.close())
self.actionExtractSelected.triggered.connect(lambda: self.extractItems(False))
self.actionExtractAll.triggered.connect(lambda: self.extractItems(True))
self.extractSelected.clicked.connect(lambda: self.extractItems(False))
self.extractAll.clicked.connect(lambda: self.extractItems(True))
# workers
@pyqtSlot(list)
def progressBarSlot(self, progress):
if progress[0] == "total":
self.progress.setValue(progress[1])
self.totalProgress.setValue(progress[1])
elif progress[0] == "task":
self.taskProgress.setValue(progress[1])
self.fileProgress.setValue(progress[1])
@pyqtSlot(dict)
def handleFinished(self, data):
@@ -119,6 +131,19 @@ class AnimeWwise(QMainWindow):
self.tabs.setTabEnabled(1, True)
self.tabs.setTabEnabled(2, True)
self.tabs.setCurrentIndex(1)
if data["action"] == "error":
QMessageBox.warning(None, "Warning", data["content"]["msg"], QMessageBox.Ok)
state = data["content"]["state"]
if state == 1:
self.tabs.setTabEnabled(0, True)
elif state == 2:
self.tabs.setTabEnabled(1, True)
self.tabs.setTabEnabled(2, True)
if data["action"] == "extract":
self.tabs.setTabEnabled(1, True)
self.tabs.setTabEnabled(2, True)
self.tabs.setCurrentIndex(2)
print("Finished extracting everything !")
# page 1 - config
def loadFiles(self):
@@ -192,22 +217,29 @@ class AnimeWwise(QMainWindow):
# page 3 - extraction
def extractItems(self, _all):
if self.folders["output"] == "":
QMessageBox.warning(None, "Warning", "Missing output folder !", QMessageBox.Ok)
return
checked_items = []
def check_items(item, _all):
if item.checkState(0) == Qt.Checked or _all:
checked_items.append([item.text(column) for column in range(item.columnCount())])
if item.text(1) != "":
checked_items.append(self.getFileMeta(item))
for i in range(item.childCount()):
check_items(item.child(i), _all)
for i in range(self.treeWidget.topLevelItemCount()):
check_items(self.treeWidget.topLevelItem(i), _all)
print(checked_items)
self.tabs.setTabEnabled(1, False)
self.tabs.setTabEnabled(2, False)
self.tabs.setCurrentIndex(2)
# yet another block of threading bs
self.backgroundThread = QThread()
self.backgroundWorker = BackgroundWorker("extract", self.extract, {"input": self.folders["input"], "files": checked_items})
self.backgroundWorker = BackgroundWorker("extract", self.extract, {"input": self.folders["input"], "files": checked_items, "format": "wem", "output": self.folders["output"]})
self.backgroundWorker.moveToThread(self.backgroundThread)
self.backgroundThread.started.connect(self.backgroundWorker.run)
self.backgroundWorker.finished.connect(self.handleFinished)
@@ -218,6 +250,22 @@ class AnimeWwise(QMainWindow):
self.backgroundWorker.progress.connect(self.progressBarSlot)
self.backgroundThread.start()
def getFileMeta(self, item):
path = []
current_item = item
while current_item is not None:
path.insert(0, current_item.text(0))
current_item = current_item.parent()
return {
"name": item.text(0),
"path": path[1:-1],
"source": path[0],
"offset": int(item.text(1), 16),
"size": int(item.text(2))
}
# misc
def resetApp(self):
self.resetTreeWidget()
@@ -225,6 +273,7 @@ class AnimeWwise(QMainWindow):
self.tabs.setTabEnabled(0, True)
self.tabs.setTabEnabled(1, False)
self.tabs.setTabEnabled(2, False)
print("Reset !")
def _appendText(self, text):
cursor = self.console.textCursor()

View File

@@ -29,8 +29,6 @@ skips = "000000000" # used for debugging
class WwiseExtract:
def __init__(self):
# self.map = _map
# self.format = _format
self.paths = {
"input": "",
@@ -41,8 +39,6 @@ class WwiseExtract:
self.allocator = Allocator()
# self.progress = progress
def path(self, base, path):
base_path = self.paths[base]
if base == "temp":
@@ -307,7 +303,6 @@ class WwiseExtract:
print("-"*30)
print("Done extracting everything !")
### loading files ###
def load_folder(self, _map, path):
@@ -318,6 +313,9 @@ class WwiseExtract:
files = [f for f in os.listdir(path) if f.endswith(".pck")]
if len(files) == 0:
return None
for file in files:
self.load_file(os.path.join(path, file))
@@ -370,11 +368,28 @@ class WwiseExtract:
### extracting files ###
def extract_files(self, _input):
# load all pck, then extract each file and apply conversion if required
# allocator.load_file(os.path.join(_input, "2050.pck"))
# allocator.read_at("2050.pck", 0, 0)
pass
def extract_files(self, _input, files, output, format, progress):
all_sources = list(set([e["source"] for e in files]))
for source in all_sources:
self.allocator.load_file(os.path.join(_input, source))
pos = 0
for file in files:
pos += 1
progress(["total", pos * 100 // len(files)])
data = self.allocator.read_at(file["source"], file["offset"], file["size"])
filepath = os.path.join("/".join(file["path"]), file["name"])
fullpath = os.path.join(output, filepath)
os.makedirs(os.path.dirname(fullpath), exist_ok=True)
with open(fullpath, "wb") as f:
f.write(data)
f.close()
self.allocator.free_mem()
os.startfile(output)
### other ###
def reset(self):

43
gui.ui
View File

@@ -293,23 +293,23 @@
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="extractLayout">
<item>
<layout class="QHBoxLayout" name="extractLayout">
<item>
<widget class="QPushButton" name="extractAll">
<property name="text">
<string>Extract All</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="extractSelected">
<property name="text">
<string>Extract Selected</string>
</property>
</widget>
</item>
</layout>
<widget class="QPushButton" name="extractAll">
<property name="text">
<string>Extract All</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="extractSelected">
<property name="text">
<string>Extract Selected</string>
</property>
</widget>
</item>
</layout>
</item>
@@ -360,18 +360,7 @@
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
<widget class="QMenu" name="menuExtract">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Extract</string>
</property>
<addaction name="actionExtractAll"/>
<addaction name="actionExtractSelected"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuExtract"/>
</widget>
<action name="actionnot_working_here_yet">
<property name="text">