mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-07-01 12:26:26 +00:00
wip: arcaea-offline==0.2.0
This commit is contained in:
@ -1,9 +1,15 @@
|
||||
import json
|
||||
import logging
|
||||
import traceback
|
||||
import zipfile
|
||||
|
||||
from arcaea_offline.database import Database
|
||||
from arcaea_offline.external.arcaea.st3 import St3ScoreParser
|
||||
from arcaea_offline.external.arcaea import (
|
||||
PacklistParser,
|
||||
SonglistParser,
|
||||
St3ScoreParser,
|
||||
)
|
||||
from arcaea_offline.external.arcaea.common import ArcaeaParser
|
||||
from arcaea_offline.external.arcsong import ArcsongDbParser
|
||||
from PySide6.QtCore import QDir, Slot
|
||||
from PySide6.QtWidgets import QFileDialog, QMessageBox, QWidget
|
||||
@ -40,6 +46,93 @@ class TabDb_Manage(Ui_TabDb_Manage, QWidget):
|
||||
self, "Sync Error", "\n".join(traceback.format_exception(e))
|
||||
)
|
||||
|
||||
def importFromArcaeaParser(self, parser: ArcaeaParser, logName, path):
|
||||
# extracted by sourcery
|
||||
db = Database()
|
||||
with db.sessionmaker() as session:
|
||||
parser.write_database(session)
|
||||
itemNum = len(parser.parse())
|
||||
logger.info(f"updated {itemNum} {logName} from {path}")
|
||||
return itemNum
|
||||
|
||||
def importPacklist(self, packlistPath) -> int:
|
||||
packlistParser = PacklistParser(packlistPath)
|
||||
return self.importFromArcaeaParser(packlistParser, "packs", packlistPath)
|
||||
|
||||
def importSonglist(self, songlistPath) -> int:
|
||||
songlistParser = SonglistParser(songlistPath)
|
||||
return self.importFromArcaeaParser(songlistParser, "songs", songlistPath)
|
||||
|
||||
@Slot()
|
||||
def on_importPacklistButton_clicked(self):
|
||||
try:
|
||||
packlistFile, filter = QFileDialog.getOpenFileName(
|
||||
self, "Select packlist file"
|
||||
)
|
||||
|
||||
if not packlistFile:
|
||||
return
|
||||
|
||||
packNum = self.importPacklist(packlistFile)
|
||||
QMessageBox.information(
|
||||
self, None, f"Updated {packNum} packs from<br>{packlistFile}"
|
||||
)
|
||||
except Exception as e:
|
||||
logger.exception("import packlist error")
|
||||
QMessageBox.critical(
|
||||
self, "Import Error", "\n".join(traceback.format_exception(e))
|
||||
)
|
||||
|
||||
@Slot()
|
||||
def on_importSonglistButton_clicked(self):
|
||||
try:
|
||||
songlistFile, filter = QFileDialog.getOpenFileName(
|
||||
self, "Select songlist file"
|
||||
)
|
||||
|
||||
if not songlistFile:
|
||||
return
|
||||
|
||||
songNum = self.importSonglist(songlistFile)
|
||||
QMessageBox.information(
|
||||
self, None, f"Updated {songNum} songs from<br>{songlistFile}"
|
||||
)
|
||||
except Exception as e:
|
||||
logger.exception("import songlist error")
|
||||
QMessageBox.critical(
|
||||
self, "Import Error", "\n".join(traceback.format_exception(e))
|
||||
)
|
||||
|
||||
@Slot()
|
||||
def on_importApkButton_clicked(self):
|
||||
apkFile, filter = QFileDialog.getOpenFileName(
|
||||
self, "Select APK file", "", "APK File (*.apk);;*"
|
||||
)
|
||||
|
||||
if not apkFile:
|
||||
return
|
||||
|
||||
try:
|
||||
logger.info(f"Importing {apkFile}")
|
||||
|
||||
with zipfile.ZipFile(apkFile) as zf:
|
||||
packlistPath = zipfile.Path(zf) / "assets" / "songs" / "packlist"
|
||||
songlistPath = zipfile.Path(zf) / "assets" / "songs" / "songlist"
|
||||
|
||||
packsNum = self.importPacklist(packlistPath)
|
||||
songsNum = self.importSonglist(songlistPath)
|
||||
|
||||
message = [
|
||||
f"{packsNum} packs and {songsNum} songs updated from",
|
||||
str(apkFile),
|
||||
]
|
||||
QMessageBox.information(self, None, "<br>".join(message))
|
||||
except Exception as e:
|
||||
logging.exception("import apk error")
|
||||
QMessageBox.critical(
|
||||
self, "Import Error", "\n".join(traceback.format_exception(e))
|
||||
)
|
||||
|
||||
@Slot()
|
||||
def on_importSt3Button_clicked(self):
|
||||
dbFile, filter = QFileDialog.getOpenFileName(self, "Select st3 file")
|
||||
@ -77,3 +170,17 @@ class TabDb_Manage(Ui_TabDb_Manage, QWidget):
|
||||
)
|
||||
with open(exportLocation, "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
|
||||
@Slot()
|
||||
def on_exportArcsongJsonButton_clicked(self):
|
||||
scores = Database().generate_arcsong()
|
||||
content = json.dumps(scores, ensure_ascii=False)
|
||||
|
||||
exportLocation, _filter = QFileDialog.getSaveFileName(
|
||||
self,
|
||||
"Save your scores to...",
|
||||
QDir.current().filePath("arcsong.json"),
|
||||
"JSON (*.json);;*",
|
||||
)
|
||||
with open(exportLocation, "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
|
Reference in New Issue
Block a user