Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/gwdevhub/GWToolboxpp into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
3vcloud committed Oct 15, 2024
2 parents 0152a6f + 278fd1a commit 691b948
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 238 deletions.
28 changes: 6 additions & 22 deletions GWToolbox/Inject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "Inject.h"

#include "Settings.h"

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

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

if (settings.quiet && inject_processes.size() == 1) {
if (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 @@ -229,7 +231,6 @@ InjectWindow::InjectWindow()
: m_hCharacters(nullptr)
, m_hLaunchButton(nullptr)
, m_hRestartAsAdmin(nullptr)
, m_hSettings(nullptr)
, m_Selected(-1) {}

InjectWindow::~InjectWindow() {}
Expand Down Expand Up @@ -343,34 +344,17 @@ 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, const LONG ControlId, LONG NotificationCode)
void InjectWindow::OnCommand(HWND hwnd, LONG ControlId, LONG NotificateCode)
{
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: 0 additions & 5 deletions GWToolbox/Inject.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

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

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

public:
InjectWindow();
InjectWindow(const InjectWindow&) = delete;
InjectWindow(InjectWindow&&) = delete;
Expand All @@ -35,12 +33,9 @@ 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: 6 additions & 25 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(const bool quiet)
bool Install()
{
if (IsInstalled()) {
return true;
Expand All @@ -133,36 +133,17 @@ bool Install(const bool quiet)
return false;
}

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

return true;
}

bool Uninstall(const bool quiet)
bool Uninstall()
{
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;
}
}
// Delete all files
DeleteInstallationDirectory();

if (DeleteAllFiles) {
// Delete all files
DeleteInstallationDirectory();
}

if (quiet == false) {
MessageBoxW(nullptr, L"Uninstallation successful", L"Uninstallation", 0);
}
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 quiet);
bool Uninstall(bool quiet);
bool Install();
bool Uninstall();

bool IsInstalled();
129 changes: 0 additions & 129 deletions GWToolbox/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ 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 @@ -31,46 +29,6 @@ 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 @@ -104,7 +62,6 @@ 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 @@ -125,24 +82,14 @@ 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 @@ -338,79 +285,3 @@ 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: 0 additions & 30 deletions GWToolbox/Settings.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
#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 @@ -20,34 +15,9 @@ 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 691b948

Please sign in to comment.