Skip to content

Commit

Permalink
style refactor + added segfault handler
Browse files Browse the repository at this point in the history
  • Loading branch information
frak0d committed Oct 24, 2022
1 parent b3217ae commit 5466f44
Showing 1 changed file with 59 additions and 46 deletions.
105 changes: 59 additions & 46 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <QtWidgets/QSystemTrayIcon>
#include <QtCore/QPropertyAnimation>

#define elif else if
using namespace std::literals;
namespace fs = std::filesystem;

Expand All @@ -60,6 +59,12 @@ void println(const auto& ...args)
print_queue.emplace(ss.str().c_str());
};

void segfault_handler()
{
MessageBox(NULL, L"SegFault! This Shoudn't Happen!\n"
"Please File a Bug report on GitHub Repository.", L"Fatal Error", MB_OK);
}

void cwd2ExePath()
{
char buffer[MAX_PATH];
Expand Down Expand Up @@ -145,8 +150,8 @@ int status()
auto s = cmd2(R"FucK(powershell -Command "Get-WindowsErrorReporting")FucK");
std::cout << s << std::endl;

if (s == "Enabled\r\n" ) return 1;
elif (s == "Disabled\r\n") return 0;
;;;; if (s == "Enabled\r\n" ) return 1;
else if (s == "Disabled\r\n") return 0;
else return 6;
}

Expand All @@ -161,23 +166,23 @@ void warning(int time_msec)

