diff --git a/GWToolbox/Inject.cpp b/GWToolbox/Inject.cpp index e283a56d6..da64a9bf2 100644 --- a/GWToolbox/Inject.cpp +++ b/GWToolbox/Inject.cpp @@ -4,6 +4,8 @@ #include "Inject.h" +#include "Settings.h" + #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) // @Cleanup: @Remark: @@ -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 } @@ -229,7 +231,6 @@ InjectWindow::InjectWindow() : m_hCharacters(nullptr) , m_hLaunchButton(nullptr) , m_hRestartAsAdmin(nullptr) - , m_hSettings(nullptr) , m_Selected(-1) {} InjectWindow::~InjectWindow() {} @@ -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() diff --git a/GWToolbox/Inject.h b/GWToolbox/Inject.h index d21c4889d..0c8128e0d 100644 --- a/GWToolbox/Inject.h +++ b/GWToolbox/Inject.h @@ -1,7 +1,6 @@ #pragma once #include "Process.h" -#include "Settings.h" #include "Window.h" enum InjectReply { @@ -16,7 +15,6 @@ class InjectWindow : public Window { public: static InjectReply AskInjectProcess(Process* target_process); -public: InjectWindow(); InjectWindow(const InjectWindow&) = delete; InjectWindow(InjectWindow&&) = delete; @@ -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; }; diff --git a/GWToolbox/Install.cpp b/GWToolbox/Install.cpp index 052b4f70e..5d8d36d2e 100644 --- a/GWToolbox/Install.cpp +++ b/GWToolbox/Install.cpp @@ -112,7 +112,7 @@ bool DeleteInstallationDirectory() return true; } -bool Install(const bool quiet) +bool Install() { if (IsInstalled()) { return true; @@ -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; } diff --git a/GWToolbox/Install.h b/GWToolbox/Install.h index c8aa89ebb..cd44666d1 100644 --- a/GWToolbox/Install.h +++ b/GWToolbox/Install.h @@ -1,6 +1,6 @@ #pragma once -bool Install(bool quiet); -bool Uninstall(bool quiet); +bool Install(); +bool Uninstall(); bool IsInstalled(); diff --git a/GWToolbox/Settings.cpp b/GWToolbox/Settings.cpp index 72cfb64f2..2609bbec4 100644 --- a/GWToolbox/Settings.cpp +++ b/GWToolbox/Settings.cpp @@ -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" @@ -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; @@ -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; @@ -125,24 +82,14 @@ void ParseCommandLine() } settings.pid = static_cast(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) { @@ -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(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(); - } -} diff --git a/GWToolbox/Settings.h b/GWToolbox/Settings.h index e63478889..432e4bd80 100644 --- a/GWToolbox/Settings.h +++ b/GWToolbox/Settings.h @@ -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; @@ -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; -}; diff --git a/GWToolbox/main.cpp b/GWToolbox/main.cpp index 7cdbfad0e..b8d276de6 100644 --- a/GWToolbox/main.cpp +++ b/GWToolbox/main.cpp @@ -123,46 +123,33 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n return 0; } - ParseRegSettings(); - ParseCommandLine(); - assert(settings.help == false); if (settings.version) { printf("GWToolbox version %s\n", GWTOOLBOXEXE_VERSION); return 0; } - if (settings.asadmin && !IsRunningAsAdmin()) { - RestartWithSameArgs(true); - } - AsyncRestScopeInit RestInitializer; Process proc; if (settings.install) { - Install(settings.quiet); + Install(); return 0; } if (settings.uninstall) { - Uninstall(settings.quiet); + Uninstall(); return 0; } if (settings.reinstall) { // @Enhancement: // Uninstall shouldn't remove the existing data, that would instead be a // "repair" or something along those lines. - Uninstall(settings.quiet); - Install(settings.quiet); + Uninstall(); + Install(); return 0; } if (!IsInstalled() && !settings.noinstall) { - if (settings.quiet) { - ShowError(L"Can't ask to install if started with '/quiet'"); - fprintf(stderr, "Can't ask to install if started with '/quiet'\n"); - return 1; - } - const int iRet = MessageBoxW( nullptr, L"GWToolbox doesn't seem to be installed, do you want to install it?", @@ -176,19 +163,12 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n if (iRet == IDYES) { // @Cleanup: Check return value - if (!Install(settings.quiet)) { + if (!Install()) { fprintf(stderr, "Failed to install\n"); return 1; } } } - else if (!settings.noupdate) { - if (!DownloadWindow::DownloadAllFiles()) { - ShowError(L"Failed to download GWToolbox DLL"); - fprintf(stderr, "DownloadWindow::DownloadAllFiles failed\n"); - return 1; - } - } if (settings.pid) { if (!proc.Open(settings.pid)) {