Skip to content

Commit

Permalink
Merge branch 'valinet:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
deep-soft authored Nov 22, 2023
2 parents 9b8f80d + a7a3d27 commit 344af96
Show file tree
Hide file tree
Showing 16 changed files with 578 additions and 255 deletions.
2 changes: 1 addition & 1 deletion ExplorerPatcher-L10N
17 changes: 3 additions & 14 deletions ExplorerPatcher/ArchiveMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,8 @@ LRESULT CALLBACK ArchiveMenuWndProc(
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam,
INT64(*ImmersiveContextMenuHelper_ApplyOwnerDrawToMenuFunc)(
HMENU h1,
HMENU h2,
HWND a3,
unsigned int a4,
void* data
),
void(*ImmersiveContextMenuHelper_RemoveOwnerDrawFromMenuFunc)(
HMENU _this,
HMENU hWnd,
HWND a3
)
HRESULT(*ImmersiveContextMenuHelper_ApplyOwnerDrawToMenuFunc)(HMENU hMenu, HWND hWnd, POINT* pPt, unsigned int options, void* data),
void(*ImmersiveContextMenuHelper_RemoveOwnerDrawFromMenuFunc)(HMENU hMenu, HWND hWnd)
)
{
LRESULT result;
Expand Down Expand Up @@ -145,8 +135,7 @@ LRESULT CALLBACK ArchiveMenuWndProc(

ImmersiveContextMenuHelper_RemoveOwnerDrawFromMenuFunc(
hMenu,
hWnd,
&(pt)
hWnd
);
free(unknown_array);
SetForegroundWindow(prevhWnd);
Expand Down
14 changes: 2 additions & 12 deletions ExplorerPatcher/ArchiveMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,8 @@ LRESULT CALLBACK ArchiveMenuWndProc(
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam,
INT64(*ImmersiveContextMenuHelper_ApplyOwnerDrawToMenuFunc)(
HMENU h1,
HMENU h2,
HWND a3,
unsigned int a4,
void* data
),
void(*ImmersiveContextMenuHelper_RemoveOwnerDrawFromMenuFunc)(
HMENU _this,
HMENU hWnd,
HWND a3
)
HRESULT(*ImmersiveContextMenuHelper_ApplyOwnerDrawToMenuFunc)(HMENU hMenu, HWND hWnd, POINT* pPt, unsigned int options, void* data),
void(*ImmersiveContextMenuHelper_RemoveOwnerDrawFromMenuFunc)(HMENU hMenu, HWND hWnd)
);

#endif
2 changes: 2 additions & 0 deletions ExplorerPatcher/ExplorerPatcher.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="Localization.cpp" />
<ClCompile Include="lvt.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -322,6 +323,7 @@
<ClInclude Include="hooking.h" />
<ClInclude Include="ep_private.h" />
<ClInclude Include="ImmersiveFlyouts.h" />
<ClInclude Include="Localization.h" />
<ClInclude Include="lvt.h" />
<ClInclude Include="osutility.h" />
<ClInclude Include="queryversion.h" />
Expand Down
146 changes: 146 additions & 0 deletions ExplorerPatcher/Localization.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#include "Localization.h"

#include <algorithm>
#include <vector>

#include "def.h"

extern "C"
{

EP_L10N_Language LangIDToEPLanguage(LANGID wLanguage)
{
EP_L10N_Language language = {};
language.id = wLanguage;
GetLocaleInfoW(wLanguage, LOCALE_SNAME, language.wszId, ARRAYSIZE(language.wszId));
GetLocaleInfoW(wLanguage, LOCALE_SLOCALIZEDLANGUAGENAME, language.wszDisplayName, ARRAYSIZE(language.wszDisplayName));
return language;
}

BOOL EP_L10N_ApplyPreferredLanguageForCurrentThread()
{
BOOL rv = FALSE;
HKEY hKey = nullptr;
RegCreateKeyExW(
HKEY_CURRENT_USER,
TEXT(REGPATH),
0,
nullptr,
REG_OPTION_NON_VOLATILE,
KEY_READ | KEY_WOW64_64KEY,
nullptr,
&hKey,
nullptr
);
if (hKey == nullptr || hKey == INVALID_HANDLE_VALUE)
{
hKey = nullptr;
}
if (hKey)
{
DWORD dwPreferredLanguage = 0;
DWORD dwSize = sizeof(dwPreferredLanguage);
LSTATUS lres = RegQueryValueExW(
hKey,
TEXT("Language"),
nullptr,
nullptr,
(LPBYTE)&dwPreferredLanguage,
&dwSize
);
if (lres == ERROR_SUCCESS && dwPreferredLanguage != 0)
{
EP_L10N_Language language = LangIDToEPLanguage((LANGID)dwPreferredLanguage);
rv = SetThreadPreferredUILanguages(MUI_LANGUAGE_NAME, language.wszId, nullptr);
}
else
{
rv = SetThreadPreferredUILanguages(MUI_LANGUAGE_NAME, nullptr, nullptr);
}
RegCloseKey(hKey);
}
return rv;
}

BOOL EP_L10N_GetCurrentUserLanguage(wchar_t* wszLanguage, int cch)
{
BOOL bOk = FALSE;
ULONG ulNumLanguages = 0;
ULONG cchLanguagesBuffer = 0;
if (GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &ulNumLanguages, nullptr, &cchLanguagesBuffer))
{
wchar_t* wszLanguagesBuffer = (wchar_t*)malloc(cchLanguagesBuffer * sizeof(wchar_t));
if (wszLanguagesBuffer)
{
if (GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &ulNumLanguages, wszLanguagesBuffer, &cchLanguagesBuffer))
{
wcscpy_s(wszLanguage, cch, wszLanguagesBuffer);
bOk = TRUE;
}
free(wszLanguagesBuffer);
}
}
if (!bOk)
{
wcscpy_s(wszLanguage, cch, L"en-US");
}
return TRUE;
}

BOOL EP_L10N_GetCurrentThreadLanguage(wchar_t* wszLanguage, int cch)
{
BOOL bOk = FALSE;
ULONG ulNumLanguages = 0;
ULONG cchLanguagesBuffer = 0;
if (GetThreadPreferredUILanguages(MUI_LANGUAGE_NAME, &ulNumLanguages, nullptr, &cchLanguagesBuffer))
{
wchar_t* wszLanguagesBuffer = (wchar_t*)malloc(cchLanguagesBuffer * sizeof(wchar_t));
if (wszLanguagesBuffer)
{
if (GetThreadPreferredUILanguages(MUI_LANGUAGE_NAME, &ulNumLanguages, wszLanguagesBuffer, &cchLanguagesBuffer))
{
wcscpy_s(wszLanguage, cch, wszLanguagesBuffer);
bOk = TRUE;
}
free(wszLanguagesBuffer);
}
}
if (!bOk)
{
wcscpy_s(wszLanguage, cch, L"en-US");
}
return TRUE;
}

void EP_L10N_EnumerateLanguages(HMODULE hModule, LPCWSTR lpType, LPCWSTR lpName, EP_L10N_EnumerateLanguagesProc_t pfnProc, void* data)
{
std::vector<EP_L10N_Language> languages;

// English (US) is our primary language
languages.push_back(LangIDToEPLanguage(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)));

// Add the rest below it
EnumResourceLanguagesW(hModule, lpType, lpName, [](HMODULE, LPCWSTR, LPCWSTR, WORD wLanguage, LONG_PTR lParam) -> BOOL
{
if (wLanguage != MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US))
{
EP_L10N_Language language = LangIDToEPLanguage(wLanguage);
((std::vector<EP_L10N_Language>*)lParam)->push_back(language);
}
return TRUE;
}, (LONG_PTR)&languages);

