/* * PS4Delta : PS4 emulation and research project * * Copyright 2019-2020 Force67. * For information regarding licensing see LICENSE * in the root of the source tree. */ #include #include #include #include #include #include #include #include #include "ui/mainwindow.h" #include #include #include inline std::string sstr(const QString& _in) { return _in.toStdString(); } class deltaApp final : public QApplication { public: deltaApp(int& argc, char** argv) : QApplication(argc, argv) {} bool init() { LOG_INFO("Initializing delta qt app " rsc_copyright " at " GIT_BRANCH "-" GIT_COMMIT); auto& sys = core::System::get(); if (!sys.init()) return false; if (!headless) window = std::make_unique(sys); else LOG_INFO("Starting in headless mode"); if (window) window->init(); return true; } private: std::unique_ptr window; bool headless = false; }; #ifdef _WIN32 #include #include #include static void applyQtFixes() { using NtQueryTimerResolution_t = LONG(WINAPI*)(PULONG, PULONG, PULONG); using NtSetTimerResolution_t = LONG(WINAPI*)(ULONG, BOOLEAN, PULONG); auto hNtLib = GetModuleHandleW(L"ntdll.dll"); auto NtQueryTimerResolution_f = reinterpret_cast( GetProcAddress(hNtLib, "NtQueryTimerResolution")); auto NtSetTimerResolution_f = reinterpret_cast(GetProcAddress(hNtLib, "NtSetTimerResolution")); if (NtQueryTimerResolution_f && NtSetTimerResolution_f) { // qt resets our timer, so wet set it back manually ULONG min_res, max_res, orig_res, new_res; if (NtQueryTimerResolution_f(&min_res, &max_res, &orig_res) == 0) NtSetTimerResolution_f(max_res, TRUE, &new_res); } // don't even get me started on how stupid // locales are setlocale(LC_ALL, "C"); } #endif inline int dmain(int argc, char** argv) { // create log sinks utl::createLogger(true); // create opts config::load(); // search plug ins in /qt/ dir { static auto x = QString::fromUtf8(utl::make_abs_path("qt").c_str()); QCoreApplication::addLibraryPath(x); } QCoreApplication::setOrganizationName(rsc_company); QCoreApplication::setApplicationName(rsc_productname); QCoreApplication::setApplicationVersion(rsc_productversion); QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QScopedPointer app(new deltaApp(argc, argv)); #ifdef _WIN32 applyQtFixes(); #endif QCommandLineParser parser; parser.setApplicationDescription("Welcome to the " rsc_productname " command line."); parser.addPositionalArgument("File", "Path for directly loading a file"); parser.addPositionalArgument("[Args...]", "Optional args for the executable"); parser.addOption(QCommandLineOption("headless", "Run " rsc_productname " in headless mode.")); parser.process(*app); if (app->init()) { // propagate command line arguments auto args = parser.positionalArguments(); if (args.length() > 0) { std::vector xargv; if (args.length() > 1) { xargv.emplace_back(); for (int i = 1; i < args.length(); i++) xargv.emplace_back(args[i].toStdString()); } // Ugly workaround QTimer::singleShot(2, [path = sstr(QFileInfo(args.at(0)).canonicalFilePath()), xargv = std::move(xargv)]() mutable { core::System::get().argv = std::move(xargv); core::System::get().load(path); }); } return app->exec(); } return 0; } DELTA_MAIN(dmain);