Skip to content

Commit

Permalink
Revert launcher to aug 2024 until review
Browse files Browse the repository at this point in the history
  • Loading branch information
3vcloud committed Nov 18, 2024
1 parent 5dd0bb0 commit 2bb9ebb
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 19 deletions.
28 changes: 22 additions & 6 deletions GWToolbox/Inject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "Inject.h"

#include "Settings.h"

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

// @Cleanup: @Remark:
Expand Down Expand Up @@ -181,7 +179,7 @@ InjectReply InjectWindow::AskInjectProcess(Process* target_process)
return InjectReply_NoValidProcess;
}

if (inject_processes.size() == 1) {
if (settings.quiet && inject_processes.size() == 1) {
*target_process = std::move(inject_processes[0].m_Process);
return InjectReply_Inject; // Inject if 1 process found
}
Expand Down Expand Up @@ -231,6 +229,7 @@ InjectWindow::InjectWindow()
: m_hCharacters(nullptr)
, m_hLaunchButton(nullptr)
, m_hRestartAsAdmin(nullptr)
, m_hSettings(nullptr)
, m_Selected(-1) {}

InjectWindow::~InjectWindow() {}
Expand Down Expand Up @@ -344,17 +343,34 @@ void InjectWindow::OnCreate(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
SendMessageW(m_hRestartAsAdmin, WM_SETFONT, (WPARAM)m_hFont, MAKELPARAM(TRUE, 0));
Button_SetElevationRequiredState(m_hRestartAsAdmin, TRUE);
}

m_hSettings = CreateWindowW(
WC_BUTTONW,
L"Settings...",
WS_VISIBLE | WS_CHILD | WS_TABSTOP,
200,
65,
80,
25,
hWnd,
nullptr,
m_hInstance,
nullptr);
SendMessageW(m_hSettings, WM_SETFONT, (WPARAM)m_hFont, MAKELPARAM(TRUE, 0));
}

