1+ #include < thread>
2+ #include " Bootstrapper.hpp"
3+ #include " BootstrapScripts/LuaScript.hpp"
4+ #include " BootstrapScripts/ScriptManager.hpp"
5+ #include " Logger.hpp"
6+ #include " UserInterface/BootstrapWindow.hpp"
7+ #include " UserInterface/OnboardingWindow.hpp"
8+ #include < QCoreApplication>
9+ #include < QProcess>
10+ #include < QMessageBox>
11+
12+ std::string Bootstrapper::Exception = " " ;
13+
14+ Bootstrapper::BootstrapResult Bootstrapper::MainBootstrap (NativeStrapper::ArgConfig* argConfig) {
15+ if (argConfig->URI && argConfig->BootstrapScript ) {
16+ Logger::Log (" Launched with bootstrap script and URI." , Logger::LogSeverity::SLOG , " MainBootstrap" );
17+ QString safeTitle = QString::fromStdString (std::string (argConfig->BootstrapScript )).toLower ().replace (" " , " -" );
18+
19+ ScriptManager::BootstrapScript* script = ScriptManager::FindFirstScriptByName (argConfig->BootstrapScript );
20+ if (script == NULL ) {
21+ Logger::Log (" Couldn't find bootstrap script." , Logger::LogSeverity::SFATAL , " MainBootstrap" );
22+ Bootstrapper::Exception = QString (" Bootstrap script \" %1\" not found. Please open NativeStrapper and re-import it." ).arg (argConfig->BootstrapScript ).toStdString ();
23+ return Bootstrapper::BootstrapResult::BOOTSTRAP_SCRIPT_NOT_FOUND ;
24+ }
25+
26+ Logger::Log (" Found bootstrap script, creating bootstrapper window" , Logger::LogSeverity::SLOG , " MainBootstrap" );
27+ BootstrapWindow *w = new BootstrapWindow ();
28+ w->show ();
29+
30+ Logger::OnLog = [w](std::string message, Logger::LogSeverity severity, std::string from) {
31+ QMetaObject::invokeMethod (w, [w, message]() {
32+ w->setLog (QString::fromStdString (message));
33+ }, Qt::QueuedConnection);
34+ };
35+
36+ Logger::Log (" Executing bootstrap script..." , Logger::LogSeverity::SINFO , " MainBootstrap" );
37+
38+ std::string scriptPath = ScriptManager::GetScriptPath (script->title );
39+ std::string uri = std::string (argConfig->URI );
40+ std::string runCmd = script->run ;
41+
42+ size_t pos = runCmd.find (" %u" );
43+ if (pos != std::string::npos) {
44+ runCmd.replace (pos, 2 , uri);
45+ }
46+
47+ std::thread scriptThread ([scriptPath, uri, w, runCmd, safeTitle]() {
48+ bool RunResult = LuaScript::RunScript (scriptPath, uri, w);
49+ if (!RunResult) {
50+ Logger::Log (" Script experienced an error while running." , Logger::LogSeverity::SFATAL , " MainBootstrap" );
51+ Bootstrapper::Exception = " Script experienced an error while running." ;
52+ return Bootstrapper::BootstrapResult::BOOTSTRAP_SCRIPT_ERR ;
53+ }
54+
55+ // calling these functions directly causes a segfault, smh... SMH. SHAKING MY HEAD, SHAKING MY FUCKING HEAD
56+ QMetaObject::invokeMethod (w, [w]() {
57+ w->setStatus (" Starting Roblox..." );
58+ w->setIndeterminate (true );
59+ }, Qt::QueuedConnection);
60+
61+ QStringList parts = QProcess::splitCommand (
62+ QString::fromStdString (runCmd)
63+ );
64+ QString robloxexepath = parts.takeFirst ();
65+ QString exePath = QCoreApplication::applicationFilePath ();
66+
67+ bool robloxStarted = QProcess::startDetached (robloxexepath, parts);
68+
69+ if (robloxStarted) {
70+ QProcess::startDetached (exePath, {" --bootstrap-script" , safeTitle, " --activity-watch" });
71+ QMetaObject::invokeMethod (qApp,[]() {
72+ QCoreApplication::quit ();
73+ }, Qt::QueuedConnection);
74+ }
75+ });
76+
77+ scriptThread.detach ();
78+
79+ return Bootstrapper::BootstrapResult::BOOTSTRAP_SUCCESS ;
80+ } else {
81+ auto * w = new OnboardingWindow (); /* putting onboarding window on the stack causes it to not show */
82+ w->show ();
83+ }
84+
85+ return Bootstrapper::BootstrapResult::BOOTSTRAP_SUCCESS ;
86+ }
0 commit comments