mirror of
https://github.com/modernw/App-Installer-For-Windows-8.x-Reset.git
synced 2026-04-11 17:57:19 +10:00
Merge branch 'master' of https://github.com/bingtangxh/App-Installer-For-Windows-8.x-Reset
This commit is contained in:
@@ -12,26 +12,57 @@ static std::wstring StringToWString (const std::string &str, UINT codePage = CP_
|
||||
}
|
||||
|
||||
#undef GetLocaleInfo
|
||||
/// <summary>
|
||||
/// 获取指定 LCID 的区域设置信息(ANSI 版本)。
|
||||
/// </summary>
|
||||
/// <param name="code">区域标识符(LCID)。</param>
|
||||
/// <param name="type">要获取的信息类型(LCTYPE)。</param>
|
||||
/// <returns>以 ANSI 字符串形式返回的区域设置信息。</returns>
|
||||
std::string GetLocaleInfoA (LCID code, LCTYPE type)
|
||||
{
|
||||
char buf [LOCALE_NAME_MAX_LENGTH] = {0};
|
||||
GetLocaleInfoA (code, type, buf, LOCALE_NAME_MAX_LENGTH);
|
||||
return buf;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取指定 LCID 的区域设置信息(Unicode 版本)。
|
||||
/// </summary>
|
||||
/// <param name="code">区域标识符(LCID)。</param>
|
||||
/// <param name="type">要获取的信息类型(LCTYPE)。</param>
|
||||
/// <returns>以宽字符串形式返回的区域设置信息。</returns>
|
||||
std::wstring GetLocaleInfoW (LCID code, LCTYPE type)
|
||||
{
|
||||
WCHAR buf [LOCALE_NAME_MAX_LENGTH] = {0};
|
||||
GetLocaleInfoW (code, type, buf, LOCALE_NAME_MAX_LENGTH);
|
||||
return buf;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取指定 LCID 的区域设置信息(宽字符串输出)。
|
||||
/// </summary>
|
||||
/// <param name="code">区域标识符(LCID)。</param>
|
||||
/// <param name="type">要获取的信息类型(LCTYPE)。</param>
|
||||
/// <param name="output">接收信息的宽字符串引用。</param>
|
||||
void GetLocaleInfo (LCID code, LCTYPE type, std::wstring &output)
|
||||
{
|
||||
output = GetLocaleInfoW (code, type);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取指定 LCID 的区域设置信息(ANSI 字符串输出)。
|
||||
/// </summary>
|
||||
/// <param name="code">区域标识符(LCID)。</param>
|
||||
/// <param name="type">要获取的信息类型(LCTYPE)。</param>
|
||||
/// <param name="output">接收信息的 ANSI 字符串引用。</param>
|
||||
void GetLocaleInfo (LCID code, LCTYPE type, std::string &output)
|
||||
{
|
||||
output = GetLocaleInfoA (code, type);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取指定区域名称的区域设置信息(扩展版本,支持 Windows Vista+)。
|
||||
/// </summary>
|
||||
/// <param name="lpLocaleName">区域名称(如 "en-US")。</param>
|
||||
/// <param name="type">要获取的信息类型(LCTYPE)。</param>
|
||||
/// <param name="output">接收信息的宽字符串引用。</param>
|
||||
/// <returns>成功返回非零值,失败返回 0;如果 lpLocaleName 无效,则函数会返回 0。</returns>
|
||||
int GetLocaleInfoEx (std::wstring lpLocaleName, LCTYPE type, std::wstring &output)
|
||||
{
|
||||
WCHAR buf [LOCALE_NAME_MAX_LENGTH] = {0};
|
||||
@@ -41,57 +72,130 @@ int GetLocaleInfoEx (std::wstring lpLocaleName, LCTYPE type, std::wstring &outpu
|
||||
}
|
||||
|
||||
#undef SetLocaleInfo
|
||||
/// <summary>
|
||||
/// 设置指定 LCID 的区域设置信息(ANSI 版本)。
|
||||
/// </summary>
|
||||
/// <param name="code">区域标识符(LCID)。</param>
|
||||
/// <param name="type">要设置的信息类型(LCTYPE)。</param>
|
||||
/// <param name="lcData">要设置的数据(ANSI 字符串)。</param>
|
||||
/// <returns>成功返回非零值,失败返回 0。</returns>
|
||||
BOOL SetLocaleInfoA (LCID code, LCTYPE type, const std::string &lcData)
|
||||
{
|
||||
return SetLocaleInfoA (code, type, lcData.c_str ());
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置指定 LCID 的区域设置信息(Unicode 版本)。
|
||||
/// </summary>
|
||||
/// <param name="code">区域标识符(LCID)。</param>
|
||||
/// <param name="type">要设置的信息类型(LCTYPE)。</param>
|
||||
/// <param name="lcData">要设置的数据(宽字符串)。</param>
|
||||
/// <returns>成功返回非零值,失败返回 0。</returns>
|
||||
BOOL SetLocaleInfoW (LCID code, LCTYPE type, const std::wstring &lcData)
|
||||
{
|
||||
return SetLocaleInfoW (code, type, lcData.c_str ());
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置指定 LCID 的区域设置信息(宽字符串重载)。
|
||||
/// </summary>
|
||||
/// <param name="code">区域标识符(LCID)。</param>
|
||||
/// <param name="type">要设置的信息类型(LCTYPE)。</param>
|
||||
/// <param name="lcData">要设置的数据(宽字符串)。</param>
|
||||
/// <returns>成功返回非零值,失败返回 0。</returns>
|
||||
BOOL SetLocaleInfo (LCID code, LCTYPE type, const std::wstring &lcData)
|
||||
{
|
||||
return SetLocaleInfoW (code, type, lcData);
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置指定 LCID 的区域设置信息(ANSI 字符串重载)。
|
||||
/// </summary>
|
||||
/// <param name="code">区域标识符(LCID)。</param>
|
||||
/// <param name="type">要设置的信息类型(LCTYPE)。</param>
|
||||
/// <param name="lcData">要设置的数据(ANSI 字符串)。</param>
|
||||
/// <returns>成功返回非零值,失败返回 0。</returns>
|
||||
BOOL SetLocaleInfo (LCID code, LCTYPE type, const std::string &lcData)
|
||||
{
|
||||
return SetLocaleInfoA (code, type, lcData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从 LCID 获取受限区域代码(如 "en"),ANSI 版本。
|
||||
/// </summary>
|
||||
/// <param name="lcid">区域标识符。</param>
|
||||
/// <returns>受限区域代码的 ANSI 字符串。</returns>
|
||||
std::string GetLocaleRestrictedCodeFromLcidA (LCID lcid)
|
||||
{
|
||||
return GetLocaleInfoA (lcid, 89);
|
||||
}
|
||||
/// <summary>
|
||||
/// 从 LCID 获取受限区域代码(如 "en"),Unicode 版本。
|
||||
/// </summary>
|
||||
/// <param name="lcid">区域标识符。</param>
|
||||
/// <returns>受限区域代码的宽字符串。</returns>
|
||||
std::wstring GetLocaleRestrictedCodeFromLcidW (LCID lcid)
|
||||
{
|
||||
return GetLocaleInfoW (lcid, 89);
|
||||
}
|
||||
/// <summary>
|
||||
/// 从 LCID 获取受限区域代码(ANSI 输出)。
|
||||
/// </summary>
|
||||
/// <param name="lcid">区域标识符。</param>
|
||||
/// <param name="ret">输出 ANSI 字符串。</param>
|
||||
void GetLocaleRestrictedCodeFromLcid (LCID lcid, std::string &ret)
|
||||
{
|
||||
ret = GetLocaleRestrictedCodeFromLcidA (lcid);
|
||||
}
|
||||
/// <summary>
|
||||
/// 从 LCID 获取受限区域代码(宽字符串输出)。
|
||||
/// </summary>
|
||||
/// <param name="lcid">区域标识符。</param>
|
||||
/// <param name="ret">输出宽字符串。</param>
|
||||
void GetLocaleRestrictedCodeFromLcid (LCID lcid, std::wstring &ret)
|
||||
{
|
||||
ret = GetLocaleRestrictedCodeFromLcidW (lcid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从 LCID 获取详细区域代码(如 "US"),ANSI 版本。
|
||||
/// </summary>
|
||||
/// <param name="lcid">区域标识符。</param>
|
||||
/// <returns>详细区域代码的 ANSI 字符串。</returns>
|
||||
std::string GetLocaleElaboratedCodeFromLcidA (LCID lcid)
|
||||
{
|
||||
return GetLocaleInfoA (lcid, 90);
|
||||
}
|
||||
/// <summary>
|
||||
/// 从 LCID 获取详细区域代码(如 "US"),Unicode 版本。
|
||||
/// </summary>
|
||||
/// <param name="lcid">区域标识符。</param>
|
||||
/// <returns>详细区域代码的宽字符串。</returns>
|
||||
std::wstring GetLocaleElaboratedCodeFromLcidW (LCID lcid)
|
||||
{
|
||||
return GetLocaleInfoW (lcid, 90);
|
||||
}
|
||||
/// <summary>
|
||||
/// 从 LCID 获取详细区域代码(宽字符串输出)。
|
||||
/// </summary>
|
||||
/// <param name="lcid">区域标识符。</param>
|
||||
/// <param name="ret">输出宽字符串。</param>
|
||||
void GetLocaleElaboratedCodeFromLcid (LCID lcid, std::wstring &ret)
|
||||
{
|
||||
ret = GetLocaleElaboratedCodeFromLcidW (lcid);
|
||||
}
|
||||
/// <summary>
|
||||
/// 从 LCID 获取详细区域代码(ANSI 输出)。
|
||||
/// </summary>
|
||||
/// <param name="lcid">区域标识符。</param>
|
||||
/// <param name="ret">输出 ANSI 字符串。</param>
|
||||
void GetLocaleElaboratedCodeFromLcid (LCID lcid, std::string &ret)
|
||||
{
|
||||
ret = GetLocaleElaboratedCodeFromLcidA (lcid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将宽字符串形式的区域名称转换为 LCID。
|
||||
/// </summary>
|
||||
/// <param name="localeCode">区域名称(如 L"en-US")。</param>
|
||||
/// <returns>对应的 LCID;若失败返回 0。</returns>
|
||||
LCID LocaleCodeToLcidW (const std::wstring &localeCode)
|
||||
{
|
||||
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
|
||||
@@ -108,62 +212,149 @@ LCID LocaleCodeToLcidW (const std::wstring &localeCode)
|
||||
return LocaleNameToLCID (localeCode.c_str (), 0);
|
||||
#endif
|
||||
}
|
||||
/// <summary>
|
||||
/// 将 ANSI 字符串形式的区域名称转换为 LCID。
|
||||
/// </summary>
|
||||
/// <param name="localeCode">区域名称(如 "en-US")。</param>
|
||||
/// <returns>对应的 LCID;若失败返回 0。</returns>
|
||||
LCID LocaleCodeToLcidA (const std::string &localeCode)
|
||||
{
|
||||
std::wstring lcWide = StringToWString (std::string (localeCode));
|
||||
return LocaleCodeToLcidW (lcWide.c_str ());
|
||||
}
|
||||
/// <summary>
|
||||
/// 将宽字符串区域名称转换为 LCID(重载)。
|
||||
/// </summary>
|
||||
/// <param name="loccode">区域名称(宽字符串)。</param>
|
||||
/// <returns>对应的 LCID。</returns>
|
||||
LCID LocaleCodeToLcid (const std::wstring &loccode)
|
||||
{
|
||||
return LocaleCodeToLcidW (loccode.c_str ());
|
||||
}
|
||||
/// <summary>
|
||||
/// 将 ANSI 字符串区域名称转换为 LCID(重载)。
|
||||
/// </summary>
|
||||
/// <param name="loccode">区域名称(ANSI 字符串)。</param>
|
||||
/// <returns>对应的 LCID。</returns>
|
||||
LCID LocaleCodeToLcid (const std::string &loccode)
|
||||
{
|
||||
return LocaleCodeToLcidA (loccode.c_str ());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据区域名称获取受限区域代码(ANSI 版本,接受 C 字符串)。
|
||||
/// </summary>
|
||||
/// <param name="lc">区域名称(如 "en-US")。</param>
|
||||
/// <returns>受限区域代码的 ANSI 字符串。</returns>
|
||||
std::string GetLocaleRestrictedCodeA (LPCSTR lc)
|
||||
{
|
||||
return GetLocaleInfoA (LocaleCodeToLcidA (lc), 89);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据区域名称获取受限区域代码(ANSI 版本,接受 std::string)。
|
||||
/// </summary>
|
||||
/// <param name="lc">区域名称(std::string)。</param>
|
||||
/// <returns>受限区域代码的 ANSI 字符串。</returns>
|
||||
std::string GetLocaleRestrictedCodeA (const std::string &lc)
|
||||
{
|
||||
return GetLocaleInfoA (LocaleCodeToLcidA (lc.c_str ()), 89);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据区域名称获取受限区域代码(Unicode 版本,接受 C 宽字符串)。
|
||||
/// </summary>
|
||||
/// <param name="lc">区域名称(如 L"en-US")。</param>
|
||||
/// <returns>受限区域代码的宽字符串。</returns>
|
||||
std::wstring GetLocaleRestrictedCodeW (LPCWSTR lc)
|
||||
{
|
||||
return GetLocaleInfoW (LocaleCodeToLcidW (lc), 89);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据区域名称获取受限区域代码(Unicode 版本,接受 std::wstring)。
|
||||
/// </summary>
|
||||
/// <param name="lc">区域名称(std::wstring)。</param>
|
||||
/// <returns>受限区域代码的宽字符串。</returns>
|
||||
std::wstring GetLocaleRestrictedCodeW (const std::wstring &lc)
|
||||
{
|
||||
return GetLocaleInfoW (LocaleCodeToLcidW (lc.c_str ()), 89);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据区域名称获取受限区域代码(宽字符串重载)。
|
||||
/// </summary>
|
||||
/// <param name="lc">区域名称(std::wstring)。</param>
|
||||
/// <returns>受限区域代码的宽字符串。</returns>
|
||||
std::wstring GetLocaleRestrictedCode (const std::wstring &lc) { return GetLocaleRestrictedCodeW (lc); }
|
||||
/// <summary>
|
||||
/// 根据区域名称获取受限区域代码(ANSI 字符串重载)。
|
||||
/// </summary>
|
||||
/// <param name="lc">区域名称(std::string)。</param>
|
||||
/// <returns>受限区域代码的 ANSI 字符串。</returns>
|
||||
std::string GetLocaleRestrictedCode (const std::string &lc) { return GetLocaleRestrictedCodeA (lc); }
|
||||
|
||||
/// <summary>
|
||||
/// 根据区域名称获取详细区域代码(ANSI 版本,接受 C 字符串)。
|
||||
/// </summary>
|
||||
/// <param name="lc">区域名称(如 "en-US")。</param>
|
||||
/// <returns>详细区域代码的 ANSI 字符串。</returns>
|
||||
std::string GetLocaleElaboratedCodeA (LPCSTR lc)
|
||||
{
|
||||
return GetLocaleInfoA (LocaleCodeToLcidA (lc), 90);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据区域名称获取详细区域代码(ANSI 版本,接受 std::string)。
|
||||
/// </summary>
|
||||
/// <param name="lc">区域名称(std::string)。</param>
|
||||
/// <returns>详细区域代码的 ANSI 字符串。</returns>
|
||||
std::string GetLocaleElaboratedCodeA (const std::string &lc)
|
||||
{
|
||||
return GetLocaleInfoA (LocaleCodeToLcidA (lc.c_str ()), 90);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据区域名称获取详细区域代码(Unicode 版本,接受 C 宽字符串)。
|
||||
/// </summary>
|
||||
/// <param name="lc">区域名称(如 L"en-US")。</param>
|
||||
/// <returns>详细区域代码的宽字符串。</returns>
|
||||
std::wstring GetLocaleElaboratedCodeW (LPCWSTR lc)
|
||||
{
|
||||
return GetLocaleInfoW (LocaleCodeToLcidW (lc), 90);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据区域名称获取详细区域代码(Unicode 版本,接受 std::wstring)。
|
||||
/// </summary>
|
||||
/// <param name="lc">区域名称(std::wstring)。</param>
|
||||
/// <returns>详细区域代码的宽字符串。</returns>
|
||||
std::wstring GetLocaleElaboratedCodeW (const std::wstring &lc)
|
||||
{
|
||||
return GetLocaleInfoW (LocaleCodeToLcidW (lc.c_str ()), 90);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据区域名称获取详细区域代码(宽字符串重载)。
|
||||
/// </summary>
|
||||
/// <param name="lc">区域名称(std::wstring)。</param>
|
||||
/// <returns>详细区域代码的宽字符串。</returns>
|
||||
std::wstring GetLocaleElaboratedCode (const std::wstring &lc) { return GetLocaleElaboratedCodeW (lc); }
|
||||
/// <summary>
|
||||
/// 根据区域名称获取详细区域代码(ANSI 字符串重载)。
|
||||
/// </summary>
|
||||
/// <param name="lc">区域名称(std::string)。</param>
|
||||
/// <returns>详细区域代码的 ANSI 字符串。</returns>
|
||||
std::string GetLocaleElaboratedCode (const std::string &lc) { return GetLocaleElaboratedCodeA (lc); }
|
||||
|
||||
/// <summary>
|
||||
/// 将 LCID 转换为区域名称(ANSI 格式,如 "en-US")。
|
||||
/// </summary>
|
||||
/// <param name="lcid">区域标识符。</param>
|
||||
/// <param name="divide">分隔符,默认为 '-'。</param>
|
||||
/// <returns>区域名称的 ANSI 字符串。</returns>
|
||||
std::string LcidToLocaleCodeA (LCID lcid, char divide = '-')
|
||||
{
|
||||
return GetLocaleRestrictedCodeFromLcidA (lcid) + divide + GetLocaleElaboratedCodeFromLcidA (lcid);
|
||||
}
|
||||
/// <summary>
|
||||
/// 将 LCID 转换为区域名称(Unicode 格式,如 L"en-US")。
|
||||
/// </summary>
|
||||
/// <param name="lcid">区域标识符。</param>
|
||||
/// <param name="divide">分隔符,默认为 L'-'。</param>
|
||||
/// <returns>区域名称的宽字符串。</returns>
|
||||
std::wstring LcidToLocaleCodeW (LCID lcid, WCHAR divide = L'-')
|
||||
{
|
||||
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
|
||||
@@ -179,9 +370,25 @@ std::wstring LcidToLocaleCodeW (LCID lcid, WCHAR divide = L'-')
|
||||
return GetLocaleRestrictedCodeFromLcidW (lcid) + divide + GetLocaleElaboratedCodeFromLcidW (lcid);
|
||||
#endif
|
||||
}
|
||||
/// <summary>
|
||||
/// 将 LCID 转换为区域名称(宽字符串重载)。
|
||||
/// </summary>
|
||||
/// <param name="lcid">区域标识符。</param>
|
||||
/// <param name="divide">分隔符,默认为 L'-'。</param>
|
||||
/// <returns>区域名称的宽字符串。</returns>
|
||||
std::wstring LcidToLocaleCode (LCID lcid, WCHAR divide = L'-') { return LcidToLocaleCodeW (lcid, divide); }
|
||||
/// <summary>
|
||||
/// 将 LCID 转换为区域名称(ANSI 字符串重载)。
|
||||
/// </summary>
|
||||
/// <param name="lcid">区域标识符。</param>
|
||||
/// <param name="divide">分隔符,默认为 '-'。</param>
|
||||
/// <returns>区域名称的 ANSI 字符串。</returns>
|
||||
std::string LcidToLocaleCode (LCID lcid, char divide = '-') { return LcidToLocaleCodeA (lcid, divide); }
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户的默认区域名称(Unicode)。
|
||||
/// </summary>
|
||||
/// <returns>用户默认区域名称的宽字符串。</returns>
|
||||
std::wstring GetUserDefaultLocaleName ()
|
||||
{
|
||||
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
|
||||
@@ -197,6 +404,10 @@ std::wstring GetUserDefaultLocaleName ()
|
||||
return LcidToLocaleCodeW (GetUserDefaultLCID ());
|
||||
#endif
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取系统默认的区域名称(Unicode)。
|
||||
/// </summary>
|
||||
/// <returns>系统默认区域名称的宽字符串。</returns>
|
||||
std::wstring GetSystemDefaultLocaleName ()
|
||||
{
|
||||
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
|
||||
@@ -213,6 +424,10 @@ std::wstring GetSystemDefaultLocaleName ()
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前计算机的区域设置名称(优先使用线程区域,然后用户默认,最后系统默认)。
|
||||
/// </summary>
|
||||
/// <returns>计算机区域名称的宽字符串。</returns>
|
||||
std::wstring GetComputerLocaleCodeW ()
|
||||
{
|
||||
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
|
||||
@@ -250,6 +465,13 @@ std::wstring GetComputerLocaleCodeW ()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/// <summary>
|
||||
/// 比较两个区域名称是否相等(支持字符串直接比较或通过 LCID 比较)。
|
||||
/// </summary>
|
||||
/// <param name="left">左区域名称。</param>
|
||||
/// <param name="right">右区域名称。</param>
|
||||
/// <returns>如果区域名称相同(字符串相等或 LCID 相等)则返回 true,否则 false。</returns>
|
||||
/// <remarks>注意:此处使用的 std::wnstring::equals 非标准,可能为自定义函数,实际应替换为 wstring 比较。</remarks>
|
||||
bool LocaleNameCompare (const std::wstring &left, const std::wstring &right)
|
||||
{
|
||||
return std::wnstring::equals (left, right) || LocaleCodeToLcidW (left) == LocaleCodeToLcidW (right);
|
||||
|
||||
@@ -563,6 +563,7 @@ void PriFileIterateTask (PCSPRIFILE pFilePri)
|
||||
System::Runtime::InteropServices::GCHandle handle = System::Runtime::InteropServices::GCHandle::FromIntPtr (handlePtr);
|
||||
auto pri = safe_cast <PriFileInst ^> (handle.Target);
|
||||
auto &priFile = pri;
|
||||
if (!priFile) return;
|
||||
auto resmapsect = pri->inst->PriDescriptorSection->ResourceMapSections;
|
||||
bool isallsearched = true;
|
||||
size_t allitemslen = 0;
|
||||
@@ -788,12 +789,14 @@ void PriFileIterateTaskCli (Object^ pFilePriObj)
|
||||
// t->Start (IntPtr (pFilePri));
|
||||
// }
|
||||
//}
|
||||
#ifdef ELDER_FUNC
|
||||
void AddPriResourceName (PCSPRIFILE pFilePri, const std::vector <std::wnstring> &urilist)
|
||||
{
|
||||
if (!pFilePri) return;
|
||||
if (!urilist.size ()) return;
|
||||
{
|
||||
CreateScopedLock (g_threadlock);
|
||||
CreateScopedLock (g_iterlock);
|
||||
if (g_tasklist.find (pFilePri) == g_tasklist.end ())
|
||||
{
|
||||
g_tasklist [pFilePri] = TASKINFO_SEARCH ();
|
||||
@@ -802,11 +805,13 @@ void AddPriResourceName (PCSPRIFILE pFilePri, const std::vector <std::wnstring>
|
||||
TASKINFO_SEARCH *ptask = nullptr;
|
||||
{
|
||||
CreateScopedLock (g_threadlock);
|
||||
CreateScopedLock (g_iterlock);
|
||||
ptask = &g_tasklist.at (pFilePri);
|
||||
}
|
||||
auto &task = *ptask;
|
||||
bool isallfined = true;
|
||||
{
|
||||
CreateScopedLock (g_threadlock);
|
||||
CreateScopedLock (g_iterlock);
|
||||
for (auto &it : urilist)
|
||||
{
|
||||
@@ -832,6 +837,7 @@ void AddPriResourceName (PCSPRIFILE pFilePri, const std::vector <std::wnstring>
|
||||
if (isallfined) return;
|
||||
{
|
||||
CreateScopedLock (g_threadlock);
|
||||
CreateScopedLock (g_iterlock);
|
||||
if (!task.bIsRunning)
|
||||
{
|
||||
System::Threading::Thread ^t = gcnew System::Threading::Thread (gcnew System::Threading::ParameterizedThreadStart (PriFileIterateTaskCli));
|
||||
@@ -873,7 +879,7 @@ LPWSTR GetPriResource (PCSPRIFILE pFilePri, LPCWSTR lpswResId)
|
||||
auto &result = task.mapTasks [TASKITEM_SEARCH (lpswResId)];
|
||||
if (result.has_search ()) return _wcsdup (result.swValue.c_str ());
|
||||
}
|
||||
BYTE buf [sizeof (LPCWSTRLIST) + sizeof (LPCWSTR)] = {0};
|
||||
BYTE buf [sizeof (LPCWSTRLIST) + sizeof (LPCWSTR)] = { 0 };
|
||||
HLPCWSTRLIST hStrList = (HLPCWSTRLIST)buf;
|
||||
hStrList->dwLength = 1;
|
||||
hStrList->aswArray [0] = lpswResId;
|
||||
@@ -893,6 +899,7 @@ LPWSTR GetPriResource (PCSPRIFILE pFilePri, LPCWSTR lpswResId)
|
||||
}
|
||||
LPWSTR GetPriStringResource (PCSPRIFILE pFilePri, LPCWSTR lpswUri) { return GetPriResource (pFilePri, lpswUri); }
|
||||
LPWSTR GetPriPathResource (PCSPRIFILE pFilePri, LPCWSTR lpswFilePath) { return GetPriResource (pFilePri, lpswFilePath); }
|
||||
#endif
|
||||
void ClearPriCacheData ()
|
||||
{
|
||||
g_tasklist.clear ();
|
||||
@@ -1209,3 +1216,252 @@ HWSDSPAIRLIST GetPriResourcesAllValuesList (PCSPRIFILE pPriFile, const LPCWSTR *
|
||||
if (rnout.empty ()) return nullptr;
|
||||
return CreateWSDSPAIRLISTFromMap (rnout);
|
||||
}
|
||||
|
||||
#ifndef ELDER_FUNC
|
||||
size_t GetPriLocaleStringResources (
|
||||
PCSPRIFILE pPriFile,
|
||||
const std::vector <std::wstring> &resnames,
|
||||
std::map <std::wnstring, std::map <std::wnstring, std::wstring>> &output
|
||||
)
|
||||
{
|
||||
output.clear ();
|
||||
if (!pPriFile) return 0;
|
||||
auto inst = GetPriFileInst (pPriFile);
|
||||
auto pri = inst->inst;
|
||||
auto priFile = inst;
|
||||
auto resmapsect = pri->PriDescriptorSection->ResourceMapSections;
|
||||
std::set <std::wnstring> rnlist;
|
||||
for (auto &it : resnames) rnlist.insert (std::wnstring (it));
|
||||
for (size_t i = 0; i < resmapsect->Count; i ++)
|
||||
{
|
||||
auto resourceMapSectionRef = resmapsect [i];
|
||||
auto resourceMapSection = pri->GetSectionByRef (resourceMapSectionRef);
|
||||
if (resourceMapSection->HierarchicalSchemaReference != nullptr) continue;
|
||||
auto decisionInfoSection = pri->GetSectionByRef (resourceMapSection->DecisionInfoSection);
|
||||
for each (auto candidateSet in resourceMapSection->CandidateSets->Values)
|
||||
{
|
||||
auto item = pri->GetResourceMapItemByRef (candidateSet->ResourceMapItem);
|
||||
std::wstring itemfullname = MPStringToStdW (item->FullName);
|
||||
std::vector <std::wnstring> itempath;
|
||||
{
|
||||
auto ips = split_wcstok (itemfullname, L"\\");
|
||||
for (auto &it : ips)
|
||||
{
|
||||
if (std::wnstring::empty (it)) continue;
|
||||
itempath.push_back (it);
|
||||
}
|
||||
}
|
||||
bool isfind = false;
|
||||
std::wnstring taskkey = L"";
|
||||
int tasktype = 1;
|
||||
for (auto &it : rnlist)
|
||||
{
|
||||
TASKITEM_SEARCH key (it);
|
||||
std::vector <std::wnstring> namepath;
|
||||
key.get_path (namepath);
|
||||
if (PathEquals (itempath, namepath))
|
||||
{
|
||||
taskkey = it;
|
||||
tasktype = key.iTaskType;
|
||||
isfind = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isfind) continue;
|
||||
std::map <std::wnstring, std::wstring> values;
|
||||
for each (auto candidate in candidateSet->Candidates)
|
||||
{
|
||||
std::wnstring resc = L"";
|
||||
System::String ^value = nullptr;
|
||||
if (candidate->SourceFile.HasValue)
|
||||
{
|
||||
// 内嵌资源,暂无法处理
|
||||
// value = System::String::Format ("<external in {0}>", pri->GetReferencedFileByRef (candidate->SourceFile.Value)->FullName);
|
||||
value = pri->GetReferencedFileByRef (candidate->SourceFile.Value)->FullName;
|
||||
}
|
||||
else
|
||||
{
|
||||
ByteSpan ^byteSpan = nullptr;
|
||||
if (candidate->DataItem.HasValue) byteSpan = priFile->inst->GetDataItemByRef (candidate->DataItem.Value);
|
||||
else byteSpan = candidate->Data.Value;
|
||||
priFile->Seek (byteSpan->Offset, System::IO::SeekOrigin::Begin);
|
||||
auto binaryReader = gcnew System::IO::BinaryReader (priFile, System::Text::Encoding::Default, true);
|
||||
auto data = binaryReader->ReadBytes ((int)byteSpan->Length);
|
||||
switch (candidate->Type)
|
||||
{
|
||||
case ResourceValueType::AsciiPath:
|
||||
case ResourceValueType::AsciiString:
|
||||
value = System::Text::Encoding::ASCII->GetString (data)->TrimEnd ('\0');
|
||||
break;
|
||||
case ResourceValueType::Utf8Path:
|
||||
case ResourceValueType::Utf8String:
|
||||
value = System::Text::Encoding::UTF8->GetString (data)->TrimEnd ('\0');
|
||||
break;
|
||||
case ResourceValueType::Path:
|
||||
case ResourceValueType::String:
|
||||
value = System::Text::Encoding::Unicode->GetString (data)->TrimEnd ('\0');
|
||||
break;
|
||||
case ResourceValueType::EmbeddedData:
|
||||
value = Convert::ToBase64String (data);
|
||||
break;
|
||||
}
|
||||
delete binaryReader;
|
||||
delete data;
|
||||
binaryReader = nullptr;
|
||||
data = nullptr;
|
||||
}
|
||||
auto qualifierSet = decisionInfoSection->QualifierSets [candidate->QualifierSet];
|
||||
auto qualis = gcnew System::Collections::Generic::Dictionary <QualifierType, Object ^> ();
|
||||
for each (auto quali in qualifierSet->Qualifiers)
|
||||
{
|
||||
auto type = quali->Type;
|
||||
auto value = quali->Value;
|
||||
qualis->Add (type, value);
|
||||
}
|
||||
if (qualis->ContainsKey (QualifierType::Language))
|
||||
{
|
||||
resc = MPStringToStdW (qualis [QualifierType::Language]->ToString ());
|
||||
values [resc] = MPStringToStdW (value ? value : System::String::Empty);
|
||||
}
|
||||
delete qualis;
|
||||
qualis = nullptr;
|
||||
}
|
||||
output [taskkey] = values;
|
||||
rnlist.erase (taskkey);
|
||||
}
|
||||
resourceMapSection = nullptr;
|
||||
}
|
||||
}
|
||||
std::wstring GetConfirmLocaleResources (const std::map <std::wnstring, std::wstring> &strvalue, const std::wnstring &lang)
|
||||
{
|
||||
for (auto &it : strvalue)
|
||||
{
|
||||
if (it.first.equals (lang)) return it.second;
|
||||
}
|
||||
for (auto &it : strvalue)
|
||||
{
|
||||
if (LocaleNameCompare (it.first, lang)) return it.second;
|
||||
}
|
||||
auto rest = GetLocaleRestrictedCode (lang);
|
||||
for (auto &it : strvalue)
|
||||
{
|
||||
if (LocaleNameCompare (GetLocaleRestrictedCode (it.first), rest)) return it.second;
|
||||
}
|
||||
return L"";
|
||||
}
|
||||
std::wstring GetSuitableLocaleResources (const std::map <std::wnstring, std::wstring> &strvalue)
|
||||
{
|
||||
auto ret = GetConfirmLocaleResources (strvalue, GetComputerLocaleCodeW ());
|
||||
if (ret.empty ()) ret = GetConfirmLocaleResources (strvalue, L"en-US");
|
||||
if (ret.empty ())
|
||||
{
|
||||
if (strvalue.size () > 0) ret = strvalue.begin ()->second;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
std::wstring GetConfirmFileResources (const std::map <DWORD, std::wnstring> &input, unsigned short dpi, unsigned short contrast)
|
||||
{
|
||||
auto &output = input;
|
||||
auto get_type = [] (DWORD key) -> DWORD {
|
||||
return (key & PRI_TYPE_MASK) >> PRI_TYPE_SHIFT;
|
||||
};
|
||||
auto get_contrast = [] (DWORD key) -> DWORD {
|
||||
return (key & PRI_CONTRAST_MASK) >> PRI_CONTRAST_SHIFT;
|
||||
};
|
||||
auto get_value = [] (DWORD key) -> DWORD {
|
||||
return key & PRI_VALUE_MASK;
|
||||
};
|
||||
struct Candidate
|
||||
{
|
||||
DWORD scale;
|
||||
std::wnstring value;
|
||||
};
|
||||
std::vector <Candidate> exact_contrast;
|
||||
std::vector <Candidate> none_contrast;
|
||||
for (const auto& kv : output) {
|
||||
DWORD key = kv.first;
|
||||
DWORD type = get_type (key);
|
||||
if (type != 0) continue;
|
||||
DWORD cont = get_contrast (key);
|
||||
DWORD scale = get_value (key);
|
||||
if (StrInclude (kv.second, L"layoutdir-RTL", true)) continue;
|
||||
if (cont == contrast) {
|
||||
exact_contrast.push_back ({ scale, kv.second });
|
||||
}
|
||||
else if (cont == 0) {
|
||||
none_contrast.push_back ({ scale, kv.second });
|
||||
}
|
||||
}
|
||||
auto select_best = [dpi] (std::vector<Candidate>& candidates) -> std::wstring {
|
||||
if (candidates.empty ()) return L"";
|
||||
std::sort (candidates.begin (), candidates.end (),
|
||||
[] (const Candidate& a, const Candidate& b) {
|
||||
return a.scale < b.scale;
|
||||
});
|
||||
for (const auto &cand : candidates) {
|
||||
if (cand.scale == dpi) {
|
||||
return cand.value.c_str ();
|
||||
}
|
||||
}
|
||||
for (const auto &cand : candidates) {
|
||||
if (cand.scale > dpi) {
|
||||
return cand.value.c_str ();
|
||||
}
|
||||
}
|
||||
return candidates.back ().value.c_str ();
|
||||
};
|
||||
std::wstring result = select_best (exact_contrast);
|
||||
if (!result.empty ()) return result;
|
||||
return L"";
|
||||
}
|
||||
std::wstring GetSuitableFileResources (const std::map <DWORD, std::wnstring> &input)
|
||||
{
|
||||
std::wstring ret = GetConfirmFileResources (input, GetDPI (), 0);
|
||||
if (ret.empty ()) ret = GetConfirmFileResources (input, GetDPI (), 2);
|
||||
if (ret.empty ()) ret = GetConfirmFileResources (input, GetDPI (), 1);
|
||||
if (ret.empty ())
|
||||
{
|
||||
if (input.size () > 0)
|
||||
{
|
||||
ret = input.begin ()->second;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
void AddPriResourceName (PCSPRIFILE pFilePri, const std::vector <std::wnstring> &urilist) {}
|
||||
void FindPriResource (PCSPRIFILE pFilePri, HLPCWSTRLIST hUriList) {}
|
||||
void FindPriStringResource (PCSPRIFILE pFilePri, HLPCWSTRLIST hUriList) {}
|
||||
void FindPriPathResource (PCSPRIFILE pFilePri, HLPCWSTRLIST hPathList) {}
|
||||
LPWSTR GetPriResource (PCSPRIFILE pFilePri, LPCWSTR lpswResId)
|
||||
{
|
||||
if (strnull (lpswResId)) return NULL;
|
||||
auto resid = lpswResId ? lpswResId : L"";
|
||||
std::vector <std::wstring> ress;
|
||||
ress.push_back (lpswResId ? lpswResId : L"");
|
||||
std::map <std::wnstring, std::map <std::wnstring, std::wstring>> strRes;
|
||||
if (IsMsResourcePrefix (lpswResId))
|
||||
{
|
||||
GetPriLocaleStringResources (pFilePri, ress, strRes);
|
||||
if (strRes.size () > 0)
|
||||
{
|
||||
auto &res = strRes [std::wnstring (resid)];
|
||||
return _wcsdup (GetSuitableLocaleResources (res).c_str ());
|
||||
}
|
||||
}
|
||||
std::map <std::wnstring, std::map <DWORD, std::wnstring>> fileRes;
|
||||
GetPriScaleAndTargetSizeFileList (pFilePri, ress, fileRes);
|
||||
if (fileRes.size () > 0)
|
||||
{
|
||||
auto &fres = fileRes [std::wnstring (resid)];
|
||||
return _wcsdup (GetSuitableFileResources (fres).c_str ());
|
||||
}
|
||||
GetPriLocaleStringResources (pFilePri, ress, strRes);
|
||||
if (strRes.size () > 0)
|
||||
{
|
||||
auto &res = strRes [std::wnstring (resid)];
|
||||
return _wcsdup (GetSuitableLocaleResources (res).c_str ());
|
||||
}
|
||||
}
|
||||
LPWSTR GetPriStringResource (PCSPRIFILE pFilePri, LPCWSTR lpswUri) { return GetPriResource (pFilePri, lpswUri); }
|
||||
LPWSTR GetPriPathResource (PCSPRIFILE pFilePri, LPCWSTR lpswFilePath) { return GetPriResource (pFilePri, lpswFilePath); }
|
||||
#endif
|
||||
Reference in New Issue
Block a user