Browse Source

Simplify the NanaZip.Frieren because we follow the 2025 baseline.

pull/659/merge
MouriNaruto 2 days ago
parent
commit
3ee36f3045
  1. 236
      NanaZip.Frieren/NanaZip.Frieren.DarkMode.cpp
  2. 243
      NanaZip.Frieren/NanaZip.Frieren.RuntimeObjectWrapper.cpp
  3. 8
      NanaZip.Frieren/NanaZip.Frieren.cpp
  4. 8
      NanaZip.Frieren/NanaZip.Frieren.h
  5. 2
      NanaZip.Frieren/NanaZip.Frieren.props
  6. 1
      NanaZip.Frieren/NanaZip.Frieren.vcxproj

236
NanaZip.Frieren/NanaZip.Frieren.DarkMode.cpp

@ -1,9 +1,9 @@
/* /*
* PROJECT: NanaZip
* FILE: NanaZip.Frieren.DarkMode.cpp
* PURPOSE: Implementation for NanaZip dark mode support
* PROJECT: NanaZip
* FILE: NanaZip.Frieren.DarkMode.cpp
* PURPOSE: Implementation for NanaZip dark mode support
* *
* LICENSE: The MIT License
* LICENSE: The MIT License
* *
* MAINTAINER: MouriNaruto (Kenji.Mouri@outlook.com) * MAINTAINER: MouriNaruto (Kenji.Mouri@outlook.com)
*/ */
@ -35,222 +35,6 @@ EXTERN_C HTHEME WINAPI OpenNcThemeData(
namespace namespace
{ {
static HMODULE GetSHCoreModuleHandle()
{
static HMODULE CachedResult = ::GetModuleHandleW(L"SHCore.dll");
return CachedResult;
}
static FARPROC GetGetDpiForMonitorProcAddress()
{
static FARPROC CachedResult = ([]() -> FARPROC
{
HMODULE ModuleHandle = ::GetSHCoreModuleHandle();
if (ModuleHandle)
{
return ::GetProcAddress(
ModuleHandle,
"GetDpiForMonitor");
}
return nullptr;
}());
return CachedResult;
}
static HMODULE GetUser32ModuleHandle()
{
static HMODULE CachedResult = ::GetModuleHandleW(L"user32.dll");
return CachedResult;
}
static FARPROC GetGetDisplayConfigBufferSizesProcAddress()
{
static FARPROC CachedResult = ([]() -> FARPROC
{
HMODULE ModuleHandle = ::GetUser32ModuleHandle();
if (ModuleHandle)
{
return ::GetProcAddress(
ModuleHandle,
"GetDisplayConfigBufferSizes");
}
return nullptr;
}());
return CachedResult;
}
static FARPROC GetQueryDisplayConfigProcAddress()
{
static FARPROC CachedResult = ([]() -> FARPROC
{
HMODULE ModuleHandle = ::GetUser32ModuleHandle();
if (ModuleHandle)
{
return ::GetProcAddress(
ModuleHandle,
"QueryDisplayConfig");
}
return nullptr;
}());
return CachedResult;
}
static FARPROC GetDisplayConfigGetDeviceInfoProcAddress()
{
static FARPROC CachedResult = ([]() -> FARPROC
{
HMODULE ModuleHandle = ::GetUser32ModuleHandle();
if (ModuleHandle)
{
return ::GetProcAddress(
ModuleHandle,
"DisplayConfigGetDeviceInfo");
}
return nullptr;
}());
return CachedResult;
}
static FARPROC GetGetDpiForWindowProcAddress()
{
static FARPROC CachedResult = ([]() -> FARPROC
{
HMODULE ModuleHandle = ::GetUser32ModuleHandle();
if (ModuleHandle)
{
return ::GetProcAddress(
ModuleHandle,
"GetDpiForWindow");
}
return nullptr;
}());
return CachedResult;
}
static LONG WINAPI GetDisplayConfigBufferSizesWrapper(
_In_ UINT32 flags,
_Out_ UINT32* numPathArrayElements,
_Out_ UINT32* numModeInfoArrayElements)
{
using ProcType = decltype(::GetDisplayConfigBufferSizes)*;
ProcType ProcAddress = reinterpret_cast<ProcType>(
::GetGetDisplayConfigBufferSizesProcAddress());
if (ProcAddress)
{
return ProcAddress(
flags,
numPathArrayElements,
numModeInfoArrayElements);
}
return ERROR_NOT_SUPPORTED;
}
static LONG WINAPI QueryDisplayConfigWrapper(
_In_ UINT32 flags,
_Inout_ UINT32* numPathArrayElements,
_Out_ DISPLAYCONFIG_PATH_INFO* pathArray,
_Inout_ UINT32* numModeInfoArrayElements,
_Out_ DISPLAYCONFIG_MODE_INFO* modeInfoArray,
_Out_opt_ DISPLAYCONFIG_TOPOLOGY_ID* currentTopologyId)
{
using ProcType = decltype(::QueryDisplayConfig)*;
ProcType ProcAddress = reinterpret_cast<ProcType>(
::GetQueryDisplayConfigProcAddress());
if (ProcAddress)
{
return ProcAddress(
flags,
numPathArrayElements,
pathArray,
numModeInfoArrayElements,
modeInfoArray,
currentTopologyId);
}
return ERROR_NOT_SUPPORTED;
}
static LONG WINAPI DisplayConfigGetDeviceInfoWrapper(
_Inout_ DISPLAYCONFIG_DEVICE_INFO_HEADER* requestPacket)
{
using ProcType = decltype(::DisplayConfigGetDeviceInfo)*;
ProcType ProcAddress = reinterpret_cast<ProcType>(
::GetDisplayConfigGetDeviceInfoProcAddress());
if (ProcAddress)
{
return ProcAddress(requestPacket);
}
return ERROR_NOT_SUPPORTED;
}
static UINT WINAPI GetDpiForWindowWrapper(
_In_ HWND hWnd)
{
{
using ProcType = decltype(::GetDpiForWindow)*;
ProcType ProcAddress = reinterpret_cast<ProcType>(
::GetGetDpiForWindowProcAddress());
if (ProcAddress)
{
return ProcAddress(hWnd);
}
}
{
using ProcType = decltype(::GetDpiForMonitor)*;
ProcType ProcAddress = reinterpret_cast<ProcType>(
::GetGetDpiForMonitorProcAddress());
if (ProcAddress)
{
HMONITOR MonitorHandle = ::MonitorFromWindow(
hWnd,
MONITOR_DEFAULTTONEAREST);
if (MonitorHandle)
{
UINT DpiX = 0;
UINT DpiY = 0;
if (SUCCEEDED(ProcAddress(
MonitorHandle,
MDT_EFFECTIVE_DPI,
&DpiX,
&DpiY)))
{
return DpiX;
}
}
}
}
UINT DpiValue = USER_DEFAULT_SCREEN_DPI;
{
HDC WindowContextHandle = ::GetDC(hWnd);
if (WindowContextHandle)
{
DpiValue = ::GetDeviceCaps(WindowContextHandle, LOGPIXELSX);
::ReleaseDC(hWnd, WindowContextHandle);
}
}
return DpiValue;
}
static bool IsStandardDynamicRangeMode() static bool IsStandardDynamicRangeMode()
{ {
static bool CachedResult = ([]() -> bool static bool CachedResult = ([]() -> bool
@ -259,7 +43,7 @@ namespace
UINT32 NumPathArrayElements = 0; UINT32 NumPathArrayElements = 0;
UINT32 NumModeInfoArrayElements = 0; UINT32 NumModeInfoArrayElements = 0;
if (ERROR_SUCCESS == ::GetDisplayConfigBufferSizesWrapper(
if (ERROR_SUCCESS == ::GetDisplayConfigBufferSizes(
QDC_ONLY_ACTIVE_PATHS, QDC_ONLY_ACTIVE_PATHS,
&NumPathArrayElements, &NumPathArrayElements,
&NumModeInfoArrayElements)) &NumModeInfoArrayElements))
@ -268,7 +52,7 @@ namespace
NumPathArrayElements); NumPathArrayElements);
std::vector<DISPLAYCONFIG_MODE_INFO> ModeInfoArray( std::vector<DISPLAYCONFIG_MODE_INFO> ModeInfoArray(
NumModeInfoArrayElements); NumModeInfoArrayElements);
if (ERROR_SUCCESS == ::QueryDisplayConfigWrapper(
if (ERROR_SUCCESS == ::QueryDisplayConfig(
QDC_ONLY_ACTIVE_PATHS, QDC_ONLY_ACTIVE_PATHS,
&NumPathArrayElements, &NumPathArrayElements,
&PathArray[0], &PathArray[0],
@ -292,7 +76,7 @@ namespace
AdvancedColorInfo.header.id = AdvancedColorInfo.header.id =
Path.targetInfo.id; Path.targetInfo.id;
if (ERROR_SUCCESS == if (ERROR_SUCCESS ==
::DisplayConfigGetDeviceInfoWrapper(
::DisplayConfigGetDeviceInfo(
&AdvancedColorInfo.header)) &AdvancedColorInfo.header))
{ {
if (AdvancedColorInfo.advancedColorEnabled) if (AdvancedColorInfo.advancedColorEnabled)
@ -554,7 +338,7 @@ namespace
} }
else if (::IsFileManagerWindow(hWnd)) else if (::IsFileManagerWindow(hWnd))
{ {
UINT DpiValue = ::GetDpiForWindowWrapper(hWnd);
UINT DpiValue = ::GetDpiForWindow(hWnd);
Margins.cyTopHeight = Margins.cyTopHeight =
::MulDiv(80, DpiValue, USER_DEFAULT_SCREEN_DPI); ::MulDiv(80, DpiValue, USER_DEFAULT_SCREEN_DPI);
Margins.cyBottomHeight = Margins.cyBottomHeight =
@ -606,7 +390,7 @@ namespace
} }
else if (::IsFileManagerWindow(hWnd)) else if (::IsFileManagerWindow(hWnd))
{ {
UINT DpiValue = ::GetDpiForWindowWrapper(hWnd);
UINT DpiValue = ::GetDpiForWindow(hWnd);
MARGINS Margins = { 0 }; MARGINS Margins = { 0 };
Margins.cyTopHeight = Margins.cyTopHeight =
@ -669,7 +453,7 @@ namespace
g_MicaBackdropAvailable); g_MicaBackdropAvailable);
if (!ShouldExtendFrame && ::IsFileManagerWindow(hWnd)) if (!ShouldExtendFrame && ::IsFileManagerWindow(hWnd))
{ {
UINT DpiValue = ::GetDpiForWindowWrapper(hWnd);
UINT DpiValue = ::GetDpiForWindow(hWnd);
MARGINS Margins = { 0 }; MARGINS Margins = { 0 };
Margins.cyTopHeight = Margins.cyTopHeight =

243
NanaZip.Frieren/NanaZip.Frieren.RuntimeObjectWrapper.cpp

@ -1,243 +0,0 @@
/*
* PROJECT: NanaZip
* FILE: NanaZip.Frieren.RuntimeObjectWrapper.cpp
* PURPOSE: Implementation for Windows Runtime C API Wrapper
*
* LICENSE: The MIT License
*
* MAINTAINER: MouriNaruto (Kenji.Mouri@outlook.com)
*/
#include <Windows.h>
#define _ROAPI_
#include <roapi.h>
#include <roerrorapi.h>
#include <hstring.h>
#include <winstring.h>
// WINDOWS_RUNTIME_HSTRING_FLAGS
#define WRHF_NONE 0x00000000
#define WRHF_STRING_REFERENCE 0x00000001
#define WRHF_VALID_UNICODE_FORMAT_INFO 0x00000002
#define WRHF_WELL_FORMED_UNICODE 0x00000004
#define WRHF_HAS_EMBEDDED_NULLS 0x00000008
#define WRHF_EMBEDDED_NULLS_COMPUTED 0x00000010
#define WRHF_RESERVED_FOR_PREALLOCATED_STRING_BUFFER 0x80000000
typedef struct _HSTRING_HEADER_INTERNAL
{
UINT32 Flags;
UINT32 Length;
UINT32 Padding1;
UINT32 Padding2;
PCWSTR StringRef;
} HSTRING_HEADER_INTERNAL;
#include <Mile.Helpers.CppBase.h>
namespace
{
static HMODULE GetComBaseModuleHandle()
{
static HMODULE CachedResult = ::LoadLibraryExW(
L"combase.dll",
nullptr,
LOAD_LIBRARY_SEARCH_SYSTEM32);
return CachedResult;
}
static FARPROC GetRoGetActivationFactoryProcAddress()
{
static FARPROC CachedResult = ([]() -> FARPROC
{
HMODULE ModuleHandle = ::GetComBaseModuleHandle();
if (ModuleHandle)
{
return ::GetProcAddress(
ModuleHandle,
"RoGetActivationFactory");
}
return nullptr;
}());
return CachedResult;
}
static FARPROC GetRoOriginateLanguageExceptionProcAddress()
{
static FARPROC CachedResult = ([]() -> FARPROC
{
HMODULE ModuleHandle = ::GetComBaseModuleHandle();
if (ModuleHandle)
{
return ::GetProcAddress(
ModuleHandle,
"RoOriginateLanguageException");
}
return nullptr;
}());
return CachedResult;
}
struct ErrorInfoFallback : public Mile::ComObject<
ErrorInfoFallback,
IErrorInfo,
IRestrictedErrorInfo>
{
private:
HRESULT m_Code;
BSTR m_Message;
public:
ErrorInfoFallback(
_In_ HRESULT Code,
_In_opt_ HSTRING Message) :
m_Code(Code),
m_Message(::SysAllocString(Message
? reinterpret_cast<HSTRING_HEADER_INTERNAL*>(
this->m_Message)->StringRef
: nullptr))
{
}
~ErrorInfoFallback()
{
::SysFreeString(this->m_Message);
}
HRESULT STDMETHODCALLTYPE GetGUID(
_Out_ GUID* pGUID)
{
std::memset(pGUID, 0, sizeof(GUID));
return S_OK;
}
HRESULT STDMETHODCALLTYPE GetSource(
_Out_ BSTR* pBstrSource)
{
*pBstrSource = nullptr;
return S_OK;
}
HRESULT STDMETHODCALLTYPE GetDescription(
_Out_ BSTR* pBstrDescription)
{
*pBstrDescription = ::SysAllocString(this->m_Message);
return *pBstrDescription ? S_OK : E_OUTOFMEMORY;
}
HRESULT STDMETHODCALLTYPE GetHelpFile(
_Out_ BSTR* pBstrHelpFile)
{
*pBstrHelpFile = nullptr;
return S_OK;
}
HRESULT STDMETHODCALLTYPE GetHelpContext(
_Out_ DWORD* pdwHelpContext)
{
*pdwHelpContext = 0;
return S_OK;
}
HRESULT STDMETHODCALLTYPE GetErrorDetails(
_Out_ BSTR* description,
_Out_ HRESULT* error,
_Out_ BSTR* restrictedDescription,
_Out_ BSTR* capabilitySid)
{
*description = nullptr;
*error = this->m_Code;
*capabilitySid = nullptr;
*restrictedDescription = ::SysAllocString(this->m_Message);
return *restrictedDescription ? S_OK : E_OUTOFMEMORY;
}
virtual HRESULT STDMETHODCALLTYPE GetReference(
_Out_ BSTR* reference)
{
*reference = nullptr;
return S_OK;
}
};
static FARPROC GetRoFailFastWithErrorContextProcAddress()
{
static FARPROC CachedResult = ([]() -> FARPROC
{
HMODULE ModuleHandle = ::GetComBaseModuleHandle();
if (ModuleHandle)
{
return ::GetProcAddress(
ModuleHandle,
"RoFailFastWithErrorContext");
}
return nullptr;
}());
return CachedResult;
}
}
EXTERN_C HRESULT WINAPI RoGetActivationFactory(
_In_ HSTRING activatableClassId,
_In_ REFIID iid,
_Out_ LPVOID* factory)
{
using ProcType = decltype(::RoGetActivationFactory)*;
ProcType ProcAddress = reinterpret_cast<ProcType>(
::GetRoGetActivationFactoryProcAddress());
if (ProcAddress)
{
return ProcAddress(activatableClassId, iid, factory);
}
*factory = nullptr;
return CLASS_E_CLASSNOTAVAILABLE;
}
EXTERN_C BOOL WINAPI RoOriginateLanguageException(
_In_ HRESULT error,
_In_opt_ HSTRING message,
_In_opt_ IUnknown* languageException)
{
using ProcType = decltype(::RoOriginateLanguageException)*;
ProcType ProcAddress = reinterpret_cast<ProcType>(
::GetRoOriginateLanguageExceptionProcAddress());
if (ProcAddress)
{
return ProcAddress(error, message, languageException);
}
IErrorInfo* ErrorInfo = new ErrorInfoFallback(error, message);
::SetErrorInfo(0, ErrorInfo);
return TRUE;
}
EXTERN_C VOID WINAPI RoFailFastWithErrorContext(
_In_ HRESULT hrError)
{
using ProcType = decltype(::RoFailFastWithErrorContext)*;
ProcType ProcAddress = reinterpret_cast<ProcType>(
::GetRoFailFastWithErrorContextProcAddress());
if (ProcAddress)
{
ProcAddress(hrError);
}
std::abort();
}

8
NanaZip.Frieren/NanaZip.Frieren.cpp

@ -1,9 +1,9 @@
/* /*
* PROJECT: NanaZip
* FILE: NanaZip.Frieren.cpp
* PURPOSE: Implementation for NanaZip.Frieren
* PROJECT: NanaZip
* FILE: NanaZip.Frieren.cpp
* PURPOSE: Implementation for NanaZip.Frieren
* *
* LICENSE: The MIT License
* LICENSE: The MIT License
* *
* MAINTAINER: MouriNaruto (Kenji.Mouri@outlook.com) * MAINTAINER: MouriNaruto (Kenji.Mouri@outlook.com)
*/ */

8
NanaZip.Frieren/NanaZip.Frieren.h

@ -1,9 +1,9 @@
/* /*
* PROJECT: NanaZip
* FILE: NanaZip.Frieren.h
* PURPOSE: Definition for NanaZip.Frieren
* PROJECT: NanaZip
* FILE: NanaZip.Frieren.h
* PURPOSE: Definition for NanaZip.Frieren
* *
* LICENSE: The MIT License
* LICENSE: The MIT License
* *
* MAINTAINER: MouriNaruto (Kenji.Mouri@outlook.com) * MAINTAINER: MouriNaruto (Kenji.Mouri@outlook.com)
*/ */

2
NanaZip.Frieren/NanaZip.Frieren.props

@ -14,7 +14,7 @@
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup> <ItemDefinitionGroup>
<Link> <Link>
<AdditionalDependencies>$(OutDir)NanaZip.Frieren.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>$(OutDir)NanaZip.Frieren.lib;runtimeobject.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>

1
NanaZip.Frieren/NanaZip.Frieren.vcxproj

@ -26,7 +26,6 @@
<ItemGroup> <ItemGroup>
<ClCompile Include="NanaZip.Frieren.cpp" /> <ClCompile Include="NanaZip.Frieren.cpp" />
<ClCompile Include="NanaZip.Frieren.DarkMode.cpp" /> <ClCompile Include="NanaZip.Frieren.DarkMode.cpp" />
<ClCompile Include="NanaZip.Frieren.RuntimeObjectWrapper.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Mile.Windows.Helpers"> <PackageReference Include="Mile.Windows.Helpers">

Loading…
Cancel
Save