void crash_fix()
{
if (status() == 1)
;;;; if (status() == 1)
{
print("Enabling Crash Fix... ");
cmd(R"FucK(powershell -Command "Disable-WindowsErrorReporting")FucK");

status() == 0 ? println("Success")
: println("Failed");
}
elif (status() == 0)
else if (status() == 0)
{
print("Disabling Crash Fix... ");
cmd(R"FucK(powershell -Command "Enable-WindowsErrorReporting")FucK");

status() == 1 ? println("Success")
: println("Failed");
}
elif (status() == 6)
else if (status() == 6)
{
println("SOMETHING WENT WRONG...");
}
Expand All @@ -187,11 +192,13 @@ void crash_fix()
void store_fix()
{
println("Applying Store Fix....");
try {
try
{
cmd2(R"FucK(reg import "./assets/Fix_SVC.reg")FucK");
println("PLEASE RESTART YOUR PC FOR CHANGES TO TAKE EFFECT !"_bldgrn);
}
catch (...) {
catch (...)
{
println("TRY RUNNING BLAUNCHER AS ADMINISTRATOR !"_bldred);
}
}
Expand Down Expand Up @@ -256,21 +263,23 @@ void check_startup_conditions()

int main(int argc, char* argv[])
{
std::signal(SIGSEGV, segfault_handler);

cwd2ExePath();
check_startup_conditions();
QApplication app(argc, argv);

QSystemTrayIcon tray_icon_obj{};
tray_icon = &tray_icon_obj;
tray_icon->setIcon(QIcon("assets/logo.ico"));
tray_icon->setToolTip("BLauncher is Running!");
tray_icon->show();
std::atexit([]{tray_icon->~QSystemTrayIcon();});

Ui::window ui;
QWidget win;
ui.setupUi(&win);

auto print_handler = [&ui]()
{
while (!print_queue.empty())
Expand All @@ -281,15 +290,15 @@ int main(int argc, char* argv[])
ui.console->moveCursor(QTextCursor::End);
}
};

QTimer timer;
QObject::connect(&timer, &QTimer::timeout, print_handler);
timer.start(250/*ms*/);

auto savef = [&]()
{
Ini::File cfg("settings.ini");

cfg["SLIDERS"]["S1"] = QString(std::to_string( ui.slider1 -> value() ).c_str());
cfg["SLIDERS"]["S2"] = QString(std::to_string( ui.slider2 -> value() ).c_str());
cfg["EXTRAS"]["NOTIF_AGREE"] = QString(std::to_string( ui.notif_agree -> isChecked() ).c_str());
Expand All @@ -298,7 +307,7 @@ int main(int argc, char* argv[])
cfg["WINDOW"]["H_EXPAND"] = QString(std::to_string(win.width() == win.maximumWidth() ).c_str());
cfg["WINDOW"]["V_EXPAND"] = QString(std::to_string(win.height() == win.maximumHeight()).c_str());
};

auto startf = [&]()
{
if (KillerRunning)
Expand All @@ -308,38 +317,42 @@ int main(int argc, char* argv[])
else
{
print("\nInitiating Startup....\n"_grn);

uint tame1 = ui.slider1->value() * 1;
uint tame2 = ui.slider2->value() * 60;

try {

try
{
haxx_on();
cmd("explorer.exe shell:AppsFolder/Microsoft.MinecraftUWP_8wekyb3d8bbwe!App");
auto killer = std::thread(tamer, tame1, tame2, ui);
killer.detach();
}
catch (...) {
catch (...)
{
println("OOPS SOMETHING WENT WRONG..."_red);
println("TRY RUNNING BLAUNCHER AS ADMINISTRATOR !"_bldred);
}
}
};

auto stopf = [&]()
{
savef(); // save settings.ini before exiting

if (KillerRunning)
{
print("\nStopping Killer....\n");
try {
try
{
haxx_off();
println("Killer Stopped !"_cyn);
println("EXITING PROGRAM...."_bldcyn);
sleep_for(0.2, "s");
std::exit(1);
}
catch (...) {
catch (...)
{
println("OOPS SOMETHING WENT WRONG..."_red);
println("EXITING PROGRAM...."_bldred);
sleep_for(2.0, "s");
Expand All @@ -353,11 +366,11 @@ int main(int argc, char* argv[])
std::exit(1);
}
};

auto expandf1 = [&]()
{
int TargetWidth1, TargetWidth2;

if (win.width() == win.minimumWidth())
{
TargetWidth1 = win.maximumWidth();
Expand All @@ -370,27 +383,27 @@ int main(int argc, char* argv[])
TargetWidth2 = ui.console->minimumWidth();
ui.optionb->setText("Show Options");
}

// need to do it the pointer way to prevent animation
// from going out of scope before it completes

auto animation1 = new QPropertyAnimation(&win, "size");
animation1->setDuration(500);
animation1->setEndValue(QSize(TargetWidth1, win.height()));
animation1->setEasingCurve(QEasingCurve::OutCubic);
animation1->start(QAbstractAnimation::DeleteWhenStopped);

auto animation2 = new QPropertyAnimation(ui.console, "size");
animation2->setDuration(500);
animation2->setEndValue(QSize(TargetWidth2, win.height()));
animation2->setEasingCurve(QEasingCurve::OutCubic);
animation2->start(QAbstractAnimation::DeleteWhenStopped);
};

auto expandf2 = [&]()
{
int TargetHeight;

if (win.height() == win.minimumHeight())
{
TargetHeight = win.maximumHeight();
Expand All @@ -401,71 +414,71 @@ int main(int argc, char* argv[])
TargetHeight = win.minimumHeight();
ui.consoleb->setText("Show Console");
}

// need to do it the pointer way to prevent animation
// from going out of scope before it completes

auto animation = new QPropertyAnimation(&win, "size");
animation->setDuration(400);
animation->setEndValue(QSize(win.width(), TargetHeight));
animation->setEasingCurve(QEasingCurve::OutCubic);
animation->start(QAbstractAnimation::DeleteWhenStopped);
};

QObject::connect(ui.fix1b, &QPushButton::clicked, crash_fix);
QObject::connect(ui.fix2b, &QPushButton::clicked, store_fix);

QObject::connect(ui.startb, &QPushButton::clicked, startf);
QObject::connect(ui.optionb, &QPushButton::clicked, expandf1);
QObject::connect(ui.consoleb, &QPushButton::clicked, expandf2);

QApplication::connect(&app, &QApplication::aboutToQuit, stopf);

QObject::connect(ui.DISCORD, &QPushButton::clicked, [](){cmd("start https://discord.gg/5pkSfFF");});
QObject::connect(ui.YOUTUBE, &QPushButton::clicked, [](){cmd("start https://youtube.com/frakod?sub_confirmation=1");});

QObject::connect(ui.slider1, &QSlider::valueChanged, [&](int value)
{
ui.spinbox1->setValue(value);
});

QObject::connect(ui.slider2, &QSlider::valueChanged, [&](int value)
{
ui.spinbox2->setValue(value);
});

QObject::connect(ui.spinbox1, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [&](double value)
{
ui.slider1->setValue(value);
});

QObject::connect(ui.spinbox2, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [&](double value)
{
ui.slider2->setValue(value);
});

for (auto& entry : fs::directory_iterator("themes"))
{
if (entry.is_regular_file() && entry.path().string().ends_with(".blt"))
ui.comboBox->addItem(entry.path().stem().string().c_str());
}

QObject::connect(ui.comboBox, &QComboBox::currentTextChanged, [&](const QString& ThemeName)
{
set_app_theme_ex(app, ThemeName, ui.auth_name);
});

// Loading last used values
if (fs::exists("settings.ini"))
{
Ini::File cfg; cfg.load("settings.ini");

ui.slider1 -> setValue(cfg["SLIDERS"]["S1"].toInt());
ui.slider2 -> setValue(cfg["SLIDERS"]["S2"].toInt());
ui.notif_agree -> setChecked(cfg["EXTRAS"]["NOTIF_AGREE"].toInt());
ui.notif_duration -> setValue(cfg["EXTRAS"]["NOTIF_DURATION"].toInt());
ui.comboBox -> setCurrentText(cfg["EXTRAS"]["CURRENT_THEME"]);

if (cfg["WINDOW"]["H_EXPAND"].toInt())
{
win.resize(win.maximumWidth(), win.height());
Expand All @@ -478,7 +491,7 @@ int main(int argc, char* argv[])
ui.consoleb->setText("Hide Console");
}
}

set_app_theme_ex(app, ui.comboBox->currentText());
win.show(); return app.exec();
}

0 comments on commit 5466f44

Please sign in to comment.