Skip to content

Commit

Permalink
* Added setup wizard (closes #4)
Browse files Browse the repository at this point in the history
* Fixed possible issue with getting DWM pid.
  • Loading branch information
oberrich committed Nov 16, 2023
1 parent bc5c382 commit b49a1dd
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 9 deletions.
23 changes: 15 additions & 8 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
#include <algorithm>
#include <cinttypes>
#include <concepts>
#include <chrono>
#include <cstdio>
#include <format>
#include <functional>
#include <iostream>
#include <optional>
#include <ranges>
#include <string_view>
#include <thread>

#include <windows.h>
#include <tlhelp32.h>
Expand Down Expand Up @@ -69,9 +71,9 @@ struct ProgramOptions {
}

constexpr std::wstring_view program_name_friendly{L"Win11 Toggle Rounded Corners"sv};
constexpr std::wstring_view version {L"v1.1"sv};
constexpr std::wstring_view version {L"v1.2"sv};
constexpr std::wstring_view license {L"MIT License"};
constexpr std::wstring_view copyright_year {L"2022"sv};
constexpr std::wstring_view copyright_year {L"2023"sv};
constexpr std::wstring_view author {L"oberrich"sv};

std::wcout << std::format(L"{} {}\nCopyright (C) {} {}, {}\n\n"sv, program_name_friendly, version, copyright_year, author, license);
Expand Down Expand Up @@ -314,10 +316,11 @@ bool enable_privilege(LPCTSTR name) noexcept {
int main() try
{
using namespace std::string_view_literals;
using namespace std::chrono_literals;

using clock = std::chrono::steady_clock;

ProgramOptions const options{
// TODO: Implement --no-autostart
Option{L"no-autostart"sv, L"Puts the program into auto-start with the currently specified options. NOT IMPLEMENTED"sv},
Option{L"no-patching"sv, L"Force DWM to use WARP adapter instead of patching .rdata section. This is used as a "
"fallback method by default in case the .rdata method fails."sv},
Option{L"verbose"sv, L"Enables verbose output."sv},
Expand All @@ -327,19 +330,24 @@ int main() try

set_verbose(options[L"verbose"sv].value);

detail::assert_status(ZYAN_STATUS_INVALID_ARGUMENT);
auto should_disable = options[L"disable"sv].value;
auto const should_override_toggle = should_disable || options[L"enable"sv].value;

if (!enable_privilege(SE_DEBUG_NAME))
throw std::runtime_error(std::format("Failed to enable '{}', make sure you are running as admin.", SE_DEBUG_NAME));

auto const dwm_hwnd = FindWindowA("Dwm", nullptr);
DWORD dwm_pid = 0u;

if (!dwm_hwnd || !GetWindowThreadProcessId(dwm_hwnd, &dwm_pid))
for (auto first_attempt_at = clock::now(); clock::now() - first_attempt_at < 5s; std::this_thread::sleep_for(250ms)) {
if (auto const dwm_hwnd = FindWindowA("Dwm", nullptr); dwm_hwnd && GetWindowThreadProcessId(dwm_hwnd, &dwm_pid))
break;
}

if (!dwm_pid)
throw std::runtime_error("Failed to find dwm process.\n");

verbose(std::format("Found dwm.exe process [window handle: {}, pid: {}].\n", static_cast<void *>(dwm_hwnd), dwm_pid));
verbose(std::format("Found dwm.exe process, pid: {}.\n", dwm_pid));

auto const dwm_process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwm_pid);
if (!dwm_process)
Expand Down Expand Up @@ -387,7 +395,6 @@ int main() try
if (!WriteProcessMemory(dwm_process, &desktop_manager->enable_sharp_corners, &should_disable, 1, &out_size) || out_size != 1)
throw std::runtime_error(std::format("Failed to write 'enable_sharp_corners' to dwm.exe, status: {:#x}.\n", GetLastError()));
} else {
// TODO: Use non-patching method as backup (maybe put both methods in own function / class and wrap with try/catch)
// .rdata method: writes to floats related to rounding
auto udwm_dll = LoadLibraryExA("udwm.dll", nullptr, DONT_RESOLVE_DLL_REFERENCES);

Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project('win11-toggle-rounded-corners', ['c', 'cpp'],
version : '1.1',
version : '1.2',
default_options : [
'cpp_std=c++latest',
'buildtype=release',
Expand Down
95 changes: 95 additions & 0 deletions setup.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "Win11 Toggle Rounded Corners"
#define MyAppVersion "1.2"
#define MyAppPublisher "oberrich"
#define MyAppURL "https://github.com/oberrich/win11-toggle-rounded-corners"

[Setup]
AppId={{5B8824C9-B4BE-4B1C-AA9F-BA8362C44B96}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
AppCopyright=Copyright (C) 2023 oberrich, MIT License
DefaultDirName={autopf}\{#MyAppName}
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
LicenseFile=LICENSE
PrivilegesRequired=admin
OutputBaseFilename=win11-toggle-rounded-corners-setup
Compression=lzma
SolidCompression=yes
WizardStyle=modern
ArchitecturesAllowed=x64
ArchitecturesInstallIn64BitMode=x64
MissingRunOnceIdsWarning=no
OutputDir=build

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
; Place any regular files here
Source: "LICENSE"; DestDir: "{app}";
; These files will be downloaded
Source: "{tmp}\win11-toggle-rounded-corners.exe"; DestDir: "{app}"; Flags: external

[Code]
var
DownloadPage: TDownloadWizardPage;
function OnDownloadProgress(const Url, FileName: String; const Progress, ProgressMax: Int64): Boolean;
begin
if Progress = ProgressMax then
Log(Format('Successfully downloaded file to {tmp}: %s', [FileName]));
Result := True;
end;
procedure InitializeWizard;
begin
DownloadPage := CreateDownloadPage(SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc), @OnDownloadProgress);
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
if CurPageID = wpReady then begin
DownloadPage.Clear;
DownloadPage.Add('https://github.com/oberrich/win11-toggle-rounded-corners/releases/latest/download/win11-toggle-rounded-corners.exe', 'win11-toggle-rounded-corners.exe', '');
DownloadPage.Show;
try
try
DownloadPage.Download; // This downloads the files to {tmp}
Result := True;
except
if DownloadPage.AbortedByUser then
Log('Aborted by user.')
else
SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbCriticalError, MB_OK, IDOK);
Result := False;
end;
finally
DownloadPage.Hide;
end;
end else
Result := True;
end;
[Run]
Filename: "schtasks"; \
Parameters: "/Create /F /RL highest /SC onlogon /TN ""Run win11-toggle-rounded-corners as admin on logon"" /TR ""'{app}\win11-toggle-rounded-corners.exe' --disable"""; \
Description: "Automatically run on logon"; \
Flags: runhidden runascurrentuser postinstall
Filename: "{app}\win11-toggle-rounded-corners.exe"; \
Description: "Run now"; \
Parameters: "--disable"; \
Flags: runhidden runascurrentuser nowait postinstall

[UninstallRun]
Filename: "schtasks"; \
Parameters: "/Delete /F /TN ""Run win11-toggle-rounded-corners as admin on logon"""; \
Flags: runhidden runascurrentuser

0 comments on commit b49a1dd

Please sign in to comment.