mirror of
https://github.com/redstrate/Novus.git
synced 2025-04-27 14:17:45 +00:00
karaku: Add feature to download definitions from Godbert
This commit is contained in:
parent
23e47da0f1
commit
f6c9d13b09
4 changed files with 87 additions and 3 deletions
|
@ -31,8 +31,8 @@ ecm_setup_version(${PROJECT_VERSION}
|
||||||
VERSION_HEADER ${CMAKE_CURRENT_BINARY_DIR}/novus-version.h
|
VERSION_HEADER ${CMAKE_CURRENT_BINARY_DIR}/novus-version.h
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package(Qt6 ${QT_MIN_VERSION} COMPONENTS Core Widgets Concurrent Core5Compat Sql HttpServer CONFIG REQUIRED)
|
find_package(Qt6 ${QT_MIN_VERSION} COMPONENTS Core Widgets Concurrent Core5Compat Sql HttpServer Network CONFIG REQUIRED)
|
||||||
find_package(KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS CoreAddons Config XmlGui)
|
find_package(KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS CoreAddons Config XmlGui Archive)
|
||||||
find_package(Vulkan REQUIRED)
|
find_package(Vulkan REQUIRED)
|
||||||
find_package(glm REQUIRED)
|
find_package(glm REQUIRED)
|
||||||
if (NOT TARGET glm::glm)
|
if (NOT TARGET glm::glm)
|
||||||
|
|
|
@ -15,12 +15,14 @@ target_include_directories(novus-karuku
|
||||||
include)
|
include)
|
||||||
target_link_libraries(novus-karuku
|
target_link_libraries(novus-karuku
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
KF6::Archive
|
||||||
Novus::Common
|
Novus::Common
|
||||||
Novus::ExdPart
|
Novus::ExdPart
|
||||||
Physis::Physis
|
Physis::Physis
|
||||||
Physis::Logger
|
Physis::Logger
|
||||||
Qt6::Core
|
Qt6::Core
|
||||||
Qt6::Widgets)
|
Qt6::Widgets
|
||||||
|
Qt6::Network)
|
||||||
|
|
||||||
install(FILES zone.xiv.karaku.desktop DESTINATION ${KDE_INSTALL_APPDIR})
|
install(FILES zone.xiv.karaku.desktop DESTINATION ${KDE_INSTALL_APPDIR})
|
||||||
install(FILES zone.xiv.karaku.svg DESTINATION ${KDE_INSTALL_FULL_ICONDIR}/hicolor/scalable/apps)
|
install(FILES zone.xiv.karaku.svg DESTINATION ${KDE_INSTALL_FULL_ICONDIR}/hicolor/scalable/apps)
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
|
||||||
#include "novusmainwindow.h"
|
#include "novusmainwindow.h"
|
||||||
|
|
||||||
struct GameData;
|
struct GameData;
|
||||||
|
@ -14,6 +16,10 @@ class MainWindow : public NovusMainWindow
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(GameData *data);
|
explicit MainWindow(GameData *data);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void setupFileMenu(QMenu *menu) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GameData *data = nullptr;
|
GameData *data = nullptr;
|
||||||
|
QNetworkAccessManager *mgr = nullptr;
|
||||||
};
|
};
|
|
@ -3,11 +3,17 @@
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
#include <KZip>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
#include <QTemporaryDir>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <physis.hpp>
|
#include <physis.hpp>
|
||||||
|
|
||||||
|
@ -21,6 +27,8 @@ MainWindow::MainWindow(GameData *data)
|
||||||
setMinimumSize(1280, 720);
|
setMinimumSize(1280, 720);
|
||||||
setupMenubar();
|
setupMenubar();
|
||||||
|
|
||||||
|
mgr = new QNetworkAccessManager(this);
|
||||||
|
|
||||||
auto dummyWidget = new QWidget();
|
auto dummyWidget = new QWidget();
|
||||||
setCentralWidget(dummyWidget);
|
setCentralWidget(dummyWidget);
|
||||||
|
|
||||||
|
@ -44,4 +52,72 @@ MainWindow::MainWindow(GameData *data)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupFileMenu(QMenu *menu)
|
||||||
|
{
|
||||||
|
auto openList = menu->addAction(QStringLiteral("Import Definitions..."));
|
||||||
|
openList->setIcon(QIcon::fromTheme(QStringLiteral("document-open")));
|
||||||
|
connect(openList, &QAction::triggered, [this] {
|
||||||
|
auto fileName = QFileDialog::getOpenFileName(nullptr, QStringLiteral("Open Path List"), QStringLiteral("~"));
|
||||||
|
});
|
||||||
|
|
||||||
|
auto downloadList = menu->addAction(QStringLiteral("Download Definitions..."));
|
||||||
|
downloadList->setIcon(QIcon::fromTheme(QStringLiteral("download-symbolic")));
|
||||||
|
connect(downloadList, &QAction::triggered, [this] {
|
||||||
|
const int ret =
|
||||||
|
QMessageBox::information(this,
|
||||||
|
QStringLiteral("Download Confirmation"),
|
||||||
|
QStringLiteral("This will download the definitions from the <a "
|
||||||
|
"href=\"https://github.com/xivapi/SaintCoinach\">SaintCoinach repository on GitHub</a>.<br><br>Continue?"),
|
||||||
|
QMessageBox::Ok | QMessageBox::Cancel,
|
||||||
|
QMessageBox::Ok);
|
||||||
|
|
||||||
|
if (ret != QMessageBox::Ok) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QUrl url;
|
||||||
|
url.setScheme(QStringLiteral("https"));
|
||||||
|
url.setHost(QStringLiteral("github.com"));
|
||||||
|
url.setPath(QStringLiteral("/xivapi/SaintCoinach/releases/latest/download/Godbert.zip"));
|
||||||
|
|
||||||
|
// TODO: Use Qcoro?
|
||||||
|
auto reply = mgr->get(QNetworkRequest(url));
|
||||||
|
connect(reply, &QNetworkReply::finished, this, [this, reply] {
|
||||||
|
qInfo() << "Finished downloading definitions!";
|
||||||
|
|
||||||
|
QTemporaryDir tempDir;
|
||||||
|
|
||||||
|
QFile file(tempDir.filePath(QStringLiteral("Godbert.zip")));
|
||||||
|
file.open(QIODevice::WriteOnly);
|
||||||
|
file.write(reply->readAll());
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
KZip archive(tempDir.filePath(QStringLiteral("Godbert.zip")));
|
||||||
|
if (!archive.open(QIODevice::ReadOnly)) {
|
||||||
|
// TODO: these should show as message boxes
|
||||||
|
qFatal() << "Failed to open Godbert zip!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const KArchiveDirectory *root = dynamic_cast<const KArchiveDirectory *>(archive.directory()->entry(QStringLiteral("Definitions")));
|
||||||
|
|
||||||
|
const QDir dataDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||||
|
const QDir definitionsDir = dataDir.absoluteFilePath(QStringLiteral("definitions"));
|
||||||
|
|
||||||
|
// delete old directory
|
||||||
|
if (definitionsDir.exists()) {
|
||||||
|
QDir().rmdir(definitionsDir.absolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir().mkpath(definitionsDir.absolutePath());
|
||||||
|
|
||||||
|
root->copyTo(definitionsDir.absolutePath(), true);
|
||||||
|
|
||||||
|
archive.close();
|
||||||
|
|
||||||
|
QMessageBox::information(this, QStringLiteral("Definitions"), QStringLiteral("Successfully updated definitions!"));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#include "moc_mainwindow.cpp"
|
#include "moc_mainwindow.cpp"
|
Loading…
Add table
Reference in a new issue