Skip to content

Commit

Permalink
qtfied everything
Browse files Browse the repository at this point in the history
  • Loading branch information
frak0d committed Apr 18, 2022
1 parent 979f13b commit 12a82a6
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 1,529 deletions.
1,379 changes: 0 additions & 1,379 deletions libs/wintoast.hpp

This file was deleted.

14 changes: 7 additions & 7 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

project('BLauncher', 'cpp', version: '2.0_alpha',
project('BLauncher', 'cpp', version: '2.0_alpha2',
subproject_dir: 'libs', meson_version: '>=0.60',
default_options: ['buildtype=release', 'strip=true',
'b_lto=true', 'cpp_rtti=false',
Expand All @@ -24,21 +24,21 @@ install_subdir('themes', strip_directory: true,
exe_name = 'BLauncher_v' + meson.project_version()

bl_exe = executable(
exe_name,
'src/main.cpp', gui,
dependencies: deps,
exe_name,'src/main.cpp',
gui, dependencies: deps,
install: true,
install_dir: dir_install,
cpp_args: ['-Wno-unused-variable',
'-Wno-unused-parameter',
'-Wno-ignored-attributes'])

upx = find_program('upx')
echo = find_program('echo')
upx = find_program('upx') # needed to compress the final exe
echo = find_program('echo') # needed as a stub for upx
pkgcfg = find_program('pkg-config') # needed for static build on msys2

if get_option('static')
run_target('compress', depends: bl_exe,
command: [upx, '-9', '--lzma', install_dir/exe_name])
command: [upx, '-9', '--lzma', dir_install/exe_name])
else
run_target('compress',
command: [echo, '\nERROR: UPX Compression requires a static Build (use -Dstatic=true flag)\n'])
Expand Down
37 changes: 37 additions & 0 deletions src/cmd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <QtCore/QString>
#include <QtCore/QProcess>

bool cmd(const QString& cmd)
{
auto args = QProcess::splitCommand(cmd);

QProcess sp;
sp.setProgram(args[0]);
args.erase(args.begin());
sp.setArguments(args);
sp.start();

if (sp.waitForFinished(10000))
if (sp.exitStatus() == QProcess::NormalExit)
return true;

return false;
}

QString cmd2(const QString& cmd)
{
auto args = QProcess::splitCommand(cmd);

QProcess sp;
sp.setProgram(args[0]);
args.erase(args.begin());
sp.setArguments(args);
sp.start();

if (sp.waitForFinished(10000))
return sp.readAll();
else
throw sp.errorString();
}
31 changes: 16 additions & 15 deletions src/colors.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
#include <string>
#pragma once

#include <QtCore/QString>

std::string operator ""_bld (const char* str, size_t)
QString operator ""_bld (const char* str, size_t)
{
return "<b>" + std::string(str) + "</b>";
return "<b>" + QString(str) + "</b>";
}

std::string operator ""_red (const char* str, size_t)
QString operator ""_red (const char* str, size_t)
{
return "<font color=red>" + std::string(str) + "</font>";
return "<font color=red>" + QString(str) + "</font>";
}

std::string operator ""_bldred (const char* str, size_t)
QString operator ""_bldred (const char* str, size_t)
{
return "<font color=red><b>" + std::string(str) + "</b></font>";
return "<font color=red><b>" + QString(str) + "</b></font>";
}

std::string operator ""_grn (const char* str, size_t)
QString operator ""_grn (const char* str, size_t)
{
return "<font color=green>" + std::string(str) + "</font>";
return "<font color=green>" + QString(str) + "</font>";
}

std::string operator ""_bldgrn (const char* str, size_t)
QString operator ""_bldgrn (const char* str, size_t)
{
return "<font color=green><b>" + std::string(str) + "</b></font>";
return "<font color=green><b>" + QString(str) + "</b></font>";
}

std::string operator ""_cyn (const char* str, size_t)
QString operator ""_cyn (const char* str, size_t)
{
return "<font color=cyan>" + std::string(str) + "</font>";
return "<font color=cyan>" + QString(str) + "</font>";
}

std::string operator ""_bldcyn (const char* str, size_t)
QString operator ""_bldcyn (const char* str, size_t)
{
return "<font color=cyan><b>" + std::string(str) + "</b></font>";
return "<font color=cyan><b>" + QString(str) + "</b></font>";
}
146 changes: 53 additions & 93 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,105 +1,62 @@
#include <ostream>
#include <tuple>
#include <string>
#include <cstdlib>
#include <cstdint>
#include <sstream>
#include <ostream>
#include <iostream>
#include <filesystem>
#include <string_view>

#include "cmd.cpp"
#include "nini.cpp"
#include "print.cpp"
#include "sleep.cpp"
#include "colors.cpp"
#include "libs/nini.hpp"
#include "str2color.cpp"

#include <ui_main.h>

#include <QtGui>
#include <QtCore>
#include <QtWidgets>
#include <QtGui/QIcon>
#include <QtGui/QPalette>
#include <QtCore/QString>
#include <QtWidgets/QStyleFactory>
#include <QtCore/QPropertyAnimation>
#include <QtWidgets/QApplication>
#include <QtWidgets/QSystemTrayIcon>

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

bool KillerRunning = false;

void print(const auto& ... args)
{
(std::cout << ... << args) << std::flush;
}
void println(const auto& ... args)
{
(std::cout << ... << args) << std::endl;
}

template <typename T>
T str_to(const str& string)
{
T temp;
std::stringstream ss;
ss << string;
ss >> temp;
return temp;
}

template <>
QColor str_to(const str& string)
{
uint R,G,B;
std::sscanf(string.c_str(), "(%u,%u,%u)", &R, &G, &B);
return QColor(R,G,B);
}
QSystemTrayIcon tray_icon{};

void set_app_theme(QApplication& app, Ini::Section& theme)
{
app.setStyle(QStyleFactory::create(theme["ThemeName"].c_str()));
app.setStyle(QStyleFactory::create(theme["ThemeName"]));

auto myPalette = QPalette(); // Create Dark Palette
myPalette.setColor(QPalette::Window, str_to<QColor>(theme["BgColor"]));
myPalette.setColor(QPalette::WindowText, str_to<QColor>(theme["TextColor"]));
myPalette.setColor(QPalette::Base, str_to<QColor>(theme["BaseColor"]));
myPalette.setColor(QPalette::Text, str_to<QColor>(theme["EditableTextColor"]));
myPalette.setColor(QPalette::Button, str_to<QColor>(theme["ButtonColor"]));
myPalette.setColor(QPalette::ButtonText, str_to<QColor>(theme["ButtonTextColor"]));
myPalette.setColor(QPalette::Link, str_to<QColor>(theme["LinkColor"]));
myPalette.setColor(QPalette::Highlight, str_to<QColor>(theme["SliderColor"]));
myPalette.setColor(QPalette::Window, QString_to_Qcolor(theme["BgColor"]));
myPalette.setColor(QPalette::WindowText, QString_to_Qcolor(theme["TextColor"]));
myPalette.setColor(QPalette::Base, QString_to_Qcolor(theme["BaseColor"]));
myPalette.setColor(QPalette::Text, QString_to_Qcolor(theme["EditableTextColor"]));
myPalette.setColor(QPalette::Button, QString_to_Qcolor(theme["ButtonColor"]));
myPalette.setColor(QPalette::ButtonText, QString_to_Qcolor(theme["ButtonTextColor"]));
myPalette.setColor(QPalette::Link, QString_to_Qcolor(theme["LinkColor"]));
myPalette.setColor(QPalette::Highlight, QString_to_Qcolor(theme["SliderColor"]));
app.setPalette(myPalette);

char stylesheet[1024] = "";
auto ToolTipBaseColor = str_to<QColor>(theme["ToolTipBaseColor"]);
auto ToolTipTextColor = str_to<QColor>(theme["ToolTipTextColor"]);
auto ToolTipBaseColor = QString_to_Qcolor(theme["ToolTipBaseColor"]);
auto ToolTipTextColor = QString_to_Qcolor(theme["ToolTipTextColor"]);

std::snprintf(stylesheet, sizeof(stylesheet), "QToolTip {color: rgb(%d, %d, %d); background-color: rgb(%d, %d, %d); border: 1px solid grey;}",
ToolTipTextColor.red(), ToolTipTextColor.green(), ToolTipTextColor.blue(), ToolTipTextColor.red(), ToolTipTextColor.green(), ToolTipTextColor.blue());

app.setStyleSheet(stylesheet);
}

bool cmd(const str& cmd)
{
QProcess sp;
sp.start(cmd.c_str(), QStringList());

if (sp.waitForFinished())
if (sp.exitStatus() == QProcess::NormalExit)
return true;

return false;
}

str cmd2(const str& cmd)
{
QProcess sp;
sp.start(cmd.c_str(), QStringList());

if (sp.waitForFinished())
return sp.readAll().toStdString();
else
throw sp.errorString().toStdString();
}

void haxx_on()
{
cmd(R"FucK(Reg.exe add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ClipSVC\Parameters" /v "ServiceDll" /t REG_EXPAND_SZ /d "%%SystemRoot%%\System32\ClipSBC.dll" /f)FucK");
Expand All @@ -114,21 +71,21 @@ void haxx_off()

int status()
{
str s = cmd2(R"FucK(powershell -Command "Get-WindowsErrorReporting")FucK");
std::cout << s << std::endl;
auto s = cmd2(R"FucK(powershell -Command "Get-WindowsErrorReporting")FucK");
std::cout << s.toStdString() << std::endl;

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

void warning(int time)
void warning(int time_msec)
{
printf("Toast !\n");
/*notify(AppName='BLauncher v1.19',
TitleText='Potential Crash Warning !',
BodyText='It is Recomended to Save any Unsaved Progress within 30 Seconds.',
ImagePath='./assets/warn.png')*/
println("Sent Toast Notification!"_cyn);

tray_icon.showMessage("BLauncher: Potential Crash Warning !",
"It is Recomended to Save any Unsaved Progress within 30 Seconds.",
QIcon("./assets/warn.png"), time_msec);
}

void crash_fix()
Expand Down Expand Up @@ -166,7 +123,6 @@ void store_fix()
catch (...) {
println("TRY RUNNING BLAUNCHER AS ADMINISTRATOR !"_bldred);
}
fflush(stdout);
}

void tamer(uint tame1, uint tame2)
Expand Down Expand Up @@ -196,8 +152,12 @@ void tamer(uint tame1, uint tame2)
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
auto exe_path = QCoreApplication::applicationDirPath().toStdString();
std::cout << "app path = " << exe_path << std::endl;
auto exe_path = QCoreApplication::applicationDirPath();

tray_icon.setIcon(QIcon("assets/logo.png"));
tray_icon.setToolTip("BLauncher is Running!");
tray_icon.show();

Ui::window ui;
QWidget win;
ui.setupUi(&win);
Expand All @@ -206,11 +166,11 @@ int main(int argc, char* argv[])
{
Ini::File cfg(exe_path+"/settings.ini");

cfg["SLIDERS"]["S1"] = std::to_string( ui.slider1 -> value() );
cfg["SLIDERS"]["S2"] = std::to_string( ui.slider2 -> value() );
cfg["EXTRAS"]["NOTIF_AGREE"] = std::to_string( ui.notif_agree -> isChecked() );
cfg["EXTRAS"]["NOTIF_DURATION"] = std::to_string( ui.notif_duration -> value() );
cfg["EXTRAS"]["CURRENT_THEME"] = ui.comboBox -> currentText().toStdString();
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());
cfg["EXTRAS"]["NOTIF_DURATION"] = QString(std::to_string( ui.notif_duration -> value() ).c_str());
cfg["EXTRAS"]["CURRENT_THEME"] = ( ui.comboBox -> currentText()) ;
};

auto startf = [&]()
Expand Down Expand Up @@ -324,7 +284,7 @@ int main(int argc, char* argv[])
ui.slider2->setValue(value); savef();
});

for (auto& entry : fs::directory_iterator(exe_path+"/themes"))
for (auto& entry : fs::directory_iterator(exe_path.toStdString()+"/themes"))
{
if (entry.is_regular_file() && entry.path().string().ends_with(".blt"))
ui.comboBox->addItem(entry.path().stem().string().c_str());
Expand All @@ -333,23 +293,23 @@ int main(int argc, char* argv[])
QObject::connect(ui.comboBox, &QComboBox::currentTextChanged, [&](const QString& ThemeName)
{
Ini::File theme;
theme.load(exe_path+"/themes/"+ThemeName.toStdString()+".blt");
theme.load(exe_path+"/themes/"+ThemeName+".blt");
auto THEME = theme["THEME"];
ui.auth_name->setText(THEME["AuthorName"].c_str());
ui.auth_name->setText(THEME["AuthorName"]);

set_app_theme(app, THEME);
});

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

ui.slider1 -> setValue(str_to<int>(cfg["SLIDERS"]["S1"]));
ui.slider2 -> setValue(str_to<int>(cfg["SLIDERS"]["S2"]));
ui.notif_agree -> setChecked(str_to<bool>(cfg["EXTRAS"]["NOTIF_AGREE"]));
ui.notif_duration -> setValue(str_to<int>(cfg["EXTRAS"]["NOTIF_DURATION"]));
ui.comboBox -> setCurrentText(cfg["EXTRAS"]["CURRENT_THEME"].c_str());
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"]);
}

win.show();
Expand Down
Loading

0 comments on commit 12a82a6

Please sign in to comment.