// Sort the non-primary languages by localized display name
std::sort(languages.begin() + 1, languages.end(), [](const EP_L10N_Language& a, const EP_L10N_Language& b) -> bool
{
return wcscmp(a.wszDisplayName, b.wszDisplayName) < 0;
});

// Call the callback for each language
for (const EP_L10N_Language& language : languages)
{
pfnProc(&language, data);
}
}

}
26 changes: 26 additions & 0 deletions ExplorerPatcher/Localization.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <Windows.h>

#ifdef __cplusplus
extern "C"
{
#endif

typedef struct EP_L10N_Language
{
LANGID id;
wchar_t wszId[LOCALE_NAME_MAX_LENGTH];
wchar_t wszDisplayName[LOCALE_NAME_MAX_LENGTH];
} EP_L10N_Language;

typedef void(*EP_L10N_EnumerateLanguagesProc_t)(const EP_L10N_Language* language, void* data);

BOOL EP_L10N_ApplyPreferredLanguageForCurrentThread();
BOOL EP_L10N_GetCurrentUserLanguage(wchar_t* wszLanguage, int cch);
BOOL EP_L10N_GetCurrentThreadLanguage(wchar_t* wszLanguage, int cch);
void EP_L10N_EnumerateLanguages(HMODULE hModule, LPCWSTR lpType, LPCWSTR lpName, EP_L10N_EnumerateLanguagesProc_t pfnProc, void* data);

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit 344af96

Please sign in to comment.