void InjectWindow::OnCommand(HWND hwnd, LONG ControlId, LONG NotificateCode)
void InjectWindow::OnCommand(HWND hWnd, const LONG ControlId, LONG NotificationCode)
{
if (hwnd == m_hLaunchButton && ControlId == STN_CLICKED) {
if (hWnd == m_hLaunchButton && ControlId == STN_CLICKED) {
m_Selected = SendMessageW(m_hCharacters, CB_GETCURSEL, 0, 0);
DestroyWindow(m_hWnd);
}
else if (hwnd == m_hRestartAsAdmin && ControlId == STN_CLICKED) {
else if (hWnd == m_hRestartAsAdmin && ControlId == STN_CLICKED) {
RestartWithSameArgs(true);
}
else if (hWnd == m_hSettings && ControlId == STN_CLICKED) {
m_SettingsWindow.Create();
}
}

static FARPROC GetLoadLibrary()
Expand Down
5 changes: 5 additions & 0 deletions GWToolbox/Inject.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "Process.h"
#include "Settings.h"
#include "Window.h"

enum InjectReply {
Expand All @@ -15,6 +16,7 @@ class InjectWindow : public Window {
public:
static InjectReply AskInjectProcess(Process* target_process);

public:
InjectWindow();
InjectWindow(const InjectWindow&) = delete;
InjectWindow(InjectWindow&&) = delete;
Expand All @@ -33,9 +35,12 @@ class InjectWindow : public Window {
void OnCreate(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void OnCommand(HWND hwnd, LONG ControlId, LONG NotificateCode);

private:
HWND m_hCharacters;
HWND m_hLaunchButton;
HWND m_hRestartAsAdmin;
HWND m_hSettings;
SettingsWindow m_SettingsWindow;

int m_Selected;
};
Expand Down
31 changes: 25 additions & 6 deletions GWToolbox/Install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ bool DeleteInstallationDirectory()
return true;
}

bool Install()
bool Install(const bool quiet)
{
if (IsInstalled()) {
return true;
Expand All @@ -133,17 +133,36 @@ bool Install()
return false;
}

MessageBoxW(nullptr, L"Installation successful", L"Installation", 0);
if (!quiet) {
MessageBoxW(nullptr, L"Installation successful", L"Installation", 0);
}

return true;
}

bool Uninstall()
bool Uninstall(const bool quiet)
{
// Delete all files
DeleteInstallationDirectory();
bool DeleteAllFiles = true;
if (quiet == false) {
const int iRet = MessageBoxW(
nullptr,
L"Do you want to delete *all* possible files from installation folder? (Default: no)\n",
L"Uninstallation",
MB_YESNO);

if (iRet != IDYES) {
DeleteAllFiles = false;
}
}

MessageBoxW(nullptr, L"Uninstallation successful", L"Uninstallation", 0);
if (DeleteAllFiles) {
// Delete all files
DeleteInstallationDirectory();
}

if (quiet == false) {
MessageBoxW(nullptr, L"Uninstallation successful", L"Uninstallation", 0);
}

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions GWToolbox/Install.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

bool Install();
bool Uninstall();
bool Install(bool quiet);
bool Uninstall(bool quiet);

bool IsInstalled();
129 changes: 129 additions & 0 deletions GWToolbox/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ void PrintUsage(const bool terminate)

" /?, /help Print this help\n"
" /version Print version and exist\n"
" /quiet Doesn't create any interaction with the user\n\n"

" /install Create necessary folders and download GWToolboxdll\n"
" /uninstall Remove all data used by GWToolbox\n"
" /reinstall Do a fresh installation\n\n"

" /asadmin GWToolbox will try to run as admin\n"
" /noupdate Won't try to update\n"
" /noinstall Won't try to install if missing\n"
" /localdll Check launcher directory for toolbox dll, won't try to install or update\n\n"

Expand All @@ -29,6 +31,46 @@ void PrintUsage(const bool terminate)
}
}

void ParseRegSettings()
{
HKEY SettingsKey;
if (!OpenSettingsKey(&SettingsKey)) {
fprintf(stderr, "OpenSettingsKey failed\n");
return;
}

DWORD asadmin;
if (RegReadDWORD(SettingsKey, L"asadmin", &asadmin)) {
settings.asadmin = asadmin != 0;
}

DWORD noupdate;
if (RegReadDWORD(SettingsKey, L"noupdate", &noupdate)) {
settings.noupdate = noupdate != 0;
}

RegCloseKey(SettingsKey);
}

static void WriteRegSettings()
{
HKEY SettingsKey;
if (!OpenSettingsKey(&SettingsKey)) {
fprintf(stderr, "OpenUninstallKey failed\n");
return;
}

if (RegWriteDWORD(SettingsKey, L"asadmin", settings.asadmin)) {
fprintf(stderr, "Failed to write 'asadmin' registry key\n");
}

if (RegWriteDWORD(SettingsKey, L"noupdate", settings.noupdate)) {
fprintf(stderr, "Failed to write 'noupdate' registry key\n");
}

RegCloseKey(SettingsKey);
}

static bool IsOneOrZeroOf3(const bool b1, const bool b2, const bool b3)
{
int count = 0;
Expand Down Expand Up @@ -62,6 +104,7 @@ void ParseCommandLine()
}
else if (wcscmp(arg, L"/install") == 0) {
settings.install = true;
settings.noupdate = false;
}
else if (wcscmp(arg, L"/uninstall") == 0) {
settings.uninstall = true;
Expand All @@ -82,14 +125,24 @@ void ParseCommandLine()
}
settings.pid = static_cast<uint32_t>(pid);
}
else if (wcscmp(arg, L"/asadmin") == 0) {
settings.asadmin = true;
}
else if (wcscmp(arg, L"/noupdate") == 0) {
settings.noupdate = true;
}
else if (wcscmp(arg, L"/help") == 0) {
settings.help = true;
}
else if (wcscmp(arg, L"/noinstall") == 0) {
settings.noinstall = true;
}
else if (wcscmp(arg, L"/quiet") == 0) {
settings.quiet = true;
}
else if (wcscmp(arg, L"/localdll") == 0) {
settings.localdll = true;
settings.noupdate = true;
settings.noinstall = true;
}
else if (wcscmp(arg, L"/?") == 0) {
Expand Down Expand Up @@ -285,3 +338,79 @@ static bool ToggleCheckbox(HWND hWnd)
SetCheckbox(hWnd, !Checked);
return !Checked;
}

bool SettingsWindow::Create()
{
SetWindowName(L"GWToolbox - Settings");
SetWindowDimension(305, 135);
return Window::Create();
}

LRESULT SettingsWindow::WndProc(HWND hWnd, const UINT uMsg, const WPARAM wParam, const LPARAM lParam)
{
switch (uMsg) {
case WM_CREATE:
OnCreate(hWnd, uMsg, wParam, lParam);
break;

case WM_CLOSE:
DestroyWindow(hWnd);
break;

case WM_DESTROY:
SignalStop();
break;

case WM_COMMAND:
OnCommand(reinterpret_cast<HWND>(lParam), LOWORD(wParam), HIWORD(wParam));
break;
}

return DefWindowProcW(hWnd, uMsg, wParam, lParam);
}

void SettingsWindow::OnCreate(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
m_hNoUpdate = CreateWindowW(
WC_BUTTONW,
L"Never check for update",
WS_VISIBLE | WS_CHILD | WS_TABSTOP | BS_CHECKBOX,
10,
10,
150,
15,
hWnd,
nullptr,
m_hInstance,
nullptr);
SendMessageW(m_hNoUpdate, WM_SETFONT, (WPARAM)m_hFont, MAKELPARAM(TRUE, 0));

m_hStartAsAdmin = CreateWindowW(
WC_BUTTONW,
L"Always start as admin",
WS_VISIBLE | WS_CHILD | WS_TABSTOP | BS_CHECKBOX,
10,
30,
150,
15,
hWnd,
nullptr,
m_hInstance,
nullptr);
SendMessageW(m_hStartAsAdmin, WM_SETFONT, (WPARAM)m_hFont, MAKELPARAM(TRUE, 0));

SetCheckbox(m_hNoUpdate, settings.noupdate);
SetCheckbox(m_hStartAsAdmin, settings.asadmin);
}

void SettingsWindow::OnCommand(HWND hWnd, LONG ControlId, LONG NotificateCode) const
{
if (hWnd == m_hNoUpdate) {
settings.noupdate = ToggleCheckbox(m_hNoUpdate);
WriteRegSettings();
}
else if (hWnd == m_hStartAsAdmin) {
settings.asadmin = ToggleCheckbox(m_hStartAsAdmin);
WriteRegSettings();
}
}
30 changes: 30 additions & 0 deletions GWToolbox/Settings.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#pragma once

#include "Window.h"

struct Settings {
bool help = false;
bool version = false;
bool quiet = false;
bool install = false;
bool uninstall = false;
bool reinstall = false;
bool asadmin = false;
bool noupdate = false;
bool noinstall = false;
bool localdll = false;
uint32_t pid;
Expand All @@ -15,9 +20,34 @@ extern Settings settings;

void PrintUsage(bool terminate);

void ParseRegSettings();
void ParseCommandLine();

bool IsRunningAsAdmin();
bool CreateProcessInt(const wchar_t* path, const wchar_t* args, const wchar_t* workdir, bool as_admin = false);
bool Restart(const wchar_t* args, bool force_admin = false);
bool RestartAsAdmin(const wchar_t* args);
void RestartWithSameArgs(bool force_admin = false);
bool EnableDebugPrivilege();

class SettingsWindow : public Window {
public:
SettingsWindow() = default;
SettingsWindow(const SettingsWindow&) = delete;
SettingsWindow(SettingsWindow&&) = delete;
~SettingsWindow() override = default;

SettingsWindow& operator=(const SettingsWindow&) = delete;

bool Create() override;

private:
LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) override;

void OnCreate(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void OnCommand(HWND hwnd, LONG ControlId, LONG NotificateCode) const;

private:
HWND m_hNoUpdate = nullptr;
HWND m_hStartAsAdmin = nullptr;
};
Loading

0 comments on commit 2bb9ebb

Please sign in to comment.