Skip to content

Commit

Permalink
File Explorer: Fixed UB caused by wrong ShouldAppsUseDarkMode signatu…
Browse files Browse the repository at this point in the history
…re (#2429, #2431)
  • Loading branch information
Amrsatrio committed Nov 12, 2023
1 parent c5bb636 commit 3b902d0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Tested on OS builds 22000.2416, 22621.2361, 22621.2506, and 23585.1001.
* Changing the taskbar alignment requires restarting `explorer.exe` in order to take effect.
* File Explorer: Added option to disable the modern navigation bar of Moment 4. (2dc1340)
* File Explorer: Restored "Apply Mica" functionality on OS builds 22621+. (f62c532)
* Localization: Officially added Japanese translations. (Thanks @creeper-0910, @reindex-ot, and @Rukoto!)
* Localization: Officially added translations for the following languages:
* Chinese, Simplified (Thanks @zetaloop!)
* Japanese (Thanks @creeper-0910, @reindex-ot, and @Rukoto!)
* GUI: Decoupled the Properties window into `ep_gui.dll` from the main DLL in order to reduce the main DLL size and to allow scalable localization. (f6f6d89, 639d7aa)
* `rundll32 C:\Windows\dxgi.dll,ZZGUI` will continue to work as before.

Expand Down
6 changes: 3 additions & 3 deletions ExplorerPatcher/dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -3906,7 +3906,7 @@ HWND WINAPI explorerframe_SHCreateWorkerWindowHook(
{
SetWindowSubclass(hWndParent, HideExplorerSearchBarSubClass, HideExplorerSearchBarSubClass, 0);
}
if (bIsExplorerProcess && dwFileExplorerCommandUI != 0 && IsWindows11Version22H2OrHigher())
if (bIsExplorerProcess && (dwFileExplorerCommandUI == 1 || dwFileExplorerCommandUI == 2 || dwFileExplorerCommandUI == 3) && IsWindows11Version22H2OrHigher())
{
// Fix initial title bar style after disabling TIFE
// If we don't do this, it will only fix itself once the user changes the system color scheme or toggling transparency effects
Expand All @@ -3917,8 +3917,8 @@ HWND WINAPI explorerframe_SHCreateWorkerWindowHook(
}
if (ShouldAppsUseDarkMode)
{
BOOL value = ShouldAppsUseDarkMode();
DwmSetWindowAttribute(hWndParent, DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(BOOL));
BOOL bDarkMode = ShouldAppsUseDarkMode() && !IsHighContrast();
DwmSetWindowAttribute(hWndParent, DWMWA_USE_IMMERSIVE_DARK_MODE, &bDarkMode, sizeof(BOOL));
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions ExplorerPatcher/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <activscp.h>
#include <netlistmgr.h>
#include <Psapi.h>
#include <stdbool.h>

#include "def.h"

Expand Down Expand Up @@ -367,18 +368,16 @@ BOOL(WINAPI* SetWindowBand)(HWND hWnd, HWND hwndInsertAfter, DWORD dwBand);

INT64(*SetWindowCompositionAttribute)(HWND, void*);

static void(*SetPreferredAppMode)(INT64 bAllowDark);
static void(*SetPreferredAppMode)(bool bAllowDark);

static void(*AllowDarkModeForWindow)(HWND hWnd, INT64 bAllowDark);
static void(*AllowDarkModeForWindow)(HWND hWnd, bool bAllowDark);

static BOOL(*ShouldAppsUseDarkMode)();
static bool(*ShouldAppsUseDarkMode)();

static BOOL(*ShouldSystemUseDarkMode)();
static bool(*ShouldSystemUseDarkMode)();

static void(*GetThemeName)(void*, void*, void*);

static BOOL AppsShouldUseDarkMode() { return TRUE; }

void* ReadFromFile(wchar_t* wszFileName, DWORD* dwSize);

int ComputeFileHash(LPCWSTR filename, LPSTR hash, DWORD dwHash);
Expand Down
1 change: 0 additions & 1 deletion ep_gui/GUI.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ void* GUI_FileMapping = NULL;
DWORD GUI_FileSize = 0;
BOOL g_darkModeEnabled = FALSE;
static void(*RefreshImmersiveColorPolicyState)() = NULL;
// static BOOL(*ShouldAppsUseDarkMode)() = nullptr; // Already defined in utility.h
DWORD dwTaskbarPosition = 3;
BOOL gui_bOldTaskbar = TRUE;

Expand Down

0 comments on commit 3b902d0

Please sign in to comment.