mirror of
https://github.com/Escartem/AnimeWwise.git
synced 2026-06-17 00:10:25 +08:00
can extract files again
This commit is contained in:
67
app.py
67
app.py
@@ -44,15 +44,27 @@ class BackgroundWorker(QObject):
|
|||||||
self.map = data["map"]
|
self.map = data["map"]
|
||||||
if action == "extract":
|
if action == "extract":
|
||||||
self.input = data["input"]
|
self.input = data["input"]
|
||||||
|
self.files = data["files"]
|
||||||
|
self.format = data["format"]
|
||||||
|
self.output = data["output"]
|
||||||
|
|
||||||
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)
|
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 !")
|
print("Done !")
|
||||||
self.finished.emit({"action": "load", "content": fileStructure})
|
self.finished.emit({"action": "load", "content": fileStructure})
|
||||||
if self.action == "extract":
|
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):
|
class AnimeWwise(QMainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -99,16 +111,16 @@ class AnimeWwise(QMainWindow):
|
|||||||
self.actionReset.triggered.connect(lambda: self.resetApp())
|
self.actionReset.triggered.connect(lambda: self.resetApp())
|
||||||
self.actionExit.triggered.connect(lambda: self.close())
|
self.actionExit.triggered.connect(lambda: self.close())
|
||||||
|
|
||||||
self.actionExtractSelected.triggered.connect(lambda: self.extractItems(False))
|
self.extractSelected.clicked.connect(lambda: self.extractItems(False))
|
||||||
self.actionExtractAll.triggered.connect(lambda: self.extractItems(True))
|
self.extractAll.clicked.connect(lambda: self.extractItems(True))
|
||||||
|
|
||||||
# workers
|
# workers
|
||||||
@pyqtSlot(list)
|
@pyqtSlot(list)
|
||||||
def progressBarSlot(self, progress):
|
def progressBarSlot(self, progress):
|
||||||
if progress[0] == "total":
|
if progress[0] == "total":
|
||||||
self.progress.setValue(progress[1])
|
self.totalProgress.setValue(progress[1])
|
||||||
elif progress[0] == "task":
|
elif progress[0] == "task":
|
||||||
self.taskProgress.setValue(progress[1])
|
self.fileProgress.setValue(progress[1])
|
||||||
|
|
||||||
@pyqtSlot(dict)
|
@pyqtSlot(dict)
|
||||||
def handleFinished(self, data):
|
def handleFinished(self, data):
|
||||||
@@ -119,6 +131,19 @@ class AnimeWwise(QMainWindow):
|
|||||||
self.tabs.setTabEnabled(1, True)
|
self.tabs.setTabEnabled(1, True)
|
||||||
self.tabs.setTabEnabled(2, True)
|
self.tabs.setTabEnabled(2, True)
|
||||||
self.tabs.setCurrentIndex(1)
|
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
|
# page 1 - config
|
||||||
def loadFiles(self):
|
def loadFiles(self):
|
||||||
@@ -192,22 +217,29 @@ class AnimeWwise(QMainWindow):
|
|||||||
|
|
||||||
# page 3 - extraction
|
# page 3 - extraction
|
||||||
def extractItems(self, _all):
|
def extractItems(self, _all):
|
||||||
|
if self.folders["output"] == "":
|
||||||
|
QMessageBox.warning(None, "Warning", "Missing output folder !", QMessageBox.Ok)
|
||||||
|
return
|
||||||
|
|
||||||
checked_items = []
|
checked_items = []
|
||||||
|
|
||||||
def check_items(item, _all):
|
def check_items(item, _all):
|
||||||
if item.checkState(0) == Qt.Checked or _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()):
|
for i in range(item.childCount()):
|
||||||
check_items(item.child(i), _all)
|
check_items(item.child(i), _all)
|
||||||
|
|
||||||
for i in range(self.treeWidget.topLevelItemCount()):
|
for i in range(self.treeWidget.topLevelItemCount()):
|
||||||
check_items(self.treeWidget.topLevelItem(i), _all)
|
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
|
# yet another block of threading bs
|
||||||
self.backgroundThread = QThread()
|
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.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)
|
||||||
@@ -218,6 +250,22 @@ class AnimeWwise(QMainWindow):
|
|||||||
self.backgroundWorker.progress.connect(self.progressBarSlot)
|
self.backgroundWorker.progress.connect(self.progressBarSlot)
|
||||||
self.backgroundThread.start()
|
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
|
# misc
|
||||||
def resetApp(self):
|
def resetApp(self):
|
||||||
self.resetTreeWidget()
|
self.resetTreeWidget()
|
||||||
@@ -225,6 +273,7 @@ class AnimeWwise(QMainWindow):
|
|||||||
self.tabs.setTabEnabled(0, True)
|
self.tabs.setTabEnabled(0, True)
|
||||||
self.tabs.setTabEnabled(1, False)
|
self.tabs.setTabEnabled(1, False)
|
||||||
self.tabs.setTabEnabled(2, False)
|
self.tabs.setTabEnabled(2, False)
|
||||||
|
print("Reset !")
|
||||||
|
|
||||||
def _appendText(self, text):
|
def _appendText(self, text):
|
||||||
cursor = self.console.textCursor()
|
cursor = self.console.textCursor()
|
||||||
|
|||||||
35
extract.py
35
extract.py
@@ -29,8 +29,6 @@ skips = "000000000" # used for debugging
|
|||||||
|
|
||||||
class WwiseExtract:
|
class WwiseExtract:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# self.map = _map
|
|
||||||
# self.format = _format
|
|
||||||
|
|
||||||
self.paths = {
|
self.paths = {
|
||||||
"input": "",
|
"input": "",
|
||||||
@@ -41,8 +39,6 @@ class WwiseExtract:
|
|||||||
|
|
||||||
self.allocator = Allocator()
|
self.allocator = Allocator()
|
||||||
|
|
||||||
# self.progress = progress
|
|
||||||
|
|
||||||
def path(self, base, path):
|
def path(self, base, path):
|
||||||
base_path = self.paths[base]
|
base_path = self.paths[base]
|
||||||
if base == "temp":
|
if base == "temp":
|
||||||
@@ -307,7 +303,6 @@ class WwiseExtract:
|
|||||||
print("-"*30)
|
print("-"*30)
|
||||||
print("Done extracting everything !")
|
print("Done extracting everything !")
|
||||||
|
|
||||||
|
|
||||||
### loading files ###
|
### loading files ###
|
||||||
|
|
||||||
def load_folder(self, _map, path):
|
def load_folder(self, _map, path):
|
||||||
@@ -318,6 +313,9 @@ class WwiseExtract:
|
|||||||
|
|
||||||
files = [f for f in os.listdir(path) if f.endswith(".pck")]
|
files = [f for f in os.listdir(path) if f.endswith(".pck")]
|
||||||
|
|
||||||
|
if len(files) == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
self.load_file(os.path.join(path, file))
|
self.load_file(os.path.join(path, file))
|
||||||
|
|
||||||
@@ -370,11 +368,28 @@ class WwiseExtract:
|
|||||||
|
|
||||||
### extracting files ###
|
### extracting files ###
|
||||||
|
|
||||||
def extract_files(self, _input):
|
def extract_files(self, _input, files, output, format, progress):
|
||||||
# load all pck, then extract each file and apply conversion if required
|
all_sources = list(set([e["source"] for e in files]))
|
||||||
# allocator.load_file(os.path.join(_input, "2050.pck"))
|
|
||||||
# allocator.read_at("2050.pck", 0, 0)
|
for source in all_sources:
|
||||||
pass
|
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 ###
|
### other ###
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
|
|||||||
43
gui.ui
43
gui.ui
@@ -293,23 +293,23 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="extractLayout">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="extractLayout">
|
<widget class="QPushButton" name="extractAll">
|
||||||
<item>
|
<property name="text">
|
||||||
<widget class="QPushButton" name="extractAll">
|
<string>Extract All</string>
|
||||||
<property name="text">
|
</property>
|
||||||
<string>Extract All</string>
|
</widget>
|
||||||
</property>
|
</item>
|
||||||
</widget>
|
<item>
|
||||||
</item>
|
<widget class="QPushButton" name="extractSelected">
|
||||||
<item>
|
<property name="text">
|
||||||
<widget class="QPushButton" name="extractSelected">
|
<string>Extract Selected</string>
|
||||||
<property name="text">
|
</property>
|
||||||
<string>Extract Selected</string>
|
</widget>
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
@@ -360,18 +360,7 @@
|
|||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionExit"/>
|
<addaction name="actionExit"/>
|
||||||
</widget>
|
</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="menuFile"/>
|
||||||
<addaction name="menuExtract"/>
|
|
||||||
</widget>
|
</widget>
|
||||||
<action name="actionnot_working_here_yet">
|
<action name="actionnot_working_here_yet">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|||||||
Reference in New Issue
Block a user