2022-10-18 09:35:04 +00:00
|
|
|
#include "document.h"
|
|
|
|
#include "document_window.h"
|
|
|
|
#include "theme.h"
|
|
|
|
#include "version.h"
|
2021-11-18 14:58:01 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QDebug>
|
2022-10-18 09:35:04 +00:00
|
|
|
#include <QSurfaceFormat>
|
2021-11-18 14:58:01 +00:00
|
|
|
#include <cstdio>
|
2022-10-14 08:21:20 +00:00
|
|
|
#include <dust3d/base/string.h>
|
2022-10-18 09:35:04 +00:00
|
|
|
#include <iostream>
|
2021-11-18 14:58:01 +00:00
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
int main(int argc, char* argv[])
|
2021-11-18 14:58:01 +00:00
|
|
|
{
|
|
|
|
QApplication app(argc, argv);
|
2022-10-18 09:35:04 +00:00
|
|
|
|
2021-11-18 14:58:01 +00:00
|
|
|
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
|
|
|
|
format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);
|
|
|
|
format.setVersion(3, 3);
|
|
|
|
QSurfaceFormat::setDefaultFormat(format);
|
2022-10-18 09:35:04 +00:00
|
|
|
|
2021-11-18 14:58:01 +00:00
|
|
|
Theme::initialize();
|
2022-10-18 09:35:04 +00:00
|
|
|
|
2021-11-18 14:58:01 +00:00
|
|
|
QCoreApplication::setApplicationName(APP_NAME);
|
|
|
|
QCoreApplication::setOrganizationName(APP_COMPANY);
|
|
|
|
QCoreApplication::setOrganizationDomain(APP_HOMEPAGE_URL);
|
2022-10-18 09:35:04 +00:00
|
|
|
|
2022-09-20 12:48:22 +00:00
|
|
|
//freopen("dust3d.log", "w", stdout);
|
|
|
|
//setvbuf(stdout, 0, _IONBF, 0);
|
2022-10-18 09:35:04 +00:00
|
|
|
|
|
|
|
DocumentWindow* firstWindow = DocumentWindow::createDocumentWindow();
|
2022-10-12 13:24:45 +00:00
|
|
|
|
|
|
|
QStringList openFileList;
|
|
|
|
QStringList waitingExportList;
|
2022-10-14 08:21:20 +00:00
|
|
|
bool toggleColor = false;
|
2022-10-12 13:24:45 +00:00
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
if ('-' == argv[i][0]) {
|
2022-10-18 09:35:04 +00:00
|
|
|
if (0 == strcmp(argv[i], "-output") || 0 == strcmp(argv[i], "-o")) {
|
2022-10-12 13:24:45 +00:00
|
|
|
++i;
|
|
|
|
if (i < argc)
|
|
|
|
waitingExportList.append(argv[i]);
|
|
|
|
continue;
|
2022-10-14 08:21:20 +00:00
|
|
|
} else if (0 == strcmp(argv[i], "-toggle-color")) {
|
|
|
|
++i;
|
|
|
|
if (i < argc)
|
|
|
|
toggleColor = dust3d::String::isTrue(argv[i]);
|
|
|
|
continue;
|
2022-10-12 13:24:45 +00:00
|
|
|
}
|
|
|
|
qDebug() << "Unknown option:" << argv[i];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QString arg = argv[i];
|
|
|
|
if (arg.endsWith(".ds3")) {
|
|
|
|
openFileList.append(arg);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2022-10-18 09:35:04 +00:00
|
|
|
|
2022-10-12 13:24:45 +00:00
|
|
|
int finishedExportFileNum = 0;
|
|
|
|
int totalExportFileNum = 0;
|
|
|
|
int succeedExportNum = 0;
|
|
|
|
int exitCode = -1;
|
2022-10-18 09:35:04 +00:00
|
|
|
std::vector<DocumentWindow*> windowList;
|
2022-10-12 13:24:45 +00:00
|
|
|
auto checkToSafelyExit = [&]() {
|
|
|
|
if (-1 == exitCode)
|
|
|
|
return;
|
|
|
|
for (int i = 0; i < openFileList.size(); ++i) {
|
|
|
|
if (windowList[i]->isWorking())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
app.exit(exitCode);
|
|
|
|
};
|
|
|
|
if (!openFileList.empty()) {
|
|
|
|
windowList.push_back(firstWindow);
|
|
|
|
for (int i = 1; i < openFileList.size(); ++i) {
|
|
|
|
windowList.push_back(DocumentWindow::createDocumentWindow());
|
|
|
|
}
|
2022-10-14 08:21:20 +00:00
|
|
|
if (toggleColor) {
|
2022-10-18 09:35:04 +00:00
|
|
|
for (auto& it : windowList)
|
2022-10-14 08:21:20 +00:00
|
|
|
it->toggleRenderColor();
|
|
|
|
}
|
2022-10-18 09:35:04 +00:00
|
|
|
if (!waitingExportList.empty() && openFileList.size() == 1) {
|
2022-10-12 13:24:45 +00:00
|
|
|
totalExportFileNum = openFileList.size() * waitingExportList.size();
|
|
|
|
for (int i = 0; i < openFileList.size(); ++i) {
|
|
|
|
QObject::connect(windowList[i], &DocumentWindow::workingStatusChanged, &app, checkToSafelyExit);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < openFileList.size(); ++i) {
|
2022-10-18 09:35:04 +00:00
|
|
|
QObject::connect(windowList[i], &DocumentWindow::waitingExportFinished, &app, [&](const QString& filename, bool isSuccessful) {
|
2022-10-12 13:24:45 +00:00
|
|
|
qDebug() << "Export to" << filename << (isSuccessful ? "isSuccessful" : "failed");
|
|
|
|
++finishedExportFileNum;
|
|
|
|
if (isSuccessful)
|
|
|
|
++succeedExportNum;
|
|
|
|
if (finishedExportFileNum == totalExportFileNum) {
|
|
|
|
if (succeedExportNum == totalExportFileNum) {
|
|
|
|
exitCode = 0;
|
|
|
|
checkToSafelyExit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
exitCode = 1;
|
|
|
|
checkToSafelyExit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
for (int i = 0; i < openFileList.size(); ++i) {
|
|
|
|
QObject::connect(windowList[i]->document(), &Document::exportReady, windowList[i], &DocumentWindow::checkExportWaitingList);
|
|
|
|
windowList[i]->setExportWaitingList(waitingExportList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < openFileList.size(); ++i) {
|
|
|
|
windowList[i]->openPathAs(openFileList[i], openFileList[i]);
|
|
|
|
}
|
|
|
|
}
|
2022-10-18 09:35:04 +00:00
|
|
|
|
2021-11-18 14:58:01 +00:00
|
|
|
return app.exec();
|
|
|
|
}
|