#include #include #include #include #include #include #include #include #include void logMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { QString message_type; switch (type) { case QtDebugMsg: message_type = "[LEGACY_FORWARD_HELPER][DEBG]"; break; case QtInfoMsg: message_type = "[LEGACY_FORWARD_HELPER][INFO]"; break; case QtWarningMsg: message_type = "[LEGACY_FORWARD_HELPER][WARN]"; break; case QtCriticalMsg: message_type = "[LEGACY_FORWARD_HELPER][CRIT]"; break; case QtFatalMsg: message_type = "[LEGACY_FORWARD_HELPER][FATL]"; break; default: message_type = "[LEGACY_FORWARD_HELPER][UNKN]"; break; } QString filename = context.category; QString function = context.function; QString line_number = QString::number(context.line); QString s = QString("%1: %2 ||| %3:%4 %5\n") .arg(message_type) .arg(msg) .arg(filename) .arg(line_number) .arg(function); #ifndef QT_DEBUG QFile log_file("legacy_log.txt"); QFileInfo log_file_info(log_file); if (log_file_info.size() >= 10 * 1024 * 1024) { QFile::remove("legacy_log.old.txt"); QFile::copy("legacy_log.txt", "legacy_log.old.txt"); QFile::remove("legacy_log.txt"); } log_file.open(QIODevice::ReadWrite | QIODevice::Append); QTextStream stream(&log_file); stream << s; log_file.close(); #endif fprintf(stderr, "%s", qUtf8Printable(s)); fflush(stderr); } int main(int argc, char** argv) { if (argc <= 1 || (argc > 1 && std::string(argv[1]) != "-prelaunched")) { QApplication a(argc, argv); QMessageBox msgBox; msgBox.setIcon(QMessageBox::Warning); #ifdef DEBUG msgBox.setText("ЭТО ТЕСТОВАЯ ВЕРСИЯ ЛАУНЧЕРА! НЕ ДЛЯ РАСПРОСТРАНЕНИЯ!"); msgBox.exec(); long long cur_time = time(0); if (cur_time >= DEBUG_EXPIRE) return 0; #else msgBox.setText("Запуск Наследия невозможен без лаунчера. Используйте лаунчер Наследия для запуска приложения!"); msgBox.exec(); a.exit(0); return 0; #endif } QCoreApplication a(argc, argv); qInstallMessageHandler(logMessageHandler); QThread::currentThread()->sleep(1); // Sleep 2 seconds to ensure that application-caller finished its work const QString app_path = QCoreApplication::applicationDirPath(); const QDir::Filters filters = (QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); QDirIterator it(app_path, filters, QDirIterator::Subdirectories); while (it.hasNext()) { QString path = it.next(); if (QFileInfo(path).isFile() && path.endsWith(".forward")) { QString path_stripped = path.left(path.length() - QString(".forward").length()); QFile::remove(path_stripped); if (QFile::copy(path, path_stripped)) { QFile::remove(path); } qInfo() << "Renaming file " << path << " to file " << path_stripped; } } QProcess process; process.setProgram("./Legacy.exe"); process.setArguments({"-prelaunched"}); process.startDetached(); process.waitForFinished(-1); return 0; }